提交
This commit is contained in:
73
main.js
73
main.js
@@ -9,6 +9,11 @@ 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';
|
||||
@@ -24,14 +29,48 @@ const directives = import.meta.glob('./directives/*.js', {
|
||||
eager: true
|
||||
});
|
||||
|
||||
import {
|
||||
createSSRApp,
|
||||
} from 'vue'
|
||||
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)
|
||||
|
||||
@@ -43,11 +82,16 @@ export function createApp() {
|
||||
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];
|
||||
const name = path.match(/\/directives\/(.*)\.js$/)[1];
|
||||
app.directive(name, directiveModule.default);
|
||||
}
|
||||
|
||||
@@ -58,11 +102,28 @@ export function createApp() {
|
||||
});
|
||||
app.provide('deviceInfo', globalFunction.getdeviceInfo());
|
||||
|
||||
app.use(SelectPopupPlugin);
|
||||
// 先注册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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user