From 398794afbbe0696e763aa002313dcf4c3b82420c Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: Tue, 30 Jun 2026 08:35:44 +0800
Subject: [PATCH] 中科大支线—用户导入
---
.env.development | 4 +-
public/files/userExcel.xlsx | 0
src/api/hazardousChemicals/user.js | 8 ++++
src/views/hazardousChemicals/systemManage/user/index.vue | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 114 insertions(+), 4 deletions(-)
diff --git a/.env.development b/.env.development
index 4ae6cac..de98814 100644
--- a/.env.development
+++ b/.env.development
@@ -7,6 +7,6 @@
# 危化品全生命周期管理/开发环境
#董
-#VITE_APP_BASE_API = 'http://192.168.2.152:8083/api'
+VITE_APP_BASE_API = 'http://192.168.2.152:8005/api'
#线上
-VITE_APP_BASE_API = 'http://106.15.95.149:8005/api'
+#VITE_APP_BASE_API = 'http://106.15.95.149:8005/api'
diff --git a/public/files/userExcel.xlsx b/public/files/userExcel.xlsx
new file mode 100644
index 0000000..27f2e52
--- /dev/null
+++ b/public/files/userExcel.xlsx
Binary files differ
diff --git a/src/api/hazardousChemicals/user.js b/src/api/hazardousChemicals/user.js
index 25bacd6..ac0303c 100644
--- a/src/api/hazardousChemicals/user.js
+++ b/src/api/hazardousChemicals/user.js
@@ -45,3 +45,11 @@
method: 'put'
})
}
+
+export function uploadTemplate(data) {
+ return request({
+ url: '/system/user/importExcel',
+ method: 'post',
+ data: data
+ })
+}
diff --git a/src/views/hazardousChemicals/systemManage/user/index.vue b/src/views/hazardousChemicals/systemManage/user/index.vue
index 79afaf4..538fd82 100644
--- a/src/views/hazardousChemicals/systemManage/user/index.vue
+++ b/src/views/hazardousChemicals/systemManage/user/index.vue
@@ -23,6 +23,10 @@
plain
@click="reset"
>重置</el-button>
+ <el-button
+ type="primary"
+ @click="exportUser"
+ >导入</el-button>
</el-form-item>
</el-form>
</div>
@@ -61,6 +65,39 @@
/>
<user-dialog ref="dialogRef" @getList=getList></user-dialog>
+ <el-dialog
+ v-model="data.exportDialog"
+ title="导入模板"
+ width="550px"
+ :before-close="handleCloseExport"
+ :close-on-press-escape="false"
+ :close-on-click-modal="false"
+ >
+ <el-form :model="state.form" size="default" ref="superRef" :rules="state.formRules" label-width="110px" >
+ <el-form-item label="表格模板:" >
+ <el-button @click="downloadFileTable" size="default" type="primary" plain>下载模板</el-button>
+ </el-form-item>
+ <el-form-item label="导入文件" prop="filePath">
+ <el-upload
+ accept=".xlsx,.xls"
+ :before-upload="beforeUpload"
+ v-model:file-list="state.exportFileList"
+ action="#"
+ :auto-upload="false"
+ :on-change="handleChange"
+ style="width: 100%"
+ >
+ <el-button size="default" type="primary">点击上传</el-button>
+ </el-upload>
+ </el-form-item>
+ </el-form>
+ <template #footer>
+ <span class="dialog-footer">
+ <el-button @click="handleCloseExport" size="default">取 消</el-button>
+ <el-button type="primary" @click="onUpload" size="default">确定</el-button>
+ </span>
+ </template>
+ </el-dialog>
</div>
</template>
@@ -68,7 +105,7 @@
import {getCurrentInstance, onMounted, onUnmounted, reactive, ref, toRefs} from "vue";
import {ElMessage, ElMessageBox} from "element-plus";
import userDialog from './components/userDialog.vue'
-import {delUser, getUser} from "@/api/hazardousChemicals/user";
+import {delUser, getUser, uploadTemplate} from "@/api/hazardousChemicals/user";
import Cookies from "js-cookie";
@@ -84,6 +121,7 @@
},
total: 0,
dataList: [],
+ exportDialog: false,
userTypeList: [
{
id: 0,
@@ -109,6 +147,18 @@
});
+const state = reactive({
+ form: {
+ id: null,
+ filePath: '',
+ companyId: null
+ },
+ formRules:{
+ companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
+ filePath: [{ required: true, message: '请上传文件', trigger: 'blur' }]
+ },
+ exportFileList: [],
+})
const isAdmin = ref(false)
const { queryParams, total, dataList } = toRefs(data);
const userInfo = ref()
@@ -168,5 +218,57 @@
}
})
}
-
+const exportUser = () => {
+ data.exportDialog = true
+}
+const handleCloseExport = () => {
+ state.exportFileList = []
+ data.exportDialog = false
+}
+const beforeUpload = (file) => {
+ state.exportFileList = [...state.exportFileList, file]
+ state.exportFileList = state.exportFileList.slice(-1)
+ return false;
+}
+const fileBinaryList = ref([])
+const handleChange = (file, files) => {
+ fileBinaryList.value = files;
+};
+const downloadFileTable = () => {
+ const filePath = '/files/userExcel.xlsx';
+ const link = document.createElement('a');
+ link.href = filePath;
+ link.download = filePath.substr(filePath.lastIndexOf('/') + 1);
+ link.click();
+}
+const onUpload = async () => {
+ if(state.exportFileList.length == 0){
+ ElMessage({
+ type: 'warning',
+ message: '请先上传表格文件'
+ });
+ return
+ }else{
+ const formData = new FormData();
+ fileBinaryList.value.forEach((file) => {
+ formData.append('file', file.raw)
+ })
+ console.log('form',formData)
+ const res = await uploadTemplate(formData)
+ if(res.code == 200){
+ ElMessage({
+ type: 'success',
+ message: '导入成功'
+ });
+ state.exportFileList = []
+ data.exportDialog = false
+ await getList()
+ }else{
+ ElMessage({
+ type: 'error',
+ message: res.message
+ });
+ }
+ }
+}
</script>
--
Gitblit v1.9.2