main.ts
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import './utils/baidu'
import './utils/system.copyright'
import ElementPlus from 'element-plus'
import App from './App.vue'
// import pinia from './store'
import router from './router'
import useSettingsStore from './store/modules/settings';
import sysConfigStore from '@/store/modules/sysConfig'
import { ElMessage } from "element-plus"
import { openMessageBox } from "@/utils/common"
// pinia设置
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
// 自定义指令
import directive from '@/utils/directive'
// 加载 svg 图标
import 'virtual:svg-icons-register'
// 全局样式
import '@/assets/styles/globals.scss'
// 加载 iconify 图标(element plus)
import { downloadAndInstall } from '@/iconify-ep'
// 封装请求配置文件的函数
const loadConfig = async () => {
try {
const response = await fetch('/config.json');
if (!response.ok) {
throw new Error(`请求配置失败,状态码: ${response.status}`);
}
const config = await response.json();
return config;
} catch (error) {
console.error('加载配置时出错:', error);
throw error;
}
};
// 初始化应用的异步函数
const initApp = async () => {
try {
// 加载配置文件
const config = await loadConfig();
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);
// 将配置信息存储到 Pinia 中
const configStore = sysConfigStore(pinia);
configStore.setConfig(config);
const app = createApp(App)
app.use(ElementPlus)
app.use(pinia)
app.use(router)
directive(app)
if (useSettingsStore().settings.app.iconifyOfflineUse) {
downloadAndInstall()
}
app.config.globalProperties.$passCode = "00000";// 定义全局变量
app.config.globalProperties.$ElMessage = ElMessage; // 全局消息提示
app.config.globalProperties.$openMessageBox = openMessageBox; // 二次确认提示对话框。
app.mount('#main-app')
} catch (error) {
console.error('应用初始化失败:', error);
// 这里可以添加一些错误处理逻辑,比如显示错误提示给用户
}
};
// 启动应用
initApp();