|
@@ -11,13 +11,18 @@
|
|
|
<el-upload
|
|
<el-upload
|
|
|
ref="upload"
|
|
ref="upload"
|
|
|
class="upload-demo"
|
|
class="upload-demo"
|
|
|
|
|
+ :multiple="false"
|
|
|
|
|
+ :limit="1"
|
|
|
drag
|
|
drag
|
|
|
action="http://localhost:8092/api/user/import"
|
|
action="http://localhost:8092/api/user/import"
|
|
|
:headers="headers"
|
|
:headers="headers"
|
|
|
:with-credentials="true"
|
|
:with-credentials="true"
|
|
|
:auto-upload="false"
|
|
:auto-upload="false"
|
|
|
|
|
+ :on-exceed="handleExceed"
|
|
|
:before-upload="beforeUpload"
|
|
:before-upload="beforeUpload"
|
|
|
:on-success="handleUploadSuccess"
|
|
:on-success="handleUploadSuccess"
|
|
|
|
|
+ :on-exceed="handleExceed"
|
|
|
|
|
+ :limit="1"
|
|
|
style="width: 384px; height: 192px; border-radius: 8px"
|
|
style="width: 384px; height: 192px; border-radius: 8px"
|
|
|
>
|
|
>
|
|
|
<el-icon class="el-icon--upload" style="width: 33px; height: 42px"><Document /></el-icon>
|
|
<el-icon class="el-icon--upload" style="width: 33px; height: 42px"><Document /></el-icon>
|
|
@@ -101,7 +106,8 @@
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import { Close, Document, CircleCheck, Warning } from '@element-plus/icons-vue';
|
|
import { Close, Document, CircleCheck, Warning } from '@element-plus/icons-vue';
|
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
|
- import type { UploadInstance } from 'element-plus';
|
|
|
|
|
|
|
+ import { genFileId, ElMessage } from 'element-plus';
|
|
|
|
|
+ import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
|
|
|
import { downloadByUrl } from '@/utils/file/download';
|
|
import { downloadByUrl } from '@/utils/file/download';
|
|
|
import { useUserStore } from '@/store/modules/user';
|
|
import { useUserStore } from '@/store/modules/user';
|
|
|
import { onMounted } from 'vue';
|
|
import { onMounted } from 'vue';
|
|
@@ -148,6 +154,14 @@
|
|
|
target: '_self',
|
|
target: '_self',
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ const handleExceed: UploadProps['onExceed'] = (files) => {
|
|
|
|
|
+ upload.value!.clearFiles();
|
|
|
|
|
+ const file = files[0] as UploadRawFile;
|
|
|
|
|
+ file.uid = genFileId();
|
|
|
|
|
+ upload.value!.handleStart(file);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const handleImport = async () => {
|
|
const handleImport = async () => {
|
|
|
upload.value!.submit();
|
|
upload.value!.submit();
|
|
|
};
|
|
};
|
|
@@ -156,6 +170,10 @@
|
|
|
const isExcel = /\.(xlsx|xls)$/.test(file.name.toLowerCase());
|
|
const isExcel = /\.(xlsx|xls)$/.test(file.name.toLowerCase());
|
|
|
if (!isExcel) {
|
|
if (!isExcel) {
|
|
|
// 提示用户选择正确的文件类型
|
|
// 提示用户选择正确的文件类型
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '仅支持上传.xlsx .xls格式文件',
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ });
|
|
|
return false; // 阻止上传
|
|
return false; // 阻止上传
|
|
|
}
|
|
}
|
|
|
return true; // 允许上传
|
|
return true; // 允许上传
|
|
@@ -190,6 +208,13 @@
|
|
|
emits('change');
|
|
emits('change');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const handleExceed: UploadProps['onExceed'] = (files) => {
|
|
|
|
|
+ upload.value!.clearFiles();
|
|
|
|
|
+ const file = files[0] as UploadRawFile;
|
|
|
|
|
+ file.uid = genFileId();
|
|
|
|
|
+ upload.value!.handleStart(file);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
//对话框
|
|
//对话框
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|