PhysicalModelModal.vue
5.44 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
<template>
<div>
<BasicModal
:maskClosable="false"
v-bind="$attrs"
width="55rem"
@register="register"
@ok="handleSubmit"
@cancel="handleCancel"
>
<div v-if="isViewDetail">
<Attribute v-show="activeKey === '1'" ref="AttrRef" />
<Service v-show="activeKey === '2'" ref="ServiceRef" />
<Events v-show="activeKey === '3'" ref="EventsRef" />
</div>
<div v-if="!isViewDetail">
<div>
<Typography>
<TypographyParagraph>
<blockquote style="background: #f2f2f2">{{ useBlockPhysicalContent }}</blockquote>
</TypographyParagraph>
</Typography>
</div>
<Tabs type="card" v-model:activeKey="activeKey" :size="size">
<TabPane :disabled="attrDisable" forceRender key="1" tab="属性">
<Attribute v-show="activeKey === '1'" ref="AttrRef" />
</TabPane>
<TabPane :disabled="serveiceDisable" forceRender key="2" tab="服务">
<Service v-show="activeKey === '2'" ref="ServiceRef" />
</TabPane>
<TabPane
:disabled="eventDisable"
forceRender
key="3"
v-show="activeKey === '3'"
tab="事件"
>
<Events v-show="activeKey === '3'" ref="EventsRef" />
</TabPane>
</Tabs>
</div>
</BasicModal>
</div>
</template>
<script lang="ts" setup>
import { ref, unref, reactive, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { Tabs, TabPane, Typography, TypographyParagraph } from 'ant-design-vue';
import Attribute from './cpns/Attribute.vue';
import Service from './cpns/Service.vue';
import Events from './cpns/Events.vue';
import { mockData } from '../physical/cpns/components/mock';
import useCommon from './hook/useCommon';
import { IAllData } from './types';
defineEmits(['register']);
const attrDisable = ref(false);
const serveiceDisable = ref(false);
const eventDisable = ref(false);
const { useBlockPhysicalContent } = useCommon();
const activeKey = ref('1');
const size = ref('small');
const AttrRef = ref<InstanceType<typeof Attribute>>();
const ServiceRef = ref<InstanceType<typeof Service>>();
const EventsRef = ref<InstanceType<typeof Events>>();
const isUpdate = ref(false);
const isViewDetail = ref('');
const isText = ref('');
const dType = ref('');
const allData = reactive<IAllData>({
properties: [],
events: [],
services: [],
productKey: '',
_ppk: {},
});
const setAttrFormData = (data: {}) => AttrRef.value?.setFormData(data);
const setServiceFormData = (data: {}) => ServiceRef.value?.setFormData(data);
const setEventsFormData = (data: {}) => EventsRef.value?.setFormData(data);
const enums = {
attr: setAttrFormData,
service: setServiceFormData,
events: setEventsFormData,
};
function action(val, data) {
let F = enums[val];
F(data);
}
function dynamicDisable(a, s, e) {
attrDisable.value = a;
serveiceDisable.value = s;
eventDisable.value = e;
}
function dynamicActive(n, callback) {
activeKey.value = n;
callback;
}
const dynamicData = (t, a, s, e) => {
switch (t) {
case 'attr':
dynamicActive('1', action(t, a));
dynamicDisable(false, true, true);
break;
case 'service':
dynamicActive('2', action(t, s));
dynamicDisable(true, false, true);
break;
case 'events':
dynamicActive('3', action(t, e));
dynamicDisable(true, true, false);
break;
}
};
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ loading: true });
handleCancel(false);
isUpdate.value = data.isUpdate;
isViewDetail.value = data.isView;
isText.value = data.isText;
dType.value = data.record?.dType;
if (!unref(isViewDetail)) {
const title = !unref(isUpdate) ? '编辑物模型' : '新增物模型';
if (!unref(isUpdate)) {
nextTick(() => {
dynamicData(dType.value, mockData.properties, mockData.services, mockData.events);
});
}
setModalProps({ title, showOkBtn: true, showCancelBtn: true });
} else {
setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看物模型' });
nextTick(() => {
dynamicData(dType.value, mockData.properties, mockData.services, mockData.events);
});
}
setModalProps({ loading: false });
});
const handleCancel = (flag) => {
AttrRef.value?.resetFormData();
ServiceRef.value?.resetFormData();
EventsRef.value?.resetFormData();
activeKey.value = '1';
allData.properties = [];
allData.events = [];
allData.services = [];
attrDisable.value = false;
serveiceDisable.value = false;
eventDisable.value = false;
if (flag) {
closeModal();
}
};
const handleSubmit = async () => {
if (activeKey.value == '1') {
const valueAttr = await AttrRef.value?.getFormData();
allData.properties.push(valueAttr);
} else if (activeKey.value == '2') {
const valueService = await ServiceRef.value?.getFormData();
allData.services.push(valueService);
} else {
const valueEvents = await EventsRef.value?.getFormData();
allData.events.push(valueEvents);
}
console.log('搜集值', allData);
closeModal();
};
</script>
<style lang="less" scope></style>