更新vxetable框架并升级前端组件框架
This commit is contained in:
37
openhis-ui-vue3/src/patches/el-form-nan-plugin.js
Normal file
37
openhis-ui-vue3/src/patches/el-form-nan-plugin.js
Normal 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');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
56
openhis-ui-vue3/src/patches/el-form-utils.mjs
Normal file
56
openhis-ui-vue3/src/patches/el-form-utils.mjs
Normal 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 };
|
||||
10
openhis-ui-vue3/src/patches/hasOwnProp.js
Normal file
10
openhis-ui-vue3/src/patches/hasOwnProp.js
Normal 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
|
||||
Reference in New Issue
Block a user