Jelajahi Sumber

Merge branch 'yh307'

ldong 1 hari lalu
induk
melakukan
3ccd7050ed

+ 5 - 2
src/views/knowledge_manage/components/importFileDia.vue

@@ -104,7 +104,10 @@ export default {
     },
     importFileUrl: {
       type: String
-    }
+    },
+    fileName: {
+      type: String
+    },
   },
   computed: {
     formatTime() {
@@ -114,7 +117,7 @@ export default {
   watch: {
     show(nval) {
       if(!nval) return 
-
+      this.eventForm.title=this.fileName
       this.getClassifyList();
       this.getTagsList();
     }

+ 319 - 0
src/views/knowledge_manage/components/importMoreFileDia.vue

@@ -0,0 +1,319 @@
+<template>
+  <div>
+    <el-dialog :visible.sync="show" :close-on-click-modal="false" :modal-append-to-body="false" @close="cancelHandle"
+      custom-class="knowledge-import-dialog" top="10vh" v-dialogDrag title="事件信息" width="1200px">
+      <div class="more-set-btn">
+        <el-button type="primary" @click="setMore">批量设置</el-button>
+      </div>
+      <el-form class="more-set-form" ref="formRef" hide-required-asterisk :model="eventForm" :rules="formRules"
+        label-width="0">
+        <el-table :data="eventForm.tableData" ref="table" element-loading-text="加载中..." v-loading="tableLoading" border
+          style="width: 100%;" max-height="400">
+          <el-table-column label="标题" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.title'" :rules="formRules.title">
+                <el-input v-model="scope.row.title" placeholder="请输入标题" style="width:100%" />
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column label="分类" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.classifyId'" :rules="formRules.classifyId">
+                <el-cascader :options="classifyOptions" v-model="scope.row.classifyId" :props="{
+                  value: 'ClassifyId',
+                  label: 'ClassifyName',
+                  children: 'Child',
+                  emitPath: false
+                }" clearable placeholder="请选择分类" style="width:100%"></el-cascader>
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column label="来源" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.source'" :rules="formRules.source">
+                <el-input v-model="scope.row.source" placeholder="请输入来源" style="width:100%" clearable />
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column label="标签" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.tagId'" :rules="formRules.tagId">
+                <el-select v-model="scope.row.tagId" placeholder="请选择标签" size="medium" clearable style="width:100%">
+                  <el-option v-for="item in tagsOptions" :key="item.TagId" :label="item.TagName" :value="item.TagId" />
+                </el-select>
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column label="开始时间" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.startTime'" :rules="formRules.startTime">
+                <el-date-picker v-model="scope.row.startTime" :value-format="formatTime" :format="formatTime"
+                  :type="[2, 3].includes(ResourceType) ? 'date' : 'datetime'" placeholder="请选择开始时间"
+                  style="width:100%" />
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column v-if="![2, 3].includes(ResourceType)" label="结束时间" align="center">
+            <template slot-scope="scope">
+              <el-form-item :prop="'tableData.' + scope.$index + '.endTime'" :rules="formRules.endTime">
+                <el-date-picker v-model="scope.row.endTime" :value-format="formatTime" :format="formatTime"
+                  :type="[2, 3].includes(ResourceType) ? 'date' : 'datetime'" placeholder="请选择结束时间"
+                  style="width:100%" />
+              </el-form-item>
+            </template>
+          </el-table-column>
+          <el-table-column label="操作" width="80" align="center">
+            <template slot-scope="scope">
+              <el-button type="text" style="color: #F56C6C;" size="small"
+                @click="deleteRow(scope.$index)">删除</el-button>
+            </template>
+          </el-table-column>
+          <div slot="empty" style="padding: 20px 0">
+            <tableNoData :text="$t('Table.prompt_slogan')" size="mini" />
+          </div>
+        </el-table>
+      </el-form>
+      <div class="btn-bottom">
+        <el-button type="primary" plain @click="cancelHandle">取消</el-button>
+        <el-button type="primary" @click="handleConfirmEvent">批量导入</el-button>
+      </div>
+    </el-dialog>
+    <el-dialog :visible.sync="showSet" :close-on-click-modal="false" :modal-append-to-body="false" @close="cancelSet"
+      custom-class="knowledge-import-dialog" top="10vh" v-dialogDrag title="批量设置" width="556px">
+      <el-form ref="setRef" hide-required-asterisk :model="setForm" :rules="formRules" label-width="100px">
+        <el-form-item prop="classifyId" label="分类">
+          <el-cascader :options="classifyOptions" v-model="setForm.classifyId" :props="{
+            value: 'ClassifyId',
+            label: 'ClassifyName',
+            children: 'Child',
+            emitPath: false
+          }" clearable placeholder="请选择分类" style="width:80%"></el-cascader>
+        </el-form-item>
+
+        <el-form-item prop="source" label="来源">
+          <el-input v-model="setForm.source" placeholder="请输入来源" style="width:80%" clearable />
+        </el-form-item>
+        <el-form-item prop="tagId" label="标签">
+          <el-select v-model="setForm.tagId" placeholder="请选择标签" size="medium" clearable style="width:80%">
+            <el-option v-for="item in tagsOptions" :key="item.TagId" :label="item.TagName" :value="item.TagId" />
+          </el-select>
+        </el-form-item>
+        <el-form-item prop="startTime" label="开始时间">
+          <el-date-picker v-model="setForm.startTime" :value-format="formatTime" :format="formatTime"
+            :type="[2, 3].includes(ResourceType) ? 'date' : 'datetime'" placeholder="请选择开始时间" style="width:80%" />
+        </el-form-item>
+        <el-form-item prop="endTime" v-if="![2, 3].includes(ResourceType)" label="结束时间">
+          <el-date-picker v-model="setForm.endTime" :value-format="formatTime" :format="formatTime"
+            :type="[2, 3].includes(ResourceType) ? 'date' : 'datetime'" placeholder="请选择结束时间" style="width:80%" />
+        </el-form-item>
+      </el-form>
+      <div class="btn-bottom">
+        <el-button type="primary" plain @click="cancelSet">取消</el-button>
+        <el-button type="primary" @click="handleConfirmSet">确定</el-button>
+      </div>
+    </el-dialog>
+  </div>
+</template>
+<script>
+import { eventInterface } from '@/api/modules/knowledge';
+export default {
+  props: {
+    show: {
+      type: Boolean
+    },
+    ResourceType: {
+      type: Number
+    },
+    fileList: {
+      type: Array,
+      default: () => []
+    }
+  },
+  computed: {
+    formatTime() {
+      return [2, 3].includes(this.ResourceType) ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss'
+    }
+  },
+  watch: {
+    show(nval) {
+      if (!nval) return
+      this.eventForm.tableData = this.fileList
+      this.getClassifyList();
+      this.getTagsList();
+    }
+  },
+  data() {
+    return {
+      showSet: false,
+      setForm: {
+        classifyId: '',
+        source: '',
+        tagId: '',
+        startTime: '',
+        endTime: ''
+      },
+      eventForm: {
+        tableData: []
+      },
+      formRules: {
+        title: [
+          { required: true, message: '标题不能为空', trigger: 'blur' },
+        ],
+        classifyId: [
+          { required: true, message: '分类不能为空', trigger: 'blur' },
+        ],
+        source: [
+          { required: true, message: '来源不能为空', trigger: 'blur' },
+        ],
+        startTime: [
+          { required: true, message: '开始时间不能为空', trigger: 'blur' },
+        ],
+      },
+
+      classifyOptions: [],
+      sourcesOptions: [],
+      tagsOptions: [],
+    }
+  },
+  mounted() {
+
+  },
+  methods: {
+    // 删除
+    deleteRow(index) {
+      if (this.eventForm.tableData.length < 2) {
+        this.$message.warning('当前仅剩一条文件信息时不可删除!')
+        return
+      }
+      this.eventForm.tableData.splice(index, 1)
+    },
+    // 批量设置
+    setMore() {
+      this.showSet = true
+    },
+    async getClassifyList() {
+      const res = await eventInterface.getClassify({
+        ResourceType: this.ResourceType
+      })
+      if (res.Ret !== 200) return
+
+      this.classifyOptions = res.Data.List || []
+    },
+
+    async getSourceList() {
+      const res = await eventInterface.getSourcesList({
+        ResourceType: this.ResourceType
+      })
+      if (res.Ret !== 200) return
+
+      this.sourcesOptions = res.Data.List || []
+    },
+
+    async getTagsList() {
+      const res = await eventInterface.getTagList({ ResourceType: this.ResourceType })
+      if (res.Ret !== 200) return
+
+      this.tagsOptions = res.Data.List || []
+    },
+
+    async handleConfirmSet() {
+      await this.$refs.setRef.validate()
+      this.eventForm.tableData.forEach((el, index) => {
+        const arr = ['classifyId', 'source', 'tagId', 'startTime', 'endTime']
+        arr.forEach(item => {
+          this.$set(this.eventForm.tableData[index], item, this.setForm[item])
+        })
+      })
+      this.cancelSet()
+    },
+    async handleConfirmEvent() {
+      this.$refs.formRef.validate((valid) => {
+        if (valid) {
+          let downloadHint = this.$message({
+            type: "info",
+            message: '上传中,请稍后······',
+            duration: 0,
+            iconClass: 'el-icon-loading'
+          })
+          let tableData = this.eventForm.tableData
+          let objPromises = tableData.map(async el => {
+            let formData = new FormData()
+            formData.append('File', el.file)
+            formData.append('ResourceType', this.ResourceType)
+            return eventInterface.fileImportUpload(formData).then(res => Promise.resolve(res)).catch(err => Promise.reject(err))
+          })
+          Promise.all(objPromises).then(async res => {
+            console.log(res)
+            let postArr = []
+            tableData.forEach((el, index) => {
+              postArr.push({
+                ResourceType: this.ResourceType,
+                ClassifyId: el.classifyId,
+                Title: el.title,
+                Content: '',
+                SourceFrom: el.source,
+                TagId: el.tagId || 0,
+                StartTime: el.startTime,
+                EndTime: el.endTime || '',
+                FileUrl: res[index].Data.FileUrl
+              })
+            })
+            downloadHint.close()
+            const resAdd = await eventInterface.addEvent(postArr)
+
+            if (resAdd.Ret !== 200) return
+
+            this.$message.success('添加成功')
+
+            this.$emit('confirm')
+            this.cancelHandle()
+          }).catch(err => Promise.reject(err))
+        } else {
+          this.$message.warning(' 还未填写文件信息!')
+          return false;
+        }
+      });
+
+
+
+    },
+    cancelSet() {
+      this.$refs.setRef.resetFields()
+      this.showSet = false
+    },
+
+    cancelHandle() {
+      this.$refs.formRef.resetFields()
+      this.$emit('update:show', false)
+    }
+  },
+}
+</script>
+<style scoped lang='scss'>
+.el-form {
+  padding: 0 40px;
+}
+
+.btn-bottom {
+  display: flex;
+  justify-content: center;
+  margin: 30px 0;
+
+  .el-button {
+    width: 130px;
+  }
+}
+
+.more-set-form {
+  .el-form-item {
+    margin-bottom: 0;
+  }
+}
+
+.more-set-btn {
+  display: flex;
+  justify-content: flex-end;
+  padding: 0 40px;
+  margin-bottom: 24px;
+}
+</style>

+ 1 - 1
src/views/knowledge_manage/edit.vue

@@ -265,7 +265,7 @@ export default {
           ...params,
           KnowledgeResourceId: this.id
         })
-        : await eventInterface.addEvent(params)
+        : await eventInterface.addEvent([params])
 
       if(res.Ret !== 200) return 
 

+ 66 - 4
src/views/knowledge_manage/list.vue

@@ -16,7 +16,8 @@
           >
             Excel导入
             <el-dropdown-menu slot="dropdown">
-              <el-dropdown-item command="file">文件导入</el-dropdown-item>
+              <!-- <el-dropdown-item command="file">文件导入</el-dropdown-item> -->
+              <el-dropdown-item command="moreFile">文件导入</el-dropdown-item>
             </el-dropdown-menu>
           </el-dropdown>
           <el-button 
@@ -188,6 +189,7 @@
       </div>
 
       <input type="file" @change="fileSelectedImport" id="file"  style="display: none;">
+      <input type="file" v-if="useMore" multiple @change="moreFileSelectedImport" id="moreFile" style="display: none;">
 
       <!-- 分类管理弹窗 -->
       <classifyDia
@@ -205,10 +207,18 @@
       <!-- 导入文件信息弹窗 -->
       <importFileDia
         :show.sync="isImportFileDia"
+        :fileName="fileName"
         :importFileUrl="importFileUrl"
         :ResourceType="ResourceType"
         @confirm="getTableData"
       />
+      <!-- 批量导入文件信息弹窗 -->
+      <importMoreFileDia
+        :show.sync="isImportMoreFileDia"
+        :fileList="fileList"
+        :ResourceType="ResourceType"
+        @confirm="getTableData"
+      />
   </div>
 </template>
 <script>
@@ -216,9 +226,10 @@ import { eventInterface } from '@/api/modules/knowledge';
 import classifyDia from './components/classifyDia.vue'
 import importExcelDia from './components/importExcelDia.vue';
 import importFileDia from './components/importFileDia.vue';
+import importMoreFileDia from './components/importMoreFileDia.vue';
 import mPage from '@/components/mPage.vue'
 export default {
-  components: { mPage,classifyDia,importExcelDia,importFileDia },
+  components: { mPage,classifyDia,importExcelDia,importFileDia,importMoreFileDia },
   computed: {
     ResourceType() {
       const apiMap = {
@@ -288,7 +299,19 @@ export default {
 
       //文件导入弹窗
       isImportFileDia: false,
-      importFileUrl:''
+
+      //文件批量导入弹窗
+      isImportMoreFileDia: false,
+      
+      //单个文件上传文件名称 
+      fileName:'',
+      importFileUrl:'',
+
+      // 批量上传文件列表
+      fileList:[],
+
+      // 解决再次上传相同文件无响应
+      useMore:true
     }
   },
   mounted(){
@@ -422,6 +445,39 @@ export default {
     handleImport(type) {
       if(type === 'file') {
         $(`#file`).click()
+      }else{
+        $(`#moreFile`).click()
+      }
+    },
+    //选择多个文件上传
+    async moreFileSelectedImport(){
+      let file = document.getElementById('moreFile').files;
+      console.log(file)
+      if(file.length>30){
+        return this.$message.warning('最多上传30个文件');
+      }
+      let reg = new RegExp(/\.pdf|\.docx|\.pptx|\.ppt$/,'i')
+      let arr=[]
+      if(file.length){
+        for(let i = 0; i < file.length; i++){
+          if(!reg.test(file[i].name)) return this.$message.warning('只能上传pdf/docx/ppt等文件');
+          if(file[i].size > 51*1024*1024) return this.$message.warning("上传文件大小不超过50MB");
+          arr.push({
+            title: this.getFileName(file[i].name),
+            classifyId: '',
+            source:'',
+            tagId:'',
+            startTime:'',
+            endTime:'',
+            file:file[i]
+          })
+        }
+        this.fileList=arr
+        this.isImportMoreFileDia=true
+        this.useMore=false
+        setTimeout(()=>{
+          this.useMore=true
+        },500)
       }
     },
     //选择文件上传
@@ -450,11 +506,17 @@ export default {
         if(res.Ret !== 200) return
 
         this.importFileUrl = res.Data.FileUrl
-        
+        this.fileName=this.getFileName(file.name)
         this.isImportFileDia = true;
       } 
 		},
 
+    // 获取文件名称
+    getFileName(name){
+      let fileType = name.substring(name.lastIndexOf(".") + 1);
+      return name.split('.'+fileType)[0]
+    },
+
     checkBtnAuth(key) {
       const {isShowBtn}=this.permissionBtn
        const authMap = {