DeviceProfileModal.vue
5.48 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
<template>
<BasicModal
v-bind="$attrs"
width="55rem"
@register="register"
:title="getTitle"
@ok="handleSubmit"
@cancel="handleCancel"
>
<div class="step-form-form">
<a-steps :current="current">
<a-step title="设备配置" />
<a-step title="传输配置" />
<a-step title="告警配置" />
<a-step title="告警通知" />
</a-steps>
</div>
<div class="mt-5">
<DeviceProfileStep1 :echoStep1="editEchoData" @next="handleStepNext1" v-if="current === 0" />
<DeviceProfileStep2
:echoStep2="editEchoData"
@prev="handleStepPrev"
@next="handleStep2Next"
v-if="current === 1"
/>
<DeviceProfileStep3
:echoStep3="editEchoData"
@prev="handleStepPrev"
@next="handleStep3Next"
@redo="handleRedo"
v-if="current === 2"
/>
<DeviceProfileStep4
:echoStep4="editEchoData"
ref="getStepData"
@prev="handleStepPrev"
v-if="current === 3"
/>
</div>
</BasicModal>
</template>
<script lang="ts">
import { defineComponent, ref, computed, unref, getCurrentInstance } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import DeviceProfileStep1 from '/@/views/device/profile/step/DeviceProfileStep1.vue';
import DeviceProfileStep2 from '/@/views/device/profile/step/DeviceProfileStep2.vue';
import DeviceProfileStep3 from '/@/views/device/profile/step/DeviceProfileStep3.vue';
import DeviceProfileStep4 from '/@/views/device/profile/step/DeviceProfileStep4.vue';
import { Steps } from 'ant-design-vue';
import { deviceConfigAddOrEdit } from '/@/api/device/deviceConfigApi';
import { useMessage } from '/@/hooks/web/useMessage';
export default defineComponent({
name: 'DeviceModal',
components: {
BasicModal,
DeviceProfileStep1,
DeviceProfileStep2,
DeviceProfileStep3,
DeviceProfileStep4,
[Steps.name]: Steps,
[Steps.Step.name]: Steps.Step,
},
props: {
userData: { type: Object },
},
emits: ['success'],
setup(_, { emit }) {
const { createMessage } = useMessage();
const getStepData = ref(null);
const { proxy } = getCurrentInstance();
const postDeviceConfogData: any = ref({});
const getStepOneData: any = ref({});
const getStepTwoData: any = ref({});
const getStepThreeData: any = ref({});
const editEchoData: any = ref({});
const isGetStepFourData: any = ref({});
const isGetStepThreeData: any = ref({});
const postEditId = ref('');
const current = ref(0);
const isUpdate = ref(true);
const getTitle = computed(() => (!unref(isUpdate) ? '新增设备配置' : '编辑设备配置'));
const [register, { closeModal }] = useModalInner((data) => {
isUpdate.value = !!data?.isUpdate;
if (!unref(isUpdate)) {
current.value = 0;
postDeviceConfogData.value = {};
}
if (unref(isUpdate)) {
current.value = 0;
postEditId.value = data.record.id;
editEchoData.value = data.record;
editEchoData.value.key = 'edit';
}
});
function handleStepPrev() {
current.value--;
}
function handleStepNext1(v) {
current.value++;
getStepOneData.value = v;
}
function handleStep2Next(v) {
current.value++;
getStepTwoData.value = v;
}
function handleStep3Next(v) {
current.value++;
getStepThreeData.value = v;
}
function handleRedo() {
current.value = 0;
}
const handleSubmit = async () => {
if (!unref(isUpdate)) {
isGetStepThreeData.value.alarmProfile = getStepThreeData.value;
let getStep4Data = proxy.$refs.getStepData.getAllFields();
isGetStepFourData.value.alarmProfile = getStep4Data;
Object.assign(
postDeviceConfogData.value,
getStepOneData.value,
getStepTwoData.value,
isGetStepFourData.value,
isGetStepThreeData.value
);
console.log('搜集的所有数据', postDeviceConfogData.value);
await deviceConfigAddOrEdit(postDeviceConfogData.value);
createMessage.success('新增设备配置成功');
closeModal();
emit('success');
}
if (unref(isUpdate)) {
postDeviceConfogData.value.id = postEditId.value;
isGetStepThreeData.value.alarmProfile = getStepThreeData.value;
let getStep4Data = proxy.$refs.getStepData.getAllFields();
isGetStepFourData.value.alarmProfile = getStep4Data;
Object.assign(
postDeviceConfogData.value,
getStepOneData.value,
getStepTwoData.value,
isGetStepFourData.value,
isGetStepThreeData.value
);
console.log('搜集的所有数据', postDeviceConfogData.value);
await deviceConfigAddOrEdit(postDeviceConfogData.value);
createMessage.success('新增设备配置成功');
closeModal();
emit('success');
}
};
const handleCancel = async () => {
console.log(2);
};
return {
editEchoData,
getStepData,
handleStep3Next,
handleSubmit,
handleCancel,
register,
getTitle,
current,
handleStepPrev,
handleStepNext1,
handleStep2Next,
handleRedo,
};
},
});
</script>