feat: 添加内容创建表单状态字段,优化内容保存和发布逻辑
This commit is contained in:
@@ -30,6 +30,7 @@ type ContentCreateForm struct {
|
||||
Genre string `json:"genre"`
|
||||
Key string `json:"key"`
|
||||
Price float64 `json:"price"`
|
||||
Status string `json:"status"`
|
||||
CoverIDs []string `json:"cover_ids"`
|
||||
MediaIDs []string `json:"media_ids"`
|
||||
}
|
||||
|
||||
@@ -201,6 +201,10 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
uid := userID
|
||||
|
||||
return models.Q.Transaction(func(tx *models.Query) error {
|
||||
status := consts.ContentStatusPublished
|
||||
if form.Status != "" {
|
||||
status = consts.ContentStatus(form.Status)
|
||||
}
|
||||
// 1. Create Content
|
||||
content := &models.Content{
|
||||
TenantID: tid,
|
||||
@@ -208,7 +212,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
Title: form.Title,
|
||||
Genre: form.Genre,
|
||||
Key: form.Key,
|
||||
Status: consts.ContentStatusPublished,
|
||||
Status: status,
|
||||
}
|
||||
if err := tx.Content.WithContext(ctx).Create(content); err != nil {
|
||||
return err
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
</div>
|
||||
|
||||
<div class="flex gap-3 w-1/3 justify-end">
|
||||
<button
|
||||
<button @click="saveContent('draft')"
|
||||
class="px-6 py-2 border border-slate-300 text-slate-700 rounded-lg hover:bg-slate-50 font-bold transition-colors cursor-pointer">存草稿</button>
|
||||
<button @click="submit"
|
||||
<button @click="saveContent('published')"
|
||||
class="px-8 py-2 bg-primary-600 text-white rounded-lg font-bold hover:bg-primary-700 shadow-lg shadow-primary-200 transition-all active:scale-95 cursor-pointer">发布</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -448,9 +448,13 @@ const removeMediaItem = async (type, index, item) => {
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
if (!form.title || !form.genre) {
|
||||
toast.add({ severity: 'warn', summary: '信息不完整', detail: '请填写标题和曲种', life: 3000 });
|
||||
const saveContent = async (targetStatus) => {
|
||||
if (!form.title) {
|
||||
toast.add({ severity: 'warn', summary: '提示', detail: '请至少填写标题', life: 3000 });
|
||||
return;
|
||||
}
|
||||
if (targetStatus === 'published' && !form.genre) {
|
||||
toast.add({ severity: 'warn', summary: '提示', detail: '发布需要填写曲种', life: 3000 });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -462,10 +466,10 @@ const submit = async () => {
|
||||
description: form.abstract,
|
||||
genre: form.genre,
|
||||
key: form.key,
|
||||
status: 'published', // Direct publish for demo
|
||||
status: targetStatus,
|
||||
visibility: 'public',
|
||||
preview_seconds: form.enableTrial ? form.trialTime : 0,
|
||||
price: form.priceType === 'paid' ? parseFloat(form.price) : 0, // API expects float price, service handles conversion
|
||||
price: form.priceType === 'paid' ? parseFloat(form.price) : 0,
|
||||
cover_ids: [],
|
||||
media_ids: []
|
||||
};
|
||||
@@ -475,15 +479,15 @@ const submit = async () => {
|
||||
|
||||
if (isEditMode.value) {
|
||||
await creatorApi.updateContent(contentId.value, payload);
|
||||
toast.add({ severity: 'success', summary: '更新成功', detail: '内容已更新', life: 3000 });
|
||||
toast.add({ severity: 'success', summary: '保存成功', detail: targetStatus === 'draft' ? '已保存为草稿' : '内容已更新', life: 3000 });
|
||||
} else {
|
||||
await creatorApi.createContent(payload);
|
||||
toast.add({ severity: 'success', summary: '发布成功', detail: '内容已提交审核', life: 3000 });
|
||||
toast.add({ severity: 'success', summary: targetStatus === 'draft' ? '保存成功' : '发布成功', detail: targetStatus === 'draft' ? '已保存为草稿' : '内容已提交审核', life: 3000 });
|
||||
}
|
||||
|
||||
setTimeout(() => router.push('/creator/contents'), 1500);
|
||||
} catch (e) {
|
||||
toast.add({ severity: 'error', summary: '提交失败', detail: e.message, life: 3000 });
|
||||
toast.add({ severity: 'error', summary: '操作失败', detail: e.message, life: 3000 });
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user