Commit 4b0f97d1188bd6dca84e85ed75abcd22ac30eee6
Merge branch 'main_dev' of http://git.yunteng.com/yunteng/thingskit-front into fix/rule-chain-field
Showing
12 changed files
with
146 additions
and
76 deletions
... | ... | @@ -14,6 +14,8 @@ |
14 | 14 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
15 | 15 | import { cloneDeep } from 'lodash-es'; |
16 | 16 | import { isArray } from '/@/utils/is'; |
17 | + import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | |
18 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
17 | 19 | |
18 | 20 | const emit = defineEmits(['update:value']); |
19 | 21 | |
... | ... | @@ -53,7 +55,10 @@ |
53 | 55 | const handleUpdate = (value: StructRecord) => { |
54 | 56 | openModal(true, { |
55 | 57 | mode: OpenModalMode.UPDATE, |
56 | - record: value, | |
58 | + record: { | |
59 | + ...value, | |
60 | + [FormField.HAS_STRUCT_FROM]: value?.dataType?.type === DataTypeEnum.STRUCT, | |
61 | + }, | |
57 | 62 | } as OpenModalParams); |
58 | 63 | }; |
59 | 64 | |
... | ... | @@ -90,15 +95,10 @@ |
90 | 95 | <div>参数名称: {{ item.functionName }}</div> |
91 | 96 | <div class="flex"> |
92 | 97 | <Button class="!p-0" type="link" @click="handleUpdate(item)"> |
93 | - <span>{{ $props.disabled ? '查看' : '编辑' }}</span> | |
98 | + <span>{{ disabled ? '查看' : '编辑' }}</span> | |
94 | 99 | </Button> |
95 | 100 | <Divider type="vertical" /> |
96 | - <Button | |
97 | - :disabled="$props.disabled" | |
98 | - class="!p-0" | |
99 | - type="link" | |
100 | - @click="handleDelete(item)" | |
101 | - > | |
101 | + <Button :disabled="disabled" class="!p-0" type="link" @click="handleDelete(item)"> | |
102 | 102 | <span>删除</span> |
103 | 103 | </Button> |
104 | 104 | </div> |
... | ... | @@ -114,7 +114,7 @@ |
114 | 114 | <StructFormModel |
115 | 115 | :has-struct-form="hasStructForm!" |
116 | 116 | :hidden-access-mode="hiddenAccessMode" |
117 | - :disabled="$props.disabled" | |
117 | + :disabled="disabled" | |
118 | 118 | :value-list="getValue" |
119 | 119 | @register="registerModal" |
120 | 120 | @submit="handleSaveStruct" | ... | ... |
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | import { formSchemas } from './config'; |
9 | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
10 | 10 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
11 | - import { ref, unref } from 'vue'; | |
11 | + import { computed, ref, unref } from 'vue'; | |
12 | 12 | import { transfromToStructJSON } from './util'; |
13 | 13 | import { cloneDeep } from 'lodash-es'; |
14 | 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
... | ... | @@ -32,7 +32,6 @@ |
32 | 32 | |
33 | 33 | const [register, { validate, setFieldsValue, setProps }] = useForm({ |
34 | 34 | labelWidth: 100, |
35 | - schemas: formSchemas(props.hasStructForm, props.hiddenAccessMode), | |
36 | 35 | actionColOptions: { |
37 | 36 | span: 14, |
38 | 37 | }, |
... | ... | @@ -42,6 +41,14 @@ |
42 | 41 | showActionButtonGroup: false, |
43 | 42 | }); |
44 | 43 | |
44 | + const getFormSchemas = computed(() => { | |
45 | + const { hasStructForm, hiddenAccessMode } = props; | |
46 | + return formSchemas({ | |
47 | + hasStructForm, | |
48 | + hiddenAccessMode, | |
49 | + }); | |
50 | + }); | |
51 | + | |
45 | 52 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { |
46 | 53 | modalReceiveRecord.value = record; |
47 | 54 | const data = record.record || {}; |
... | ... | @@ -97,7 +104,7 @@ |
97 | 104 | destroy-on-close |
98 | 105 | :show-ok-btn="!$props.disabled" |
99 | 106 | > |
100 | - <BasicForm @register="register" /> | |
107 | + <BasicForm @register="register" :schemas="getFormSchemas" /> | |
101 | 108 | </BasicModal> |
102 | 109 | </template> |
103 | 110 | ... | ... |
... | ... | @@ -21,11 +21,17 @@ export const validateJSON = (_rule, value = [] as ModelOfMatterParams[], _callba |
21 | 21 | return Promise.reject('JSON对象不能为空'); |
22 | 22 | }; |
23 | 23 | |
24 | -export const formSchemas = ( | |
25 | - hasStructForm: boolean, | |
26 | - hiddenAccessMode: boolean, | |
27 | - isTcp = false | |
28 | -): FormSchema[] => { | |
24 | +interface StructFormSchemasParmasType { | |
25 | + hasStructForm: boolean; | |
26 | + hiddenAccessMode: boolean; | |
27 | + isTcp?: boolean; | |
28 | +} | |
29 | + | |
30 | +export const formSchemas = ({ | |
31 | + hasStructForm, | |
32 | + hiddenAccessMode, | |
33 | + isTcp = false, | |
34 | +}: StructFormSchemasParmasType): FormSchema[] => { | |
29 | 35 | return [ |
30 | 36 | { |
31 | 37 | field: FormField.FUNCTION_NAME, |
... | ... | @@ -54,6 +60,12 @@ export const formSchemas = ( |
54 | 60 | }, |
55 | 61 | }, |
56 | 62 | { |
63 | + field: FormField.HAS_STRUCT_FROM, | |
64 | + label: '是否已存在结构体', | |
65 | + component: 'Input', | |
66 | + ifShow: false, | |
67 | + }, | |
68 | + { | |
57 | 69 | field: FormField.TYPE, |
58 | 70 | label: '数据类型', |
59 | 71 | required: true, |
... | ... | @@ -63,7 +75,7 @@ export const formSchemas = ( |
63 | 75 | }, |
64 | 76 | defaultValue: 'INT', |
65 | 77 | componentProps: ({ formActionType }) => { |
66 | - const { updateSchema, setFieldsValue } = formActionType; | |
78 | + const { setFieldsValue } = formActionType; | |
67 | 79 | return { |
68 | 80 | placeholder: '请选择数据类型', |
69 | 81 | api: async (params: Recordable) => { |
... | ... | @@ -84,13 +96,7 @@ export const formSchemas = ( |
84 | 96 | getPopupContainer: () => document.body, |
85 | 97 | onChange: (value: string) => { |
86 | 98 | if (value == DataTypeEnum.STRUCT) { |
87 | - updateSchema({ | |
88 | - field: FormField.SPECS_LIST, | |
89 | - componentProps: { | |
90 | - hasStructForm: true, | |
91 | - }, | |
92 | - }); | |
93 | - setFieldsValue({ [FormField.SPECS_LIST]: [] }); | |
99 | + setFieldsValue({ [FormField.SPECS_LIST]: [], [FormField.HAS_STRUCT_FROM]: true }); | |
94 | 100 | } |
95 | 101 | }, |
96 | 102 | }; |
... | ... | @@ -316,6 +322,11 @@ export const formSchemas = ( |
316 | 322 | colProps: { span: 24 }, |
317 | 323 | ifShow: ({ values }) => values[FormField.TYPE] === DataTypeEnum.STRUCT, |
318 | 324 | rules: [{ required: true, validator: validateJSON }], |
325 | + componentProps: ({ formModel }) => { | |
326 | + return { | |
327 | + hasStructForm: formModel[FormField.HAS_STRUCT_FROM], | |
328 | + }; | |
329 | + }, | |
319 | 330 | }, |
320 | 331 | { |
321 | 332 | field: FormField.REFARK, | ... | ... |
... | ... | @@ -58,7 +58,7 @@ |
58 | 58 | }, |
59 | 59 | selections: { |
60 | 60 | beforeSelectValidate: (record: ProfileRecord) => { |
61 | - return !record.default; | |
61 | + return !record.default && record?.name !== 'default'; | |
62 | 62 | }, |
63 | 63 | onSelect: (_record, _flag, allSelecteds) => { |
64 | 64 | disabledDeleteFlag.value = !allSelecteds.length; |
... | ... | @@ -188,7 +188,7 @@ |
188 | 188 | popconfirm: { |
189 | 189 | title: '是否确认删除操作?', |
190 | 190 | onConfirm: handleDelete.bind(null, [item.id]), |
191 | - disabled: item.default, | |
191 | + disabled: item.default || item.name == 'default', | |
192 | 192 | }, |
193 | 193 | disabled: item.default || item.name == 'default', |
194 | 194 | }, | ... | ... |
... | ... | @@ -5,48 +5,27 @@ |
5 | 5 | destroyOnClose |
6 | 6 | v-bind="$attrs" |
7 | 7 | width="25rem" |
8 | + :min-height="150" | |
8 | 9 | @register="register" |
9 | 10 | @cancel="handleCancel" |
10 | 11 | :showOkBtn="false" |
11 | 12 | > |
12 | - <div class="w-full h-full" ref="loadingRef"> | |
13 | - <div class="flex justify-end"> | |
14 | - <Button @click="handleTemplateDownload" type="link">excel模板下载</Button> | |
15 | - </div> | |
16 | - <div class="flex justify-evenly items-center h-50 !w-full"> | |
17 | - <Upload | |
18 | - accept=".json," | |
19 | - :show-upload-list="false" | |
20 | - :customRequest="handleImportModel" | |
21 | - class="flex justify-center items-center" | |
22 | - > | |
23 | - <div class="flex flex-col justify-center items-center"> | |
24 | - <Tooltip> | |
25 | - <template #title>请使用从物模型TSL导出的JSON文件在进行导入</template> | |
26 | - <img :src="JSONImage" alt="avatar" class="w-20 h-20" /> | |
27 | - </Tooltip> | |
28 | - </div> | |
29 | - </Upload> | |
30 | - <Upload | |
31 | - accept=".csv,.xls,.xlsx" | |
32 | - :show-upload-list="false" | |
33 | - :customRequest="handleCSVImport" | |
34 | - class="flex justify-center items-center" | |
35 | - > | |
36 | - <div class="flex flex-col justify-center items-center"> | |
37 | - <Tooltip> | |
38 | - <template #title>请使用下载的模板编辑之后在进行导入</template> | |
39 | - <img :src="CSVImage" alt="avatar" class="w-20 h-20" /> | |
40 | - </Tooltip> | |
41 | - </div> | |
42 | - </Upload> | |
43 | - </div> | |
44 | - </div> | |
13 | + <BasicForm @register="registerForm"> | |
14 | + <template #importType="{ model }"> | |
15 | + <RadioGroup v-model:value="model.importType"> | |
16 | + <Radio value="2">JSON导入</Radio> | |
17 | + <Radio value="1">Excel导入</Radio> | |
18 | + </RadioGroup> | |
19 | + <div v-if="model.importType === '1'" class="absolute -left-28"> | |
20 | + <Button @click="handleTemplateDownload" type="link">excel模板下载</Button> | |
21 | + </div> | |
22 | + </template> | |
23 | + </BasicForm> | |
45 | 24 | </BasicModal> |
46 | 25 | </template> |
47 | 26 | <script lang="ts" setup> |
48 | 27 | import { ref, unref } from 'vue'; |
49 | - import { Upload, Tooltip, Button } from 'ant-design-vue'; | |
28 | + import { Button, Radio, RadioGroup } from 'ant-design-vue'; | |
50 | 29 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
51 | 30 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; |
52 | 31 | import { useMessage } from '/@/hooks/web/useMessage'; |
... | ... | @@ -59,8 +38,7 @@ |
59 | 38 | excelExport, |
60 | 39 | } from '/@/api/device/modelOfMatter'; |
61 | 40 | import { useLoading } from '/@/components/Loading'; |
62 | - import JSONImage from '/@/assets/svg/JSON.svg'; | |
63 | - import CSVImage from '/@/assets/svg/excel.svg'; | |
41 | + import { BasicForm, useForm } from '/@/components/Form'; | |
64 | 42 | |
65 | 43 | const emits = defineEmits(['register', 'handleImportCSV', 'handleReload']); |
66 | 44 | |
... | ... | @@ -85,6 +63,48 @@ |
85 | 63 | const [register, { closeModal }] = useModalInner(async (data) => { |
86 | 64 | ImportInfo.value = data; |
87 | 65 | }); |
66 | + | |
67 | + const [registerForm, {}] = useForm({ | |
68 | + schemas: [ | |
69 | + { | |
70 | + field: 'importType', | |
71 | + label: '导入类型', | |
72 | + component: 'RadioGroup', | |
73 | + defaultValue: '2', | |
74 | + slot: 'importType', | |
75 | + helpMessage: | |
76 | + 'JSON导入请使用从物模型TSL导出的JSON文件在进行导入,Excel导入请使用下载的模板编辑之后在进行导入', | |
77 | + required: true, | |
78 | + }, | |
79 | + { | |
80 | + field: 'apiId', | |
81 | + label: '', | |
82 | + component: 'ApiUpload', | |
83 | + componentProps: ({ formModel }) => { | |
84 | + return { | |
85 | + maxFileLimit: 1, | |
86 | + accept: formModel.importType == 2 ? '.json,' : '.csv,.xls,.xlsx', | |
87 | + api: async (file: File) => { | |
88 | + try { | |
89 | + if (formModel.importType == 2) { | |
90 | + handleImportModel(file); | |
91 | + } else { | |
92 | + handleCSVImport(file); | |
93 | + } | |
94 | + return { | |
95 | + uid: '', | |
96 | + name: '', | |
97 | + }; | |
98 | + } catch {} | |
99 | + }, | |
100 | + }; | |
101 | + }, | |
102 | + }, | |
103 | + ], | |
104 | + labelWidth: 100, | |
105 | + showActionButtonGroup: false, | |
106 | + }); | |
107 | + | |
88 | 108 | // 导入loading |
89 | 109 | const importLoading = ref(false); |
90 | 110 | |
... | ... | @@ -101,7 +121,7 @@ |
101 | 121 | }; |
102 | 122 | |
103 | 123 | // JSON导入 |
104 | - const handleImportModel = async (data: { file: File }) => { | |
124 | + const handleImportModel = async (file: File) => { | |
105 | 125 | const fileReader = new FileReader(); |
106 | 126 | const { isCateGory, id } = unref(ImportInfo); |
107 | 127 | |
... | ... | @@ -148,11 +168,11 @@ |
148 | 168 | } |
149 | 169 | }; |
150 | 170 | |
151 | - fileReader.readAsText(data.file, 'utf-8'); | |
171 | + fileReader.readAsText(file, 'utf-8'); | |
152 | 172 | }; |
153 | 173 | |
154 | 174 | // CSV导入 |
155 | - const handleCSVImport = async ({ file }) => { | |
175 | + const handleCSVImport = async (file) => { | |
156 | 176 | const { isCateGory, id } = unref(ImportInfo); |
157 | 177 | |
158 | 178 | try { |
... | ... | @@ -200,4 +220,8 @@ |
200 | 220 | }; |
201 | 221 | </script> |
202 | 222 | |
203 | -<style lang="less" scope></style> | |
223 | +<style lang="less" scoped> | |
224 | + :deep(.ant-form-item) { | |
225 | + margin-bottom: 28px !important; | |
226 | + } | |
227 | +</style> | ... | ... |
... | ... | @@ -14,12 +14,17 @@ |
14 | 14 | import { OpenModelMode } from '../types'; |
15 | 15 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
16 | 16 | import { TransportTypeEnum } from '../../../../components/TransportDescript/const'; |
17 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
17 | 18 | |
18 | 19 | const props = defineProps<{ openModalMode: OpenModelMode; transportType?: string | undefined }>(); |
19 | 20 | |
20 | 21 | const [register, { validate, resetFields, setFieldsValue, setProps }] = useForm({ |
21 | 22 | labelWidth: 100, |
22 | - schemas: formSchemas(false, false, props.transportType === TransportTypeEnum.TCP), | |
23 | + schemas: formSchemas({ | |
24 | + hasStructForm: false, | |
25 | + hiddenAccessMode: false, | |
26 | + isTcp: props.transportType === TransportTypeEnum.TCP, | |
27 | + }), | |
23 | 28 | actionColOptions: { |
24 | 29 | span: 14, |
25 | 30 | }, |
... | ... | @@ -67,7 +72,9 @@ |
67 | 72 | ...functionJson, |
68 | 73 | ...dataType, |
69 | 74 | ...(isArray(specs) ? specs : { ...specs }), |
75 | + hasStructForm: (record?.functionJson?.dataType as DataType)?.type === DataTypeEnum.STRUCT, | |
70 | 76 | }; |
77 | + | |
71 | 78 | setFieldsValue(value); |
72 | 79 | }; |
73 | 80 | ... | ... |
... | ... | @@ -3,13 +3,15 @@ |
3 | 3 | </template> |
4 | 4 | <script lang="ts" setup> |
5 | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | - import { serviceSchemas } from './config'; | |
6 | + import { FormField, serviceSchemas } from './config'; | |
7 | 7 | import { FunctionType } from './config'; |
8 | 8 | import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; |
9 | 9 | import { ModelOfMatterParams, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
10 | 10 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; |
11 | 11 | import { excludeIdInStructJSON } from '/@/components/Form/src/externalCompns/components/StructForm/util'; |
12 | 12 | import { OpenModelMode } from '../types'; |
13 | + import { isArray } from '/@/utils/is'; | |
14 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
13 | 15 | |
14 | 16 | const props = defineProps<{ |
15 | 17 | record: DeviceRecord; |
... | ... | @@ -48,6 +50,14 @@ |
48 | 50 | serviceCommand, |
49 | 51 | callType, |
50 | 52 | }; |
53 | + | |
54 | + if ( | |
55 | + isArray(inputData) && | |
56 | + inputData.find((item) => item?.dataType?.type === DataTypeEnum.STRUCT) | |
57 | + ) { | |
58 | + Reflect.set(value, FormField.HAS_STRUCT_FROM, true); | |
59 | + } | |
60 | + | |
51 | 61 | setFieldsValue(value); |
52 | 62 | }; |
53 | 63 | ... | ... |
... | ... | @@ -28,6 +28,8 @@ export enum FormField { |
28 | 28 | REGISTER_ADDRESS = 'registerAddress', |
29 | 29 | EXTENSION_DESC = 'extensionDesc', |
30 | 30 | STRUCT = 'struct', |
31 | + | |
32 | + HAS_STRUCT_FROM = 'hasStructForm', | |
31 | 33 | } |
32 | 34 | |
33 | 35 | export enum FunctionType { |
... | ... | @@ -125,6 +127,12 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { |
125 | 127 | }, |
126 | 128 | }, |
127 | 129 | { |
130 | + field: FormField.HAS_STRUCT_FROM, | |
131 | + component: 'Input', | |
132 | + label: '是否已存在结构体', | |
133 | + ifShow: false, | |
134 | + }, | |
135 | + { | |
128 | 136 | field: FormField.INPUT_PARAM, |
129 | 137 | label: '输入参数', |
130 | 138 | component: 'StructForm', |
... | ... | @@ -133,8 +141,11 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { |
133 | 141 | rules: [{ message: '输入参数为必填项', required: true, type: 'array' }], |
134 | 142 | ifShow: !tcpDeviceFlag, |
135 | 143 | colProps: { span: 24 }, |
136 | - componentProps: { | |
137 | - hiddenAccessMode: true, | |
144 | + componentProps: ({ formModel }) => { | |
145 | + return { | |
146 | + hiddenAccessMode: true, | |
147 | + hasStructForm: formModel[FormField.HAS_STRUCT_FROM], | |
148 | + }; | |
138 | 149 | }, |
139 | 150 | }, |
140 | 151 | { | ... | ... |
... | ... | @@ -185,8 +185,8 @@ export const list = [ |
185 | 185 | { |
186 | 186 | deviceType: '网关/直连/网关子设备', |
187 | 187 | function: '事件上报', |
188 | - release: 'v1/devices/event/${deviceId}/${identifier}', | |
189 | - subscribe: 'v1/devices/event/${deviceId}/${identifier}', | |
188 | + release: 'v1/devices/event/${deviceId}||${deviceName}/${identifier}', | |
189 | + subscribe: 'v1/devices/event/${deviceId}||${deviceName}/${identifier}', | |
190 | 190 | platform: '订阅', |
191 | 191 | device: '发布', |
192 | 192 | }, | ... | ... |