优化js代码过长的问题,优化未用到的变量

This commit is contained in:
mgw
2023-11-21 14:18:01 +08:00
parent 7391b1324d
commit 890b73e108
4 changed files with 49 additions and 44 deletions

View File

@@ -45,7 +45,8 @@ patch(ListRenderer.prototype, 'jikimo_frontend.ListRenderer', {
setDefaultColumnWidths(column_num) {
// const bbb = this.state.columns[0].name
const widths = this.state.columns.map((col) => this.calculateColumnWidth(col));
const widths = this.state.columns.map((col) =>
this.calculateColumnWidth(col));
// const sumOfRelativeWidths = (widths
// .filter(({ type }) => type === "relative")
// .reduce((sum, { value }) => sum + value, 0));
@@ -65,16 +66,19 @@ patch(ListRenderer.prototype, 'jikimo_frontend.ListRenderer', {
// }
// 判断 this.state.columns 是否存在且长度大于零
if (this.state.columns && this.state.columns.length > 0 && this.state.columns[0].name === "sequence") {
if (this.state.columns && this.state.columns.length > 0 &&
this.state.columns[0].name === "sequence") {
widths[1] = { type: "relative", value: 0.1 };
}
// 1 because nth-child selectors are 1-indexed, 2 when the first column contains
// 1 because nth-child selectors are 1-indexed,
// 2 when the first column contains
// the checkboxes to select records.
const columnOffset = this.hasSelectors ? 2 : 1;
widths.forEach(({ type, value }, i) => {
const headerEl = this.tableRef.el.querySelector(`th:nth-child(${i + columnOffset})`);
widths.forEach(({ type, value }, width) => {
const headerEl = this.tableRef.el.querySelector(
`th:nth-child(${width + columnOffset})`);
if (type === "absolute") {
if (this.isEmpty) {
headerEl.style.width = value;
@@ -82,7 +86,8 @@ patch(ListRenderer.prototype, 'jikimo_frontend.ListRenderer', {
headerEl.style.minWidth = value;
}
} else if (type === "relative" && this.isEmpty) {
headerEl.style.width = `${((value / column_num) * 100).toFixed(2)}%`;
headerEl.style.width = `${((value / column_num) * 100
).toFixed(2)}%`;
}
});
},