data-area-sankey.vue
9.25 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<template>
<select-var-modal
:visible="selectVarVisible"
:dept-id="cardForm.deptId"
@cancel="handleModalClose"
:filterVarList="filterVarList"
@add="handleDeviceVarSelect"/>
<a-card>
<a-button type="primary" @click="handleAddChildList" v-if="form.varList.length<=0">添加变量</a-button>
<a-form :model="form" ref="formRef" auto-label-width>
<a-table ref="tableConfigRef" :indent-size="32" row-key="varSn" :columns="columns" v-show="form.varList.length>0"
:data="form.varList" :pagination="false"
:bordered="{ wrapper: true, cell: true }" v-bind:hide-expand-button-on-empty="true">
<!-- 变量名称 -->
<template #varName="{ record }">
<a-form-item field="varSn" no-style>
<a-input v-model="record.varName" disabled/>
</a-form-item>
</template>
<!-- 变量编码-->
<template #varSn="{ record }">
<a-form-item field="varSn" label="变量编码" no-style>
<a-input v-model="record.varSn" disabled/>
</a-form-item>
</template>
<!--图例名称-->
<template #legend="{ record }">
<a-form-item field="legend" label="图例名称" no-style>
<a-input v-model="record.legend"/>
</a-form-item>
</template>
<!--指标单位-->
<template #unit="{ record }">
<a-form-item field="unit" label="指标单位" no-style>
<a-input v-model="record.unit" :max-length="6"/>
</a-form-item>
</template>
<!--存储类型-->
<template #storageType="{ record }">
<a-form-item field="storageType" label="存储类型" no-style>
<a-select v-model="record.storageType" @change="handleStorageType(record)"
:placeholder="$t('global.pleaseSelect')" allow-clear>
<a-option v-for="(item,index) in datav_storage_type" :value="item.value" :key="index">{{ item.label }}
</a-option>
</a-select>
</a-form-item>
</template>
<!--数值类型-->
<template #changeType="{ record }">
<a-form-item field="changeType" label="数值类型" :disabled="record.storageType!=1" no-style>
<a-select v-model="record.changeType" :placeholder="$t('global.pleaseSelect')" allow-clear>
<template v-if="defaultVal.dateDim==70">
<a-option v-for="(item,index) in datav_change_type" v-show="item.value==1" :key="index"
:value="Number(item.value)">{{ item.label }}
</a-option>
</template>
<template v-else v-for="(item,index) in datav_change_type" :key="index">
<a-option :value="Number(item.value)" v-show="item.value!=1">{{ item.label }}</a-option>
</template>
</a-select>
</a-form-item>
</template>
<template #operate="{ record }">
<a-button size="small" type="text" @click="handleAddChildList(record)">添加子变量
</a-button>
<a-button size="small" type="text" status="danger" @click="handleDeviceVarDelete(record)">
{{ $t('global.delete') }}
</a-button>
</template>
</a-table>
</a-form>
</a-card>
</template>
<script setup lang="ts">
import {computed, getCurrentInstance, nextTick, onMounted, ref, watchEffect} from "vue";
import SelectVarModal from "@/views/manage/station/components/select-var-modal/index.vue";
import SankeyFormItem from "@/views/dashboard/preview/component/SankeyFormItem.vue"
import {TableInstance, Message} from "@arco-design/web-vue";
import {FormInstance} from "@arco-design/web-vue/es/form";
const proxy = getCurrentInstance()?.appContext.config.globalProperties;
const {datav_storage_type, datav_change_type} = proxy?.useDict("datav_storage_type", "datav_change_type");
const props = defineProps({
defaultVal: {
type: Object,
default: {}
},
// 站点
cardForm: {
type: Object,
default: {}
},
})
const formRef = ref<FormInstance>();
const columns = computed<any[]>(() => [
{
title: "变量名称",
dataIndex: "varName",
slotName: "varName",
align: 'center',
// width: 150,
ellipsis: true,
tooltip: {position: 'top'},
}, {
title: "变量编码",
dataIndex: "varSn",
slotName: "varSn",
align: 'center',
// width: 130,
ellipsis: true,
tooltip: {position: 'top'},
}, {
title: "图例名称",
dataIndex: "legend",
slotName: "legend",
align: 'center',
// width: 250,
}, {
title: "单位",
dataIndex: "unit",
slotName: "unit",
align: 'center',
// width: 150,
}, {
title: "存储类型",
dataIndex: "storageType",
slotName: "storageType",
align: 'center',
// width: 220,
}, {
title: "数值类型",
dataIndex: "changeType",
slotName: "changeType",
align: 'center',
// width: 220,
},
{
title: "操作",
dataIndex: "operate",
slotName: 'operate',
// width: 250,
align: 'center',
}
]);
// 弹窗显示隐藏
const selectVarVisible = ref<boolean>(false);
// 初始化数据配置
const initDataConfig = () => {
return {
comVariable: "", //通用变量(用电量 发电量 电流 电压 有功功率
varSn: "",
varName: "", //名称
legend: "",
color: "#fff",
unit: "",
percentage: 1,
baseValue: '0',
minValue: 0,
maxValue: 0,
storageType: '1',
changeType: '',
chain: false,
yoy: false,
backgroundColor: "#fff",
children: [], //子数据区
}
};
const currentRowData = ref<any>(null);
const tableConfigRef = ref<TableInstance>();
const form = ref<any>({
varList: [], //数据区域
});
const filterVarList = ref<any>([]);
const handleStorageType = (record: any) => {
record.changeType = '';
};
// 关闭变量弹窗
const handleModalClose = () => {
selectVarVisible.value = false;
};
// 选择变量
const handleDeviceVarSelect = (record: any) => {
let obj = {
varSn: record.varSn,
varName: record.deviceName + '/' + record.varName,
legend: record.varName,
unit: record.unit,
key: `${Date.now()}${Math.floor(Math.random() * 1000000)}`
}
let newConfig: any = {...initDataConfig(), ...obj};
if (JSON.stringify(form.value.varList) == '[]') {
form.value.varList.push(newConfig);
selectVarVisible.value = false;
} else {
if (props.defaultVal.dateDim == 70) {
newConfig.changeType = 1;
} else {
newConfig.changeType = 2;
}
currentRowData.value.children.push(newConfig);
}
tableConfigRef.value?.expandAll(true);
};
// 添加数据区
const handleAddChildList = async (item: any) => {
currentRowData.value = item ? item : {};
filterVarList.value = form.value.varList;
// const parentNodes = findParentNodes(item.key, form.value.varList);
// parentNodes.push(currentRowData.value);
// filterVarList.value = parentNodes;
selectVarVisible.value = true;
};
// 自变量查重
const findParentNodes = (nodeId: number | string, treeData: TreeNode[], currentParents: TreeNode[] = []): TreeNode[] =>{
for (const node of treeData) {
console.log(node)
if (node.children) {
const foundParentsInChildren = findParentNodes(nodeId, node.children, [...currentParents, node]);
if (foundParentsInChildren.length > currentParents.length) {
return foundParentsInChildren;
}
}
if (node.key === nodeId) {
return currentParents;
}
}
return [];
}
const getItem = (data: any, parentKey: string) => {
for (const item of data) {
if (item.key === parentKey) {
return item;
}
if (item.children && item.children.length > 0) {
const result: any = getItem(item.children, parentKey);
if (result) {
return result;
}
}
}
return undefined;
};
// 设备变量移除
const handleDeviceVarDelete = (record: any) => {
if (record.children && record.children.length > 0) {
Message.error({
content: `请先移除子变量`,
duration: 1.5 * 1000,
});
} else {
let data = form.value.varList;
data = removeData(data, record.key);
form.value.varList = data;
}
};
function removeData(data: any, key: string) {
return data.filter((item: any) => {
if (item.key === key) {
return false;
}
if (item.children) {
item.children = removeData(item.children, key);
}
return true;
});
}
const formInit = () => {
if (props.defaultVal.dateDim == 70) {
handleChange(form.value.varList, 1)
} else if (!props.defaultVal.isDetail) {
handleChange(form.value.varList, 2)
}
}
// 修改changeType
const handleChange = (data: any, changeType: number) => {
data.map((item: any) => {
item.changeType = changeType;
if (item.storageType == 2) {
item.changeType = '';
}
if (item.children) {
handleChange(item.children, changeType);
}
})
}
watchEffect(() => {
formInit();
tableConfigRef.value?.expandAll(true);
})
onMounted(() => {
console.log(tableConfigRef.value)
tableConfigRef.value?.expandAll(true);
})
defineExpose({
form,
formRef,
setForm: (val: any) => {
form.value.varList = [];
form.value = val;
}
});
</script>
<style lang="less" scoped>
.input-width {
width: 500px;
}
.delete-icon {
font-size: 16px;
margin-left: 6px;
}
</style>