/*
* @Author: yeminglong
* @Date: 2023-09-09 10:23:30
* @LastEditTime: 2023-09-09 14:51:52
* @LastEditors: yeminglong
* @Description:
*/
/**
* tree2Array
* @param {tree} tree
* @returns
*/
export function treeToArray(tree) {
let res = [];
for (const item of tree) {
const { children, ...i } = item;
if (children && children.length) {
res = res.concat(treeToArray(children));
}
res.push(i);
}
return res;
}
const columns = [
{
label: '监控时间',
prop: 'data_time',
show: true,
width: '150',
},
{
label: '生产设施工况标记',
prop: 'workcordSc',
show: false,
width: '120',
align: 'center',
children: [
{
label: '自动',
prop: 'zd_workcordSc',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_workcordSc',
show: true,
width: '85',
},
],
},
{
label: '流量',
prop: 'B01',
show: true,
width: '78',
children: [
{
label: '瞬时流量(升/秒)',
prop: 'avg_value_B01',
show: false,
width: '110',
},
{
label: '累计流量(立方米)',
prop: 'cou_value_B01',
show: true,
width: '110',
},
{
label: '自动监测设备维护标记',
prop: 'flag_B01',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_B01',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_B01',
show: true,
width: '85',
},
],
},
],
},
{
label: 'pH',
prop: '001',
show: true,
width: '78',
children: [
{
label: '监测值',
prop: 'sbz_001',
show: true,
width: '78',
children: [
{
label: '最小值',
prop: 'min_value_001',
show: true,
width: '78',
},
{
label: '平均值',
prop: 'avg_value_001',
show: true,
width: '78',
},
{
label: '最大值',
prop: 'max_value_001',
show: true,
width: '78',
},
],
},
{
label: '标准值',
prop: 'outlet_standard_001',
show: true,
width: '75',
},
{
label: '自动监测设备维护标记',
prop: 'flag_001',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_001',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_001',
show: true,
width: '85',
},
],
},
],
},
{
label: '化学需氧量(毫克/升)',
prop: '011',
show: true,
width: '78',
children: [
{
label: '上报值',
prop: 'yuanshi_011',
show: true,
width: '78',
children: [
{
label: '浓度',
prop: 'avg_value_011',
show: true,
width: '78',
},
{
label: '最小值',
prop: 'min_value_011',
show: false,
width: '78',
},
{
label: '最大值',
prop: 'max_value_011',
show: false,
width: '78',
},
{
label: '标准值',
prop: 'outlet_standard_011',
show: true,
width: '75',
},
{
label: '排放量(千克)',
prop: 'cou_value_011',
show: true,
width: '85',
},
{
label: '自动监测设备维护标记',
prop: 'flag_011',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_011',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_011',
show: true,
width: '85',
},
],
},
],
},
{
label: '修正值',
prop: 'xiuzhen_011',
show: true,
width: '78',
children: [
{
label: '浓度值',
prop: 'avg_revised_011',
show: true,
width: '78',
},
{
label: '排放量(千克)',
prop: 'cou_revised_011',
show: true,
width: '85',
},
],
},
],
},
{
label: '氨氮(毫克/升)',
prop: '060',
show: true,
width: '78',
children: [
{
label: '上报值',
prop: 'yuanshi_060',
show: true,
width: '78',
children: [
{
label: '浓度',
prop: 'avg_value_060',
show: true,
width: '78',
},
{
label: '最小值',
prop: 'min_value_060',
show: false,
width: '78',
},
{
label: '最大值',
prop: 'max_value_060',
show: false,
width: '78',
},
{
label: '标准值',
prop: 'outlet_standard_060',
show: true,
width: '75',
},
{
label: '排放量(千克)',
prop: 'cou_value_060',
show: true,
width: '85',
},
{
label: '自动监测设备维护标记',
prop: 'flag_060',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_060',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_060',
show: true,
width: '85',
},
],
},
],
},
{
label: '修正值',
prop: 'xiuzhen_060',
show: true,
width: '78',
children: [
{
label: '浓度值',
prop: 'avg_revised_060',
show: true,
width: '78',
},
{
label: '排放量(千克)',
prop: 'cou_revised_060',
show: true,
width: '85',
},
],
},
],
},
{
label: '总氮(毫克/升)',
prop: '065',
show: true,
width: '78',
children: [
{
label: '上报值',
prop: 'yuanshi_065',
show: true,
width: '78',
children: [
{
label: '浓度',
prop: 'avg_value_065',
show: true,
width: '78',
},
{
label: '最小值',
prop: 'min_value_065',
show: false,
width: '78',
},
{
label: '最大值',
prop: 'max_value_065',
show: false,
width: '78',
},
{
label: '标准值',
prop: 'outlet_standard_065',
show: true,
width: '75',
},
{
label: '排放量(千克)',
prop: 'cou_value_065',
show: true,
width: '85',
},
{
label: '自动监测设备维护标记',
prop: 'flag_065',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_065',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_065',
show: true,
width: '85',
},
],
},
],
},
{
label: '修正值',
prop: 'xiuzhen_065',
show: true,
width: '78',
children: [
{
label: '浓度值',
prop: 'avg_revised_065',
show: true,
width: '78',
},
{
label: '排放量(千克)',
prop: 'cou_revised_065',
show: true,
width: '85',
},
],
},
],
},
{
label: '总磷(毫克/升)',
prop: '101',
show: true,
width: '78',
children: [
{
label: '上报值',
prop: 'yuanshi_101',
show: true,
width: '78',
children: [
{
label: '浓度',
prop: 'avg_value_101',
show: true,
width: '78',
},
{
label: '最小值',
prop: 'min_value_101',
show: false,
width: '78',
},
{
label: '最大值',
prop: 'max_value_101',
show: false,
width: '78',
},
{
label: '标准值',
prop: 'outlet_standard_101',
show: true,
width: '75',
},
{
label: '排放量(千克)',
prop: 'cou_value_101',
show: true,
width: '85',
},
{
label: '自动监测设备维护标记',
prop: 'flag_101',
show: true,
width: '120',
children: [
{
label: '自动',
prop: 'zd_flag_101',
show: true,
width: '85',
},
{
label: '人工',
prop: 'rg_flag_101',
show: true,
width: '85',
},
],
},
],
},
{
label: '修正值',
prop: 'xiuzhen_101',
show: true,
width: '78',
children: [
{
label: '浓度值',
prop: 'avg_revised_101',
show: true,
width: '78',
},
{
label: '排放量(千克)',
prop: 'cou_revised_101',
show: true,
width: '85',
},
],
},
],
},
];
const propsObj = {
props: [
'workcordSc',
'zd_flag',
'rg_flag',
'avg_value_B',
'cou_value_B',
'avg_revised',
'cou_revised_',
'min',
'max',
'avg_hm_revised_S',
'ndbjh_',
'ndhmh_',
'hand',
'avg_revised_S',
'outlet_standard_',
],
dic: {
workcordSc: {
prop: 'workcordSc',
checked: false,
type: '1',
},
zd_flag: {
prop: 'zd_flag',
checked: false,
type: '1',
},
rg_flag: {
prop: 'rg_flag',
checked: false,
type: '1',
},
avg_value_B: {
prop: 'avg_value_B',
checked: false,
type: '1',
},
cou_value_B: {
prop: 'cou_value_B',
checked: false,
type: '1',
},
avg_revised: {
prop: 'avg_revised',
checked: false,
type: '1',
},
cou_revised_: {
prop: 'cou_revised_',
checked: false,
type: '1',
},
min: {
prop: 'min',
checked: false,
type: '1',
},
max: {
prop: 'max',
checked: false,
type: '1',
},
avg_hm_revised_S: {
prop: 'avg_hm_revised_S',
checked: false,
type: '1',
},
ndbjh_: {
prop: 'ndbjh_',
checked: true,
type: '1',
},
ndhmh_: {
prop: 'ndhmh_',
checked: true,
type: '1',
},
hand: {
prop: 'hand',
checked: false,
type: '1',
},
avg_revised_S: {
prop: 'avg_revised_S',
checked: false,
type: '1',
},
outlet_standard_: {
prop: 'outlet_standard_',
checked: false,
},
},
};
const setShow = (tree = []) => {
try {
for (const v of tree) {
const ft = propsObj.props.filter((s) => v.prop.indexOf(s) > -1);
// if (ft.length) {
// console.log(v.prop);
// }
if (ft.length) {
const ftProp=ft[0];
if (propsObj.dic[ftProp] && v.show != propsObj.dic[ftProp].checked) {
v.show = propsObj.dic[ftProp].checked;
setShow(columns);
break;
}
}
if (v.children && v.children.length) {
if (v.show && v.children.filter((x) => x.show).length == 0) {
v.show = false;
setShow(columns);
break;
}
setShow(v.children);
}
}
} catch (e) {
console.error(e);
}
};
setShow(columns);
console.log(columns);
console.log(treeToArray(columns));
标签:show,单元测试,label,width,prop,true,78 From: https://blog.51cto.com/u_15311558/8016255