Commit 4cceac9c0d70d2ba61bb938b8b0b6f30bc08003e

Authored by fengtao
1 parent d43a6e0b

fix: 修复设备导入时,模版下载是XLSX的文件类型,然后上传一个CSV的文件格式,提示服务器500,前端过滤只能导入跟模版文件一致的类型,图二读出来的数据必填

... ... @@ -60,3 +60,8 @@ export function dateFormat(date, block) {
60 60 });
61 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 97 /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/;
98 98 return reg.test(path);
99 99 }
  100 +
  101 +export const isXlsxFile = (name: string) => name === 'xlsx';
... ...
... ... @@ -14,6 +14,7 @@
14 14 import { ColumnDataRecord, Options, UploadFileParseValue } from './type';
15 15 import { DEVICE_NAME_INDEX } from './const';
16 16 import { buildUUID } from '/@/utils/uuid';
  17 + import { useMessage } from '/@/hooks/web/useMessage';
17 18
18 19 const props = defineProps({
19 20 ...basicProps,
... ... @@ -29,6 +30,8 @@
29 30
30 31 const emit = defineEmits(['update:value']);
31 32
  33 + const { createMessage } = useMessage();
  34 +
32 35 const columnTypeRepeatWhiteList = [
33 36 ColumTypeEnum.SERVER_ATTRIBUTE,
34 37 ColumTypeEnum.SHARED_ATTRIBUTE,
... ... @@ -104,8 +107,13 @@
104 107 props.goPreviousStep?.();
105 108 };
106 109
  110 + const hasEmpty = (columns: Recordable[]) => {
  111 + return columns.some((column) => !column.type);
  112 + };
  113 +
107 114 const handleGoNextStep = () => {
108 115 const columns = getDataSource<ColumnDataRecord>().map((item) => ({ type: item.type }));
  116 + if (hasEmpty(columns)) return createMessage.error('列类型必选');
109 117 emit('update:value', columns);
110 118 props.goNextStep?.();
111 119 };
... ...
... ... @@ -7,6 +7,8 @@
7 7 import { UploadFileParseValue } from './type';
8 8 import { useMessage } from '/@/hooks/web/useMessage';
9 9 import { readCsvFile, readXLSXFile } from './config';
  10 + import { fileSuffix } from '/@/utils/common/compUtils';
  11 + import { isXlsxFile } from '/@/utils/is';
10 12
11 13 const props = defineProps({
12 14 ...basicProps,
... ... @@ -41,6 +43,9 @@
41 43 };
42 44
43 45 const handleParseFile = async ({ file, onSuccess, onError }: FileRequestParams) => {
  46 + if (!isXlsxFile(fileSuffix(file.name)!.toLowerCase())) {
  47 + return createMessage.error('请检查文件类型是否正确');
  48 + }
44 49 const value = await readFile(file);
45 50 if (!value) {
46 51 onError();
... ...