@weitutech/by-components-v3 1.1.2 → 1.1.4
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 (targetField && targetField !== "" && 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.filter((col) => col.field && col.field !== "").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,19 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36869
36959
|
};
|
|
36870
36960
|
});
|
|
36871
36961
|
const listeners = ref({});
|
|
36962
|
+
const CustomColumnRef = ref();
|
|
36963
|
+
const vxeGridRef = ref();
|
|
36964
|
+
const showResetCache = ref(false);
|
|
36965
|
+
const hasCache = ref(false);
|
|
36966
|
+
const originColumns = ref([]);
|
|
36872
36967
|
onMounted(() => {
|
|
36968
|
+
showResetCache.value = !!props.name;
|
|
36969
|
+
originColumns.value = deepClone(props.gridOptions.columns);
|
|
36873
36970
|
events.forEach((eventName) => {
|
|
36874
36971
|
listeners.value["on" + eventName.split("-").map((item) => capitalizeFirstLetter(item)).join("")] = (event) => emit(eventName, event);
|
|
36875
36972
|
});
|
|
36876
36973
|
console.log(listeners.value, "listeners");
|
|
36877
36974
|
});
|
|
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
36975
|
const handlePagerChange = (context) => {
|
|
36908
36976
|
emit("pageChange", context);
|
|
36909
36977
|
};
|
|
@@ -36928,32 +36996,25 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36928
36996
|
};
|
|
36929
36997
|
const handleResizableChange = (context) => {
|
|
36930
36998
|
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));
|
|
36999
|
+
saveCachedColumns(props.name, context);
|
|
37000
|
+
setHasCache();
|
|
37001
|
+
};
|
|
37002
|
+
const setHasCache = () => {
|
|
37003
|
+
hasCache.value = isCachedTableColumns(props.name);
|
|
37004
|
+
};
|
|
37005
|
+
const resetCachedTableColumns = () => {
|
|
37006
|
+
removeCachedTableColumns(props.name);
|
|
37007
|
+
setHasCache();
|
|
37008
|
+
if (vxeGridRef.value) {
|
|
37009
|
+
vxeGridRef.value.reloadColumn(originColumns.value);
|
|
37010
|
+
}
|
|
36951
37011
|
};
|
|
36952
37012
|
const handleOpenCustomColumn = () => {
|
|
36953
37013
|
console.log(CustomColumnRef.value.dialogVisible, "CustomColumnRef.value.dialogVisible");
|
|
36954
37014
|
CustomColumnRef.value.dialogVisible = true;
|
|
36955
37015
|
};
|
|
36956
37016
|
const changeTableFields = (cols) => {
|
|
37017
|
+
originColumns.value = deepClone(cols);
|
|
36957
37018
|
const noFixedCol = cols.filter((col) => !col.field);
|
|
36958
37019
|
const result = JSON.parse(JSON.stringify([...cols.filter((col) => col.field === "left")[0].children.map((child) => ({
|
|
36959
37020
|
...child,
|
|
@@ -36997,7 +37058,8 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36997
37058
|
}
|
|
36998
37059
|
}
|
|
36999
37060
|
}
|
|
37000
|
-
const newColumns =
|
|
37061
|
+
const newColumns = replaceColumnWidthToColumns(props.name, result);
|
|
37062
|
+
setHasCache();
|
|
37001
37063
|
emit("setColumns", newColumns);
|
|
37002
37064
|
};
|
|
37003
37065
|
expose({
|
|
@@ -37057,9 +37119,25 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
37057
37119
|
"submit-method": props.gridOptions.customColumnConfig.submitMethod,
|
|
37058
37120
|
"submitMethodParams": ((_f = (_e2 = props.gridOptions) == null ? void 0 : _e2.customColumnConfig) == null ? void 0 : _f.submitMethodParams) ?? {},
|
|
37059
37121
|
"onChangeTable": changeTableFields
|
|
37060
|
-
}, null) : null, props.gridOptions.pagerConfig ? createVNode(
|
|
37122
|
+
}, null) : null, props.gridOptions.pagerConfig ? createVNode("div", {
|
|
37123
|
+
"class": "pager-container"
|
|
37124
|
+
}, [showResetCache.value && createVNode(resolveComponent("el-button"), {
|
|
37125
|
+
"disabled": !hasCache.value,
|
|
37126
|
+
"size": "mini",
|
|
37127
|
+
"onClick": resetCachedTableColumns
|
|
37128
|
+
}, {
|
|
37129
|
+
default: () => [createTextVNode("重置列宽")]
|
|
37130
|
+
}), createVNode(BasePager, mergeProps(props.gridOptions.pagerConfig, {
|
|
37061
37131
|
"onChange": handlePagerChange
|
|
37062
|
-
}), null) :
|
|
37132
|
+
}), null)]) : createVNode("div", {
|
|
37133
|
+
"class": "reset-button"
|
|
37134
|
+
}, [showResetCache.value && createVNode(resolveComponent("el-button"), {
|
|
37135
|
+
"disabled": !hasCache.value,
|
|
37136
|
+
"size": "mini",
|
|
37137
|
+
"onClick": resetCachedTableColumns
|
|
37138
|
+
}, {
|
|
37139
|
+
default: () => [createTextVNode("重置列宽")]
|
|
37140
|
+
})])]);
|
|
37063
37141
|
};
|
|
37064
37142
|
}
|
|
37065
37143
|
});
|