Ver código fonte

上传附件功能

yin_yu820 2 anos atrás
pai
commit
8adf891d30

+ 7 - 0
src/api/sys/tools.js

@@ -37,6 +37,13 @@ export default class Tools {
             formData
         )
     };
+    // 文件删除
+    uploadFiledelete(formData, uploadPath) {
+        return request.delete(
+            `/sys/file/webupload/deleteByUrl?url=${uploadPath}`,
+            formData
+        )
+    };
     // 用户查询
     queryById(id) {
         return request.get(

+ 68 - 11
src/views/activityMan/securityFacilitiesErr/securityFacilitiesErrView.vue

@@ -111,17 +111,23 @@
         </van-popup>
       </van-cell-group>
 
-      
-
       <van-cell-group>
         <van-field name="uploader" label="附件:">
           <template #input>
-            <van-uploader>
+            <van-uploader
+              :after-read="afterRead"
+              v-model="fileList"
+              :max-count="6"
+              capture="camera"
+              accept=""
+              :before-delete="fjdelete"
+            >
               <van-button icon="plus">上传文件</van-button>
             </van-uploader>
           </template>
         </van-field>
       </van-cell-group>
+
       <van-cell-group>
         <div class="rowTextArea">
           <van-field
@@ -147,6 +153,7 @@ import { reactive, ref } from "vue";
 import personList from "../personList.vue";
 import securityFacilitiesErrService from "@/api/securityFacilitiesErr/securityFacilitiesErrService";
 import tools from "@/api/sys/tools";
+
 export default {
   components: { personList },
   setup() {
@@ -262,19 +269,63 @@ export default {
       }
     };
 
+    // 文件上传
+    let fileList = ref([]);
+    let fileupList = ref([]);
+    const afterRead = (file) => {
+      // 此时可以自行将文件上传至服务器
+      new tools()
+        .uploadFile(file, `afssyc/securityFacilitiesErr`)
+        .then(({ data }) => {
+        
+          data.name = decodeURIComponent(
+            data.url.substring(
+              data.url.lastIndexOf("/") + 1
+            )
+          );
+
+          //data.url = `${$base}` + data.url;    
+          fileupList.value.push(data);
+
+        });
+    };
+    const fjdelete = (file) => {
+      //删除文件操作
+      for (let index = 0; index < fileList.value.length; index++) {
+        if(file.file==fileList.value[index].file){
+          let delurl=fileupList.value[index].url;                   
+          new tools()
+            .uploadFiledelete("", delurl)
+            .then(({ data }) => {
+          });
+          fileupList.value.splice(index,1);
+          fileList.value.splice(index,1); 
+        }        
+      }      
+    };
+
     // 提交数据
     const submit = () => {
       //添加保存前判断
+      if(siteInspection.siteName.id==""){
+        window.xm.showToast({
+          message:"请先选择场所信息!"
+        })
+      }else{
 
-      new securityFacilitiesErrService().save(securityFacilitiesErr).then((res) => {
-        if(res.data=="保存安防设施异常成功"){
-          window.xm.showToast({
-             message:"保存成功!"
-          })
-          history.back();
-        }
+        //保存前附件处理
+        siteInspection.enclosure = fileupList.value.map((option) => option.url).join("|");
+        new securityFacilitiesErrService().save(securityFacilitiesErr).then((res) => {
+          if(res.data=="保存安防设施异常成功"){
+            window.xm.showToast({
+              message:"保存成功!"
+            })
+            history.back();
+          }
 
-      });
+        });
+        
+      }
     };
     return {
       securityFacilitiesErr,
@@ -299,6 +350,12 @@ export default {
       FireStations,
       setFireStations,
       
+      // 文件上传
+      afterRead,
+      fileList,
+      fileupList,
+      fjdelete,
+
       // 返回
       onClickLeft,
       submit,

+ 33 - 38
src/views/activityMan/siteInspection/siteInspectionView.vue

@@ -88,16 +88,6 @@
         </van-popup>
       </van-cell-group>
 
-      <!-- <van-cell-group>
-        <van-field name="uploader" label="附件:">
-          <template #input>
-            <van-uploader>
-              <van-button icon="plus">上传文件</van-button>
-            </van-uploader>
-          </template>
-        </van-field>
-      </van-cell-group> -->
-
       <van-cell-group>
         <van-field name="uploader" label="附件:">
           <template #input>
@@ -110,9 +100,6 @@
               :before-delete="fjdelete"
             >
               <van-button icon="plus">上传文件</van-button>
-              <!-- <template #preview-cover="file">
-                <div class="preview-cover van-ellipsis">{{ file.name }}</div>
-              </template> -->
             </van-uploader>
           </template>
         </van-field>
@@ -227,6 +214,7 @@ export default {
     };
     // 文件上传
     let fileList = ref([]);
+    let fileupList = ref([]);
     const afterRead = (file) => {
       // 此时可以自行将文件上传至服务器
       new tools()
@@ -239,42 +227,48 @@ export default {
             )
           );
 
-          data.url = `${$base}` + data.url;      
-          
-
-          //fileList.value[0].url = `${$base}` + fileList.value[0].url;
-          // fileList.value[0].name = decodeURIComponent(
-          //   fileList.value[0].url.substring(
-          //     fileList.value[0].url.lastIndexOf("/") + 1
-          //   )
-          // );
-
-
+          //data.url = `${$base}` + data.url;    
+          fileupList.value.push(data);
 
         });
     };
-
     const fjdelete = (file) => {
-      console.log(file);
+      //删除文件操作
+      for (let index = 0; index < fileList.value.length; index++) {
+        if(file.file==fileList.value[index].file){
+          let delurl=fileupList.value[index].url;                   
+          new tools()
+            .uploadFiledelete("", delurl)
+            .then(({ data }) => {
+          });
+          fileupList.value.splice(index,1);
+          fileList.value.splice(index,1); 
+        }        
+      }      
     };
     
     // 提交数据
     const submit = () => {
       //添加保存前判断
+      if(siteInspection.siteName.id==""){
+        window.xm.showToast({
+          message:"请先选择场所信息!"
+        })
+      }else{
 
-      //保存前附件处理
-      siteInspection.enclosure = data.url;
-
-
-      new siteInspectionService().save(siteInspection).then((res) => {
-        if(res.data=="保存场所检查情况成功"){
-          window.xm.showToast({
-             message:"保存成功!"
-          })
-          history.back();
-        }
+        //保存前附件处理
+        siteInspection.enclosure = fileupList.value.map((option) => option.url).join("|");
+        new siteInspectionService().save(siteInspection).then((res) => {
+          if(res.data=="保存场所检查情况成功"){
+            window.xm.showToast({
+              message:"保存成功!"
+            })
+            history.back();
+          }
+        });
 
-      });
+      }
+      
     };
     return {
       siteInspection,
@@ -300,6 +294,7 @@ export default {
       // 文件上传
       afterRead,
       fileList,
+      fileupList,
       fjdelete,
       submit,
     };