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

125 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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';
// 导入packageRc中的request.js用于字典服务
import { request } from '@/packageRc/utils/request.js';
// 引入Element Plus组件库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 组件
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';
// iconfont.css 已在 App.vue 中通过 @import 引入,无需在此处重复引入
// 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'
// 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());
// 注册其他插件
app.use(SelectPopupPlugin);
app.use(ElementPlus);
// Vue 3 中挂载全局属性 - 字典获取方法
app.config.globalProperties.$getDict = getDict;
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
}
}