/* * @Date: 2025-10-23 14:48:48 * @LastEditors: shirlwang * @LastEditTime: 2025-10-31 16:51:55 */ import App from './App' import * as Pinia from 'pinia' import globalFunction from './common/globalFunction' import './lib/string-similarity.min.js' import similarityJobs from './utils/similarity_Job.js'; import config from './config.js'; // 导入主包中的request.js用于字典服务 // 在uni-app小程序环境中,主包不能直接引用分包中的模块 import { request, get, post, packageRcRequest, packageRcGet, packageRcPost } from './utils/request.js'; // 将request, get, post函数挂载到全局,方便使用 // 挂载分包专用的请求函数(使用固定baseURL和token) // 组件 import AppLayout from './components/AppLayout/AppLayout.vue'; import Empty from './components/empty/empty.vue'; import NoBouncePage from './components/NoBouncePage/NoBouncePage.vue' import MsgTips from './components/MsgTips/MsgTips.vue' import SelectPopup from './components/selectPopup/selectPopup.vue' import SelectPopupPlugin from './components/selectPopup/selectPopupPlugin'; import RenderJobs from './components/renderJobs/renderJobs.vue'; import RenderCompanys from './components/renderCompanys/renderCompanys.vue'; // import Tabbar from '@/components/tabbar/midell-box.vue' // 自动导入 directives 目录下所有指令 const directives = import.meta.glob('./directives/*.js', { eager: true }); import { createSSRApp } from 'vue' // 导入已安装的uni-ui组件 import uniIcons from './uni_modules/uni-icons/components/uni-icons/uni-icons.vue' import uniPopup from './uni_modules/uni-popup/components/uni-popup/uni-popup.vue' import storeRc from './utilsRc/store/index.js' // const foldFeature = window.visualViewport && 'segments' in window.visualViewport // console.log('是否支持多段屏幕:', foldFeature) // 全局组件 // 字典缓存,避免重复请求 const dictCache = new Map(); // 获取字典数据的方法 async function getDict(dictType, forceRefresh = false) { // 检查缓存 if (dictCache.has(dictType) && !forceRefresh) { return dictCache.get(dictType); } try { // 使用packageRc/utils/request.js中的请求方法 // 注意:这里使用的baseURL是 http://10.160.0.5:8907/ const response = await request({ url: `system/dict/data/type/${dictType}`, method: 'GET', load: true }); // 处理响应数据 if (response.code === 200 && response.data) { // 缓存数据 dictCache.set(dictType, response.data); return response.data; } return []; } catch (error) { console.error(`获取字典[${dictType}]失败:`, error); return []; } } export function createApp() { const app = createSSRApp(App) app.component('AppLayout', AppLayout) app.component('Empty', Empty) app.component('NoBouncePage', NoBouncePage) app.component('MsgTips', MsgTips) app.component('SelectPopup', SelectPopup) app.component('RenderJobs', RenderJobs) app.component('RenderCompanys', RenderCompanys) // app.component('tabbar-custom', Tabbar) // 注册已安装的uni-ui组件 app.component('uni-icons', uniIcons) app.component('uni-popup', uniPopup) // 注意:项目缺少表单相关组件,需要将模板中的uni-ui组件改为原生元素 for (const path in directives) { const directiveModule = directives[path]; // 文件名作为指令名,./directives/fade.js => v-fade const name = path.match(/\/directives\/(.*)\.js$/)[1]; app.directive(name, directiveModule.default); } app.provide('globalFunction', { ...globalFunction, similarityJobs, config }); app.provide('deviceInfo', globalFunction.getdeviceInfo()); // 先注册Pinia app.use(Pinia.createPinia()); // 注册vuex app.use(storeRc); // 注册其他插件 app.use(SelectPopupPlugin); // Vue 3 中挂载全局属性 - 字典获取方法 app.config.globalProperties.$getDict = getDict; app.config.globalProperties.$store = storeRc; app.config.globalProperties.$getDictSelectOption = async (dictType, isDigital = false, forceRefresh = false) => { const dictData = await getDict(dictType, forceRefresh); return dictData.map(item => ({ value: isDigital ? Number(item.dictValue || item.dictvalue) : (item.dictValue || item.dictvalue), label: item.dictLabel || item.dictlabel, ...item })); }; return { app, Pinia } }