PhysicalModelModal.vue
3.43 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
<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" />
</div>
<div v-if="!isViewDetail">
<div>
<Typography>
<TypographyParagraph>
<blockquote style="background: #f2f2f2">{{ blockContent }}</blockquote>
</TypographyParagraph>
</Typography>
</div>
<Tabs type="card" v-model:activeKey="activeKey" :size="size">
<TabPane key="1" tab="属性">
<Attribute v-show="activeKey === '1'" ref="AttrRef" />
</TabPane>
<TabPane key="2" tab="服务">
<Service v-show="activeKey === '2'" ref="ServiceRef" />
</TabPane>
<TabPane 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 } 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';
defineEmits(['register']);
const blockContent = `属性一般是设备的运行状态,如当前温度等;服务是设备可被调用的方法,支持定义参数,如执行某项任务;事件则是设备上报的
通知,如告警,需要被及时处理。`;
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 allData: any = reactive({
properties: [],
events: [],
services: [],
productKey: '',
_ppk: {},
});
const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
setModalProps({ loading: true });
handleCancel(false);
isUpdate.value = data.isUpdate;
isViewDetail.value = data.isView;
isText.value = data.isText;
if (!unref(isViewDetail)) {
const title = !unref(isUpdate) ? '编辑物模型' : '新增物模型';
if (!unref(isUpdate)) {
AttrRef.value?.setFormData(mockData.properties);
}
setModalProps({ title, showOkBtn: true, showCancelBtn: true });
if (!unref(isUpdate)) {
}
} else {
setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看物模型' });
AttrRef.value?.setFormData(mockData.properties);
}
setModalProps({ loading: false });
});
const handleCancel = (flag) => {
AttrRef.value?.resetFormData();
activeKey.value = '1';
allData.properties = [];
allData.events = [];
allData.services = [];
if (flag) {
closeModal();
}
};
const handleSubmit = async () => {
const value = await AttrRef.value?.getFormData();
if (!value) return;
allData.properties.push(value);
console.log('搜集值', allData);
closeModal();
};
</script>
<style lang="less" scope></style>