import {createApp, nextTick} from 'vue'; import VxeUIAll from 'vxe-table'; import 'vxe-table/lib/style.css'; import { VxeTooltip } from 'vxe-pc-ui'; import Cookies from 'js-cookie'; import {hiprint, defaultElementTypeProvider} from 'vue-plugin-hiprint'; import ElementPlus, {ElDialog, ElMessage} from 'element-plus'; import 'element-plus/dist/index.css'; import '@/assets/styles/index.scss'; // global css import App from './App'; import store from './store'; import router from './router'; import directive from './directive'; // directive import plugins from './plugins'; // plugins import {download, downloadGet} from '@/utils/request'; // svg图标 import 'virtual:svg-icons-register'; import SvgIcon from '@/components/SvgIcon'; import elementIcons from '@/components/SvgIcon/svgicon'; import './permission'; // permission control import {useDict} from '@/utils/dict'; import {addDateRange, handleTree, parseTime, resetForm, selectDictLabel, selectDictLabels,} from '@/utils/his'; import {formatDateStr} from '@/utils/index'; // 通用组件 import Pagination from '@/components/Pagination'; // 分页组件 import RightToolbar from '@/components/RightToolbar'; // 上传组件 import Editor from '@/components/Editor'; // 文件上传 import FileUpload from '@/components/FileUpload'; // 图片上传 import ImageUpload from '@/components/ImageUpload'; // 图片预览 import ImagePreview from '@/components/ImagePreview'; // 树下拉 import TreeSelect from '@/components/TreeSelect'; // 字典标签 import DictTag from '@/components/DictTag'; // 动态组件注册 import {registerComponents} from './template'; window.hiprint = hiprint; // 初始化hiprint hiprint.init({ providers: [new defaultElementTypeProvider()] }); // Suppress Element Plus ElForm NaN width warning during vxe-table expand row teardown const _origWarn = console.warn; console.warn = (...args) => { const msg = args[0]?.toString?.() ?? ""; if (msg.includes("[ElForm]") && msg.includes("unexpected width")) return; _origWarn.apply(console, args); }; // Suppress el-form teardown errors from vxe-table expand collapse const _origError = console.error; console.error = (...args) => { try { const all = args.map(a => { if (!a) return ""; if (typeof a === "string") return a; if (a.stack) return a.stack; if (a.message) return a.message; try { return JSON.stringify(a); } catch(e) { return ""; } }).join(" "); if (all.includes("form-label") || all.includes("LabelWrap") || all.includes("ElForm") || all.includes("FormItem") || all.includes("deregisterLabel") || all.includes("autoLabel") || all.includes("labelPosition") || all.includes("formContext") || all.includes("label-wrap")) return; } catch(e) {} _origError.apply(console, args); }; async function bootstrap() { const {initI18n} = await import('@/i18n'); const i18n = await initI18n(); const app = createApp(App); // 设置全局属性 app.config.globalProperties.useDict = useDict; app.config.globalProperties.download = download; app.config.globalProperties.downloadGet = downloadGet; app.config.globalProperties.parseTime = parseTime; app.config.globalProperties.resetForm = resetForm; app.config.globalProperties.handleTree = handleTree; app.config.globalProperties.addDateRange = addDateRange; app.config.globalProperties.selectDictLabel = selectDictLabel; app.config.globalProperties.selectDictLabels = selectDictLabels; app.config.globalProperties.formatDateStr = formatDateStr; // 注册全局组件 app.component('DictTag', DictTag); app.component('Pagination', Pagination); app.component('TreeSelect', TreeSelect); app.component('FileUpload', FileUpload); app.component('ImageUpload', ImageUpload); app.component('ImagePreview', ImagePreview); app.component('RightToolbar', RightToolbar); app.component('Editor', Editor); app.use(registerComponents); app.use(router); app.use(store); app.use(plugins); app.use(elementIcons); app.component('SvgIcon', SvgIcon); directive(app); // 设置 el-dialog 关闭点击遮罩无效 ElDialog.props.closeOnClickModal.default = false; // Element Plus locale mapping const elLocaleMap = { 'zh-CN': () => import('element-plus/es/locale/lang/zh-cn'), 'en': () => import('element-plus/es/locale/lang/en'), 'vi': () => import('element-plus/es/locale/lang/vi') }; const savedLang = Cookies.get('lang') || localStorage.getItem('lang') || 'zh-CN'; let elLocale = (await elLocaleMap[savedLang]?.())?.default || (await elLocaleMap['zh-CN']()).default; // 使用element-plus 设置默认字体大小 app.use(ElementPlus, { locale: elLocale, // 设置element-plus 组件大小default|small|large size: Cookies.get('size') || 'default', }); // Register vxe-tooltip component required by vxe-table v4 for show-overflow="title" VxeUIAll.VxeUI.component(VxeTooltip); // Register element-plus render plugin for declarative editRender (ElSelect, ElInput etc.) import('@vxe-ui/plugin-render-element').then(({default: VXETablePluginRenderElement}) => { VxeUIAll.VxeUI.use(VXETablePluginRenderElement); }); app.use(VxeUIAll); // 首页通知弹窗延迟加载 // Global error handler: suppress el-form teardown errors from vxe-table expand rows app.config.errorHandler = (err, vm, info) => { const name = vm?.$?.type?.name ?? ''; if (name.includes('LabelWrap') || name.includes('ElForm') || name.includes('FormItem')) return; console.error(err); }; window.addEventListener('unhandledrejection', (e) => { const msg = e?.reason?.message ?? e?.reason?.toString?.() ?? ''; const stack = e?.reason?.stack ?? ''; const all = msg + ' ' + stack; if (all.includes('form-label') || all.includes('LabelWrap') || all.includes('ElForm') || all.includes('FormItem') || all.includes('deregisterLabel') || all.includes('labelPosition') || all.includes('autoLabel') || all.includes('label') || all.includes('width') || all.includes('NaN') || all.includes('formContext')) { e.preventDefault(); } }); // Catch uncaught errors from el-form teardown in vxe-table expand rows window.addEventListener("error", (e) => { const stack = e?.error?.stack ?? ""; if (stack.includes("form-label") || stack.includes("LabelWrap") || stack.includes("ElForm") || stack.includes("FormItem") || stack.includes("deregisterLabel")) { e.preventDefault(); return true; } }, true); // 登录成功后延迟加载首页通知弹窗 nextTick(() => { import('@/utils/noticeHelper').then(({initNoticePopupAfterLogin}) => initNoticePopupAfterLogin()); }); app.use(i18n); app.mount('#app'); } bootstrap();