2 Commits 104119c0ea ... 7221288d8b

Author SHA1 Message Date
  qule 7221288d8b Merge branch 'master' of http://39.106.8.246:3003/BDTP/adm-frontend 2 years ago
  qule bb02574807 cad文件上传 2 years ago

+ 97 - 32
src/components/cadDrawingManage/index.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: ql
  * @Date: 2022-01-11 14:46:04
- * @LastEditTime: 2022-01-14 15:18:59
+ * @LastEditTime: 2022-01-24 16:10:38
  * @LastEditors: Please set LastEditors
  * @FilePath: \adm-frontend\src\components\cadDrawingManage\index.vue
 -->
@@ -30,13 +30,12 @@
                     <el-upload
                       class="upload"
                       ref="upload"
+                      action=''
+                      accept=".dwg"
                       :multiple="true"
-                      action="https://jsonplaceholder.typicode.com/posts/"
-                      :file-list="fileList"
-                      :show-file-list="false"
-                      :on-change='fileChange'
-                      :on-progress='progressHandle'
-                      :auto-upload="false">
+                      :http-request='uploadHandle'
+                      :before-upload="beforeUpload"
+                      :show-file-list="false">
                         <Button slot="trigger"  type="primary" icon="el-icon-download">上传.dwg CAD文件</Button>
                     </el-upload>
                   </div>
@@ -49,11 +48,8 @@
                   tooltip-effect="dark"
                   v-loading="tableLoading"
                   style="width: 100%"
-                  @selection-change="handleSelectionChange">
-                  <el-table-column
-                    type="selection"
-                    width="55">
-                  </el-table-column>
+                >
+                  
                   <el-table-column
                     label="文件名称"
                     prop="fileName"
@@ -62,7 +58,7 @@
                   <el-table-column 
                     label="最新上传时间"
                   >
-                    <template slot-scope="scope">{{ scope.row.modifiedTime }}</template>
+                    <template slot-scope="scope">{{ scope.row.modifiedTime | timeFormat }}</template>
                   </el-table-column>
                   <el-table-column
                     prop="creator"
@@ -93,6 +89,9 @@ import { Tree, Tabs, Button } from 'meri-design'
 import { MENU_MAP } from '@/data/cadConst'
 import BuildController from "@/controller/old-adm/buildController"
 import cadDrawingController from '@/controller/cadDarwingController'
+import moment from 'moment'
+import { mapState, mapMutations } from 'vuex'
+import { logicConfig } from "@/logicConfig";
 export default {
   components: {
     Tree,
@@ -100,16 +99,38 @@ export default {
     Button,
   },
   watch: {
+    async successList(nv, ov) {
+      if (nv?.length) {
+        const files = this.successList.map(item => ({
+          fileKey: item.fileId,
+          fileName: item.fileName
+        }))
+        const params = {
+          buildingId: this.buildingId,
+          floorId: this.floorId,
+          majorCode: this.currentTab,
+          files
+        }
+        const res = cadDrawingController.addFile(params);
+        this.getFileList();
+        this.$message({
+          type: 'success',
+          message: '上传成功!'
+        });
+      }
+    },
     currentTab(nv, ov) {
-      console.log({nv, ov})
+      this.getFileList()
     }
   },
   data() {
     return {
-      currentTab: 'id1',
+      currentTab: 'CF',
       MENU_MAP,
       options: [],
       tableList: [],  //文件列表数据
+      floorId: '',  //当前楼层
+      buildingId: '', //当前建筑
       tableLoading: false,
       fileList: [], //已选择文件
       // 基础表格表头列表
@@ -133,7 +154,19 @@ export default {
       ],
     }
   },
+  computed: {
+    ...mapState('uploadFile', ['successList', 'uploadVisible', 'errorList'])
+  },
+  filters: {
+    timeFormat(timestr) {
+      if(timestr) {
+         return moment(timestr).format('YYYY-MM-DD HH:mm:ss')
+      } 
+      return '--'
+    }
+  },
   methods: {
+    ...mapMutations('uploadFile', ['updata']),
     // 获取楼层信息
     async getCascader() {
       let param = {
@@ -143,39 +176,71 @@ export default {
       };
     
       this.options = await BuildController.buildDataFormat(param);
+      if(this.options.length) {
+        this.floorId = this.options[0]?.children[0].id
+        this.buildingId = this.options[0].id
+      }
       
     },
     // 选择楼层
-    selectFloorHandle(id) {
-      console.log({id})
+    selectFloorHandle(obj) {
+      const { buildingId, id: floorId } = obj;
+      this.buildingId = buildingId;
+      this.floorId = floorId;
+      this.getFileList()
     },
     // 获取文件列表数据
     async getFileList () {
       this.tableLoading = true
-      this.tableList = await cadDrawingController.queryFileList();
+       const res = await cadDrawingController.queryFileList({
+        buildingId: this.buildingId,
+        floorId: this.floorId,
+        majorCode: this.currentTab
+      });
+      this.tableList = res?.data
       this.tableLoading = false
-      console.log({res})
     },
-    fileChange(file, fileList) {
-      console.log({file, fileList})
+    async uploadHandle(option) {
+      const isHas = this.fileList.find(item => option.file.name === item.name);
+      // if(isHas) {
+      //   this.$message.closeAll();
+      //   this.$message({ type: 'error', message: '当前文件已存在,请重新选择' });
+      //   return;
+      // }
+       const file = {
+        fileName: option.file.name,
+        file: option.file
+      }
+      this.fileList.push(file);
+      this.updata({uploadVisible: true, fileList: this.fileList})
+      
+
     },
-    progressHandle(e, file, fileList) {
-       console.log({file, fileList})
+    beforeUpload(file) {
+      console.log(file)
+      // if()
+      // return false
     },
+   
     delHandle(row) {
+      const id = row.id
       this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(async() => {
           this.tableLoading = true
-          await cadDrawingController.delFile(row);
-          this.tableLoading = false;
-          this.getFileList();
-          this.$message({
-            type: 'success',
-            message: '删除成功!'
-          });
+          const res = await cadDrawingController.delFile({id});
+          if(res.result === logicConfig.resultObj.success) {
+            this.tableLoading = false;
+            this.getFileList();
+            this.$message({
+              type: 'success',
+              message: '删除成功!'
+            });
+          }
+
+          
         }).catch(() => {
           this.$message({
             type: 'info',
@@ -185,8 +250,8 @@ export default {
     }
 
   },
-  mounted() {
-    this.getCascader()
+  async mounted() {
+    await this.getCascader()
     this.getFileList()
   }
 

+ 2 - 2
src/components/uploadFile/constant.ts

@@ -1,5 +1,5 @@
 export const PROGRESS_BG_COLOR = {
     uploading: '#409EFF',
-    success: '#00d6b9',
-    failed: '#f54e45'
+    success: '#67c23a',
+    failed: '#f56c6c'
 }

+ 75 - 24
src/components/uploadFile/index.vue

@@ -1,16 +1,24 @@
 <template>
     <div>
-        <div v-if='uploadVisible' class="uploadWarp">
-            <el-collapse v-model="activeNames" style="position: absolute; width: 100%">
-                <div class="full-progress" :style="{width: percentage + '%', 'background-color': PROGRESS_BG_COLOR.success }"></div>
-                <el-progress :text-inside="true" :show-text='false' :stroke-width="3" :percentage="percentage" class="smallProgess"></el-progress>
+        <div v-if='uploadVisible' class="uploadWarp" :style="{height: (!!activeNames ? 133 : 50) + 'px'  }">
+            <el-collapse v-model="activeNames" :accordion='true' style="position: absolute; width: 100%">
+                <div class="full-progress" :style="{width: percentage + '%', backgroundColor: !!activeNames ? '#fff' : uploading ? 
+                PROGRESS_BG_COLOR.uplaoding : isHasError ? 
+                PROGRESS_BG_COLOR.error : PROGRESS_BG_COLOR.success }"></div>
+                <el-progress :status="uploading ? null : isHasError ? 'warning' : 'success'" v-show='!!!activeNames' :text-inside="true" :show-text='false' :stroke-width="3" :percentage="percentage" class="smallProgess"></el-progress>
                 <i class="el-icon-close" @click="cancelUpload"></i>
                 <el-collapse-item :title="uploading ? '上传中...' : '上传完成'" name="1">
                     <div class="tip">
-                        <span>已成功同步100个文件,共200个文件</span>
-                        <Icon class="icon" :name="'tagCompleted'" />
+                        <span>已成功同步{{synced}}个文件,共{{fileList.length}}个文件</span>
+                        <Icon v-if="!uploading" class="icon" :name="'tagCompleted'" :color="isHasError ? PROGRESS_BG_COLOR.failed : PROGRESS_BG_COLOR.success" />
                     </div>
-                    <el-progress :text-inside="true" :show-text='false' :stroke-width="3" :percentage="percentage"></el-progress>
+                    <el-progress 
+                        :text-inside="true" 
+                        :show-text='false' 
+                        :stroke-width="3" 
+                        :percentage="percentage"
+                        :status="uploading ? null : isHasError ? 'warning' : 'success'"
+                    ></el-progress>
                 </el-collapse-item>
             </el-collapse>
         </div>
@@ -34,8 +42,9 @@
 </template>
 
 <script>
-import { mapState } from 'vuex'
+import { mapState, mapMutations } from 'vuex'
 import { PROGRESS_BG_COLOR } from './constant'
+import FileController from '@/controller/fileController'
 export default {
     components: {
 
@@ -43,21 +52,49 @@ export default {
     data() {
         return {
             activeNames: '1',
-            modalStatusTip: false,
-            uploading: true,
-            percentage: 0,
-            PROGRESS_BG_COLOR,
+            modalStatusTip: false,  //确认框
+            uploading: false,
+            percentage: 0,   //进度比例
+            PROGRESS_BG_COLOR, 
+            synced: 0,
+            isHasError: false,  //上传是否出现错误
+            uploadSuccessList: [],
         }
     },
     watch: {
-        uploadVisible(nv, ov) {
-            console.log({nv, ov})
+        async uploadVisible(nv, ov) {
+            const that = this;
+            if (nv) {
+                this.uploading = true
+                const res = await FileController.uploadFiles({
+                    uploadProgressCall(_obj) {
+                        console.log("uploadProgressCall", _obj);
+                    },
+                    oneUploadedCall(_obj) {
+                        that.synced  += 1
+                        that.percentage = (that.synced / that.fileList?.length) * 100;
+                        if(that.percentage === 100) {
+                            that.uploading = false
+                        }
+                        that.uploadSuccessList.push(_obj)
+                    },
+                    files: that.fileList
+                });
+                console.log({res})
+            }
+        },
+        uploading(nv, ov) {
+            if(!nv){
+                this.updata({successList: this.uploadSuccessList})
+            }
         }
     },
     computed: {
-        ...mapState('uploadFile', ['uploadVisible'])
+        ...mapState('uploadFile', ['uploadVisible', 'fileList'])
     },
+
     mounted() {
+       
         // setInterval(() => {
         //     if (this.percentage < 99.9) {
         //          this.percentage += 0.1
@@ -65,17 +102,29 @@ export default {
         //     }
 
         // }, 20);
-
-    },
+        
+    }, 
     methods: {
+        ...mapMutations('uploadFile', ['updata']),
+        onprogress(param) {
+            console.log({param})
+        },
+        onuploaded(param) {
+            console.log({param})
+        },
         cancelUpload() {
             this.modalStatusTip = true;
         },
         confirmHandle() {
-            console.log(123)
+            this.modalStatusTip = false;
+            this.updata({'uploadVisible': false, 'fileList': []});
+            this.uploading = false;
+            this.percentage = 0;
+            this.synced = 0;
+            this.uploadSuccessList = [];
         },
         modalClose() {
-            this.modalStatusTip = false
+            this.modalStatusTip = false;
         },
     },
 }
@@ -85,9 +134,10 @@ export default {
     .uploadWarp {
         position: fixed;
         right: 64px;
-        bottom: 80px;
+        z-index: 99;
+        top: 75%;
         width: 420px;
-        height: 133px;
+        transition: height 0.6s ease;
         box-shadow: 0px 0px 6px #aaa;
         & /deep/ .el-collapse-item__header {
             padding: 16px;
@@ -111,15 +161,16 @@ export default {
             left: 0;
             height: 47px;
             opacity: 0.2;
+            transition: width 0.6s ease;
         }
         .smallProgess {
             position: absolute;
             left: 0;
             width: 100%;
             top: 46px;
-            & /deep/ .el-progress-bar__inner {
-                transition: none;
-            }
+            // & /deep/ .el-progress-bar__inner {
+            //     transition: none;
+            // }
         }
         .tip {
             display: flex;

+ 11 - 21
src/controller/cadDarwingController.ts

@@ -1,18 +1,20 @@
 /*
  * @Author: your name
  * @Date: 2022-01-12 15:29:56
- * @LastEditTime: 2022-01-14 11:34:27
+ * @LastEditTime: 2022-01-24 14:41:08
  * @LastEditors: Please set LastEditors
  * @Description: CAD图纸核查管理
  * @FilePath: \adm-frontend\src\controller\cadDarwingController.ts
  */
 import { baseHttpUtils } from "@/utils/http/baseHttpUtils";
 import { customHttpUtils } from '@/utils/http/customHttpUtils'
+import { admServerHttpUtils } from '@/utils/http/admServerHttpUtils'
 import { logicConfig } from "@/logicConfig";
 export default class cadDarwingController {
     static baseUril = (window as any).__systemConf.baseServiceUrl;
     static http = new baseHttpUtils();
     static customHttp = new customHttpUtils()
+    static admService = new admServerHttpUtils()
 
     /**
      * @description: 查询文件列表接口
@@ -20,17 +22,9 @@ export default class cadDarwingController {
      * @return {*}
      */    
     static async queryFileList (params={}) {
-        const headers = {
-            'Content-Type': 'application/json',
-            'token': '16:31eyJhbGciOiJIUzI1NiJ9.eyJkZXZpY2VUeXBlIjoxLCJhdWQiOiJ5dXNodS1zYWFzLWNsaWVudCIsInN1YiI6Inl1c2h1LXVzZXIiLCJhY2NvdW50SWQiOiIxNDc4MjcyMTQwNjU4MjAwNTc4IiwiYWNjb3VudE5hbWUiOiLmnY7mnbAiLCJpc3MiOiJ5dXNodSIsImp0aSI6ImEyYzgwYWQxLTRkZTgtNDVjMy04ODMyLTE5MzUxNWU3OWFmMCJ9.HYLA4Tc2c4TEDRXdi9dJ39zWuVmBoGoj5VrGRJk_9Ec'
-        }
         try {
-            const res = await this.customHttp.customRequest(`${this.baseUril}/adm-server/adm/adm-file/queryCadFiles?projectId=Pj5001120003&groupCode=XG&userId=adm`, headers, params, 'post');
-            if(res?.result != logicConfig.resultObj.success) {
-                console.log('error');
-                return []
-            }
-            return res.data
+            const res = await this.admService.postRequest('/adm/adm-file/queryCadFiles', params);
+            return res
         } catch (error) {
             
         } 
@@ -41,19 +35,15 @@ export default class cadDarwingController {
      * @return {*}
      */    
     static async delFile(params) {
-        const headers = {
-            'Content-Type': 'application/x-www-form-urlencoded',
-            'token': '16:31eyJhbGciOiJIUzI1NiJ9.eyJkZXZpY2VUeXBlIjoxLCJhdWQiOiJ5dXNodS1zYWFzLWNsaWVudCIsInN1YiI6Inl1c2h1LXVzZXIiLCJhY2NvdW50SWQiOiIxNDc4MjcyMTQwNjU4MjAwNTc4IiwiYWNjb3VudE5hbWUiOiLmnY7mnbAiLCJpc3MiOiJ5dXNodSIsImp0aSI6ImEyYzgwYWQxLTRkZTgtNDVjMy04ODMyLTE5MzUxNWU3OWFmMCJ9.HYLA4Tc2c4TEDRXdi9dJ39zWuVmBoGoj5VrGRJk_9Ec'
-        }
         try {
-            const res = await this.customHttp.customRequest(`${this.baseUril}/adm-server/adm/adm-file/delete?projectId=Pj5001120003&groupCode=XG&userId=adm&id=${params.id}`, headers, {}, 'post');
-            if(res?.result != logicConfig.resultObj.success) {
-                console.log('error');
-                return []
-            }
-            return res.data
+            const res = await this.admService.postRequest('/adm/adm-file/delete?id=' + params.id, params);
+            return res
         } catch (error) {
             
         }
     }
+    static async addFile(params) {
+        const res = await this.admService.postRequest('/adm/adm-file/saveCadFileInfo', params);
+        return res
+    }
 }

+ 6 - 5
src/controller/old-adm/buildController.ts

@@ -33,19 +33,20 @@ class BuildController {
       if (res.result != logicConfig.resultObj.success) {
         return;
       }
-      return res?.content.map((item) => {
+      return res?.content.map((item, index) => {
         const { id, localName: name } = item;
-        const children = item?.floor?.map((subitem) => ({
-          id: subitem.buildingId,
+        const children = item?.floor?.map((subitem, subindex) => ({
+          id: subitem.id,
+          buildingId: item.id,
           name: subitem.localName,
           open: false,
           disabled: false,
-          checked: "uncheck",
+          checked: subindex === 0 ? "checked" : 'uncheck',
         }));
         return {
           id,
           name,
-          open: false,
+          open: index === 0 ? true : false,
           disabled: false,
           checked: "uncheck",
           children,

+ 5 - 5
src/data/cadConst.js

@@ -1,14 +1,14 @@
 /*
  * @Author: ql
  * @Date: 2022-01-12 11:46:51
- * @LastEditTime: 2022-01-12 14:18:29
+ * @LastEditTime: 2022-01-22 16:29:41
  * @LastEditors: Please set LastEditors
  * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  * @FilePath: \adm-frontend\src\data\cadConst.js
  */
 export const MENU_MAP = [
-    {name: '土建精装', id:'id1'},
-    {name: '空调专业', id:'id2' },
-    {name: '消防专业' , id:'id3'},
-    {name: '给排水专业', id:'id4' },
+    {name: '土建精装', id:'CF'},
+    {name: '空调专业', id:'AC' },
+    {name: '消防专业' , id:'WS'},
+    {name: '给排水专业', id:'FF' },
 ]

+ 3 - 1
src/store/modules/uploadFile.ts

@@ -2,13 +2,15 @@ export default {
     namespaced: true,
     state: {
         uploadVisible: false,
+        fileList: [],
+        successList: [],
+        errorList: [],
     },
     getters: {
 
     },
     mutations: {
         updata(state, payload) {
-            console.log({state, payload})
             for (const key in payload) {
                 state[key] = payload[key]
             }

+ 5 - 0
src/utils/http/basic/axiosUtils.ts

@@ -8,13 +8,18 @@ import vueStore from "@/store";
 import { logicConfig } from "@/logicConfig";
 import { toolUtils } from "@/utils/toolUtils";
 import SparkMD5 from "spark-md5";
+import {sessionStore} from '@/store/sessionStore'
 
 var CancelToken = axios.CancelToken;
 var cancel;
 
+
 // 创建axios实例
 const axiosservice = axios.create({
   timeout: 3000000, // 请求超时时间
+  headers: {
+    token: sessionStore.userToken
+  },
   cancelToken: new CancelToken(function executor(c) {
     // executor 函数接收一个 cancel 函数作为参数
     cancel = c;