From 7d05c69630d066c0992368423f90e440e3638f91 Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期日, 29 九月 2024 11:01:51 +0800
Subject: [PATCH] 整合代码

---
 Source/UBCS-WEB/src/components/file/main.vue |  201 +++++++++++++++++++++++++-------------------------
 1 files changed, 101 insertions(+), 100 deletions(-)

diff --git a/Source/UBCS-WEB/src/components/file/main.vue b/Source/UBCS-WEB/src/components/file/main.vue
index 9330a59..fbfd11e 100644
--- a/Source/UBCS-WEB/src/components/file/main.vue
+++ b/Source/UBCS-WEB/src/components/file/main.vue
@@ -1,81 +1,82 @@
 <template>
   <basic-container>
-    <avue-crud :option="option"
-               :table-loading="loading"
-               :data="data"
-               :page.sync="page"
-               :before-open="beforeOpen"
-               :permission="permissionList"
+    <avue-crud ref="crud"
                v-model="form"
-               ref="crud"
+               :before-open="beforeOpen"
+               :data="data"
+               :option="option"
+               :page.sync="page"
+               :permission="permissionList"
+               :table-loading="loading"
                @row-del="rowDel"
                @search-change="searchChange"
                @search-reset="searchReset"
                @selection-change="selectionChange"
+               @row-click="selectedRowClick"
                @current-change="currentChange"
                @size-change="sizeChange"
                @refresh-change="refreshChange"
                @on-load="onLoad">
       <template slot="menuLeft">
-        <el-button v-if="hasUpload" type="primary"
-                   size="small"
+        <el-button v-if="hasUpload" icon="el-icon-upload2"
                    plain
-                   icon="el-icon-upload2"
+                   size="small"
+                   type="primary"
                    @click="handleUpload">涓� 浼�
         </el-button>
-        <el-button v-if="hasEdit" type="primary"
-                   size="small"
+        <el-button v-if="hasEdit" icon="el-icon-edit"
                    plain
-                   icon="el-icon-edit"
+                   size="small"
+                   type="primary"
                    @click="handleEdit">淇� 鏀�
         </el-button>
-        <el-button  v-if="hasDownload" type="primary"
-                    size="small"
-                    icon="el-icon-download"
-                    plain
-                    @click="handleDownload">涓� 杞�
-        </el-button>
-        <el-button  v-if="hasDel" type="danger"
-                   size="small"
-                   icon="el-icon-delete"
+        <el-button v-if="hasDownload" icon="el-icon-download"
                    plain
+                   size="small"
+                   type="primary"
+                   @click="handleDownload">涓� 杞�
+        </el-button>
+        <el-button v-if="hasDel" icon="el-icon-delete"
+                   plain
+                   size="small"
+                   type="danger"
                    @click="handleDelete">鍒� 闄�
         </el-button>
       </template>
-      <template slot-scope="scope" slot="menu">
-        <el-button v-if="hasDownload" type="text"
-                   icon="el-icon-download"
+      <template slot="menu" slot-scope="scope">
+        <el-button v-if="hasDownload" icon="el-icon-download"
                    size="small"
+                   type="text"
                    @click="handleDownload(scope.row)">涓嬭浇
         </el-button>
       </template>
     </avue-crud>
-    <el-dialog title="闄勪欢绠$悊"
+    <el-dialog :visible.sync="attachBox"
                append-to-body
-               :visible.sync="attachBox"
+               title="闄勪欢绠$悊"
                width="555px">
-      <avue-form ref="form" :option="attachOption" v-model="attachForm" :upload-before="uploadBefore"  :upload-after="uploadAfter" :upload-error="uploadError">
+      <avue-form ref="form" v-model="attachForm" :option="attachOption" :upload-after="uploadAfter"
+                 :upload-before="uploadBefore" :upload-error="uploadError">
       </avue-form>
     </el-dialog>
   </basic-container>
 </template>
 
 <script>
-import {getList, getFile,upload,update, remove,download} from "@/api/resource/file";
+import {getList, getFile, upload, update, remove, download} from "@/api/resource/file";
 import {mapGetters} from "vuex";
-import {dateFormat} from "@/util/date";
 import {validatenull} from "@/util/validate";
 import func from "@/util/func";
 
 export default {
-  props: ["options","visible","ownbizOid"],
+  props: ["options", "visible", "ownbizOid"],
   data() {
     return {
       form: {},
       query: {},
-      params:{},
+      params: {},
       loading: false,
-      hasPage:this.options.hasPage||false,
+      hasPage: this.options.hasPage || false,
       page: {
         pageSize: 10,
         currentPage: 1,
@@ -83,12 +84,13 @@
       },
       attachBox: false,
       selectionList: [],
-      hasUpload:validatenull(this.options.hasUpload) ? true :this.options.hasUpload,
-      hasEdit:validatenull(this.options.hasEdit) ? true :this.options.hasEdit,
-      hasDel:validatenull(this.options.hasDel) ? true :this.options.hasDel,
-      hasDownload:validatenull(this.options.hasDownload) ? true :this.options.hasDownload,
+      //榛樿涓簄ull鍏ㄩ儴鏄痶rue
+      hasUpload: validatenull(this.options.hasUpload) ? true : this.options.hasUpload,
+      hasEdit: validatenull(this.options.hasEdit) ? true : this.options.hasEdit,
+      hasDel: validatenull(this.options.hasDel) ? true : this.options.hasDel,
+      hasDownload: validatenull(this.options.hasDownload) ? true : this.options.hasDownload,
       option: {
-        height:(this.options.tableHeight?this.options.tableHeight:'200'),
+        height: (this.options.tableHeight ? this.options.tableHeight : '300'),
         calcHeight: 30,
         tip: false,
         searchShow: false,
@@ -96,6 +98,7 @@
         border: true,
         index: true,
         viewBtn: true,
+        refreshBtn: false,
         selection: true,
         dialogClickModal: false,
         column: [
@@ -115,34 +118,26 @@
           {
             label: "鏂囦欢澶у皬",
             prop: "fileSize",
-            formatter:function(d){
-              if(!d.fileSize || d.fileSize == null || d.fileSize*1 == 0 || isNaN(d.fileSize*1) ){
+            formatter: function (d) {
+              if (!d.fileSize || d.fileSize == null || d.fileSize * 1 == 0 || isNaN(d.fileSize * 1)) {
                 return "鏈煡澶у皬";
-              }else{
+              } else {
                 //鍘熷澶у皬鏄疊
-                var filesize = d.fileSize*1;
-                if(filesize>1024*1024*1024*1024){
-                  return parseInt(filesize/(1024*1024*1024*1024)) + "TB";
-                }else if(filesize> 1024*1024*1024){
-                  return parseInt(filesize/(1024*1024*1024)) + "GB";
-                }else if(filesize> 1024*1024){
-                  return parseInt(filesize/(1024*1024)) + "MB";
-                }else if(filesize> 1024){
-                  return parseInt(filesize/1024) + "KB";
-                }else {
+                var filesize = d.fileSize * 1;
+                if (filesize > 1024 * 1024 * 1024 * 1024) {
+                  return parseInt(filesize / (1024 * 1024 * 1024 * 1024)) + "TB";
+                } else if (filesize > 1024 * 1024 * 1024) {
+                  return parseInt(filesize / (1024 * 1024 * 1024)) + "GB";
+                } else if (filesize > 1024 * 1024) {
+                  return parseInt(filesize / (1024 * 1024)) + "MB";
+                } else if (filesize > 1024) {
+                  return parseInt(filesize / 1024) + "KB";
+                } else {
                   return filesize + "B";
                 }
               }
             }
           },
-          /*{
-            label: "瀵嗙骇",
-            prop: "secretGradeText"
-          },
-          {
-            label: "鏂囨。绫诲埆",
-            prop: "fileDocClassifyName"
-          },*/
           {
             label: "鍒涘缓鑰�",
             prop: "creator"
@@ -190,7 +185,7 @@
           prop: 'attachFile',
           type: 'upload',
           dragFile: true,
-          showFileList:false,
+          showFileList: false,
           accept: this.options.uploadAccept || 'file',
           loadText: '鏂囦欢涓婁紶涓紝璇风◢绛�',
           span: 24,
@@ -198,10 +193,10 @@
             res: 'data'
           },
           data: {
-            ownbizOid:this.options.ownbizOid || "share",
-            ownBtmName:this.options.ownbizBtm || "share",
-            fileDocClassify:this.options.fileDocClassify || "ADMIN_SHARE",
-            fileDocClassifyName:this.options.fileDocClassifyName || "绠$悊鍛樺叡浜枃浠�"
+            ownbizOid: this.options.ownbizOid || "share",
+            ownBtmName: this.options.ownbizBtm || "share",
+            fileDocClassify: this.options.fileDocClassify || "ADMIN_SHARE",
+            fileDocClassifyName: this.options.fileDocClassifyName || "绠$悊鍛樺叡浜枃浠�"
           },
           action: "/api/ubcs-resource/fileController/uploadFile"
         }
@@ -210,7 +205,7 @@
     };
   },
   computed: {
-    ...mapGetters([ "permission"]),
+    ...mapGetters(["permission"]),
     permissionList() {
       return {
         addBtn: false,
@@ -234,21 +229,21 @@
   mounted() {
 
   },
-  watch:{
-    ownbizOid(val){
+  watch: {
+    ownbizOid(val) {
       this.setParams()
       this.refreshChange()
-    }
+    },
   },
   methods: {
-    setFormItem(){
+    setFormItem() {
       /*this.options.formItems=[{
         field: 'fileDocClassify11',
         title: '鏂囦欢绫诲瀷',
         type:  'combox',
         data: [{key: 'text', value: '鏂囨湰妗�'},{key: 'number', value: '鏁板瓧妗�'}]
       }]*/
-      if(this.options && this.options.formItems){
+      if (this.options && this.options.formItems) {
         this.options.formItems.forEach(item => {
           // 璁剧疆琛ㄥ崟鏍¢獙鐨勮鍒欙紝鏂囨湰
           let message = "璇烽�夋嫨";
@@ -257,7 +252,7 @@
             message = "璇疯緭鍏�";
             trigger = "blur";
           }
-          this.attachOption.column.push( {
+          this.attachOption.column.push({
             ...item,
             label: item.title,
             prop: item.field,
@@ -267,12 +262,12 @@
             type: this.columnType[item.type],
             dicData: this.getDataList(item.type, item.data),
             change: () => {
-              if(item.type !== "text"  && item.type !== "number" && item.type !== "textarea"){
+              if (item.type !== "text" && item.type !== "number" && item.type !== "textarea") {
                 this.changeFun(item.field);
               }
             },
             blur: () => {
-              if(item.type == "text"  || item.type == "number" || item.type == "textarea"){
+              if (item.type == "text" || item.type == "number" || item.type == "textarea") {
                 this.changeFun(item.field);
               }
             },
@@ -297,8 +292,8 @@
         })
       }
     },
-    changeFun( prop) {
-      this.attachOption.column[1].data[prop]=this.attachForm[prop]
+    changeFun(prop) {
+      this.attachOption.column[1].data[prop] = this.attachForm[prop]
     },
     getDataList(type, dicData) {
       if (type === "truefalse") {
@@ -346,25 +341,25 @@
 
     },
     handleUpload() {
-      this.attachOption.column[1].data.fileOid='';
+      this.attachOption.column[1].data.fileOid = '';
       delete this.attachOption.column[1].data.oid;
       delete this.attachOption.column[1].data.updateFileFlag;
       this.attachBox = true;
     },
     handleEdit() {
-      if(this.selectionList.length==0){
+      if (this.selectionList.length == 0) {
         this.$message.warning('璇烽�夋嫨闇�瑕佷慨鏀圭殑鏂囦欢')
         return false;
-      }else if(this.selectionList.length>1){
+      } else if (this.selectionList.length > 1) {
         this.$message.warning('璇烽�夋嫨涓�鏉℃暟鎹�')
         return false;
       }
-      this.attachOption.column[1].data.fileOid=this.oids;
-      this.attachOption.column[1].data.oid=this.oids;
-      this.attachOption.column[1].data.updateFileFlag=true
+      this.attachOption.column[1].data.fileOid = this.oids;
+      this.attachOption.column[1].data.oid = this.oids;
+      this.attachOption.column[1].data.updateFileFlag = true
       this.attachBox = true;
     },
-    uploadBefore(file, done, loading,column) {
+    uploadBefore(file, done, loading, column) {
       done();
     },
     uploadAfter(res, done, loading, column) {
@@ -378,25 +373,24 @@
     },
     handleDownload(row) {
       //window.open(`${row.link}`);
-      let data=new FormData();
-      if(row && row.oid){
-        data.append('fileOids',row.oid)
+      let data = new FormData();
+      if (row && row.oid) {
+        data.append('fileOids', row.oid)
         this.downloadFile(data);
-      }else{
+      } else {
         if (this.selectionList.length === 0) {
           this.$message.warning("璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹�");
           return;
         }
-        data.append('fileOids',this.oids)
+        data.append('fileOids', this.oids)
         this.downloadFile(data);
       }
     },
-    downloadFile(data){
-      download(data).then(res=>{
-        // console.log(res);
-        if(res){
-          func.downloadFileByBlob(res);
-          window.URL.revokeObjectURL(src); //閲婃斁鎺塨lob瀵硅薄
+    downloadFile(data) {
+      download(data).then(res => {
+        console.log(res);
+        if (res) {
+          func.downloadFileByBlobHandler(res);
         }
       });
     },
@@ -459,6 +453,13 @@
     },
     selectionChange(list) {
       this.selectionList = list;
+      this.$refs.crud.setCurrentRow(this.selectionList[list.length - 1]);
+    },
+    selectedRowClick(row) {
+      this.selectionList = row;
+      this.$refs.crud.toggleSelection();
+      this.$refs.crud.setCurrentRow(row);
+      this.$refs.crud.toggleRowSelection(row); //閫変腑褰撳墠琛�
     },
     selectionClear() {
       this.selectionList = [];
@@ -473,33 +474,33 @@
     refreshChange() {
       this.onLoad(this.page);
     },
-    onLoad(page, params={}) {
+    onLoad(page, params = {}) {
       this.loading = true;
-      var query={}
+      var query = {}
       if (this.query) {
         for (var key in this.query) {
           query['conditionMap["' + key + '"]'] = this.query[key];
         }
       }
-      getList(page.currentPage, page.pageSize, Object.assign(params,this.params, query,this.query)).then(res => {
+      getList(page.currentPage, page.pageSize, Object.assign(params, this.params, query, this.query)).then(res => {
         const data = res.data.data;
         this.page.total = data.total;
-        if(this.options.fileDocClassifyCombox){
+        if (this.options.fileDocClassifyCombox) {
           this.data = data.records.map(item => {
-            if(validatenull(item.fileDocClassifyName)&& !validatenull(item.fileDocClassify)){
+            if (validatenull(item.fileDocClassifyName) && !validatenull(item.fileDocClassify)) {
               item.fileDocClassifyName = this.options.fileDocClassifyCombox[item.fileDocClassify] || '';
             }
             return {
               ...item
             }
           })
-        }else{
+        } else {
           this.data = data.records;
         }
 
         this.loading = false;
         this.selectionClear();
-      }).catch(error=>{
+      }).catch(error => {
         this.$message.error(error);
         this.loading = false;
       });

--
Gitblit v1.9.3