Browse Source

表格优化提交

main
likunming 9 months ago
parent
commit
330588fe77
  1. 77
      io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue

77
io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue

@ -1518,6 +1518,13 @@ const addRowKey = (rows: []) => {
if (rows && rows.length > 0) {
rows.forEach((item: any, index) => {
item[rowKey_] = Tools.uuid();
if (item[table.tickedField] === true) {
item['tickedCount'] = 1;
} else if (item['tickedCount'] === false) {
item['tickedCount'] = 0;
} else {
item['tickedCount'] = 0;
}
item[table.tickedField] = item[table.tickedField] || false;
item[table.selectedField] = item[table.selectedField] || false;
if (props.tree) {
@ -1525,6 +1532,16 @@ const addRowKey = (rows: []) => {
}
if (props.tree && item.children && item.children.length > 0) {
addRowKey(item.children);
item.children.forEach((child) => {
item['tickedCount'] = child['tickedCount'] === null ? item['tickedCount'] : item['tickedCount'] + child['tickedCount'];
});
if (item['tickedCount'] === 0) {
item[table.tickedField] = false;
} else if (item['tickedCount'] === item.children.length) {
item[table.tickedField] = true;
} else {
item[table.tickedField] = null;
}
}
});
}
@ -2417,11 +2434,71 @@ const cleanTicked = (arr = table.rows) => {
});
};
const getCascadeChildrenData = (rows: [], propertyName) => {
const data = <any>[];
if (rows && rows.length > 0) {
rows.forEach((item: any, index) => {
data.push(propertyName ? item[propertyName] : item);
if (props.tree && item.children && item.children.length > 0) {
const childrenData = getCascadeChildrenData(item.children, propertyName);
data.push(...childrenData);
}
});
}
return data;
};
//
const getCascadeChildren = (propertyName: string) => {
return getCascadeChildrenData([getSelectedRow()], propertyName);
};
const getRow = (arr, key, parent) => {
let result = undefined;
for (let i = 0; i < arr.length; i++) {
let item = arr[i];
if (parent ? item[props.primaryKey] === key : item[rowKey_] === key) {
result = item;
break;
} else if (item.children && item.children.length > 0) {
const temp = getRow(item.children, key, parent);
if (temp) {
result = temp;
}
}
}
return result;
};
const getCascadeParentData = (row, propertyName) => {
const data = <any>[];
if (row && row[props.foreignKey]) {
const parent = getRow(table.rows, row[props.foreignKey], true);
if (parent) {
data.push(propertyName ? parent[propertyName] : parent);
if (parent[props.foreignKey]) {
const parentData = getCascadeParentData(parent, propertyName);
data.push(...parentData);
}
}
}
return data;
};
//
const getCascadeParent = (propertyName: string) => {
const row = getSelectedRow();
const parent = getCascadeParentData(row, propertyName);
const result = <any>[propertyName ? row[propertyName] : row];
if (parent && parent.length > 0) {
result.push(...parent);
}
return result;
};
const getElement = () => {
return tableRef?.value?.$el;
};
defineExpose({
getCascadeChildren,
getCascadeParent,
getSelectedRow,
getSelectedRows,
getTickedRow,

Loading…
Cancel
Save