Commit 0886355b8d83d6aa88001307e476b51df7b12a96

Authored by ww
1 parent 0284f844

feat: 物模型新增导入功能

... ... @@ -55,3 +55,11 @@ export interface GetModelTslParams {
55 55 functionType: FunctionType;
56 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 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 7 import { defHttp } from '/@/utils/http/axios';
4 8 import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config';
5 9
... ... @@ -11,6 +15,8 @@ enum ModelOfMatter {
11 15 LIST = '/things_model/page',
12 16 RELEASE = '/things_model',
13 17
  18 + IMPORT = '/things_model/import',
  19 +
14 20 GET_MODEL_SERVICE = '/things_model/get_services',
15 21 }
16 22
... ... @@ -69,3 +75,10 @@ export const getModelServices = (params: { deviceProfileId: string }) => {
69 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 281 colProps: {
282 282 span: 24,
283 283 },
  284 + ifShow: () => !hasStructForm,
284 285 defaultValue: 'r',
285 286 componentProps: {
286 287 placeholder: '请选择读写类型',
... ...
... ... @@ -33,9 +33,9 @@
33 33 </Button>
34 34 </Authority>
35 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 39 </div>
40 40 <div class="flex gap-2">
41 41 <Authority :value="ModelOfMatterPermission.RELEASE">
... ... @@ -126,10 +126,15 @@
126 126 import { Authority } from '/@/components/Authority';
127 127 import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue';
128 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 130 import { useMessage } from '/@/hooks/web/useMessage';
131 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 138 import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types';
134 139 import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
135 140 import { ref } from 'vue';
... ... @@ -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 249 defineExpose({});
235 250 </script>
... ...
... ... @@ -85,7 +85,13 @@
85 85 try {
86 86 loading.value = true;
87 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 95 } catch (error) {
90 96 } finally {
91 97 loading.value = false;
... ...