From 6d9e8a35d81e6d1feb2136690661d43c6cfd53b7 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期二, 05 三月 2024 18:11:35 +0800
Subject: [PATCH] Excel导入部分

---
 src/views/scenery/sceneryOperationData/index.vue |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/src/views/scenery/sceneryOperationData/index.vue b/src/views/scenery/sceneryOperationData/index.vue
index 518eb93..4ed518f 100644
--- a/src/views/scenery/sceneryOperationData/index.vue
+++ b/src/views/scenery/sceneryOperationData/index.vue
@@ -38,6 +38,9 @@
           <el-col :span="1.5">
             <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['demo:sceneryOperationData:export']">瀵煎嚭</el-button>
           </el-col>
+          <el-col :span="1.5">
+            <el-button type="info" plain icon="Top" @click="handleImport" v-hasPermi="['demo:sceneryOperationData:importTemplate']">瀵煎叆</el-button>
+          </el-col>
           <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
         </el-row>
       </template>
@@ -129,6 +132,39 @@
         <div class="dialog-footer">
           <el-button :loading="buttonLoading" type="primary" @click="submitForm">纭� 瀹�</el-button>
           <el-button @click="cancel">鍙� 娑�</el-button>
+        </div>
+      </template>
+    </el-dialog>
+
+    <!-- 鏁版嵁瀵煎叆瀵硅瘽妗� -->
+    <el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
+      <el-upload
+        ref="uploadRef"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url + '?updateSupport=' + upload.updateSupport"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :auto-upload="false"
+        drag
+      >
+        <el-icon class="el-icon--upload">
+          <i-ep-upload-filled />
+        </el-icon>
+        <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
+        <template #tip>
+          <div class="text-center el-upload__tip">
+            <span>浠呭厑璁稿鍏ls銆亁lsx鏍煎紡鏂囦欢銆�</span>
+            <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">涓嬭浇妯℃澘</el-link>
+          </div>
+        </template>
+      </el-upload>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary" @click="submitFileForm">纭� 瀹�</el-button>
+          <el-button @click="upload.open = false">鍙� 娑�</el-button>
         </div>
       </template>
     </el-dialog>
@@ -358,4 +394,53 @@
   }
 }
 
+import { globalHeaders } from "@/utils/request";
+/*** 瀵煎叆鍙傛暟 */
+const upload = reactive<ImportOption>({
+  // 鏄惁鏄剧ず寮瑰嚭灞傦紙瀵煎叆锛�
+  open: false,
+  // 寮瑰嚭灞傛爣棰橈紙瀵煎叆锛�
+  title: "",
+  // 鏄惁绂佺敤涓婁紶
+  isUploading: false,
+  // 鏄惁鏇存柊宸茬粡瀛樺湪鐨勭敤鎴锋暟鎹�
+  updateSupport: 0,
+  // 璁剧疆涓婁紶鐨勮姹傚ご閮�
+  headers: globalHeaders(),
+  // 涓婁紶鐨勫湴鍧�
+  url: import.meta.env.VITE_APP_BASE_API + "/demo/sceneryOperationData/importData"
+})
+/** 涓嬭浇妯℃澘鎿嶄綔 */
+const importTemplate = () => {
+  proxy?.download("demo/sceneryOperationData/importTemplate", {
+  }, `鏅尯杩愯鏁版嵁瀵煎叆妯℃澘_${new Date().getTime()}.xlsx`);
+}
+
+/** 瀵煎叆鎸夐挳鎿嶄綔 */
+const handleImport = () => {
+  upload.title = "鐢ㄦ埛瀵煎叆";
+  upload.open = true;
+}
+
+/**鏂囦欢涓婁紶涓鐞� */
+const handleFileUploadProgress = () => {
+  upload.isUploading = true;
+}
+
+const uploadRef = ref<ElUploadInstance>();
+
+/** 鏂囦欢涓婁紶鎴愬姛澶勭悊 */
+const handleFileSuccess = (response: any, file: UploadFile) => {
+  upload.open = false;
+  upload.isUploading = false;
+  uploadRef.value?.handleRemove(file);
+  ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "瀵煎叆缁撴灉", { dangerouslyUseHTMLString: true });
+  getList();
+}
+
+/** 鎻愪氦涓婁紶鏂囦欢 */
+function submitFileForm() {
+  uploadRef.value?.submit();
+}
+
 </script>

--
Gitblit v1.8.0