Kaynağa Gözat

批量设置功能

gangyj 2 yıl önce
ebeveyn
işleme
80d6a27999
1 değiştirilmiş dosya ile 112 ekleme ve 2 silme
  1. 112 2
      src/views/file/records.vue

+ 112 - 2
src/views/file/records.vue

@@ -186,6 +186,9 @@
                         <el-option v-for="item in storagePeriod" :key="item['dictKey']" :label="item['dictValue']" :value="item['dictKey']"/>
                     </el-select>
                 </span>
+                <span class="ml-5">
+                    <el-button type="primary" @click="batchSetHandle">设置</el-button>
+                </span>
             </div>
             <HcTable ui="hc-form-table" :column="tableUploadColumn" :datas="tableUploadData" :loading="uploadSaveLoading" :isIndex="false" :class="{'set-table': tableUploadType === 'add'}">
                 <template #no="{index}">
@@ -957,7 +960,7 @@ const uploadsChange = ({fileList}) => {
         const item = fileList[i]
         let name = item['originalName'] || ''
         let fileName = name.substring(0, name.lastIndexOf("."))
-        newArr.push({
+        tableUploadData.value.push({
             projectId: projectId.value,
             contractId: contractId.value,
             nodeId: nodeIds.value,
@@ -977,7 +980,6 @@ const uploadsChange = ({fileList}) => {
             }]
         })
     }
-    tableUploadData.value.push(newArr[0])
 }
 
 //上传进度
@@ -1124,6 +1126,114 @@ const batchSet = ref({
     storagePeriod:''
 })
 
+//批量设置
+const batchSetHandle = () => {
+    setSecurityLevel()
+    setStoragePeriod()
+    setFileNumber()
+}
+
+//批量设置密级
+const setSecurityLevel = () => {
+    if(batchSet.value.securityLevel){
+        let isSet = true;
+        for (let i = 0; i < tableUploadData.value.length; i++) {
+            if(tableUploadData.value[i].secretLevel!=='0' && tableUploadData.value[i].secretLevel){
+                isSet = false;
+                return;
+            }
+        }
+        //如果有一条数据选了,其他的都不进行设置
+        if(isSet){
+            tableUploadData.value.forEach((element)=>{
+                element.secretLevel = batchSet.value.securityLevel
+            })
+        }
+    }
+}
+
+//批量设置保管期限
+const setStoragePeriod = () => {
+    if(batchSet.value.storagePeriod){
+        let isSet = true;
+        for (let i = 0; i < tableUploadData.value.length; i++) {
+            if(tableUploadData.value[i].storageTime!=='0' && tableUploadData.value[i].storageTime){
+                isSet = false;
+                return;
+            }
+        }
+        //如果有一条数据选了,其他的都不进行设置
+        if(isSet){
+            tableUploadData.value.forEach((element)=>{
+                element.storageTime = batchSet.value.storagePeriod
+            })
+        }
+    }
+}
+
+const setFileNumber = () => {
+    let isSet = true;
+    for (let i = 0; i < tableUploadData.value.length; i++) {
+        if(tableUploadData.value[i].fileNumber){
+            isSet = false;
+            return;
+        }
+    }
+    if(!isSet){
+        return;
+    }
+
+    if(batchSet.value.prefix && batchSet.value.numberStart && batchSet.value.numberEnd){
+        const regPos = /^[0-9]+.?[0-9]*/; //判断是否是数字。
+        if(!regPos.test(batchSet.value.numberStart)){
+            window.$message?.warning('流水号 起号 存在非数字,请修改')
+            return;
+        }
+        if(!regPos.test(batchSet.value.numberEnd)){
+            window.$message?.warning('流水号 止号 存在非数字,请修改')
+            return;
+        }
+
+        const startNum = Number(batchSet.value.numberStart);
+        const endNum = Number(batchSet.value.numberEnd);
+        if(startNum > endNum){
+            window.$message?.warning('起号需要小于止号')
+            return;
+        }
+
+        //获取最长的字符串长度
+        let numL = 0;
+        if(batchSet.value.numberStart.length > batchSet.value.numberEnd.length){
+            numL = batchSet.value.numberStart.length
+        }else{
+            numL = batchSet.value.numberEnd.length
+        }
+
+        //检测前缀最后是否有-
+        let prefix = batchSet.value.prefix;
+        if(prefix.charAt(prefix.length - 1) !== '-'){
+            //没有就加上
+            prefix = prefix + '-';
+        }
+
+        //遍历赋值
+        let index = 0;
+        for (let i = startNum; i <= endNum; i++) {
+            //超出就终止
+            if(tableUploadData.value[index] === undefined){
+                return;
+            }
+            //前面补零
+            const numStr = i.toString().padStart(numL,'0');
+            tableUploadData.value[index].fileNumber = prefix + numStr;
+            index++;
+        }
+
+    }else{
+        window.$message?.warning('档号由前缀和流水号组成,请填写完整再进行批量设置档号')
+    }
+}
+
 //批量下载
 const downloadLoading = ref(false)
 const batchDownload = async () => {