Commit 4cceac9c0d70d2ba61bb938b8b0b6f30bc08003e
1 parent
d43a6e0b
fix: 修复设备导入时,模版下载是XLSX的文件类型,然后上传一个CSV的文件格式,提示服务器500,前端过滤只能导入跟模版文件一致的类型,图二读出来的数据必填
Showing
4 changed files
with
20 additions
and
0 deletions
@@ -60,3 +60,8 @@ export function dateFormat(date, block) { | @@ -60,3 +60,8 @@ export function dateFormat(date, block) { | ||
60 | }); | 60 | }); |
61 | return format; | 61 | return format; |
62 | } | 62 | } |
63 | + | ||
64 | +// 获取上传文件后缀 | ||
65 | +export const fileSuffix = (fileName: string) => { | ||
66 | + return fileName.split('.').pop(); | ||
67 | +}; |
@@ -97,3 +97,5 @@ export function isUrl(path: string): boolean { | @@ -97,3 +97,5 @@ export function isUrl(path: string): boolean { | ||
97 | /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; | 97 | /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; |
98 | return reg.test(path); | 98 | return reg.test(path); |
99 | } | 99 | } |
100 | + | ||
101 | +export const isXlsxFile = (name: string) => name === 'xlsx'; |
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | import { ColumnDataRecord, Options, UploadFileParseValue } from './type'; | 14 | import { ColumnDataRecord, Options, UploadFileParseValue } from './type'; |
15 | import { DEVICE_NAME_INDEX } from './const'; | 15 | import { DEVICE_NAME_INDEX } from './const'; |
16 | import { buildUUID } from '/@/utils/uuid'; | 16 | import { buildUUID } from '/@/utils/uuid'; |
17 | + import { useMessage } from '/@/hooks/web/useMessage'; | ||
17 | 18 | ||
18 | const props = defineProps({ | 19 | const props = defineProps({ |
19 | ...basicProps, | 20 | ...basicProps, |
@@ -29,6 +30,8 @@ | @@ -29,6 +30,8 @@ | ||
29 | 30 | ||
30 | const emit = defineEmits(['update:value']); | 31 | const emit = defineEmits(['update:value']); |
31 | 32 | ||
33 | + const { createMessage } = useMessage(); | ||
34 | + | ||
32 | const columnTypeRepeatWhiteList = [ | 35 | const columnTypeRepeatWhiteList = [ |
33 | ColumTypeEnum.SERVER_ATTRIBUTE, | 36 | ColumTypeEnum.SERVER_ATTRIBUTE, |
34 | ColumTypeEnum.SHARED_ATTRIBUTE, | 37 | ColumTypeEnum.SHARED_ATTRIBUTE, |
@@ -104,8 +107,13 @@ | @@ -104,8 +107,13 @@ | ||
104 | props.goPreviousStep?.(); | 107 | props.goPreviousStep?.(); |
105 | }; | 108 | }; |
106 | 109 | ||
110 | + const hasEmpty = (columns: Recordable[]) => { | ||
111 | + return columns.some((column) => !column.type); | ||
112 | + }; | ||
113 | + | ||
107 | const handleGoNextStep = () => { | 114 | const handleGoNextStep = () => { |
108 | const columns = getDataSource<ColumnDataRecord>().map((item) => ({ type: item.type })); | 115 | const columns = getDataSource<ColumnDataRecord>().map((item) => ({ type: item.type })); |
116 | + if (hasEmpty(columns)) return createMessage.error('列类型必选'); | ||
109 | emit('update:value', columns); | 117 | emit('update:value', columns); |
110 | props.goNextStep?.(); | 118 | props.goNextStep?.(); |
111 | }; | 119 | }; |
@@ -7,6 +7,8 @@ | @@ -7,6 +7,8 @@ | ||
7 | import { UploadFileParseValue } from './type'; | 7 | import { UploadFileParseValue } from './type'; |
8 | import { useMessage } from '/@/hooks/web/useMessage'; | 8 | import { useMessage } from '/@/hooks/web/useMessage'; |
9 | import { readCsvFile, readXLSXFile } from './config'; | 9 | import { readCsvFile, readXLSXFile } from './config'; |
10 | + import { fileSuffix } from '/@/utils/common/compUtils'; | ||
11 | + import { isXlsxFile } from '/@/utils/is'; | ||
10 | 12 | ||
11 | const props = defineProps({ | 13 | const props = defineProps({ |
12 | ...basicProps, | 14 | ...basicProps, |
@@ -41,6 +43,9 @@ | @@ -41,6 +43,9 @@ | ||
41 | }; | 43 | }; |
42 | 44 | ||
43 | const handleParseFile = async ({ file, onSuccess, onError }: FileRequestParams) => { | 45 | const handleParseFile = async ({ file, onSuccess, onError }: FileRequestParams) => { |
46 | + if (!isXlsxFile(fileSuffix(file.name)!.toLowerCase())) { | ||
47 | + return createMessage.error('请检查文件类型是否正确'); | ||
48 | + } | ||
44 | const value = await readFile(file); | 49 | const value = await readFile(file); |
45 | if (!value) { | 50 | if (!value) { |
46 | onError(); | 51 | onError(); |