更新vxetable框架并升级前端组件框架

This commit is contained in:
2026-06-03 11:19:52 +08:00
parent 5b6b23331d
commit 5a2050a736
385 changed files with 19691 additions and 21188 deletions

View File

@@ -0,0 +1,37 @@
import fs from 'fs';
import path from 'path';
// Final patch: guards ALL async paths in form-label-wrap to prevent
// errors during vxe-table expand row teardown
export default function patchElFormNan() {
return {
name: 'patch-el-form-nan',
enforce: 'pre',
buildStart() {
const target = path.resolve(
process.cwd(),
'node_modules/element-plus/es/components/form/src/form-label-wrap.mjs'
);
if (!fs.existsSync(target)) return;
const code = fs.readFileSync(target, 'utf-8');
if (code.includes('_isMounted')) return; // already patched
const patched = code
.replace('return Math.ceil(Number.parseFloat(width))', 'return Math.ceil(Number.parseFloat(width)) || 0')
.replace('const updateLabelWidth = (action = \"update\") => {',
'let _isMounted = true;\n\tconst updateLabelWidth = (action = \"update\") => {')
.replace('nextTick(() => {',
'nextTick(() => {\n\t\t\t\tif (!_isMounted) return;\n\t\t\t\ttry {')
.replace('else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);',
'else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);\n\t\t\t\t} catch (e) { /* teardown race */ }')
.replace('onBeforeUnmount(() => {', 'onBeforeUnmount(() => {\n\t\t\t_isMounted = false;')
.replace('onUpdated(() => updateLabelWidthFn())', 'onUpdated(() => { if (_isMounted) updateLabelWidthFn(); })')
.replace('if (props.updateAll) formContext?.registerLabelWidth(val, oldVal);',
'if (_isMounted && props.updateAll) formContext?.registerLabelWidth(val, oldVal);')
.replace('return () => {', 'return () => {\n\t\t\tif (!_isMounted) return null;');
if (patched !== code) {
fs.writeFileSync(target, patched, 'utf-8');
console.log('[patch-el-form-nan] Patched form-label-wrap.mjs');
}
}
};
}

View File

@@ -0,0 +1,56 @@
import { isArray } from "../../../utils/types.mjs";
import { ensureArray } from "../../../utils/arrays.mjs";
import { computed, ref } from "vue";
// Patched: suppress NaN warnings from Element Plus during vxe-table expand row teardown
const SCOPE = "ElForm";
function useFormLabelWidth() {
const potentialLabelWidthArr = ref([]);
const autoLabelWidth = computed(() => {
if (!potentialLabelWidthArr.value.length) return "0";
const max = Math.max(...potentialLabelWidthArr.value);
return max ? `${max}px` : "";
});
function getLabelWidthIndex(width) {
// Patched: skip NaN values silently (vxe-table expand row teardown)
if (width == null || isNaN(width)) return -1;
const index = potentialLabelWidthArr.value.indexOf(width);
// Patched: removed debugWarn for unexpected width — harmless during teardown
return index;
}
function registerLabelWidth(val, oldVal) {
if (val && oldVal) {
const index = getLabelWidthIndex(oldVal);
if (index > -1) potentialLabelWidthArr.value.splice(index, 1, val);
} else if (val && !isNaN(val)) {
potentialLabelWidthArr.value.push(val);
}
}
function deregisterLabelWidth(val) {
const index = getLabelWidthIndex(val);
if (index > -1) potentialLabelWidthArr.value.splice(index, 1);
}
return {
autoLabelWidth,
registerLabelWidth,
deregisterLabelWidth
};
}
const filterFields = (fields, props) => {
const normalized = ensureArray(props).map((prop) =>
isArray(prop) ? prop.join(".") : prop
);
return normalized.length > 0
? fields.filter(
(field) => field.propString && normalized.includes(field.propString)
)
: fields;
};
export { filterFields, useFormLabelWidth };

View File

@@ -0,0 +1,10 @@
/**
* Patched hasOwnProp - compatible with Vue 3 Proxy objects
* Original: obj.hasOwnProperty(key) fails on Proxy
* Fix: Object.prototype.hasOwnProperty.call(obj, key)
*/
function hasOwnProp(obj, key) {
return obj && Object.prototype.hasOwnProperty.call(obj, key)
}
export default hasOwnProp