Jelajahi Sumber

上传下载提交

yunxing 4 tahun lalu
induk
melakukan
a8c21d92dd
3 mengubah file dengan 82 tambahan dan 3 penghapusan
  1. 8 0
      src/api/equipmentList.js
  2. 15 3
      src/api/httputils.js
  3. 59 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)
+}

+ 15 - 3
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) => {
@@ -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,10 +171,11 @@ export default {
             throw err
         }
     },
-    download(url, requestData) {
+    download(url, params) {
         // 响应类型:arraybuffer, blob
         axiosservice
-            .post(url, requestData, {
+            .get(url,  {
+                params,
                 responseType: 'blob',
             })
             .then((resp) => {

+ 59 - 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,55 @@ 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 })
+        },
         // 查询tab页
         tabSyatem(item) {
             this.systemId = item.id