● fix: 修复 Vite 8 前端编译及运行时错误

- main.js: 修复 createApp/mount 缺失导致 app 未定义
  - chineseMedicineDialog: defineModel → props+emit 兼容 Vue 3.5
  - el-form-nan-plugin: 修正 try/catch 括号匹配
  - vite.config: CSS 压缩器切换为 esbuild
This commit is contained in:
wangjian963
2026-06-03 13:09:04 +08:00
parent 207516ee86
commit 7ca0b89cb2
4 changed files with 21 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import {createApp} from 'vue'; import {createApp, nextTick} from 'vue';
import VxeUIAll from 'vxe-table'; import VxeUIAll from 'vxe-table';
import 'vxe-table/lib/style.css'; import 'vxe-table/lib/style.css';
@@ -104,6 +104,8 @@ console.error = (...args) => {
_origError.apply(console, args); _origError.apply(console, args);
}; };
const app = createApp(App);
// 全局方法挂载 // 全局方法挂载
app.config.globalProperties.useDict = useDict; app.config.globalProperties.useDict = useDict;
app.config.globalProperties.download = download; app.config.globalProperties.download = download;
@@ -165,7 +167,8 @@ window.addEventListener("error", (e) => {
}, true); }, true);
// 应用启动后初始化公告弹窗功能 // 应用启动后初始化公告弹窗功能
import { nextTick } from 'vue'
nextTick(() => { nextTick(() => {
initNoticePopupAfterLogin() initNoticePopupAfterLogin()
}) })
app.mount('#app')

View File

@@ -20,9 +20,11 @@ export default function patchElFormNan() {
.replace('const updateLabelWidth = (action = \"update\") => {', .replace('const updateLabelWidth = (action = \"update\") => {',
'let _isMounted = true;\n\tconst updateLabelWidth = (action = \"update\") => {') 'let _isMounted = true;\n\tconst updateLabelWidth = (action = \"update\") => {')
.replace('nextTick(() => {', .replace('nextTick(() => {',
'nextTick(() => {\n\t\t\t\tif (!_isMounted) return;\n\t\t\t\ttry {') 'nextTick(() => {\n\t\t\t\tif (!_isMounted) return;')
.replace('if (slots.default && props.isAutoWidth) {',
'try {\n\t\t\t\tif (slots.default && props.isAutoWidth) {')
.replace('else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);', .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 */ }') 'else if (action === \"remove\") formContext?.deregisterLabelWidth(computedWidth.value);\n\t\t\t\t}\n\t\t\t} catch (e) { /* teardown race */ }')
.replace('onBeforeUnmount(() => {', 'onBeforeUnmount(() => {\n\t\t\t_isMounted = false;') .replace('onBeforeUnmount(() => {', 'onBeforeUnmount(() => {\n\t\t\t_isMounted = false;')
.replace('onUpdated(() => updateLabelWidthFn())', 'onUpdated(() => { if (_isMounted) updateLabelWidthFn(); })') .replace('onUpdated(() => updateLabelWidthFn())', 'onUpdated(() => { if (_isMounted) updateLabelWidthFn(); })')
.replace('if (props.updateAll) formContext?.registerLabelWidth(val, oldVal);', .replace('if (props.updateAll) formContext?.registerLabelWidth(val, oldVal);',

View File

@@ -1,6 +1,7 @@
<template> <template>
<el-dialog <el-dialog
v-model="visible" :model-value="visible"
@update:model-value="emit('update:visible', $event)"
title="中医诊断" title="中医诊断"
:width="width" :width="width"
:z-index="20" :z-index="20"
@@ -98,15 +99,17 @@ const props = defineProps({
type: Object, type: Object,
default: () => ({}), default: () => ({}),
}, },
visible: {
type: Boolean,
default: false,
},
}) })
const emit = defineEmits(['ok-act']) const emit = defineEmits(['ok-act', 'update:visible'])
const visible = defineModel<boolean>('visible')
const width = '500px' const width = '500px'
const cancelAct = () => { const cancelAct = () => {
visible.value = false emit('update:visible', false)
} }
function handleConditionChange() { function handleConditionChange() {
@@ -175,7 +178,7 @@ const openAct = () => {
loadSyndromeOptions() loadSyndromeOptions()
} }
const closedAct = () => { const closedAct = () => {
visible.value = false emit('update:visible', false)
} }
onMounted(() => { onMounted(() => {
loadConditionOptions() loadConditionOptions()

View File

@@ -55,6 +55,9 @@ export default defineConfig(({ mode, command }) => {
}, },
}, },
}, },
build: {
cssMinify: 'esbuild',
},
//fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file //fix:error:stdin>:7356:1: warning: "@charset" must be the first rule in the file
css: { css: {
preprocessorOptions: { preprocessorOptions: {