Explorar o código

工程现场 管理界面修改

zhanghao hai 2 meses
pai
achega
91349595c0

+ 9 - 0
src/api/zcustom/project.js

@@ -51,3 +51,12 @@ export function delProject(id) {
     method: 'get'
   })
 }
+
+// 导入excel
+export function uploadExcel(file) {
+  return request({
+    url: '/zcustom/project/upload',
+    data: file,
+    method: 'post'
+  })
+}

+ 0 - 1
src/views/zcustom/land/index.vue

@@ -383,7 +383,6 @@ export default {
       this.$refs.fileInput.click()
     },
     handleFileChange(event) {
-      console.log("734888888888")
       const selectedFile = event.target.files[0];
       const formData = new FormData();
       formData.append('file', selectedFile);

+ 33 - 1
src/views/zcustom/project/index.vue

@@ -41,6 +41,15 @@
           @click="handleDelete"
         >删除</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          icon="el-icon-upload"
+          size="mini"
+          @click="handleUpload"
+        >导入</el-button>
+      </el-col>
+      <input ref="fileInput" type="file" @change="handleFileChange" accept=".xls,.xlsx" v-show="false"></input>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -145,7 +154,7 @@
 </template>
 
 <script>
-import { listProject, getProject, delProject, addProject, updateProject } from "@/api/zcustom/project";
+import { listProject, getProject, delProject, addProject, updateProject, uploadExcel} from "@/api/zcustom/project";
 import { getListTree, listPlatAppOrg } from '@/api/zcustom/platAppOrg'
 
 export default {
@@ -386,6 +395,29 @@ export default {
         this.$modal.msgSuccess("删除成功");
       }).catch(() => {});
     },
+
+    /** 导入按钮操作 */
+    handleUpload() {
+      this.$refs.fileInput.click()
+    },
+
+    handleFileChange(event) {
+      const selectedFile = event.target.files[0];
+      const fileName = selectedFile.name.toLowerCase();
+      const allowedExtensions = /\.(xls|xlsx)$/i;
+      if (allowedExtensions.test(fileName)) {
+        const formData = new FormData();
+        formData.append('file', selectedFile);
+        uploadExcel(formData).then(res =>{
+          if (res.code === 200){
+            this.$modal.msgSuccess("导入成功");
+          }
+        });
+      }
+      else {
+        this.$modal.msgError("请选择正确的文件格式");
+      }
+    },
   }
 };
 </script>