Ver código fonte

优化修复

jiapu 2 semanas atrás
pai
commit
8e555adbf5
1 arquivos alterados com 55 adições e 182 exclusões
  1. 55 182
      cfc-web/src/views/admin/ProductEdit.vue

+ 55 - 182
cfc-web/src/views/admin/ProductEdit.vue

@@ -423,134 +423,65 @@ export default {
           }
         }
       },
-    addBundleItem() {
-
-Let me re-read the structure more carefully.
-
-```javascript
-  data() {
-    return {
-      form: { ... },
-      ...
-      editorConfig: {
-        MENU_CONF: {
-          uploadImage: { ... }
-}   // closes MENU_CONF
-    },  // closes editorConfig
-    addBundleItem() {  // THIS IS STILL IN THE RETURN OBJECT OF data()
-      ...
-    },
-    ...
-    async loadBundleItems(productId) { ... },
       toolbarConfig: {},
       editorInstance: null
     }
   },
   computed: {
-```
-
-So addBundleItem through loadBundleItems are incorrectly placed inside data() as function properties. Then toolbarConfig and editorInstance are also in data(). Then computed starts.
-
-If I replace ending with `}, toolbarConfig, editorInstance, then close data, then computed` - I would DUPLICATE computed and lose addBundleItem.
-
-I need a more surgical replace: only add uploadVideo inside MENU_CONF, don't close data().
-
-Correct replacement:
-
-FROM:
-```
-            customInsert(res, insertFn) {
-              if (res.code === 200) {
-                insertFn(resolveUploadedUrl(res))
-              }
-            }
-          },
-          uploadVideo: {
-            server: '',
-            headers: {},
-            maxNumberOfFiles: 1,
-            maxFileSize: 50 * 1024 * 1024,
-            fieldName: 'file',
-            timeout: 5 * 60 * 1000,
-            allowedFileTypes: ['video/*'],
-            customAlert: (msg, type) => {
-              this.$message && this.$message({ message: msg, type: type || 'error' })
-            },
-            onError: (file, err, res) => {
-              const msg = (file && file.name || '视频') + ' 上传失败,视频不能超过 50MB'
-              this.$message && this.$message({ message: msg, type: 'error' })
-            },
-            customInsert(res, insertFn) {
-              if (res.code === 200) {
-                insertFn(resolveUploadedUrl(res))
-              }
-            }
-          }
-        }
-      },
-    addBundleItem() {
-```
-
-TO:
-```
-            customInsert(res, insertFn) {
-              if (res.code === 200) {
-                insertFn(resolveUploadedUrl(res))
-              }
-            }
-          },
-          uploadVideo: {
-            server: '',
-            headers: {},
-            maxNumberOfFiles: 1,
-            maxFileSize: 50 * 1024 * 1024,
-            fieldName: 'file',
-            timeout: 5 * 60 * 1000,
-            allowedFileTypes: ['video/*'],
-            customAlert: (msg, type) => {
-              this.$message && this.$message({ message: msg, type: type || 'error' })
-            },
-            onError: (file, err, res) => {
-              const msg = (file && file.name || '视频') + ' 上传失败,视频不能超过 50MB'
-              this.$message && this.$message({ message: msg, type: 'error' })
-            },
-            customInsert(res, insertFn) {
-              if (res.code === 200) {
-                insertFn(resolveUploadedUrl(res))
-              }
-            }
-          }
-        }
-      },
-    addBundleItem() {
-```
-
-Wait, originally:
-```
-          }  // uploadImage
-}          // MENU_CONF
-    },       // editorConfig
-    addBundleItem() {
-```
-
-After my change:
-```
-          }, // uploadImage
-          uploadVideo: { ... }
-        }    // MENU_CONF
-      },     // editorConfig
-    addBundleItem() {
-```
-
-That's correct.
-
-And I need a resolveUploadedUrl function. I'll add it at the top of the script after imports, before export default.
-
-Also add computed uploadVideoActionUrl and created() assignments.
-
-Let me also NOT add toolbarConfig/editorInstance since they already exist later.
-
-The first StrReplace on ProductEdit might have already been attempted... looking at the function call, it was in the same batch. If it succeeded, I may have broken the file. Let me check.
+    isEdit() {
+      return !!this.$route.query.id
+    },
+    isSupplierAdmin() {
+      const rolesStr = localStorage.getItem('roles')
+      const roles = rolesStr ? JSON.parse(rolesStr) : []
+      return roles.includes('supplier') || roles.includes('supplier_admin')
+    },
+    uploadActionUrl() {
+      const baseURL = process.env.VUE_APP_BASE_API || ''
+      return baseURL + '/api/admin/articles/upload/image'
+    },
+    uploadVideoActionUrl() {
+      const baseURL = process.env.VUE_APP_BASE_API || ''
+      return baseURL + '/api/admin/articles/upload/video'
+    },
+    uploadHeaders() {
+      const token = localStorage.getItem('token')
+      return { Authorization: 'Bearer ' + token }
+    },
+    selectedSystem() {
+      if (!this.form.distributionSystemId || !this.supplySystems.length) return null
+      return this.supplySystems.find(s => s.id === this.form.distributionSystemId)
+    },
+    filteredGuides() {
+      if (!this.approvedGuides.length) return this.approvedGuides
+      if (!this.guideSearchQuery) return this.approvedGuides
+      var q = this.guideSearchQuery.toLowerCase()
+      return this.approvedGuides.filter(function(g) {
+        return (g.realName || '').toLowerCase().indexOf(q) !== -1
+          || (g.nickname || '').toLowerCase().indexOf(q) !== -1
+          || (g.title || '').toLowerCase().indexOf(q) !== -1
+          || (g.specialty || '').toLowerCase().indexOf(q) !== -1
+      })
+    }
+  },
+  created() {
+    this.loadApprovedGuides()
+    this.editorConfig.MENU_CONF.uploadImage.server = this.uploadActionUrl
+    this.editorConfig.MENU_CONF.uploadImage.headers = this.uploadHeaders
+    this.editorConfig.MENU_CONF.uploadVideo.server = this.uploadVideoActionUrl
+    this.editorConfig.MENU_CONF.uploadVideo.headers = this.uploadHeaders
+  },
+  mounted() {
+    this.loadSupplySystems()
+    this.loadPredefinedFields()
+    if (this.isEdit) {
+      this.loadProduct(this.$route.query.id)
+    }
+  },
+  methods: {
+    handleEditorCreated(editor) {
+      this.editorInstance = editor
+    },
     addBundleItem() {
       this.bundleItems.push({
         childProductId: null,
@@ -616,65 +547,7 @@ The first StrReplace on ProductEdit might have already been attempted... looking
         }
       } catch (e) { /* ignore */ }
     },
-      toolbarConfig: {},
-      editorInstance: null
-    }
-  },
-  computed: {
-    isEdit() {
-      return !!this.$route.query.id
-    },
-    isSupplierAdmin() {
-      const rolesStr = localStorage.getItem('roles')
-      const roles = rolesStr ? JSON.parse(rolesStr) : []
-      return roles.includes('supplier') || roles.includes('supplier_admin')
-    },
-  uploadActionUrl() {
-    const baseURL = process.env.VUE_APP_BASE_API || ''
-    return baseURL + '/api/admin/articles/upload/image'
-    },
-    uploadVideoActionUrl() {
-      const baseURL = process.env.VUE_APP_BASE_API || ''
-      return baseURL + '/api/admin/articles/upload/video'
-    },
-    uploadHeaders() {
-      const token = localStorage.getItem('token')
-      return { Authorization: 'Bearer ' + token }
-    },
-    selectedSystem() {
-      if (!this.form.distributionSystemId || !this.supplySystems.length) return null
-      return this.supplySystems.find(s => s.id === this.form.distributionSystemId)
-    },
-    filteredGuides() {
-      if (!this.approvedGuides.length) return this.approvedGuides
-      if (!this.guideSearchQuery) return this.approvedGuides
-      var q = this.guideSearchQuery.toLowerCase()
-      return this.approvedGuides.filter(function(g) {
-        return (g.realName || '').toLowerCase().indexOf(q) !== -1
-          || (g.nickname || '').toLowerCase().indexOf(q) !== -1
-          || (g.title || '').toLowerCase().indexOf(q) !== -1
-          || (g.specialty || '').toLowerCase().indexOf(q) !== -1
-      })
-    }
-  },
-  created() {
-    this.loadApprovedGuides()
-    this.editorConfig.MENU_CONF.uploadImage.server = this.uploadActionUrl
-    this.editorConfig.MENU_CONF.uploadImage.headers = this.uploadHeaders
-    this.editorConfig.MENU_CONF.uploadVideo.server = this.uploadVideoActionUrl
-    this.editorConfig.MENU_CONF.uploadVideo.headers = this.uploadHeaders
-  },
-  mounted() {
-    this.loadSupplySystems()
-    this.loadPredefinedFields()
-    if (this.isEdit) {
-      this.loadProduct(this.$route.query.id)
-    }
-  },
-  methods: {
-    handleEditorCreated(editor) {
-      this.editorInstance = editor
-    },
+
     async loadSupplySystems() {
       if (this.isSupplierAdmin) {
         try {