ReportConfigDrawer.vue
5.42 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
<template>
<BasicDrawer
v-bind="$attrs"
@register="registerDrawer"
showFooter
:title="getTitle"
width="30%"
@ok="handleSubmit"
>
<BasicForm @register="registerForm">
<template #deviceAttr="{ model, field }">
<deviceAttrColumn
@change="handleChange"
:orgId="!isUpdate ? model['organizationId'] : orgId"
:value="!isUpdate ? model['devices'] : deviceAttrData"
:isEdit="!isUpdate ? false : true"
/>
<p style="display: none">{{ field }}</p>
</template>
</BasicForm>
</BasicDrawer>
</template>
<script lang="ts" setup>
import { ref, computed, unref, reactive } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { formSchema } from './config.data';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { createOrEditReportManage, putReportConfigManage } from '/@/api/report/reportManager';
import { useMessage } from '/@/hooks/web/useMessage';
import deviceAttrColumn from './cpns/MappingsForm.vue';
import moment from 'moment';
import { screenLinkPageByDeptIdGetDevice } from '/@/api/ruleengine/ruleengineApi';
const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const editId = ref('');
const orgId = ref('');
let deviceAttrData: any = ref([]);
const [registerForm, { validate, setFieldsValue, resetFields, updateSchema }] = useForm({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
fieldMapToTime: [['timeZone', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
});
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
await resetFields();
setDrawerProps({ confirmLoading: false });
isUpdate.value = !!data?.isUpdate;
if (unref(isUpdate)) {
//回显
editId.value = data.record.id;
await setFieldsValue(data.record);
//TODO 模拟的数据 待服务端返回
const deviceIds: any = [
'8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
'8f5b4280-f29e-11ec-98ad-a9680487d1e0',
'54e199d0-f1f7-11ec-98ad-a9680487d1e0',
'6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
];
setFieldsValue({
agg: queryCondition?.agg,
interval: queryCondition?.interval,
devices: deviceIds,
});
orgId.value = data.record.organizationId;
//获取该组织下的设备--排除网关设备
const { items } = await screenLinkPageByDeptIdGetDevice({
organizationId: data.record.organizationId,
});
const options = items.map((item) => {
if (item.deviceType !== 'GATEWAY')
return {
label: item.name,
value: item.tbDeviceId,
};
});
updateSchema({
field: 'devices',
componentProps: {
options,
},
});
//TODO 回显设备属性 模拟的数据 待服务端返回
deviceAttrData.value = [
{
device: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
attribute: 'CO2',
name: '奥迪网关子设备',
},
{
device: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
attribute: 'co',
name: '宝马默认设备',
},
{
device: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
attribute: 'hot',
name: '奔驰默认设备',
},
{
device: '54e199d0-f1f7-11ec-98ad-a9680487d1e0',
attribute: 'wet',
name: '新增奥迪测试设备',
},
];
} else {
editId.value = '';
updateSchema({
field: 'devices',
componentProps: {
options: [],
},
});
}
});
const getAttrDevice: any = ref([]);
const getTitle = computed(() => (!unref(isUpdate) ? '新增报表配置' : '编辑报表配置'));
const handleChange = (e) => (getAttrDevice.value = e);
let postObj: any = reactive({});
let queryCondition: any = reactive({});
let executeContent: any = reactive({});
const endTs: any = ref(0);
async function handleSubmit() {
setDrawerProps({ confirmLoading: true });
try {
const { createMessage } = useMessage();
const values = await validate();
if (!values) return;
if (values.executeWay == 0) {
executeContent = null;
} else {
executeContent = {};
}
if (values.timeZone) {
const getTime = JSON.stringify(values.timeZone);
endTs.value = moment(JSON.parse(getTime)[0]).valueOf() || 1659424160000;
}
queryCondition = {
agg: values.agg,
interval: values.interval,
limit: values.limit,
};
delete values.devices;
delete values.agg;
delete values.interval;
delete values.timeZone;
postObj = {
...values,
...{ executeAttributes: getAttrDevice.value },
...{ queryCondition },
...{ endTs: endTs.value },
...{ executeContent },
...{ id: editId.value !== '' ? editId.value : '' },
};
let saveMessage = '添加成功';
let updateMessage = '修改成功';
editId.value !== ''
? await putReportConfigManage(postObj)
: await createOrEditReportManage(postObj);
closeDrawer();
emit('success');
createMessage.success(unref(isUpdate) ? updateMessage : saveMessage);
} finally {
setTimeout(() => {
setDrawerProps({ confirmLoading: false });
}, 300);
}
}
</script>