@weitutech/by-components-v3 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/by-component-v3.mjs
CHANGED
|
@@ -36800,6 +36800,96 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
36800
36800
|
}
|
|
36801
36801
|
});
|
|
36802
36802
|
const CustomColumn = /* @__PURE__ */ _export_sfc$1(_sfc_main, [["__scopeId", "data-v-0dadba78"]]);
|
|
36803
|
+
const isCachedTableColumns = (name) => {
|
|
36804
|
+
if (!name) return false;
|
|
36805
|
+
const cachedData = localStorage.getItem(name);
|
|
36806
|
+
if (!cachedData) return false;
|
|
36807
|
+
try {
|
|
36808
|
+
const parsedData = JSON.parse(cachedData);
|
|
36809
|
+
return Array.isArray(parsedData) && parsedData.length > 0;
|
|
36810
|
+
} catch (e) {
|
|
36811
|
+
return false;
|
|
36812
|
+
}
|
|
36813
|
+
};
|
|
36814
|
+
const removeCachedTableColumns = (name) => {
|
|
36815
|
+
localStorage.removeItem(name);
|
|
36816
|
+
};
|
|
36817
|
+
const saveCachedColumns = (name, context) => {
|
|
36818
|
+
if (!name) return;
|
|
36819
|
+
const collectColumn = context.$table.getTableColumn().collectColumn;
|
|
36820
|
+
const cachedColumns = getCachedColumns(name);
|
|
36821
|
+
const updateColumnWidth = (columns, targetField, newWidth) => {
|
|
36822
|
+
const result = [];
|
|
36823
|
+
for (const col of columns) {
|
|
36824
|
+
if (col.children) {
|
|
36825
|
+
const updatedChildren = updateColumnWidth(col.children, targetField, newWidth);
|
|
36826
|
+
if (updatedChildren.length > 0) {
|
|
36827
|
+
result.push({
|
|
36828
|
+
field: col.field,
|
|
36829
|
+
width: newWidth,
|
|
36830
|
+
children: updatedChildren
|
|
36831
|
+
});
|
|
36832
|
+
}
|
|
36833
|
+
} else if (col.field === targetField) {
|
|
36834
|
+
result.push({
|
|
36835
|
+
field: col.field,
|
|
36836
|
+
width: newWidth
|
|
36837
|
+
});
|
|
36838
|
+
}
|
|
36839
|
+
}
|
|
36840
|
+
return result;
|
|
36841
|
+
};
|
|
36842
|
+
const currentColumn = context.column;
|
|
36843
|
+
const updatedColumns = updateColumnWidth(collectColumn, currentColumn.field, currentColumn.renderWidth);
|
|
36844
|
+
const mergeColumns = (newColumns, cachedColumns2) => {
|
|
36845
|
+
const result = [...cachedColumns2];
|
|
36846
|
+
for (const newCol of newColumns) {
|
|
36847
|
+
const existingIndex = result.findIndex((col) => col.field === newCol.field);
|
|
36848
|
+
if (existingIndex !== -1) {
|
|
36849
|
+
if (newCol.children && result[existingIndex].children) {
|
|
36850
|
+
result[existingIndex].children = mergeColumns(newCol.children, result[existingIndex].children);
|
|
36851
|
+
} else {
|
|
36852
|
+
result[existingIndex].width = newCol.width;
|
|
36853
|
+
}
|
|
36854
|
+
} else {
|
|
36855
|
+
result.push(newCol);
|
|
36856
|
+
}
|
|
36857
|
+
}
|
|
36858
|
+
return result;
|
|
36859
|
+
};
|
|
36860
|
+
const finalColumns = mergeColumns(updatedColumns, cachedColumns);
|
|
36861
|
+
localStorage.setItem(name, JSON.stringify(finalColumns));
|
|
36862
|
+
};
|
|
36863
|
+
const getCachedColumns = (name) => {
|
|
36864
|
+
return JSON.parse(localStorage.getItem(name) || "[]");
|
|
36865
|
+
};
|
|
36866
|
+
const replaceColumnWidthToColumns = (name, columns) => {
|
|
36867
|
+
if (!name) {
|
|
36868
|
+
return columns;
|
|
36869
|
+
}
|
|
36870
|
+
const cacheColumns = getCachedColumns(name);
|
|
36871
|
+
if (!cacheColumns) {
|
|
36872
|
+
return columns;
|
|
36873
|
+
}
|
|
36874
|
+
const processColumnWidth = (columns2, cacheColumns2) => {
|
|
36875
|
+
return columns2.map((column) => {
|
|
36876
|
+
if (column.children) {
|
|
36877
|
+
const cacheColumn2 = cacheColumns2.find((col) => col.field === column.field);
|
|
36878
|
+
return {
|
|
36879
|
+
...column,
|
|
36880
|
+
...(cacheColumn2 == null ? void 0 : cacheColumn2.width) && { width: cacheColumn2.width },
|
|
36881
|
+
children: processColumnWidth(column.children, (cacheColumn2 == null ? void 0 : cacheColumn2.children) || [])
|
|
36882
|
+
};
|
|
36883
|
+
}
|
|
36884
|
+
const cacheColumn = cacheColumns2.find((col) => col.field === column.field);
|
|
36885
|
+
return {
|
|
36886
|
+
...column,
|
|
36887
|
+
...(cacheColumn == null ? void 0 : cacheColumn.width) && { width: cacheColumn.width }
|
|
36888
|
+
};
|
|
36889
|
+
});
|
|
36890
|
+
};
|
|
36891
|
+
return processColumnWidth(columns, cacheColumns);
|
|
36892
|
+
};
|
|
36803
36893
|
const events = ["keydown", "current-change", "radio-change", "checkbox-change", "checkbox-all", "checkbox-range-start", "checkbox-range-change", "checkbox-range-end", "cell-dblclick", "cell-menu", "cell-mouseenter", "cell-mouseleave", "cell-delete-value", "header-cell-click", "header-cell-dblclick", "header-cell-menu", "footer-cell-click", "footer-cell-dblclick", "footer-cell-menu", "clear-merge", "sort-change", "clear-sort", "filter-visible", "filter-change", "clear-filter", "toggle-row-expand", "toggle-tree-expand", "menu-click", "cell-selected", "edit-closed", "edit-activated", "edit-disabled", "valid-error", "scroll", "custom", "page-change", "form-submit", "form-submit-invalid", "form-reset", "form-collapse", "proxy-query", "proxy-delete", "proxy-save", "toolbar-button-click", "toolbar-tool-click", "zoom", "cell-click"];
|
|
36804
36894
|
const capitalizeFirstLetter = (str) => {
|
|
36805
36895
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
@@ -36833,12 +36923,12 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36833
36923
|
columns,
|
|
36834
36924
|
...others
|
|
36835
36925
|
} = props.gridOptions;
|
|
36836
|
-
const newColumns =
|
|
36926
|
+
const newColumns = replaceColumnWidthToColumns(props.name, columns);
|
|
36927
|
+
setHasCache();
|
|
36837
36928
|
return {
|
|
36838
36929
|
border: true,
|
|
36839
36930
|
// 'visible' 值在 v4 版本中已经不再支持 (true:显示省略号; false:不显示省略号,自动撑高)
|
|
36840
36931
|
showOverflow: !props.autoHeight,
|
|
36841
|
-
// showHeaderOverflow: props.autoHeight ? 'tooltip' : true,//表头不加,要换行显示
|
|
36842
36932
|
height: 710,
|
|
36843
36933
|
align: "center",
|
|
36844
36934
|
copyFields: [],
|
|
@@ -36869,41 +36959,17 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36869
36959
|
};
|
|
36870
36960
|
});
|
|
36871
36961
|
const listeners = ref({});
|
|
36962
|
+
const CustomColumnRef = ref();
|
|
36963
|
+
const vxeGridRef = ref();
|
|
36964
|
+
const hasCache = ref(false);
|
|
36965
|
+
const originColumns = ref([]);
|
|
36872
36966
|
onMounted(() => {
|
|
36967
|
+
originColumns.value = deepClone(props.gridOptions.columns);
|
|
36873
36968
|
events.forEach((eventName) => {
|
|
36874
36969
|
listeners.value["on" + eventName.split("-").map((item) => capitalizeFirstLetter(item)).join("")] = (event) => emit(eventName, event);
|
|
36875
36970
|
});
|
|
36876
36971
|
console.log(listeners.value, "listeners");
|
|
36877
36972
|
});
|
|
36878
|
-
const CustomColumnRef = ref();
|
|
36879
|
-
const vxeGridRef = ref();
|
|
36880
|
-
const getColumnsData = (columns) => {
|
|
36881
|
-
if (!props.name) {
|
|
36882
|
-
return columns;
|
|
36883
|
-
}
|
|
36884
|
-
const cacheColumns = JSON.parse(localStorage.getItem(props.name));
|
|
36885
|
-
if (!cacheColumns) {
|
|
36886
|
-
return columns;
|
|
36887
|
-
}
|
|
36888
|
-
const processColumnWidth = (columns2, cacheColumns2) => {
|
|
36889
|
-
return columns2.map((column) => {
|
|
36890
|
-
if (column.children) {
|
|
36891
|
-
const cacheColumn2 = cacheColumns2.find((col) => col.field === column.field);
|
|
36892
|
-
return {
|
|
36893
|
-
...column,
|
|
36894
|
-
width: (cacheColumn2 == null ? void 0 : cacheColumn2.width) || column.width,
|
|
36895
|
-
children: processColumnWidth(column.children, (cacheColumn2 == null ? void 0 : cacheColumn2.children) || [])
|
|
36896
|
-
};
|
|
36897
|
-
}
|
|
36898
|
-
const cacheColumn = cacheColumns2.find((col) => col.field === column.field);
|
|
36899
|
-
return {
|
|
36900
|
-
...column,
|
|
36901
|
-
width: (cacheColumn == null ? void 0 : cacheColumn.width) || column.width
|
|
36902
|
-
};
|
|
36903
|
-
});
|
|
36904
|
-
};
|
|
36905
|
-
return processColumnWidth(columns, cacheColumns);
|
|
36906
|
-
};
|
|
36907
36973
|
const handlePagerChange = (context) => {
|
|
36908
36974
|
emit("pageChange", context);
|
|
36909
36975
|
};
|
|
@@ -36928,26 +36994,18 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36928
36994
|
};
|
|
36929
36995
|
const handleResizableChange = (context) => {
|
|
36930
36996
|
emit("resizable-change", context);
|
|
36931
|
-
|
|
36932
|
-
|
|
36933
|
-
|
|
36934
|
-
|
|
36935
|
-
|
|
36936
|
-
|
|
36937
|
-
|
|
36938
|
-
|
|
36939
|
-
|
|
36940
|
-
|
|
36941
|
-
|
|
36942
|
-
|
|
36943
|
-
return {
|
|
36944
|
-
field: col.field,
|
|
36945
|
-
width: col.renderWidth
|
|
36946
|
-
};
|
|
36947
|
-
});
|
|
36948
|
-
};
|
|
36949
|
-
const clos = processColumns(collectColumn);
|
|
36950
|
-
localStorage.setItem(props.name, JSON.stringify(clos));
|
|
36997
|
+
saveCachedColumns(props.name, context);
|
|
36998
|
+
setHasCache();
|
|
36999
|
+
};
|
|
37000
|
+
const setHasCache = () => {
|
|
37001
|
+
hasCache.value = isCachedTableColumns(props.name);
|
|
37002
|
+
};
|
|
37003
|
+
const resetCachedTableColumns = () => {
|
|
37004
|
+
removeCachedTableColumns(props.name);
|
|
37005
|
+
setHasCache();
|
|
37006
|
+
if (vxeGridRef.value) {
|
|
37007
|
+
vxeGridRef.value.reloadColumn(originColumns.value);
|
|
37008
|
+
}
|
|
36951
37009
|
};
|
|
36952
37010
|
const handleOpenCustomColumn = () => {
|
|
36953
37011
|
console.log(CustomColumnRef.value.dialogVisible, "CustomColumnRef.value.dialogVisible");
|
|
@@ -36997,7 +37055,8 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36997
37055
|
}
|
|
36998
37056
|
}
|
|
36999
37057
|
}
|
|
37000
|
-
const newColumns =
|
|
37058
|
+
const newColumns = replaceColumnWidthToColumns(props.name, result);
|
|
37059
|
+
setHasCache();
|
|
37001
37060
|
emit("setColumns", newColumns);
|
|
37002
37061
|
};
|
|
37003
37062
|
expose({
|
|
@@ -37057,9 +37116,25 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
37057
37116
|
"submit-method": props.gridOptions.customColumnConfig.submitMethod,
|
|
37058
37117
|
"submitMethodParams": ((_f = (_e2 = props.gridOptions) == null ? void 0 : _e2.customColumnConfig) == null ? void 0 : _f.submitMethodParams) ?? {},
|
|
37059
37118
|
"onChangeTable": changeTableFields
|
|
37060
|
-
}, null) : null, props.gridOptions.pagerConfig ? createVNode(
|
|
37119
|
+
}, null) : null, props.gridOptions.pagerConfig ? createVNode("div", {
|
|
37120
|
+
"class": "pager-container"
|
|
37121
|
+
}, [createVNode(resolveComponent("el-button"), {
|
|
37122
|
+
"disabled": !hasCache.value,
|
|
37123
|
+
"size": "mini",
|
|
37124
|
+
"onClick": resetCachedTableColumns
|
|
37125
|
+
}, {
|
|
37126
|
+
default: () => [createTextVNode("重置列宽")]
|
|
37127
|
+
}), createVNode(BasePager, mergeProps(props.gridOptions.pagerConfig, {
|
|
37061
37128
|
"onChange": handlePagerChange
|
|
37062
|
-
}), null) :
|
|
37129
|
+
}), null)]) : createVNode("div", {
|
|
37130
|
+
"class": "reset-button"
|
|
37131
|
+
}, [createVNode(resolveComponent("el-button"), {
|
|
37132
|
+
"disabled": !hasCache.value,
|
|
37133
|
+
"size": "mini",
|
|
37134
|
+
"onClick": resetCachedTableColumns
|
|
37135
|
+
}, {
|
|
37136
|
+
default: () => [createTextVNode("重置列宽")]
|
|
37137
|
+
})])]);
|
|
37063
37138
|
};
|
|
37064
37139
|
}
|
|
37065
37140
|
});
|