|
@@ -106,9 +106,9 @@
|
|
|
import { ref } from 'vue';
|
|
import { ref } from 'vue';
|
|
|
import { genFileId, ElMessage } from 'element-plus';
|
|
import { genFileId, ElMessage } from 'element-plus';
|
|
|
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
|
|
import type { UploadInstance, UploadProps, UploadRawFile } from 'element-plus';
|
|
|
- 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';
|
|
|
|
|
+ import axios, { AxiosRequestConfig } from 'axios';
|
|
|
|
|
|
|
|
const userStore = useUserStore();
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
@@ -146,20 +146,31 @@
|
|
|
};
|
|
};
|
|
|
const upload = ref<UploadInstance>();
|
|
const upload = ref<UploadInstance>();
|
|
|
|
|
|
|
|
- const handleDownload = () => {
|
|
|
|
|
- downloadByUrl({
|
|
|
|
|
- url: './upload-user-templete/templete.xlsx',
|
|
|
|
|
- target: '_self',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const handleDownload = async () => {
|
|
|
|
|
+ //调用后端接口
|
|
|
|
|
+ try {
|
|
|
|
|
+ const config: AxiosRequestConfig = {
|
|
|
|
|
+ headers,
|
|
|
|
|
+ responseType: 'blob',
|
|
|
|
|
+ };
|
|
|
|
|
+ const response = await axios.get('/api/user/downloadExcel', config);
|
|
|
|
|
+ const blob = new Blob([response.data], {
|
|
|
|
|
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
|
|
+ });
|
|
|
|
|
+ // 创建下载链接
|
|
|
|
|
+ let downloadLink: HTMLAnchorElement | null = document.createElement('a');
|
|
|
|
|
+ const url = window.URL.createObjectURL(blob);
|
|
|
|
|
+ downloadLink.href = url;
|
|
|
|
|
+ downloadLink.download = '批量导入模板(重命名请加后缀.xlsm).xlsm';
|
|
|
|
|
+ downloadLink.click();
|
|
|
|
|
+ // 移除下载链接
|
|
|
|
|
+ window.URL.revokeObjectURL(url);
|
|
|
|
|
+ downloadLink = null;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('Error downloading file:', error);
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 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();
|
|
|
};
|
|
};
|
|
@@ -178,12 +189,9 @@
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleUploadSuccess = (response, _file, _fileList) => {
|
|
const handleUploadSuccess = (response, _file, _fileList) => {
|
|
|
- // const res = JSON.parse(response);
|
|
|
|
|
- console.log('response', response);
|
|
|
|
|
isSuc.value = response.data.isSuc;
|
|
isSuc.value = response.data.isSuc;
|
|
|
errDetail.value = response.data.failedInfo;
|
|
errDetail.value = response.data.failedInfo;
|
|
|
sucCount.value = response.data.sucCount || 0;
|
|
sucCount.value = response.data.sucCount || 0;
|
|
|
- console.log('errDetail', errDetail.value);
|
|
|
|
|
|
|
|
|
|
if (isSuc.value) {
|
|
if (isSuc.value) {
|
|
|
DialogVisibleSuc.value = true;
|
|
DialogVisibleSuc.value = true;
|