1
|
<template>
|
1
|
<template>
|
2
|
- <BasicDrawer
|
|
|
3
|
- v-bind="$attrs"
|
|
|
4
|
- @register="registerDrawer"
|
|
|
5
|
- showFooter
|
|
|
6
|
- :title="getTitle"
|
|
|
7
|
- width="30%"
|
|
|
8
|
- @ok="handleSubmit"
|
|
|
9
|
- >
|
2
|
+ <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="30%" @ok="handleSubmit">
|
10
|
<BasicForm @register="registerForm">
|
3
|
<BasicForm @register="registerForm">
|
11
|
<template #devices>
|
4
|
<template #devices>
|
12
|
- <Select
|
|
|
13
|
- placeholder="请选择设备"
|
|
|
14
|
- v-model:value="selectDevice"
|
|
|
15
|
- style="width: 100%"
|
|
|
16
|
- :options="selectOptions"
|
|
|
17
|
- @change="handleDeviceChange"
|
|
|
18
|
- mode="multiple"
|
|
|
19
|
- labelInValue
|
|
|
20
|
- allowClear
|
|
|
21
|
- notFoundContent="请选择设备"
|
|
|
22
|
- />
|
5
|
+ <Select placeholder="请选择设备" v-model:value="selectDevice" style="width: 100%" :options="selectOptions"
|
|
|
6
|
+ @change="handleDeviceChange" mode="multiple" labelInValue allowClear notFoundContent="请选择设备" />
|
23
|
<div style="margin-top: 1.5vh"></div>
|
7
|
<div style="margin-top: 1.5vh"></div>
|
24
|
<div v-for="(item, index) in deviceList" :key="index">
|
8
|
<div v-for="(item, index) in deviceList" :key="index">
|
25
|
- <DeviceAttrCpns
|
|
|
26
|
- ref="deviceAttrRef"
|
|
|
27
|
- @change="handleChange"
|
|
|
28
|
- :value="item"
|
|
|
29
|
- :orgId="organizationId || orgId"
|
|
|
30
|
- />
|
9
|
+ <DeviceAttrCpns ref="deviceAttrRef" @change="handleChange" :value="item" :orgId="organizationId || orgId" />
|
31
|
</div>
|
10
|
</div>
|
32
|
</template>
|
11
|
</template>
|
33
|
</BasicForm>
|
12
|
</BasicForm>
|
34
|
</BasicDrawer>
|
13
|
</BasicDrawer>
|
35
|
</template>
|
14
|
</template>
|
36
|
<script lang="ts" setup>
|
15
|
<script lang="ts" setup>
|
37
|
- import { ref, computed, unref, reactive, watch, nextTick } from 'vue';
|
|
|
38
|
- import { BasicForm, useForm } from '/@/components/Form';
|
|
|
39
|
- import { formSchema, organizationId } from './config.data';
|
|
|
40
|
- import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
|
|
41
|
- import { createOrEditReportManage, putReportConfigManage } from '/@/api/report/reportManager';
|
|
|
42
|
- import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
43
|
- import moment from 'moment';
|
|
|
44
|
- import { screenLinkPageByDeptIdGetDevice } from '/@/api/ruleengine/ruleengineApi';
|
|
|
45
|
- import { Select } from 'ant-design-vue';
|
|
|
46
|
- import DeviceAttrCpns from './cpns/DeviceAttrCpns.vue';
|
16
|
+import { ref, computed, unref, reactive, watch, nextTick, Ref } from 'vue';
|
|
|
17
|
+import { BasicForm, useForm } from '/@/components/Form';
|
|
|
18
|
+import { formSchema, organizationId } from './config.data';
|
|
|
19
|
+import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
|
|
20
|
+import { createOrEditReportManage, putReportConfigManage } from '/@/api/report/reportManager';
|
|
|
21
|
+import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
22
|
+import moment from 'moment';
|
|
|
23
|
+import { screenLinkPageByDeptIdGetDevice } from '/@/api/ruleengine/ruleengineApi';
|
|
|
24
|
+import { Select } from 'ant-design-vue';
|
|
|
25
|
+import DeviceAttrCpns from './cpns/DeviceAttrCpns.vue';
|
|
|
26
|
+import { SelectTypes } from 'ant-design-vue/es/select';
|
47
|
|
27
|
|
48
|
- const emit = defineEmits(['success', 'register']);
|
|
|
49
|
- const deviceAttrRef: any = ref(null);
|
|
|
50
|
- const isUpdate = ref(true);
|
|
|
51
|
- const editId = ref('');
|
|
|
52
|
- const orgId = ref('');
|
|
|
53
|
- const selectOptions: any = ref([]);
|
|
|
54
|
- const selectDevice = ref([]);
|
|
|
55
|
- const deviceList: any = ref([]);
|
|
|
56
|
- watch(organizationId, async (newValue: string) => {
|
|
|
57
|
- if (!newValue) return;
|
|
|
58
|
- //获取设备
|
28
|
+type TDeviceList = {
|
|
|
29
|
+ key?: string,
|
|
|
30
|
+ value?: string,
|
|
|
31
|
+ label?: string,
|
|
|
32
|
+ attribute?: string,
|
|
|
33
|
+ device?: string
|
|
|
34
|
+}
|
|
|
35
|
+const emit = defineEmits(['success', 'register']);
|
|
|
36
|
+const deviceAttrRef: any = ref(null);
|
|
|
37
|
+const isUpdate = ref(true);
|
|
|
38
|
+const editId = ref('');
|
|
|
39
|
+const orgId = ref('');
|
|
|
40
|
+const selectOptions: Ref<SelectTypes['options']> = ref([]);
|
|
|
41
|
+const selectDevice = ref([]);
|
|
|
42
|
+const deviceList: Ref<TDeviceList[]> = ref([]);
|
|
|
43
|
+
|
|
|
44
|
+watch(organizationId, async (newValue: string) => {
|
|
|
45
|
+ if (!newValue) return;
|
|
|
46
|
+ //获取设备
|
|
|
47
|
+ const { items } = await screenLinkPageByDeptIdGetDevice({
|
|
|
48
|
+ organizationId: newValue,
|
|
|
49
|
+ });
|
|
|
50
|
+ selectOptions.value = items.map((item) => {
|
|
|
51
|
+ if (item.deviceType !== 'GATEWAY')
|
|
|
52
|
+ return {
|
|
|
53
|
+ label: item.name,
|
|
|
54
|
+ value: item.tbDeviceId,
|
|
|
55
|
+ };
|
|
|
56
|
+ });
|
|
|
57
|
+});
|
|
|
58
|
+const handleDeviceChange = (e) => {
|
|
|
59
|
+ deviceList.value = e;
|
|
|
60
|
+};
|
|
|
61
|
+const [registerForm, { validate, setFieldsValue, resetFields }] = useForm({
|
|
|
62
|
+ labelWidth: 120,
|
|
|
63
|
+ schemas: formSchema,
|
|
|
64
|
+ showActionButtonGroup: false,
|
|
|
65
|
+ fieldMapToTime: [['timeZone', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
|
|
|
66
|
+});
|
|
|
67
|
+const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
|
|
68
|
+ await resetFields();
|
|
|
69
|
+ setDrawerProps({ confirmLoading: false });
|
|
|
70
|
+ isUpdate.value = !!data?.isUpdate;
|
|
|
71
|
+ if (unref(isUpdate)) {
|
|
|
72
|
+ //回显基础数据
|
|
|
73
|
+ editId.value = data.record.id;
|
|
|
74
|
+ await setFieldsValue(data.record);
|
|
|
75
|
+ //回显嵌套数据
|
|
|
76
|
+ setFieldsValue({
|
|
|
77
|
+ agg: queryCondition?.agg,
|
|
|
78
|
+ interval: queryCondition?.interval,
|
|
|
79
|
+ });
|
|
|
80
|
+ //回显设备
|
|
|
81
|
+ orgId.value = data.record.organizationId;
|
|
|
82
|
+ //获取该组织下的设备--排除网关设备
|
59
|
const { items } = await screenLinkPageByDeptIdGetDevice({
|
83
|
const { items } = await screenLinkPageByDeptIdGetDevice({
|
60
|
- organizationId: newValue,
|
84
|
+ organizationId: data.record.organizationId,
|
61
|
});
|
85
|
});
|
62
|
selectOptions.value = items.map((item) => {
|
86
|
selectOptions.value = items.map((item) => {
|
63
|
if (item.deviceType !== 'GATEWAY')
|
87
|
if (item.deviceType !== 'GATEWAY')
|
|
@@ -66,151 +90,118 @@ |
|
@@ -66,151 +90,118 @@ |
66
|
value: item.tbDeviceId,
|
90
|
value: item.tbDeviceId,
|
67
|
};
|
91
|
};
|
68
|
});
|
92
|
});
|
|
|
93
|
+ //TODO 模拟的数据 待服务端返回
|
|
|
94
|
+ const deviceIds: any = [
|
|
|
95
|
+ {
|
|
|
96
|
+ label: '奥迪网关子设备',
|
|
|
97
|
+ key: '8a4cc9a0-f201-11ec-98ad-a9680487d1e0',
|
|
|
98
|
+ },
|
|
|
99
|
+ {
|
|
|
100
|
+ label: '宝马默认设备',
|
|
|
101
|
+ key: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
102
|
+ },
|
|
|
103
|
+ {
|
|
|
104
|
+ label: '奔驰默认设备',
|
|
|
105
|
+ key: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
106
|
+ },
|
|
|
107
|
+ {
|
|
|
108
|
+ label: '新增奥迪测试设备',
|
|
|
109
|
+ key: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
|
|
|
110
|
+ },
|
|
|
111
|
+ ];
|
|
|
112
|
+ selectDevice.value = deviceIds;
|
|
|
113
|
+ //回显设备属性 TODO 模拟的数据 待服务端返回
|
|
|
114
|
+ deviceList.value = [
|
|
|
115
|
+ {
|
|
|
116
|
+ value: '8a4cc9a0-f201-11ec-98ad-a9680487d1e0',
|
|
|
117
|
+ attribute: 'CO2',
|
|
|
118
|
+ label: '奥迪网关子设备',
|
|
|
119
|
+ },
|
|
|
120
|
+ {
|
|
|
121
|
+ value: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
122
|
+ attribute: 'co',
|
|
|
123
|
+ label: '宝马默认设备',
|
|
|
124
|
+ },
|
|
|
125
|
+ {
|
|
|
126
|
+ value: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
127
|
+ attribute: 'hot',
|
|
|
128
|
+ label: '奔驰默认设备',
|
|
|
129
|
+ },
|
|
|
130
|
+ {
|
|
|
131
|
+ value: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
|
|
|
132
|
+ attribute: 'wet',
|
|
|
133
|
+ label: '新增奥迪测试设备',
|
|
|
134
|
+ },
|
|
|
135
|
+ ];
|
|
|
136
|
+ nextTick(() => { });
|
|
|
137
|
+ } else {
|
|
|
138
|
+ editId.value = '';
|
|
|
139
|
+ orgId.value = '';
|
|
|
140
|
+ selectDevice.value = [];
|
|
|
141
|
+ selectOptions.value = [];
|
|
|
142
|
+ deviceList.value = [];
|
|
|
143
|
+ }
|
|
|
144
|
+});
|
|
|
145
|
+const getAttrDevice: Ref<TDeviceList[]> = ref([]);
|
|
|
146
|
+const getTitle = computed(() => (!unref(isUpdate) ? '新增报表配置' : '编辑报表配置'));
|
|
|
147
|
+const handleChange = (e: any) => {
|
|
|
148
|
+ getAttrDevice.value.push({
|
|
|
149
|
+ device: e.value,
|
|
|
150
|
+ attribute: e.attribute
|
69
|
});
|
151
|
});
|
70
|
- const handleDeviceChange = (e) => {
|
|
|
71
|
- deviceList.value = e;
|
|
|
72
|
- };
|
|
|
73
|
- const [registerForm, { validate, setFieldsValue, resetFields }] = useForm({
|
|
|
74
|
- labelWidth: 120,
|
|
|
75
|
- schemas: formSchema,
|
|
|
76
|
- showActionButtonGroup: false,
|
|
|
77
|
- fieldMapToTime: [['timeZone', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
|
|
|
78
|
- });
|
|
|
79
|
- const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
|
|
80
|
- await resetFields();
|
|
|
81
|
- setDrawerProps({ confirmLoading: false });
|
|
|
82
|
- isUpdate.value = !!data?.isUpdate;
|
|
|
83
|
- if (unref(isUpdate)) {
|
|
|
84
|
- //回显基础数据
|
|
|
85
|
- editId.value = data.record.id;
|
|
|
86
|
- await setFieldsValue(data.record);
|
|
|
87
|
- //回显嵌套数据
|
|
|
88
|
- setFieldsValue({
|
|
|
89
|
- agg: queryCondition?.agg,
|
|
|
90
|
- interval: queryCondition?.interval,
|
|
|
91
|
- });
|
|
|
92
|
- //回显设备
|
|
|
93
|
- orgId.value = data.record.organizationId;
|
|
|
94
|
- //获取该组织下的设备--排除网关设备
|
|
|
95
|
- const { items } = await screenLinkPageByDeptIdGetDevice({
|
|
|
96
|
- organizationId: data.record.organizationId,
|
|
|
97
|
- });
|
|
|
98
|
- selectOptions.value = items.map((item) => {
|
|
|
99
|
- if (item.deviceType !== 'GATEWAY')
|
|
|
100
|
- return {
|
|
|
101
|
- label: item.name,
|
|
|
102
|
- value: item.tbDeviceId,
|
|
|
103
|
- };
|
|
|
104
|
- });
|
|
|
105
|
- //TODO 模拟的数据 待服务端返回
|
|
|
106
|
- const deviceIds: any = [
|
|
|
107
|
- {
|
|
|
108
|
- label: '奥迪网关子设备',
|
|
|
109
|
- key: '8a4cc9a0-f201-11ec-98ad-a9680487d1e0',
|
|
|
110
|
- },
|
|
|
111
|
- {
|
|
|
112
|
- label: '宝马默认设备',
|
|
|
113
|
- key: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
114
|
- },
|
|
|
115
|
- {
|
|
|
116
|
- label: '奔驰默认设备',
|
|
|
117
|
- key: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
118
|
- },
|
|
|
119
|
- {
|
|
|
120
|
- label: '新增奥迪测试设备',
|
|
|
121
|
- key: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
|
|
|
122
|
- },
|
|
|
123
|
- ];
|
|
|
124
|
- selectDevice.value = deviceIds;
|
|
|
125
|
- //回显设备属性 TODO 模拟的数据 待服务端返回
|
|
|
126
|
- deviceList.value = [
|
|
|
127
|
- {
|
|
|
128
|
- value: '8a4cc9a0-f201-11ec-98ad-a9680487d1e0',
|
|
|
129
|
- attribute: 'CO2',
|
|
|
130
|
- label: '奥迪网关子设备',
|
|
|
131
|
- },
|
|
|
132
|
- {
|
|
|
133
|
- value: '8943f0b0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
134
|
- attribute: 'co',
|
|
|
135
|
- label: '宝马默认设备',
|
|
|
136
|
- },
|
|
|
137
|
- {
|
|
|
138
|
- value: '6d9043f0-f1f7-11ec-98ad-a9680487d1e0',
|
|
|
139
|
- attribute: 'hot',
|
|
|
140
|
- label: '奔驰默认设备',
|
|
|
141
|
- },
|
|
|
142
|
- {
|
|
|
143
|
- value: '8f5b4280-f29e-11ec-98ad-a9680487d1e0',
|
|
|
144
|
- attribute: 'wet',
|
|
|
145
|
- label: '新增奥迪测试设备',
|
|
|
146
|
- },
|
|
|
147
|
- ];
|
|
|
148
|
- nextTick(() => {});
|
152
|
+};
|
|
|
153
|
+let postObj: any = reactive({});
|
|
|
154
|
+let queryCondition: any = reactive({});
|
|
|
155
|
+let executeContent: any = reactive({});
|
|
|
156
|
+const endTs = ref(0);
|
|
|
157
|
+async function handleSubmit() {
|
|
|
158
|
+ setDrawerProps({ confirmLoading: true });
|
|
|
159
|
+ try {
|
|
|
160
|
+ const { createMessage } = useMessage();
|
|
|
161
|
+ const values = await validate();
|
|
|
162
|
+ if (!values) return;
|
|
|
163
|
+ if (getAttrDevice.value.length === 0) {
|
|
|
164
|
+ return createMessage.error('请选择设备及其属性');
|
|
|
165
|
+ }
|
|
|
166
|
+ if (values.executeWay == 0) {
|
|
|
167
|
+ executeContent = null;
|
149
|
} else {
|
168
|
} else {
|
150
|
- editId.value = '';
|
|
|
151
|
- orgId.value = '';
|
|
|
152
|
- selectDevice.value = [];
|
|
|
153
|
- selectOptions.value = [];
|
|
|
154
|
- deviceList.value = [];
|
169
|
+ executeContent = {};
|
155
|
}
|
170
|
}
|
156
|
- });
|
|
|
157
|
- const getAttrDevice: any = ref([]);
|
|
|
158
|
- const getTitle = computed(() => (!unref(isUpdate) ? '新增报表配置' : '编辑报表配置'));
|
|
|
159
|
- const handleChange = (e) => {
|
|
|
160
|
- getAttrDevice.value.push(e);
|
|
|
161
|
- };
|
|
|
162
|
- let postObj: any = reactive({});
|
|
|
163
|
- let queryCondition: any = reactive({});
|
|
|
164
|
- let executeContent: any = reactive({});
|
|
|
165
|
- const endTs: any = ref(0);
|
|
|
166
|
- async function handleSubmit() {
|
|
|
167
|
- setDrawerProps({ confirmLoading: true });
|
|
|
168
|
- try {
|
|
|
169
|
- const { createMessage } = useMessage();
|
|
|
170
|
- const values = await validate();
|
|
|
171
|
- if (!values) return;
|
|
|
172
|
- if (getAttrDevice.value.length === 0) {
|
|
|
173
|
- return createMessage.error('请选择设备及其属性');
|
|
|
174
|
- }
|
|
|
175
|
- if (values.executeWay == 0) {
|
|
|
176
|
- executeContent = null;
|
|
|
177
|
- } else {
|
|
|
178
|
- executeContent = {};
|
|
|
179
|
- }
|
|
|
180
|
- if (values.timeZone) {
|
|
|
181
|
- const getTime = JSON.stringify(values.timeZone);
|
|
|
182
|
- endTs.value = moment(JSON.parse(getTime)[0]).valueOf() || 1659424160000;
|
|
|
183
|
- }
|
|
|
184
|
- queryCondition = {
|
|
|
185
|
- agg: values.agg,
|
|
|
186
|
- interval: values.interval,
|
|
|
187
|
- limit: values.limit,
|
|
|
188
|
- };
|
|
|
189
|
- delete values.devices;
|
|
|
190
|
- delete values.agg;
|
|
|
191
|
- delete values.interval;
|
|
|
192
|
- delete values.timeZone;
|
|
|
193
|
- postObj = {
|
|
|
194
|
- ...values,
|
|
|
195
|
- ...{ executeAttributes: getAttrDevice.value },
|
|
|
196
|
- ...{ queryCondition },
|
|
|
197
|
- ...{ endTs: endTs.value },
|
|
|
198
|
- ...{ executeContent },
|
|
|
199
|
- ...{ id: editId.value !== '' ? editId.value : '' },
|
|
|
200
|
- };
|
|
|
201
|
- let saveMessage = '添加成功';
|
|
|
202
|
- let updateMessage = '修改成功';
|
|
|
203
|
- editId.value !== ''
|
|
|
204
|
- ? await putReportConfigManage(postObj)
|
|
|
205
|
- : await createOrEditReportManage(postObj);
|
|
|
206
|
-
|
|
|
207
|
- closeDrawer();
|
|
|
208
|
- emit('success');
|
|
|
209
|
- createMessage.success(unref(isUpdate) ? updateMessage : saveMessage);
|
|
|
210
|
- } finally {
|
|
|
211
|
- setTimeout(() => {
|
|
|
212
|
- setDrawerProps({ confirmLoading: false });
|
|
|
213
|
- }, 300);
|
171
|
+ if (values.timeZone) {
|
|
|
172
|
+ const getTime = JSON.stringify(values.timeZone);
|
|
|
173
|
+ endTs.value = moment(JSON.parse(getTime)[0]).valueOf() || 1659424160000;
|
214
|
}
|
174
|
}
|
|
|
175
|
+ queryCondition = {
|
|
|
176
|
+ agg: values.agg,
|
|
|
177
|
+ interval: values.interval,
|
|
|
178
|
+ limit: values.limit,
|
|
|
179
|
+ };
|
|
|
180
|
+ delete values.devices;
|
|
|
181
|
+ delete values.agg;
|
|
|
182
|
+ delete values.interval;
|
|
|
183
|
+ delete values.timeZone;
|
|
|
184
|
+ postObj = {
|
|
|
185
|
+ ...values,
|
|
|
186
|
+ ...{ executeAttributes: getAttrDevice.value },
|
|
|
187
|
+ ...{ queryCondition },
|
|
|
188
|
+ ...{ endTs: endTs.value },
|
|
|
189
|
+ ...{ executeContent },
|
|
|
190
|
+ ...{ id: editId.value !== '' ? editId.value : '' },
|
|
|
191
|
+ };
|
|
|
192
|
+ let saveMessage = '添加成功';
|
|
|
193
|
+ let updateMessage = '修改成功';
|
|
|
194
|
+ editId.value !== ''
|
|
|
195
|
+ ? await putReportConfigManage(postObj)
|
|
|
196
|
+ : await createOrEditReportManage(postObj);
|
|
|
197
|
+
|
|
|
198
|
+ closeDrawer();
|
|
|
199
|
+ emit('success');
|
|
|
200
|
+ createMessage.success(unref(isUpdate) ? updateMessage : saveMessage);
|
|
|
201
|
+ } finally {
|
|
|
202
|
+ setTimeout(() => {
|
|
|
203
|
+ setDrawerProps({ confirmLoading: false });
|
|
|
204
|
+ }, 300);
|
215
|
}
|
205
|
}
|
|
|
206
|
+}
|
216
|
</script> |
207
|
</script> |