Showing
4 changed files
with
46 additions
and
9 deletions
1 | <script lang="ts" setup> | 1 | <script lang="ts" setup> |
2 | import { Button } from 'ant-design-vue'; | 2 | import { Button } from 'ant-design-vue'; |
3 | - import { nextTick, onMounted, ref } from 'vue'; | 3 | + import { computed, nextTick, onMounted } from 'vue'; |
4 | import { basicInfoForm, FieldsEnum } from './config'; | 4 | import { basicInfoForm, FieldsEnum } from './config'; |
5 | import { basicProps } from './props'; | 5 | import { basicProps } from './props'; |
6 | import StepContainer from './StepContainer.vue'; | 6 | import StepContainer from './StepContainer.vue'; |
@@ -15,7 +15,14 @@ | @@ -15,7 +15,14 @@ | ||
15 | 15 | ||
16 | const emit = defineEmits(['update:value']); | 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 | const [register, { getFieldsValue, setFieldsValue }] = useForm({ | 26 | const [register, { getFieldsValue, setFieldsValue }] = useForm({ |
20 | schemas: basicInfoForm, | 27 | schemas: basicInfoForm, |
21 | layout: 'vertical', | 28 | layout: 'vertical', |
@@ -23,9 +30,7 @@ | @@ -23,9 +30,7 @@ | ||
23 | submitFunc: async () => { | 30 | submitFunc: async () => { |
24 | await nextTick(); | 31 | await nextTick(); |
25 | const values = getFieldsValue() || {}; | 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,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 | <script lang="ts" setup> | 1 | <script lang="ts" setup> |
2 | import { computed, ref, unref } from 'vue'; | 2 | import { computed, ref, unref } from 'vue'; |
3 | import { BasicModal, useModal } from '/@/components/Modal'; | 3 | import { BasicModal, useModal } from '/@/components/Modal'; |
4 | - import { Steps } from 'ant-design-vue'; | 4 | + import { Steps, Button, Tooltip } from 'ant-design-vue'; |
5 | import BasicInfoForm from './BasicInfoForm.vue'; | 5 | import BasicInfoForm from './BasicInfoForm.vue'; |
6 | import ImportCsv from './ImportCsv.vue'; | 6 | import ImportCsv from './ImportCsv.vue'; |
7 | import { CreateEntityValue, UploadFileParseValue } from './type'; | 7 | import { CreateEntityValue, UploadFileParseValue } from './type'; |
@@ -9,6 +9,7 @@ | @@ -9,6 +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 | 13 | ||
13 | const emit = defineEmits(['importFinally']); | 14 | const emit = defineEmits(['importFinally']); |
14 | 15 | ||
@@ -73,6 +74,10 @@ | @@ -73,6 +74,10 @@ | ||
73 | reset(); | 74 | reset(); |
74 | return true; | 75 | return true; |
75 | }; | 76 | }; |
77 | + | ||
78 | + const handleTemplateDownload = () => { | ||
79 | + downloadFile(csvTemplate, 'template', 'text/csv', 'csv'); | ||
80 | + }; | ||
76 | </script> | 81 | </script> |
77 | 82 | ||
78 | <template> | 83 | <template> |
@@ -86,7 +91,7 @@ | @@ -86,7 +91,7 @@ | ||
86 | :close-func="handleCancel" | 91 | :close-func="handleCancel" |
87 | :destroy-on-close="true" | 92 | :destroy-on-close="true" |
88 | > | 93 | > |
89 | - <section class="overflow-auto"> | 94 | + <section class="overflow-auto relative"> |
90 | <Steps direction="vertical" :current="currentStep"> | 95 | <Steps direction="vertical" :current="currentStep"> |
91 | <Steps.Step | 96 | <Steps.Step |
92 | v-for="item in Object.keys(StepsEnum).filter((key) => isNaN(key as unknown as number))" | 97 | v-for="item in Object.keys(StepsEnum).filter((key) => isNaN(key as unknown as number))" |
@@ -132,6 +137,17 @@ | @@ -132,6 +137,17 @@ | ||
132 | </template> | 137 | </template> |
133 | </Steps.Step> | 138 | </Steps.Step> |
134 | </Steps> | 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 | </section> | 151 | </section> |
136 | </BasicModal> | 152 | </BasicModal> |
137 | </template> | 153 | </template> |
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | </a-button> | 21 | </a-button> |
22 | </Popconfirm> | 22 | </Popconfirm> |
23 | </Authority> | 23 | </Authority> |
24 | - <Authority> | 24 | + <Authority value="api:yt:device:import"> |
25 | <Button type="primary" @click="handleBatchImport">导入</Button> | 25 | <Button type="primary" @click="handleBatchImport">导入</Button> |
26 | </Authority> | 26 | </Authority> |
27 | <a-button | 27 | <a-button |