index.vue
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script lang="ts" setup>
import { ref } from 'vue';
import { useGenDynamicForm } from './useGenDynamicForm';
import { ModalParamsType } from '/#/utils';
import { DeviceModelOfMatterAttrs } from '/@/api/device/model/deviceModel';
import { StructJSON } from '/@/api/device/model/modelOfMatterModel';
import { BasicForm, useForm } from '/@/components/Form';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { DataTypeEnum } from '/@/views/device/profiles/step/cpns/physical/cpns/config';
import { sendCommandOneway } from '/@/api/dataBoard';
import { useMessage } from '/@/hooks/web/useMessage';
import { unref } from 'vue';
defineEmits(['register']);
const props = defineProps<{ deviceId: string; deviceName: string }>();
const [registerForm, { setProps, getFieldsValue, resetFields }] = useForm({
schemas: [],
showActionButtonGroup: false,
layout: 'vertical',
});
const { genForm } = useGenDynamicForm();
const keys = ref<string[]>([]);
const [register] = useModalInner((params: ModalParamsType<DeviceModelOfMatterAttrs>) => {
const { record } = params;
const { name, detail, identifier } = record;
const { dataType } = detail;
const { type } = dataType || {};
let schemas = [{ dataType: dataType, identifier, functionName: name } as StructJSON];
if (type === DataTypeEnum.IS_STRUCT) {
schemas = dataType?.specs as StructJSON[];
}
const formSchemas = genForm(schemas);
keys.value = schemas.map((item) => {
return item.identifier!;
});
setProps({ schemas: formSchemas });
resetFields();
});
const { createMessage } = useMessage();
const loading = ref(false);
const handleSend = async () => {
try {
loading.value = true;
if (!props.deviceId) return;
const _value = getFieldsValue();
const value = unref(keys).reduce((prev, next) => {
return { ...prev, [next]: _value[next] };
}, {});
await sendCommandOneway({
deviceId: props.deviceId,
value: {
persistent: true,
method: 'methodThingskit',
params: {
deviceName: props.deviceName,
...value,
},
},
});
createMessage.success('属性下发成功~');
} catch (error) {
throw error;
} finally {
loading.value = false;
}
};
</script>
<template>
<BasicModal
title="属性下发"
@register="register"
:min-height="60"
ok-text="属性下发"
wrap-class-name="model-of-matter-send-command-modal"
@ok="handleSend"
:ok-button-props="{ loading }"
>
<BasicForm @register="registerForm" class="dynamic-form" />
</BasicModal>
</template>
<style lang="less">
.model-of-matter-send-command-modal {
.dynamic-form {
.ant-input-number {
@apply !w-full;
}
}
}
</style>