Jelajahi Sumber

Merge branch 'develop-yx' of http://39.106.8.246:3003/web/wanda-bm-guide into develop-yx

YaolongHan 4 tahun lalu
induk
melakukan
1345cc1066
3 mengubah file dengan 114 tambahan dan 27 penghapusan
  1. 8 0
      src/api/equipmentList.js
  2. 44 27
      src/api/httputils.js
  3. 62 0
      src/views/equipment/index.vue

+ 8 - 0
src/api/equipmentList.js

@@ -70,3 +70,11 @@ export function queryBrand({ getParams }) {
 export function queryPicList({ getParams }) {
     return httputils.getJson(`/data/file/getCadList`, getParams)
 }
+// 设备设施-表格上传
+export function uploadExcel({ getParams, data }) {
+    return httputils.postupload(`/data/file/uploadExcel`, getParams, data)
+}
+// 设备设施-表格下载
+export function downloadExcel({ getParams }) {
+    return httputils.download(`/data/file/downloadExcel`, getParams)
+}

+ 44 - 27
src/api/httputils.js

@@ -34,6 +34,16 @@ axiosservice.interceptors.request.use(
                 isPreview: isPreview, //默认false,当预览开启的时候是true
             }
         }
+        // Excel文件上传
+        if (config.url.includes('/data/file/uploadExcel')) {
+            config.headers['Content-Type'] = 'multipart/form-data'
+            config.transformRequest = [
+                function (data, headers) {
+                    return data
+                },
+            ]
+        }
+
         return config
     },
     (error) => {
@@ -42,7 +52,7 @@ axiosservice.interceptors.request.use(
 )
 
 axiosservice.interceptors.response.use(
-    function(res) {
+    function (res) {
         //在这里对返回的数据进行处理
         let resp = res.data
         if (resp.result === 'unauthc') {
@@ -66,7 +76,7 @@ axiosservice.interceptors.response.use(
         }
         return res
     },
-    function(err) {
+    function (err) {
         if (err.response.status == 401) {
             store.commit('SETISREQUESTtAUTH', 'err')
             router.push({
@@ -145,10 +155,11 @@ export default {
             throw err
         }
     },
-    async postupload(url, data) {
+    async postupload(url, params, data) {
         try {
             let response = await axiosservice({
                 url,
+                params,
                 data,
                 method: 'post',
                 headers: {
@@ -160,32 +171,38 @@ export default {
             throw err
         }
     },
-    download(url, requestData) {
+    async download(url, params) {
         // 响应类型:arraybuffer, blob
-        axiosservice
-            .post(url, requestData, {
-                responseType: 'blob',
-            })
-            .then((resp) => {
-                let headers = resp.headers
-                let contentType = headers['content-type']
-                if (!resp.data) {
-                    console.error('响应异常:', resp)
-                    return false
-                } else {
-                    //console.log("下载文件:", resp)
-                    const blob = new Blob([resp.data], {
-                        type: contentType,
-                    })
-                    const contentDisposition = resp.headers['content-disposition']
-                    let fileName = 'unknown'
-                    if (contentDisposition) {
-                        fileName = window.decodeURI(resp.headers['content-disposition'].split('=')[1])
+        return new Promise((resolve, reject) => {
+            axiosservice
+                .get(url, {
+                    params,
+                    responseType: 'blob',
+                })
+                .then((resp) => {
+                    let headers = resp.headers
+                    let contentType = headers['content-type']
+                    if (!resp.data?.size) {
+                        console.error('响应异常:', resp)
+                        resolve({ msg: '文件不存在,下载失败!' })
+                        return false
+                    } else {
+                        //console.log("下载文件:", resp)
+                        const blob = new Blob([resp.data], {
+                            type: contentType,
+                        })
+                        const contentDisposition = resp.headers['content-disposition']
+                        let fileName = 'unknown'
+                        if (contentDisposition) {
+                            fileName = window.decodeURI(resp.headers['content-disposition'].split('=')[1])
+                        }
+                        downFile(blob, fileName)
+                        resolve()
                     }
-                    downFile(blob, fileName)
-                }
-            })
-            .catch(function(error) {})
+                })
+                .catch(function (error) { })
+        })
+
     },
     axios: axiosservice,
 }

+ 62 - 0
src/views/equipment/index.vue

@@ -61,6 +61,15 @@
                                         </div>
                                     </div>
                                 </el-collapse-transition>
+                                <el-upload
+                                    class=""
+                                    action="#"
+                                    :http-request="uploadExl"
+                                    :show-file-list="false"
+                                >
+                                    <el-button style="width: 45px;text-align: center;padding: 7px 5px;" size="mini" >上传</el-button>
+                                </el-upload>
+                                <el-button style="width: 45px;text-align: center;padding: 7px 5px;" size="mini"  @click="downloadExl">下载</el-button>
                             </div>
                         </div>
                     </div>
@@ -78,6 +87,7 @@ import floorMap from '@/components/floorMap/index.vue'
 import eqDialog from './eqDialog'
 import { system } from '@/utils/plugins/components.js'
 import { queryPic, getPvUv } from '@/api/public.js'
+import { uploadExcel, downloadExcel } from "@/api/equipmentList.js";
 import { mapGetters } from 'vuex'
 import store from '../../store'
 export default {
@@ -118,6 +128,58 @@ export default {
         } */
     },
     methods: {
+         /**
+         * excel文件上传
+         */
+        uploadExl(resData) {
+            const { file } = resData
+            // 创建FormData对象
+            const isLt30M = file.size / 1024 / 1024 < 30
+            if (!['xls','xlsx'].includes(file.name.split('.')[1])) {
+                this.$message.warning('上传文件只能是 xls、xlsx格式!')
+                return
+            }
+            if (!isLt30M) {
+                this.$message.warning('上传excel模板大小不能超过 30MB!')
+                return
+            }
+            const formData = new FormData()
+            // 将得到的文件流添加到FormData对象
+            formData.append('file', file, file.name)
+            const getParams ={
+                plazaId: this.plazaId,
+                smsxt: this.smsxt,
+                floor: this.floorInfo.gname, //楼层 必填
+            }
+            const data = formData
+            uploadExcel({ getParams,data }).then(res=>{
+                if(res?.result === 'success'){
+                    this.$message({
+                        message: '上传成功',
+                        type: 'success',
+                    })
+                }else{
+                    this.$message({
+                        message: '上传失败',
+                        type: 'error',
+                    })
+                }
+            })
+        },
+        /**
+         * 下载excel
+         */
+        downloadExl() {
+            const getParams={
+                plazaId: this.plazaId,
+                smsxt: this.smsxt,
+                floor: this.floorInfo.gname,
+            }
+            downloadExcel({ getParams }).then(res=>{
+                // 文件不存在,下载失败提示
+                res.msg && this.$message({ type: 'warning', message: res.msg })
+            })
+        },
         // 查询tab页
         tabSyatem(item) {
             this.systemId = item.id