Showing
4 changed files
with
27 additions
and
25 deletions
@@ -41,6 +41,8 @@ | @@ -41,6 +41,8 @@ | ||
41 | showIndexColumn: false, | 41 | showIndexColumn: false, |
42 | columns: columnTypeSchema, | 42 | columns: columnTypeSchema, |
43 | resizeHeightOffset: -300, | 43 | resizeHeightOffset: -300, |
44 | + maxHeight: 300, | ||
45 | + canResize: false, | ||
44 | }); | 46 | }); |
45 | 47 | ||
46 | const parseValueToTableData = () => { | 48 | const parseValueToTableData = () => { |
@@ -54,7 +56,7 @@ | @@ -54,7 +56,7 @@ | ||
54 | const dataSource = header.map((columnKey, index) => { | 56 | const dataSource = header.map((columnKey, index) => { |
55 | return { | 57 | return { |
56 | [ColumnFileEnum.EXAMPLE_VALUE]: exampleRow[columnKey], | 58 | [ColumnFileEnum.EXAMPLE_VALUE]: exampleRow[columnKey], |
57 | - [ColumnFileEnum.TYPE]: getColumnType(index), | 59 | + [ColumnFileEnum.TYPE]: index < 2 ? getColumnType(index) : null, |
58 | [ColumnFileEnum.KEY]: columnKey, | 60 | [ColumnFileEnum.KEY]: columnKey, |
59 | id: buildUUID(), | 61 | id: buildUUID(), |
60 | } as ColumnDataRecord; | 62 | } as ColumnDataRecord; |
@@ -136,6 +138,8 @@ | @@ -136,6 +138,8 @@ | ||
136 | :disabled="getColumnNeedDisabled(index)" | 138 | :disabled="getColumnNeedDisabled(index)" |
137 | :options="columnTypeOptions" | 139 | :options="columnTypeOptions" |
138 | :dropdown-match-select-width="false" | 140 | :dropdown-match-select-width="false" |
141 | + allow-clear | ||
142 | + placeholder="请选择列类型" | ||
139 | /> | 143 | /> |
140 | </section> | 144 | </section> |
141 | </template> | 145 | </template> |
@@ -165,11 +169,11 @@ | @@ -165,11 +169,11 @@ | ||
165 | .ant-select, | 169 | .ant-select, |
166 | .ant-input, | 170 | .ant-input, |
167 | .ant-select-selector { | 171 | .ant-select-selector { |
168 | - height: 22px !important; | 172 | + height: 30px !important; |
169 | } | 173 | } |
170 | 174 | ||
171 | .ant-select-selection-item { | 175 | .ant-select-selection-item { |
172 | - line-height: 22px !important; | 176 | + line-height: 30px !important; |
173 | } | 177 | } |
174 | } | 178 | } |
175 | </style> | 179 | </style> |
@@ -54,7 +54,7 @@ | @@ -54,7 +54,7 @@ | ||
54 | try { | 54 | try { |
55 | const data = (event.target as FileReader).result as string; | 55 | const data = (event.target as FileReader).result as string; |
56 | 56 | ||
57 | - const result = XLSX.read(data, { type: 'string' }); | 57 | + const result = XLSX.read(data, { type: 'binary' }); |
58 | 58 | ||
59 | const sheetName = result.SheetNames.at(0); | 59 | const sheetName = result.SheetNames.at(0); |
60 | const workbook = result.Sheets; | 60 | const workbook = result.Sheets; |
@@ -72,7 +72,7 @@ | @@ -72,7 +72,7 @@ | ||
72 | resolve({ header, content }); | 72 | resolve({ header, content }); |
73 | } catch (error) { | 73 | } catch (error) { |
74 | const { createMessage } = useMessage(); | 74 | const { createMessage } = useMessage(); |
75 | - createMessage.error('请检查csv文件是否正确'); | 75 | + createMessage.error('请检查xlsx文件是否正确'); |
76 | throw error; | 76 | throw error; |
77 | } | 77 | } |
78 | }; | 78 | }; |
@@ -80,7 +80,7 @@ | @@ -80,7 +80,7 @@ | ||
80 | fileReader.onerror = () => { | 80 | fileReader.onerror = () => { |
81 | reject(false); | 81 | reject(false); |
82 | }; | 82 | }; |
83 | - fileReader.readAsText(file, 'GB2312'); | 83 | + fileReader.readAsBinaryString(file); |
84 | }); | 84 | }); |
85 | }; | 85 | }; |
86 | 86 | ||
@@ -120,7 +120,7 @@ | @@ -120,7 +120,7 @@ | ||
120 | <Upload.Dragger | 120 | <Upload.Dragger |
121 | :fileList="fileList" | 121 | :fileList="fileList" |
122 | :customRequest="handleParseFile" | 122 | :customRequest="handleParseFile" |
123 | - accept=".csv" | 123 | + accept=".xlsx" |
124 | name="file" | 124 | name="file" |
125 | :remove="handleRemove" | 125 | :remove="handleRemove" |
126 | > | 126 | > |
@@ -8,6 +8,7 @@ import { FormSchema } from '/@/components/Form'; | @@ -8,6 +8,7 @@ import { FormSchema } from '/@/components/Form'; | ||
8 | import { BasicColumn } from '/@/components/Table'; | 8 | import { BasicColumn } from '/@/components/Table'; |
9 | import { copyTransFun } from '/@/utils/fnUtils'; | 9 | import { copyTransFun } from '/@/utils/fnUtils'; |
10 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | 10 | import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; |
11 | +import XLSX from 'xlsx'; | ||
11 | 12 | ||
12 | export enum FieldsEnum { | 13 | export enum FieldsEnum { |
13 | ORGANIZATION_ID = 'organizationId', | 14 | ORGANIZATION_ID = 'organizationId', |
@@ -310,6 +311,8 @@ export const generateColumnTypeOptions = () => { | @@ -310,6 +311,8 @@ export const generateColumnTypeOptions = () => { | ||
310 | }; | 311 | }; |
311 | options.push(credentialsOption); | 312 | options.push(credentialsOption); |
312 | 313 | ||
314 | + options.push({ label: '设备名称', value: ColumTypeEnum.NAME }); | ||
315 | + | ||
313 | return options; | 316 | return options; |
314 | }; | 317 | }; |
315 | 318 | ||
@@ -332,19 +335,13 @@ export const columnTypeSchema: BasicColumn[] = [ | @@ -332,19 +335,13 @@ export const columnTypeSchema: BasicColumn[] = [ | ||
332 | }, | 335 | }, |
333 | ]; | 336 | ]; |
334 | 337 | ||
335 | -export const csvTemplate = `设备名称,凭证账号,凭证密码 | ||
336 | -温湿度设备,admin,123456 | ||
337 | -`; | 338 | +export function exportTemplate() { |
339 | + const book = XLSX.utils.book_new(); | ||
340 | + const sheet = XLSX.utils.aoa_to_sheet([ | ||
341 | + ['设备名称', '访问令牌'], | ||
342 | + ['温湿度设备', 'admin'], | ||
343 | + ]); | ||
338 | 344 | ||
339 | -export const downloadFile = (data: string, fileName: string, type: string, ext: string) => { | ||
340 | - const blob = new Blob([data], { type: type }); | ||
341 | - const objectURL = URL.createObjectURL(blob); | ||
342 | - const element = document.createElement('a'); | ||
343 | - element.href = objectURL; | ||
344 | - element.download = `${fileName}.${ext}`; | ||
345 | - element.style.display = 'none'; | ||
346 | - document.body.appendChild(element); | ||
347 | - element.click(); | ||
348 | - element.remove(); | ||
349 | - URL.revokeObjectURL(objectURL); | ||
350 | -}; | 345 | + XLSX.utils.book_append_sheet(book, sheet, '设备导入模版'); |
346 | + XLSX.writeFile(book, 'template.xlsx', { bookType: 'xlsx' }); | ||
347 | +} |
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | import CreateEntity from './CreateEntity.vue'; | 9 | import CreateEntity from './CreateEntity.vue'; |
10 | import CompleteResult from './CompleteResult.vue'; | 10 | import CompleteResult from './CompleteResult.vue'; |
11 | import { ImportDeviceResponse } from '/@/api/device/model/batchImportModel'; | 11 | import { ImportDeviceResponse } from '/@/api/device/model/batchImportModel'; |
12 | - import { csvTemplate, downloadFile } from './config'; | 12 | + import { exportTemplate } from './config'; |
13 | 13 | ||
14 | const emit = defineEmits(['importFinally']); | 14 | const emit = defineEmits(['importFinally']); |
15 | 15 | ||
@@ -79,7 +79,8 @@ | @@ -79,7 +79,8 @@ | ||
79 | }; | 79 | }; |
80 | 80 | ||
81 | const handleTemplateDownload = () => { | 81 | const handleTemplateDownload = () => { |
82 | - downloadFile(csvTemplate, 'template', 'text/csv', 'csv'); | 82 | + exportTemplate(); |
83 | + // downloadFile(csvTemplate, 'template', 'text/csv,chartset=UTF-8', 'csv'); | ||
83 | }; | 84 | }; |
84 | </script> | 85 | </script> |
85 | 86 | ||
@@ -142,7 +143,7 @@ | @@ -142,7 +143,7 @@ | ||
142 | </Steps.Step> | 143 | </Steps.Step> |
143 | </Steps> | 144 | </Steps> |
144 | <Tooltip | 145 | <Tooltip |
145 | - title="模板表头的第一列为设备名称,且不能重复,如需预置访问凭证(ACCESS_TOKEN、MQTT client ID、MQTT user name、MQTT password)添加新的列即可。例如:凭证账号,凭证密码" | 146 | + title="注意:模板表头的第一列为设备名称,第二列为访问令牌。新增列时,名称和访问令牌不能重复。下载的模板建议使用文本打开,如使用wps打开请另外为新的csv文件。" |
146 | > | 147 | > |
147 | <Button | 148 | <Button |
148 | type="text" | 149 | type="text" |