Quellcode durchsuchen

feat(marketingEdit): 添加商品文字时同步更新模板数据

- 导入 updateTemplateColumn API 接口
- 将 confirmAddGoodsText 方法改为异步方法
- 添加模板ID获取逻辑
- 实现商品文字数据的接口更新
- 增加错误处理和异常捕获
- 完善用户操作反馈提示
panqiuyao vor 1 Tag
Ursprung
Commit
0c279b1158
2 geänderte Dateien mit 45 neuen und 9 gelöschten Zeilen
  1. 5 0
      frontend/src/apis/other.ts
  2. 40 9
      frontend/src/views/components/marketingEdit/index.vue

+ 5 - 0
frontend/src/apis/other.ts

@@ -54,3 +54,8 @@ export async function deleteCustomerTemplate(params: { id: number | string }) {
 export async function downlaodCustomerTemplate(params: { id: number , filename: string }){
     return DOWNLOAD('/api/ai_image/auto_photo/template_excel', params , { filename: params.filename })
 }
+
+// 更新模板列(商品文字字段)
+export async function updateTemplateColumn(params: { id: string | number; template_excel_headers: Array<{key: string; value: string}> }){
+    return POST('/api/ai_image/auto_photo/update_template_colum', params)
+}

+ 40 - 9
frontend/src/views/components/marketingEdit/index.vue

@@ -8,7 +8,7 @@ import actionsMixins from '@/views/components/PictureEditor/mixin/actions/index'
 import layerMixins from '@/views/components/PictureEditor/mixin/layer/index'
 import colorMixins from '@/views/components/PictureEditor/mixin/color/index'
 import editMixins from '@/views/components/PictureEditor/mixin/edit/index'
-import { uploadBaseImg } from '@/apis/other'
+import { uploadBaseImg, updateTemplateColumn } from '@/apis/other'
 import {markRaw} from "vue";
 import { ElMessage } from 'element-plus'
 import useClientStore from '@/stores/modules/client'
@@ -725,7 +725,7 @@ export default {
     },
 
     // 确认新增商品文字
-    confirmAddGoodsText() {
+    async confirmAddGoodsText() {
       if (!this.addGoodsTextForm.key.trim() || !this.addGoodsTextForm.value.trim()) {
         this.$message.warning('请填写完整的商品文字信息')
         return
@@ -738,14 +738,45 @@ export default {
         return
       }
 
-      // 添加到 goods_text 数组
-      this.goods_text.push({
-        key: this.addGoodsTextForm.key.trim(),
-        value: this.addGoodsTextForm.value.trim()
-      })
+      try {
+        // 获取模板ID(编辑模式下)
+        const templateId = this.$route?.params?.id
+        if (!templateId) {
+          this.$message.error('无法获取模板ID,请刷新页面后重试')
+          return
+        }
 
-      this.addGoodsTextForm.visible = false
-      this.$message.success('商品文字添加成功')
+        // 准备新的商品文字数组(包含新添加的)
+        const newGoodsText = [
+          ...this.goods_text,
+          {
+            key: this.addGoodsTextForm.key.trim(),
+            value: this.addGoodsTextForm.value.trim()
+          }
+        ]
+
+        // 调用接口更新商品文字字段
+        const response = await updateTemplateColumn({
+          id: templateId,
+          template_excel_headers: newGoodsText
+        })
+
+        if (response.data?.code === 0) {
+          // 接口调用成功,更新本地数据
+          this.goods_text.push({
+            key: this.addGoodsTextForm.key.trim(),
+            value: this.addGoodsTextForm.value.trim()
+          })
+
+          this.addGoodsTextForm.visible = false
+          this.$message.success('商品文字添加成功')
+        } else {
+          this.$message.error(response.data?.msg || '更新商品文字失败')
+        }
+      } catch (error) {
+        console.error('更新商品文字失败:', error)
+        this.$message.error('更新商品文字失败,请稍后重试')
+      }
     }
   }
 }