|
@@ -393,6 +393,7 @@ export default {
|
|
|
// 设备
|
|
|
devTreeByFacs(this.areaCode).then(response => {
|
|
|
this.objCodeOptions = response.data;
|
|
|
+ console.log("设备多少数据!!!", this.objCodeOptions);
|
|
|
this.AllCode = this.buildTree(this.objCodeOptions);
|
|
|
|
|
|
});
|
|
@@ -409,59 +410,90 @@ export default {
|
|
|
return node;
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
/** 数据自动填补*/
|
|
|
handleSelect(value) {
|
|
|
console.log("value", value);
|
|
|
- // 获取能源设施所有信息
|
|
|
- listAllFacs(this.areaCode).then(response => {
|
|
|
- const data = response.data;
|
|
|
- console.log("data", data);
|
|
|
- // 循环输出
|
|
|
- for (let i = 0; i < data.length; i++) {
|
|
|
- if (value.includes(data[i].facsCode)) {
|
|
|
- this.form.objName = data[i].facsName;
|
|
|
- this.form.insLocation = data[i].refAreaName;
|
|
|
- return;
|
|
|
+ // 检查 value 是否为数组
|
|
|
+ if (Array.isArray(value)) {
|
|
|
+ // 检查数组是否至少有一个元素,并且第一个元素的首字母是否为字母
|
|
|
+ if (value.length > 0 && /^[a-zA-Z]/.test(value[0][0])) {
|
|
|
+ // 获取能源设施所有信息
|
|
|
+ listAllFacs(this.areaCode).then(response => {
|
|
|
+ const data = response.data;
|
|
|
+ console.log("data", data);
|
|
|
+ // 循环输出
|
|
|
+ for (let i = 0; i < data.length; i++) {
|
|
|
+ if (value.includes(data[i].facsCode)) {
|
|
|
+ this.form.objName = data[i].facsName;
|
|
|
+ this.form.insLocation = data[i].refAreaName;
|
|
|
+ console.log("设施名字", this.form.objName)
|
|
|
+ console.log("设施地址", this.form.insLocation)
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
+ } else if (value.length > 0) {
|
|
|
+ // 获取能源设备所有信息
|
|
|
+ devTreeByFacs(this.areaCode).then(response => {
|
|
|
+ const data = response.data;
|
|
|
+ console.log("data", data);
|
|
|
|
|
|
- });
|
|
|
- // 获取能源设备所有信息
|
|
|
- devTreeByFacs(this.areaCode).then(response => {
|
|
|
- const data = response.data;
|
|
|
- console.log("data", data);
|
|
|
- function findDeviceById(data, path = [], ids) {
|
|
|
- for (const item of data) {
|
|
|
- const currentPath = [...path, item.label];
|
|
|
- if (ids.includes(item.id)) {
|
|
|
- let labels = currentPath.length > 2 ? currentPath.slice(0, -1) : currentPath;
|
|
|
- return {labels, lastLabel: item.label, found: true};
|
|
|
+ function findDeviceById(data, path = [], ids) {
|
|
|
+ for (const item of data) {
|
|
|
+ const currentPath = [...path, {label: item.label, tier: item.tier}];
|
|
|
+ if (ids.includes(item.id)) {
|
|
|
+ // 找到 tier 为 'Device' 的层级,并获取最后一个“-”后面的数据
|
|
|
+ const deviceTierIndex = currentPath.findIndex(p => p.tier === 'Device');
|
|
|
+ let lastSegment = '';
|
|
|
+ let deviceLabel = '';
|
|
|
+ if (deviceTierIndex !== -1) {
|
|
|
+ deviceLabel = currentPath[deviceTierIndex].label;
|
|
|
+ lastSegment = deviceLabel.split('-').pop();
|
|
|
+ }
|
|
|
+ return {labels: currentPath, lastSegment, deviceLabel, found: true};
|
|
|
+ }
|
|
|
+ if (item.children && item.children.length) {
|
|
|
+ const result = findDeviceById(item.children, currentPath, ids);
|
|
|
+ if (result.found) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {labels: [], lastSegment: null, deviceLabel: '', found: false};
|
|
|
}
|
|
|
- if (item.children && item.children.length) {
|
|
|
- const result = findDeviceById(item.children, currentPath, ids);
|
|
|
+
|
|
|
+ let lastResult = {labels: [], lastSegment: null, deviceLabel: '', found: false};
|
|
|
+ value.forEach(id => {
|
|
|
+ const result = findDeviceById(data, [], [id]);
|
|
|
if (result.found) {
|
|
|
- return result;
|
|
|
+ lastResult = result;
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- return {labels: [], lastLabel: null, found: false};
|
|
|
- }
|
|
|
- let lastResult = {labels: [], lastLabel: null, found: false};
|
|
|
- value.forEach(id => {
|
|
|
- const result = findDeviceById(data, [], [id]);
|
|
|
- if (result.found) {
|
|
|
- lastResult = result;
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
- if (lastResult.found) {
|
|
|
- this.form.objName = lastResult.lastLabel;
|
|
|
- this.form.insLocation = lastResult.labels.join(' / ');
|
|
|
- } else {
|
|
|
- console.log("没有找到匹配的设备");
|
|
|
- }
|
|
|
- });
|
|
|
+ if (lastResult.found) {
|
|
|
+ // 构建 insLocation 和 objName
|
|
|
+ let insLocationParts = [lastResult.labels[0].label]; // 第一层的 label
|
|
|
+ if (lastResult.deviceLabel) {
|
|
|
+ let deviceLabelParts = lastResult.deviceLabel.split('-');
|
|
|
+ deviceLabelParts.pop(); // 移除最后一个“-”后面的数据
|
|
|
+ insLocationParts = insLocationParts.concat(deviceLabelParts.join('-'));
|
|
|
+ }
|
|
|
|
|
|
+ this.form.insLocation = insLocationParts.join(' / ');
|
|
|
+ this.form.objName = lastResult.lastSegment;
|
|
|
+ console.log("设备名字", this.form.objName)
|
|
|
+ console.log("设备地址", this.form.insLocation)
|
|
|
+ } else {
|
|
|
+ console.log("没有找到匹配的设备");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ console.log("value 为空数组或不满足条件");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log("value 不是数组");
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**编辑按钮操作*/
|
|
@@ -484,7 +516,6 @@ export default {
|
|
|
this.form = response.data;
|
|
|
console.log("this.form",this.form)
|
|
|
this.form.objCode = this.form.objCode ? this.form.objCode.split(',') : [];
|
|
|
-
|
|
|
// 调用 changeObjOptions 来更新 AllCode
|
|
|
this.changeObjOptions(this.form.objType);
|
|
|
this.open = true;
|