Просмотр исходного кода

图文编辑时,如果有删除图片,表单实现自动提交。-- 解决用户删除图片(此时图片资源已删除),但用户却没把表单提交导致获取那些删除的图片失败(报价)

shizhongqi 10 месяцев назад
Родитель
Сommit
3d69b1fc2e

+ 24 - 4
hdApp/src/admin/picText/picTextAdd.vue

@@ -13,6 +13,7 @@
             ref="richEditor"
             v-model="form.imageTextVos" 
             @change="onContentChange"
+            @auto-submit="onEditorAutoSubmit"
             :action="getLoginInfo.imgUploadApi"
           />
         </view>
@@ -44,7 +45,8 @@ export default {
         title: '',
         imageTextVos: [] // 新增图文内容数组
       },
-      isEdit: false
+      isEdit: false,
+      autoSubmitMode: false
     };
   },
   onLoad(option) {
@@ -181,18 +183,35 @@ export default {
         if(res.code == 1){
           uni.$emit('refreshListPage');
           that.$msg(this.isEdit ? '修改成功' : '添加成功');
-          uni.navigateBack({
-            delta: 1
-          });
+          if (!this.autoSubmitMode) {
+            uni.navigateBack({
+              delta: 1
+            });
+          }
+          that.autoSubmitMode = false;
         } else {
           that.$msg(res.message || '操作失败');
+          that.autoSubmitMode = false;
         }
       }).catch(err => {
         uni.hideLoading();
         console.error('提交失败:', err);
         that.$msg('提交失败,请稍后重试');
+        that.autoSubmitMode = false;
       });
     },
+    // 接收编辑器自动提交事件
+    onEditorAutoSubmit() {
+      this.autoSubmitMode = true;
+      const e = {
+        detail: {
+          value: {
+            title: this.form.title
+          }
+        }
+      };
+      this.formSubmit(e);
+    },
     formSubmit(e) {
       let rules = [
         { name: "title", rule: ["required", "notEmpty"], msg: ["请输入标题"] },
@@ -206,6 +225,7 @@ export default {
       // 检查图文内容
       if (this.form.imageTextVos.length === 0) {
         this.$msg("请添加至少一项图文内容");
+        this.autoSubmitMode = false;
         return;
       }
       

+ 7 - 0
hdApp/src/components/RichMediaEditor/index.vue

@@ -334,6 +334,11 @@ export default {
               // 大图
               delImage({ filePath: tempList.content }).then(() => {
                 console.log('大图删除成功');
+                this.$emit('auto-submit');
+              }).catch(err => {
+                console.error('大图删除失败:', err);
+                // 删除失败也尝试自动提交,以保证数据一致
+                this.$emit('auto-submit');
               });
             } else if (tempList.type === 2) {
               // 批量删除小图
@@ -442,10 +447,12 @@ export default {
             delImage({ filePath: imageUrl }).then(() => {
               // 从数组中移除图片
               this.contentList[itemIndex].content.splice(imgIndex, 1);
+              this.$emit('auto-submit');
             }).catch(err => {
               console.error('删除图片失败:', err);
               // 即使删除失败也从数组中移除
               this.contentList[itemIndex].content.splice(imgIndex, 1);
+              this.$emit('auto-submit');
             });
           }
         }