Bladeren bron

知识分享富文本图片存储到oss中以及一些优化

lizhenhao 2 jaren geleden
bovenliggende
commit
f2a70e2113
2 gewijzigde bestanden met toevoegingen van 59 en 16 verwijderingen
  1. 52 15
      src/views/modules/knowledgeShare/InfoForm.vue
  2. 7 1
      src/views/modules/knowledgeShare/InfoList.vue

+ 52 - 15
src/views/modules/knowledgeShare/InfoForm.vue

@@ -4,15 +4,24 @@
       :title="formTitle"
       :close-on-click-modal="false"
       v-dialogDrag
-      width="1300px"
+      width="1200px"
       @close="close"
       :visible.sync="visible">
       <el-form size="middle" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method === 'view'"
-               label-width="150px" @submit.native.prevent>
+               label-width="90px" @submit.native.prevent>
         <el-row  :gutter="15">
 
           <el-col :span="24">
-            <el-form-item label="知识分享类型" prop="typeId"
+            <el-form-item label="主题" prop="title"
+                          :rules="[
+                          {required: true, message:'主题不能为空', trigger:'blur'}
+                 ]">
+              <el-input v-model="inputForm.title" placeholder="请填写主题"></el-input>
+            </el-form-item>
+          </el-col>
+
+          <el-col :span="24">
+            <el-form-item label="类型" prop="typeId"
                           :rules="[
                           {required: true, message:'分享类型不能为空', trigger:'blur'}
                  ]">
@@ -26,21 +35,16 @@
               </el-select>
             </el-form-item>
           </el-col>
-          <el-col :span="24">
-            <el-form-item label="主题" prop="title"
-                          :rules="[
-                          {required: true, message:'主题不能为空', trigger:'blur'}
-                 ]">
-              <el-input v-model="inputForm.title" placeholder="请填写主题"></el-input>
-            </el-form-item>
-          </el-col>
 
           <el-col>
             <el-form-item label="内容" prop="detail"
                           :rules="[
                           {required: true, message:'内容不能为空', trigger:'blur'}
                  ]">
-              <WangEditor ref="contentEditor" v-model="inputForm.detail"/>
+              <WangEditor ref="contentEditor" v-model="inputForm.detail"
+                          @getUrl="(url, lsUrl) => {
+                        inputForm.editorFilesDTOList.push({temporaryUrl: lsUrl, url: url});
+                        }"/>
             </el-form-item>
           </el-col>
         </el-row>
@@ -156,7 +160,8 @@
           visits: [],
           comments: [],
           files: [],
-          content: ''
+          content: '',
+          editorFilesDTOList: []
         }
       }
     },
@@ -177,6 +182,9 @@
     },
     methods: {
       init (method, id) {
+        this.knowledgeShareTypeService.list().then(({data}) => {
+          this.typeList = data.records
+        })
         this.method = method
         this.inputForm = {
           id: '',
@@ -187,7 +195,8 @@
           visits: [],
           comments: [],
           files: [],
-          content: ''
+          content: '',
+          editorFilesDTOList: []
         }
         if (method === 'add') {
           this.formTitle = `新建知识分享`
@@ -245,11 +254,11 @@
             if (this.commonJS.isEmpty(this.inputForm.files)) {
               this.inputForm.files = []
             }
+            this.getEditorFilesDTOList()
             this.inputForm.files = this.$refs.uploadComponent.getDataList()
             this.knowledgeShareInfoService.save(this.inputForm).then(({data}) => {
               this.close()
               this.$message.success(data)
-              this.$emit('refreshDataList')
               this.loading = false
             }).catch(() => {
               this.loading = false
@@ -258,11 +267,24 @@
         })
       },
       close () {
+        this.inputForm = {
+          id: '',
+          typeId: '',
+          typeName: '',
+          title: '',
+          detail: '',
+          visits: [],
+          comments: [],
+          files: [],
+          content: '',
+          editorFilesDTOList: []
+        }
         this.$refs.inputForm.resetFields()
         this.$refs.uploadComponent.clearUpload()
         // 富文本处理
         this.$refs.contentEditor.clear()
         this.visible = false
+        this.$emit('refreshDataList')
       },
       pushComment () {
         if (this.commonJS.isEmpty(this.inputForm.content)) {
@@ -300,6 +322,21 @@
         this.inputForm.typeId = rows[0].id
         this.inputForm.typeName = rows[0].klgsType
         this.$forceUpdate()
+      },
+      getEditorFilesDTOList () {
+        let a = []
+        if (this.commonJS.isNotEmpty(this.inputForm.editorFilesDTOList)) {
+          this.inputForm.detail = this.inputForm.detail.replace(/&amp;/g, '&')
+          this.inputForm.editorFilesDTOList.forEach((item) => {
+            if (this.inputForm.detail.includes(item.temporaryUrl)) {
+              a.push(item)
+            }
+          })
+        }
+        this.inputForm.editorFilesDTOList = []
+        a.forEach((item) => {
+          this.inputForm.editorFilesDTOList.push(item)
+        })
       }
     }
   }

+ 7 - 1
src/views/modules/knowledgeShare/InfoList.vue

@@ -91,7 +91,7 @@
     data () {
       return {
         typeList: [],
-        typeId: '1',
+        typeId: '',
         searchForm: {
           title: '',
           createBy: ''
@@ -120,6 +120,11 @@
       UserSelect
     },
     mounted () {
+      this.typeId = ''
+      this.refreshList()
+    },
+    activated () {
+      this.typeId = ''
       this.refreshList()
     },
     methods: {
@@ -178,6 +183,7 @@
         })
       },
       resetSearch () {
+        this.typeId = ''
         this.$refs.searchForm.resetFields()
         this.refreshList()
       },