DeviceProfileModal.vue
8.2 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
<div>
<BasicModal
:maskClosable="false"
v-bind="$attrs"
:width="dynamicWidth"
:destroy-on-close="true"
@register="register"
@ok="handleSubmit"
@cancel="handleCancel"
>
<div v-if="!isViewDetail" class="step-form-form">
<a-steps :current="current">
<a-step v-for="item in steps" :key="item.title" :title="item.title" />
</a-steps>
</div>
<div v-if="!isViewDetail" class="mt-5">
<DeviceConfigurationStep
v-show="current === 0"
ref="DevConStRef"
@next="handleStepNext(true, null)"
@emitDeviceType="handleGetDeviceType"
/>
<TransportConfigurationStep
v-show="current === 1"
ref="TransConStRef"
:deviceTypeStr="deviceTypeStr"
@prev="handleStepPrev"
/>
</div>
<div v-if="isViewDetail">
<Tabs
type="card"
:animated="true"
v-model:activeKey="activeKey"
:size="size"
@change="handleChange"
>
<TabPane forceRender key="1" :tab="t('common.productText')">
<div class="relative">
<DeviceConfigurationStep
:ifShowBtn="isViewDetail ? false : true"
v-show="activeKey === '1'"
ref="DevConStRef"
/>
<div
v-show="isViewDetail"
class="absolute w-full h-full top-0 cursor-not-allowed"
></div>
</div>
</TabPane>
<TabPane
forceRender
key="2"
:tab="t('deviceManagement.product.transportConfigurationText')"
>
<div class="relative">
<TransportConfigurationStep
:ifShowBtn="isViewDetail ? false : true"
v-show="activeKey === '2'"
ref="TransConStRef"
/>
<div
v-show="isViewDetail"
class="absolute w-full h-full top-0 cursor-not-allowed"
></div>
</div>
</TabPane>
<TabPane
forceRender
key="3"
v-show="activeKey === '3'"
:tab="t('deviceManagement.product.thingsModelManageText')"
>
<PhysicalModelManagementStep v-show="activeKey === '3'" ref="PhysicalModManRef" />
</TabPane>
</Tabs>
</div>
</BasicModal>
</div>
</template>
<script lang="ts" setup>
import { ref, unref, reactive, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import {
deviceConfigAddOrEdit,
deviceConfigGetDetail,
doQueryRuleChainList,
} from '/@/api/device/deviceConfigApi';
import { useMessage } from '/@/hooks/web/useMessage';
import { steps } from './device.profile.data';
import { isEmpty } from '/@/utils/is';
import { Tabs, TabPane } from 'ant-design-vue';
import DeviceConfigurationStep from './step/DeviceConfigurationStep.vue';
import TransportConfigurationStep from './step/TransportConfigurationStep.vue';
import PhysicalModelManagementStep from './step/PhysicalModelManagementStep.vue';
import { DeviceProfileDetail } from '/@/api/device/model/deviceConfigModel';
import { deleteFilePath } from '/@/api/oss/ossFileUploader';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const emits = defineEmits(['success', 'register']);
const activeKey = ref('1');
const size = ref('small');
const isEditId = ref('');
const isEditCreatTime = ref('');
const { createMessage } = useMessage();
const isViewDetail = ref(false);
const isUpdate = ref(false);
const current = ref(0);
const DevConStRef = ref<InstanceType<typeof DeviceConfigurationStep>>();
const TransConStRef = ref<InstanceType<typeof TransportConfigurationStep>>();
const PhysicalModManRef = ref<InstanceType<typeof PhysicalModelManagementStep>>();
const postSubmitFormData: any = reactive({
deviceConfData: {},
});
const transportConfData: any = reactive({
profileData: {},
});
const transportTypeStr = ref('');
const dynamicWidth = ref('55rem');
const isDefault = ref(false);
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false });
current.value = 0;
isUpdate.value = data.isUpdate;
isViewDetail.value = data.isView;
const res =
data.record !== undefined
? await deviceConfigGetDetail(data.record.id)
: ({} as DeviceProfileDetail);
isEditId.value = data.record !== undefined ? data.record.id : null;
isEditCreatTime.value = data.record !== undefined ? data.record.createTime : null;
isDefault.value = res.default;
const title = `${t(unref(isUpdate) ? 'common.editText' : 'common.createText')}${t(
'business.productText'
)}`;
setModalProps({ title, showOkBtn: true, showCancelBtn: true });
if (unref(isUpdate)) {
const { deviceType } = res || {};
deviceTypeStr.value = deviceType;
await setDeviceConfEditFormData(res);
await setTransConfEditFormData(res);
handleStepNext(false, res);
unref(DevConStRef)?.editOrAddDeviceTypeStatus(true);
} else {
unref(DevConStRef)?.editOrAddDeviceTypeStatus(false);
const values = ref([]) as any;
if (!values.value.length) {
values.value = await doQueryRuleChainList();
}
const defaultRuleChainId = unref(values).filter((item) => item.root)[0].id.id;
await unref(DevConStRef)?.setFieldsdefaultRuleChainId(defaultRuleChainId);
}
});
const handleChange = (e) => {
if (e == '2') {
handleStepNext(true, null);
}
};
const handleStepNext = (e, data) => {
const { deviceType } = unref(DevConStRef)?.getFieldsValue() || {};
if (e) {
current.value++;
unref(isUpdate)
? unref(TransConStRef)?.editOrAddTransportTypeStatus(true, deviceType)
: unref(TransConStRef)?.editOrAddTransportTypeStatus(false, deviceType);
} else {
setTransConfEditFormData(data);
}
};
const deviceTypeStr = ref('');
const handleGetDeviceType = async (e) => {
deviceTypeStr.value = e;
await nextTick();
TransConStRef.value?.updateDisabled(e);
};
const handleStepPrev = () => {
current.value--;
};
const setDeviceConfEditFormData = async (res) => {
await DevConStRef.value?.setFormData(res);
};
const setTransConfEditFormData = async (res) => {
await TransConStRef.value?.setFormData(res);
};
const getDeviceConfFormData = async () => {
postSubmitFormData.deviceConfData = await DevConStRef.value?.getFormData();
};
const getTransConfData = async () => {
transportConfData.profileData = await TransConStRef.value?.getFormData();
transportTypeStr.value = transportConfData.profileData.transportConfiguration.type;
Reflect.deleteProperty(transportConfData.profileData?.transportConfiguration, 'transportType');
};
const handleSubmit = async () => {
await getDeviceConfFormData();
await getTransConfData();
const isEmptyObj = isEmpty(transportConfData.profileData.transportConfiguration);
if (
Reflect.has(postSubmitFormData.deviceConfData, 'deleteUrl') &&
postSubmitFormData.deviceConfData?.deleteUrl
) {
await deleteFilePath(postSubmitFormData.deviceConfData?.deleteUrl);
Reflect.deleteProperty(postSubmitFormData.deviceConfData, 'deleteUrl');
}
await deviceConfigAddOrEdit({
...postSubmitFormData.deviceConfData,
...{ transportType: !isEmptyObj ? transportTypeStr.value : 'DEFAULT' },
...{ profileData: !isEmptyObj ? transportConfData.profileData : null },
...{ id: isUpdate.value ? isEditId.value : null },
...{ createTime: isUpdate.value ? isEditCreatTime.value : null },
default: !!unref(isDefault),
});
createMessage.success(
(isUpdate.value ? t('common.editText') : t('common.createText')) + t('common.successText')
);
handleCancel();
emits('success');
};
const handleCancel = () => {
closeModal();
activeKey.value = '1';
DevConStRef.value?.resetFormData();
TransConStRef.value?.resetFormData();
};
</script>
<style lang="less" scope>
:deep(.ant-modal-content) {
height: 700px !important;
}
</style>