Showing
5 changed files
with
51 additions
and
8 deletions
@@ -55,3 +55,11 @@ export interface GetModelTslParams { | @@ -55,3 +55,11 @@ export interface GetModelTslParams { | ||
55 | functionType: FunctionType; | 55 | functionType: FunctionType; |
56 | deviceProfileId: string; | 56 | deviceProfileId: string; |
57 | } | 57 | } |
58 | + | ||
59 | +export interface ImportModelOfMatterType { | ||
60 | + attributeModels: any[]; | ||
61 | + eventModels: any[]; | ||
62 | + functionType: string; | ||
63 | + serviceModels: any[]; | ||
64 | + tkDeviceProfileId: string; | ||
65 | +} |
1 | import { BasicPageParams } from '../model/baseModel'; | 1 | import { BasicPageParams } from '../model/baseModel'; |
2 | -import { GetModelTslParams, ModelOfMatterParams } from './model/modelOfMatterModel'; | 2 | +import { |
3 | + GetModelTslParams, | ||
4 | + ImportModelOfMatterType, | ||
5 | + ModelOfMatterParams, | ||
6 | +} from './model/modelOfMatterModel'; | ||
3 | import { defHttp } from '/@/utils/http/axios'; | 7 | import { defHttp } from '/@/utils/http/axios'; |
4 | import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | 8 | import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
5 | 9 | ||
@@ -11,6 +15,8 @@ enum ModelOfMatter { | @@ -11,6 +15,8 @@ enum ModelOfMatter { | ||
11 | LIST = '/things_model/page', | 15 | LIST = '/things_model/page', |
12 | RELEASE = '/things_model', | 16 | RELEASE = '/things_model', |
13 | 17 | ||
18 | + IMPORT = '/things_model/import', | ||
19 | + | ||
14 | GET_MODEL_SERVICE = '/things_model/get_services', | 20 | GET_MODEL_SERVICE = '/things_model/get_services', |
15 | } | 21 | } |
16 | 22 | ||
@@ -69,3 +75,10 @@ export const getModelServices = (params: { deviceProfileId: string }) => { | @@ -69,3 +75,10 @@ export const getModelServices = (params: { deviceProfileId: string }) => { | ||
69 | url: `${ModelOfMatter.GET_MODEL_SERVICE}/${deviceProfileId}`, | 75 | url: `${ModelOfMatter.GET_MODEL_SERVICE}/${deviceProfileId}`, |
70 | }); | 76 | }); |
71 | }; | 77 | }; |
78 | + | ||
79 | +export const importModelOfMatter = (data: ImportModelOfMatterType) => { | ||
80 | + return defHttp.post({ | ||
81 | + url: ModelOfMatter.IMPORT, | ||
82 | + data, | ||
83 | + }); | ||
84 | +}; |
@@ -281,6 +281,7 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => { | @@ -281,6 +281,7 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => { | ||
281 | colProps: { | 281 | colProps: { |
282 | span: 24, | 282 | span: 24, |
283 | }, | 283 | }, |
284 | + ifShow: () => !hasStructForm, | ||
284 | defaultValue: 'r', | 285 | defaultValue: 'r', |
285 | componentProps: { | 286 | componentProps: { |
286 | placeholder: '请选择读写类型', | 287 | placeholder: '请选择读写类型', |
@@ -33,9 +33,9 @@ | @@ -33,9 +33,9 @@ | ||
33 | </Button> | 33 | </Button> |
34 | </Authority> | 34 | </Authority> |
35 | <Button type="primary" @click="handleOpenTsl"> 物模型TSL </Button> | 35 | <Button type="primary" @click="handleOpenTsl"> 物模型TSL </Button> |
36 | - <Button v-if="false && isShowBtn" type="primary" @click="handleImportModel" | ||
37 | - >导入物模型</Button | ||
38 | - > | 36 | + <Upload v-if="isShowBtn" :show-upload-list="false" :customRequest="handleImportModel"> |
37 | + <Button type="primary"> 导入物模型 </Button> | ||
38 | + </Upload> | ||
39 | </div> | 39 | </div> |
40 | <div class="flex gap-2"> | 40 | <div class="flex gap-2"> |
41 | <Authority :value="ModelOfMatterPermission.RELEASE"> | 41 | <Authority :value="ModelOfMatterPermission.RELEASE"> |
@@ -126,10 +126,15 @@ | @@ -126,10 +126,15 @@ | ||
126 | import { Authority } from '/@/components/Authority'; | 126 | import { Authority } from '/@/components/Authority'; |
127 | import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue'; | 127 | import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue'; |
128 | import PhysicalModelTsl from './cpns/physical/PhysicalModelTsl.vue'; | 128 | import PhysicalModelTsl from './cpns/physical/PhysicalModelTsl.vue'; |
129 | - import { Popconfirm, Button, Alert } from 'ant-design-vue'; | 129 | + import { Popconfirm, Button, Alert, Upload } from 'ant-design-vue'; |
130 | import { useMessage } from '/@/hooks/web/useMessage'; | 130 | import { useMessage } from '/@/hooks/web/useMessage'; |
131 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; | 131 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; |
132 | - import { deleteModel, getModelList, releaseModel } from '/@/api/device/modelOfMatter'; | 132 | + import { |
133 | + deleteModel, | ||
134 | + getModelList, | ||
135 | + importModelOfMatter, | ||
136 | + releaseModel, | ||
137 | + } from '/@/api/device/modelOfMatter'; | ||
133 | import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types'; | 138 | import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types'; |
134 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | 139 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
135 | import { ref } from 'vue'; | 140 | import { ref } from 'vue'; |
@@ -229,7 +234,17 @@ | @@ -229,7 +234,17 @@ | ||
229 | } | 234 | } |
230 | }; | 235 | }; |
231 | 236 | ||
232 | - const handleImportModel = async () => {}; | 237 | + const handleImportModel = async (data: { file: File }) => { |
238 | + const fileReader = new FileReader(); | ||
239 | + | ||
240 | + fileReader.onload = () => { | ||
241 | + console.log(fileReader.result); | ||
242 | + | ||
243 | + importModelOfMatter({ tkDeviceProfileId: props.record.id }); | ||
244 | + }; | ||
245 | + | ||
246 | + fileReader.readAsText(data.file, 'utf-8'); | ||
247 | + }; | ||
233 | 248 | ||
234 | defineExpose({}); | 249 | defineExpose({}); |
235 | </script> | 250 | </script> |
@@ -85,7 +85,13 @@ | @@ -85,7 +85,13 @@ | ||
85 | try { | 85 | try { |
86 | loading.value = true; | 86 | loading.value = true; |
87 | const record = await getModelTsl({ deviceProfileId: props.record.id, functionType }); | 87 | const record = await getModelTsl({ deviceProfileId: props.record.id, functionType }); |
88 | - jsonValue.value = JSON.stringify(record, null, 2); | 88 | + jsonValue.value = JSON.stringify( |
89 | + { | ||
90 | + [functionType]: record, | ||
91 | + }, | ||
92 | + null, | ||
93 | + 2 | ||
94 | + ); | ||
89 | } catch (error) { | 95 | } catch (error) { |
90 | } finally { | 96 | } finally { |
91 | loading.value = false; | 97 | loading.value = false; |