@weitutech/by-components-v3 1.1.1 → 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,44 +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 getColumnsData = (columns) => {
|
|
36880
|
-
if (!props.name) {
|
|
36881
|
-
return columns;
|
|
36882
|
-
}
|
|
36883
|
-
const cacheColumns = JSON.parse(localStorage.getItem(props.name));
|
|
36884
|
-
if (!cacheColumns) {
|
|
36885
|
-
return columns;
|
|
36886
|
-
}
|
|
36887
|
-
const cols = compareColumnsAndCols(columns, cacheColumns);
|
|
36888
|
-
if (cols && props.name) {
|
|
36889
|
-
columns.forEach((item) => {
|
|
36890
|
-
item.width = (cols.find((col) => col.field === item.field) || {}).width || item.width || void 0;
|
|
36891
|
-
});
|
|
36892
|
-
}
|
|
36893
|
-
return columns;
|
|
36894
|
-
};
|
|
36895
|
-
const compareColumnsAndCols = (columns, cacheColumns) => {
|
|
36896
|
-
if (!cacheColumns || !props.name) {
|
|
36897
|
-
return void 0;
|
|
36898
|
-
}
|
|
36899
|
-
columns.forEach((item) => {
|
|
36900
|
-
if (item && item.field && !cacheColumns.some((col) => col && col.field === item.field)) {
|
|
36901
|
-
cacheColumns.push({
|
|
36902
|
-
field: item.field,
|
|
36903
|
-
width: item.width
|
|
36904
|
-
});
|
|
36905
|
-
}
|
|
36906
|
-
});
|
|
36907
|
-
localStorage.setItem(props.name, JSON.stringify(cacheColumns));
|
|
36908
|
-
return cacheColumns;
|
|
36909
|
-
};
|
|
36910
36973
|
const handlePagerChange = (context) => {
|
|
36911
36974
|
emit("pageChange", context);
|
|
36912
36975
|
};
|
|
@@ -36931,14 +36994,18 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36931
36994
|
};
|
|
36932
36995
|
const handleResizableChange = (context) => {
|
|
36933
36996
|
emit("resizable-change", context);
|
|
36934
|
-
|
|
36935
|
-
|
|
36936
|
-
|
|
36937
|
-
|
|
36938
|
-
|
|
36939
|
-
|
|
36940
|
-
|
|
36941
|
-
|
|
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
|
+
}
|
|
36942
37009
|
};
|
|
36943
37010
|
const handleOpenCustomColumn = () => {
|
|
36944
37011
|
console.log(CustomColumnRef.value.dialogVisible, "CustomColumnRef.value.dialogVisible");
|
|
@@ -36988,12 +37055,14 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
36988
37055
|
}
|
|
36989
37056
|
}
|
|
36990
37057
|
}
|
|
36991
|
-
const newColumns =
|
|
37058
|
+
const newColumns = replaceColumnWidthToColumns(props.name, result);
|
|
37059
|
+
setHasCache();
|
|
36992
37060
|
emit("setColumns", newColumns);
|
|
36993
37061
|
};
|
|
36994
37062
|
expose({
|
|
36995
37063
|
CustomColumnRef,
|
|
36996
|
-
handleOpenCustomColumn
|
|
37064
|
+
handleOpenCustomColumn,
|
|
37065
|
+
vxeGridRef
|
|
36997
37066
|
});
|
|
36998
37067
|
return () => {
|
|
36999
37068
|
var _a2, _b, _c, _d, _e2, _f;
|
|
@@ -37033,7 +37102,9 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
37033
37102
|
});
|
|
37034
37103
|
return createVNode("div", {
|
|
37035
37104
|
"class": "VxeGridWrap"
|
|
37036
|
-
}, [createVNode(VxeGrid, mergeProps(
|
|
37105
|
+
}, [createVNode(VxeGrid, mergeProps({
|
|
37106
|
+
"ref": vxeGridRef
|
|
37107
|
+
}, defaultOptions.value, listeners.value, {
|
|
37037
37108
|
"onCellClick": handleCellClick,
|
|
37038
37109
|
"onResizableChange": handleResizableChange
|
|
37039
37110
|
}), {
|
|
@@ -37045,9 +37116,25 @@ const ByTable = /* @__PURE__ */ defineComponent({
|
|
|
37045
37116
|
"submit-method": props.gridOptions.customColumnConfig.submitMethod,
|
|
37046
37117
|
"submitMethodParams": ((_f = (_e2 = props.gridOptions) == null ? void 0 : _e2.customColumnConfig) == null ? void 0 : _f.submitMethodParams) ?? {},
|
|
37047
37118
|
"onChangeTable": changeTableFields
|
|
37048
|
-
}, 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, {
|
|
37049
37128
|
"onChange": handlePagerChange
|
|
37050
|
-
}), 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
|
+
})])]);
|
|
37051
37138
|
};
|
|
37052
37139
|
}
|
|
37053
37140
|
});
|