Showing
4 changed files
with
46 additions
and
9 deletions
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { Button } from 'ant-design-vue'; |
3 | - import { nextTick, onMounted, ref } from 'vue'; | |
3 | + import { computed, nextTick, onMounted } from 'vue'; | |
4 | 4 | import { basicInfoForm, FieldsEnum } from './config'; |
5 | 5 | import { basicProps } from './props'; |
6 | 6 | import StepContainer from './StepContainer.vue'; |
... | ... | @@ -15,7 +15,14 @@ |
15 | 15 | |
16 | 16 | const emit = defineEmits(['update:value']); |
17 | 17 | |
18 | - const canGoNext = ref(false); | |
18 | + const canGoNext = computed(() => { | |
19 | + const values = props.value as Recordable; | |
20 | + return ( | |
21 | + Reflect.has(values, FieldsEnum.ORGANIZATION_ID) && | |
22 | + Reflect.has(values, FieldsEnum.TK_DEVICE_PROFILE_ID) && | |
23 | + Reflect.has(values, FieldsEnum.DEVICE_TYPE) | |
24 | + ); | |
25 | + }); | |
19 | 26 | const [register, { getFieldsValue, setFieldsValue }] = useForm({ |
20 | 27 | schemas: basicInfoForm, |
21 | 28 | layout: 'vertical', |
... | ... | @@ -23,9 +30,7 @@ |
23 | 30 | submitFunc: async () => { |
24 | 31 | await nextTick(); |
25 | 32 | const values = getFieldsValue() || {}; |
26 | - canGoNext.value = | |
27 | - Reflect.has(values, FieldsEnum.ORGANIZATION_ID) && | |
28 | - Reflect.has(values, FieldsEnum.TK_DEVICE_PROFILE_ID); | |
33 | + emit('update:value', values); | |
29 | 34 | }, |
30 | 35 | }); |
31 | 36 | ... | ... |
... | ... | @@ -245,4 +245,20 @@ export const columnTypeSchema: BasicColumn[] = [ |
245 | 245 | }, |
246 | 246 | ]; |
247 | 247 | |
248 | -export const assemblyData = () => {}; | |
248 | +export const csvTemplate = `name,username,password | |
249 | +Device 11,admin,password | |
250 | +Device 22,admin1,password1 | |
251 | +`; | |
252 | + | |
253 | +export const downloadFile = (data: string, fileName: string, type: string, ext: string) => { | |
254 | + const blob = new Blob([data], { type: type }); | |
255 | + const objectURL = URL.createObjectURL(blob); | |
256 | + const element = document.createElement('a'); | |
257 | + element.href = objectURL; | |
258 | + element.download = `${fileName}.${ext}`; | |
259 | + element.style.display = 'none'; | |
260 | + document.body.appendChild(element); | |
261 | + element.click(); | |
262 | + element.remove(); | |
263 | + URL.revokeObjectURL(objectURL); | |
264 | +}; | ... | ... |
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { computed, ref, unref } from 'vue'; |
3 | 3 | import { BasicModal, useModal } from '/@/components/Modal'; |
4 | - import { Steps } from 'ant-design-vue'; | |
4 | + import { Steps, Button, Tooltip } from 'ant-design-vue'; | |
5 | 5 | import BasicInfoForm from './BasicInfoForm.vue'; |
6 | 6 | import ImportCsv from './ImportCsv.vue'; |
7 | 7 | import { CreateEntityValue, UploadFileParseValue } from './type'; |
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | import CreateEntity from './CreateEntity.vue'; |
10 | 10 | import CompleteResult from './CompleteResult.vue'; |
11 | 11 | import { ImportDeviceResponse } from '/@/api/device/model/batchImportModel'; |
12 | + import { csvTemplate, downloadFile } from './config'; | |
12 | 13 | |
13 | 14 | const emit = defineEmits(['importFinally']); |
14 | 15 | |
... | ... | @@ -73,6 +74,10 @@ |
73 | 74 | reset(); |
74 | 75 | return true; |
75 | 76 | }; |
77 | + | |
78 | + const handleTemplateDownload = () => { | |
79 | + downloadFile(csvTemplate, 'template', 'text/csv', 'csv'); | |
80 | + }; | |
76 | 81 | </script> |
77 | 82 | |
78 | 83 | <template> |
... | ... | @@ -86,7 +91,7 @@ |
86 | 91 | :close-func="handleCancel" |
87 | 92 | :destroy-on-close="true" |
88 | 93 | > |
89 | - <section class="overflow-auto"> | |
94 | + <section class="overflow-auto relative"> | |
90 | 95 | <Steps direction="vertical" :current="currentStep"> |
91 | 96 | <Steps.Step |
92 | 97 | v-for="item in Object.keys(StepsEnum).filter((key) => isNaN(key as unknown as number))" |
... | ... | @@ -132,6 +137,17 @@ |
132 | 137 | </template> |
133 | 138 | </Steps.Step> |
134 | 139 | </Steps> |
140 | + <Tooltip | |
141 | + title="模板表头的第一列为设备名称,且不能重复,如需预置访问凭证(ACCESS_TOKEN、MQTT client ID、MQTT user name、MQTT password)添加新的列即可。例如:username、password" | |
142 | + > | |
143 | + <Button | |
144 | + type="text" | |
145 | + class="!absolute top-0 right-0 !text-blue-400" | |
146 | + @click="handleTemplateDownload" | |
147 | + > | |
148 | + 模版下载 | |
149 | + </Button> | |
150 | + </Tooltip> | |
135 | 151 | </section> |
136 | 152 | </BasicModal> |
137 | 153 | </template> | ... | ... |