From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目

---
 src/views/system/user/UserImportForm.vue |  138 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/src/views/system/user/UserImportForm.vue b/src/views/system/user/UserImportForm.vue
new file mode 100644
index 0000000..5cf1129
--- /dev/null
+++ b/src/views/system/user/UserImportForm.vue
@@ -0,0 +1,138 @@
+<template>
+  <Dialog v-model="dialogVisible" title="鐢ㄦ埛瀵煎叆" width="400">
+    <el-upload
+      ref="uploadRef"
+      v-model:file-list="fileList"
+      :action="importUrl + '?updateSupport=' + updateSupport"
+      :auto-upload="false"
+      :disabled="formLoading"
+      :headers="uploadHeaders"
+      :limit="1"
+      :on-error="submitFormError"
+      :on-exceed="handleExceed"
+      :on-success="submitFormSuccess"
+      accept=".xlsx, .xls"
+      drag
+    >
+      <Icon icon="ep:upload" />
+      <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div>
+      <template #tip>
+        <div class="el-upload__tip text-center">
+          <div class="el-upload__tip">
+            <el-checkbox v-model="updateSupport" />
+            鏄惁鏇存柊宸茬粡瀛樺湪鐨勭敤鎴锋暟鎹�
+          </div>
+          <span>浠呭厑璁稿鍏� xls銆亁lsx 鏍煎紡鏂囦欢銆�</span>
+          <el-link
+            :underline="false"
+            style="font-size: 12px; vertical-align: baseline"
+            type="primary"
+            @click="importTemplate"
+          >
+            涓嬭浇妯℃澘
+          </el-link>
+        </div>
+      </template>
+    </el-upload>
+    <template #footer>
+      <el-button :disabled="formLoading" type="primary" @click="submitForm">纭� 瀹�</el-button>
+      <el-button @click="dialogVisible = false">鍙� 娑�</el-button>
+    </template>
+  </Dialog>
+</template>
+<script lang="ts" setup>
+import * as UserApi from '@/api/system/user'
+import { getAccessToken, getTenantId } from '@/utils/auth'
+import download from '@/utils/download'
+
+defineOptions({ name: 'SystemUserImportForm' })
+
+const message = useMessage() // 娑堟伅寮圭獥
+
+const dialogVisible = ref(false) // 寮圭獥鐨勬槸鍚﹀睍绀�
+const formLoading = ref(false) // 琛ㄥ崟鐨勫姞杞戒腑
+const uploadRef = ref()
+const importUrl =
+  import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/system/user/import'
+const uploadHeaders = ref() // 涓婁紶 Header 澶�
+const fileList = ref([]) // 鏂囦欢鍒楄〃
+const updateSupport = ref(0) // 鏄惁鏇存柊宸茬粡瀛樺湪鐨勭敤鎴锋暟鎹�
+
+/** 鎵撳紑寮圭獥 */
+const open = () => {
+  dialogVisible.value = true
+  updateSupport.value = 0
+  fileList.value = []
+  resetForm()
+}
+defineExpose({ open }) // 鎻愪緵 open 鏂规硶锛岀敤浜庢墦寮�寮圭獥
+
+/** 鎻愪氦琛ㄥ崟 */
+const submitForm = async () => {
+  if (fileList.value.length == 0) {
+    message.error('璇蜂笂浼犳枃浠�')
+    return
+  }
+  // 鎻愪氦璇锋眰
+  uploadHeaders.value = {
+    Authorization: 'Bearer ' + getAccessToken(),
+    'tenant-id': getTenantId()
+  }
+  formLoading.value = true
+  uploadRef.value!.submit()
+}
+
+/** 鏂囦欢涓婁紶鎴愬姛 */
+const emits = defineEmits(['success'])
+const submitFormSuccess = (response: any) => {
+  if (response.code !== 0) {
+    message.error(response.msg)
+    resetForm()
+    return
+  }
+  // 鎷兼帴鎻愮ず璇�
+  const data = response.data
+  let text = '涓婁紶鎴愬姛鏁伴噺锛�' + data.createUsernames.length + ';'
+  for (let username of data.createUsernames) {
+    text += '< ' + username + ' >'
+  }
+  text += '鏇存柊鎴愬姛鏁伴噺锛�' + data.updateUsernames.length + ';'
+  for (const username of data.updateUsernames) {
+    text += '< ' + username + ' >'
+  }
+  text += '鏇存柊澶辫触鏁伴噺锛�' + Object.keys(data.failureUsernames).length + ';'
+  for (const username in data.failureUsernames) {
+    text += '< ' + username + ': ' + data.failureUsernames[username] + ' >'
+  }
+  message.alert(text)
+  formLoading.value = false
+  dialogVisible.value = false
+  // 鍙戦�佹搷浣滄垚鍔熺殑浜嬩欢
+  emits('success')
+}
+
+/** 涓婁紶閿欒鎻愮ず */
+const submitFormError = (): void => {
+  message.error('涓婁紶澶辫触锛岃鎮ㄩ噸鏂颁笂浼狅紒')
+  formLoading.value = false
+}
+
+/** 閲嶇疆琛ㄥ崟 */
+const resetForm = async (): Promise<void> => {
+  // 閲嶇疆涓婁紶鐘舵�佸拰鏂囦欢
+  formLoading.value = false
+  await nextTick()
+  uploadRef.value?.clearFiles()
+}
+
+/** 鏂囦欢鏁拌秴鍑烘彁绀� */
+const handleExceed = (): void => {
+  message.error('鏈�澶氬彧鑳戒笂浼犱竴涓枃浠讹紒')
+}
+
+/** 涓嬭浇妯℃澘鎿嶄綔 */
+const importTemplate = async () => {
+  const res = await UserApi.importUserTemplate()
+  download.excel(res, '鐢ㄦ埛瀵煎叆妯$増.xls')
+}
+</script>

--
Gitblit v1.8.0