Files
ks-app-employment-service/main.js

135 lines
4.8 KiB
JavaScript
Raw Normal View History

2025-10-23 15:04:00 +08:00
/*
* @Date: 2025-10-23 14:48:48
* @LastEditors: shirlwang
2025-11-03 08:48:43 +08:00
* @LastEditTime: 2025-10-31 18:27:06
2025-10-23 15:04:00 +08:00
*/
2025-10-31 11:04:16 +08:00
import App from './App'
2024-11-08 11:55:23 +08:00
import * as Pinia from 'pinia'
2025-10-31 11:04:16 +08:00
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
2025-05-13 11:10:38 +08:00
// 组件
import AppLayout from './components/AppLayout/AppLayout.vue';
import Empty from './components/empty/empty.vue';
2025-03-28 15:19:42 +08:00
import NoBouncePage from '@/components/NoBouncePage/NoBouncePage.vue'
2025-04-16 14:24:06 +08:00
import MsgTips from '@/components/MsgTips/MsgTips.vue'
2025-05-13 11:10:38 +08:00
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';
2025-10-20 16:15:29 +08:00
// iconfont.css 已在 App.vue 中通过 @import 引入,无需在此处重复引入
2025-04-10 10:59:25 +08:00
// import Tabbar from '@/components/tabbar/midell-box.vue'
2025-04-16 14:24:06 +08:00
// 自动导入 directives 目录下所有指令
const directives = import.meta.glob('./directives/*.js', {
eager: true
});
2025-03-29 11:51:48 +08:00
2025-10-31 09:30:04 +08:00
import { createSSRApp } from 'vue'
// 导入已安装的uni-ui组件
2025-10-31 11:04:16 +08:00
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'
2024-11-08 11:55:23 +08:00
2025-11-03 08:48:43 +08:00
import storeRc from './utilsRc/store/index.js'
2025-10-23 15:04:00 +08:00
// const foldFeature = window.visualViewport && 'segments' in window.visualViewport
// console.log('是否支持多段屏幕:', foldFeature)
2025-05-15 14:17:51 +08:00
2025-03-28 15:19:42 +08:00
// 全局组件
2025-10-31 09:30:04 +08:00
// 字典缓存,避免重复请求
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 [];
}
}
2024-11-08 11:55:23 +08:00
export function createApp() {
const app = createSSRApp(App)
2025-03-28 15:19:42 +08:00
2025-05-13 11:10:38 +08:00
app.component('AppLayout', AppLayout)
app.component('Empty', Empty)
2025-03-28 15:19:42 +08:00
app.component('NoBouncePage', NoBouncePage)
2025-04-16 14:24:06 +08:00
app.component('MsgTips', MsgTips)
2025-05-13 11:10:38 +08:00
app.component('SelectPopup', SelectPopup)
app.component('RenderJobs', RenderJobs)
app.component('RenderCompanys', RenderCompanys)
2025-04-10 10:59:25 +08:00
// app.component('tabbar-custom', Tabbar)
2025-10-31 09:30:04 +08:00
// 注册已安装的uni-ui组件
app.component('uni-icons', uniIcons)
app.component('uni-popup', uniPopup)
// 注意项目缺少表单相关组件需要将模板中的uni-ui组件改为原生元素
2025-03-28 15:19:42 +08:00
2025-04-16 14:24:06 +08:00
for (const path in directives) {
const directiveModule = directives[path];
// 文件名作为指令名,./directives/fade.js => v-fade
2025-10-31 09:30:04 +08:00
const name = path.match(/\/directives\/(.*)\.js$/)[1];
2025-04-16 14:24:06 +08:00
app.directive(name, directiveModule.default);
}
2025-03-28 15:19:42 +08:00
app.provide('globalFunction', {
...globalFunction,
2025-09-29 11:53:10 +08:00
similarityJobs,
config
2025-03-28 15:19:42 +08:00
});
2024-11-08 11:55:23 +08:00
app.provide('deviceInfo', globalFunction.getdeviceInfo());
2025-03-28 15:19:42 +08:00
2025-10-31 09:30:04 +08:00
// 先注册Pinia
2025-03-28 15:19:42 +08:00
app.use(Pinia.createPinia());
2025-10-31 17:48:31 +08:00
// 注册vuex
app.use(storeRc);
2025-10-31 09:30:04 +08:00
// 注册其他插件
app.use(SelectPopupPlugin);
// Vue 3 中挂载全局属性 - 字典获取方法
app.config.globalProperties.$getDict = getDict;
2025-10-31 17:48:31 +08:00
app.config.globalProperties.$store = storeRc;
2025-10-31 09:30:04 +08:00
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
}));
};
2024-11-08 11:55:23 +08:00
return {
app,
Pinia
}
2025-10-31 09:30:04 +08:00
2024-11-08 11:55:23 +08:00
}