332cfb2e by lxs

通过config.json配置appKey

1 parent f8d8cc89
1 {
2 "appKey": "67bd2ff5e4b0cac8f9a5beea"
3 }
...@@ -6,11 +6,12 @@ import App from './App.vue' ...@@ -6,11 +6,12 @@ import App from './App.vue'
6 // import pinia from './store' 6 // import pinia from './store'
7 import router from './router' 7 import router from './router'
8 import useSettingsStore from './store/modules/settings'; 8 import useSettingsStore from './store/modules/settings';
9 import sysConfigStore from '@/store/modules/sysConfig'
9 import { ElMessage } from "element-plus" 10 import { ElMessage } from "element-plus"
10 import { openMessageBox } from "@/utils/common" 11 import { openMessageBox } from "@/utils/common"
11 12
12 // pinia设置 13 // pinia设置
13 import {createPinia} from 'pinia' 14 import { createPinia } from 'pinia'
14 import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' 15 import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
15 16
16 // 自定义指令 17 // 自定义指令
...@@ -25,18 +26,52 @@ import '@/assets/styles/globals.scss' ...@@ -25,18 +26,52 @@ import '@/assets/styles/globals.scss'
25 // 加载 iconify 图标(element plus) 26 // 加载 iconify 图标(element plus)
26 import { downloadAndInstall } from '@/iconify-ep' 27 import { downloadAndInstall } from '@/iconify-ep'
27 28
28 const pinia = createPinia(); 29 // 封装请求配置文件的函数
29 pinia.use(piniaPluginPersistedstate); 30 const loadConfig = async () => {
31 try {
32 const response = await fetch('/config.json');
33 if (!response.ok) {
34 throw new Error(`请求配置失败,状态码: ${response.status}`);
35 }
36 const config = await response.json();
37 return config;
38 } catch (error) {
39 console.error('加载配置时出错:', error);
40 throw error;
41 }
42 };
30 43
31 const app = createApp(App) 44 // 初始化应用的异步函数
32 app.use(ElementPlus) 45 const initApp = async () => {
33 app.use(pinia) 46 try {
34 app.use(router) 47 // 加载配置文件
35 directive(app) 48 const config = await loadConfig();
36 if (useSettingsStore().settings.app.iconifyOfflineUse) { 49
50 const pinia = createPinia();
51 pinia.use(piniaPluginPersistedstate);
52
53 // 将配置信息存储到 Pinia 中
54 const configStore = sysConfigStore(pinia);
55 configStore.setConfig(config);
56
57 const app = createApp(App)
58 app.use(ElementPlus)
59 app.use(pinia)
60 app.use(router)
61 directive(app)
62 if (useSettingsStore().settings.app.iconifyOfflineUse) {
37 downloadAndInstall() 63 downloadAndInstall()
38 } 64 }
39 app.config.globalProperties.$passCode = "00000";// 定义全局变量 65 app.config.globalProperties.$passCode = "00000";// 定义全局变量
40 app.config.globalProperties.$ElMessage = ElMessage; // 全局消息提示 66 app.config.globalProperties.$ElMessage = ElMessage; // 全局消息提示
41 app.config.globalProperties.$openMessageBox = openMessageBox; // 二次确认提示对话框。 67 app.config.globalProperties.$openMessageBox = openMessageBox; // 二次确认提示对话框。
42 app.mount('#main-app') 68 app.mount('#main-app')
69 } catch (error) {
70 console.error('应用初始化失败:', error);
71 // 这里可以添加一些错误处理逻辑,比如显示错误提示给用户
72 }
73 };
74
75
76 // 启动应用
77 initApp();
......
1 const sysConfigStore = defineStore(
2 // 唯一ID
3 'config',
4 () => {
5 let configMap: any = {};
6 const setConfig = (val) => {
7 configMap = val
8 }
9
10 const getConfig = (field) => {
11 return field ? configMap[field]: configMap;
12 }
13
14 return {
15 configMap,
16 setConfig,
17 getConfig
18 }
19 },
20 )
21
22 export default sysConfigStore
1 import useRouteStore from './route' 1 import useRouteStore from './route'
2 import useMenuStore from './menu' 2 import useMenuStore from './menu'
3 import sysConfigStore from './sysConfig'
3 import router from '@/router' 4 import router from '@/router'
4 import { ElMessage } from 'element-plus' 5 import { ElMessage } from 'element-plus'
5 import apiUser from '@/api/modules/user' 6 import apiUser from '@/api/modules/user'
...@@ -33,7 +34,8 @@ const useUserStore = defineStore( ...@@ -33,7 +34,8 @@ const useUserStore = defineStore(
33 function getToken(data, state) { 34 function getToken(data, state) {
34 data.platformGuid = "7f16f697aec111ef8656fa163e60becd"; 35 data.platformGuid = "7f16f697aec111ef8656fa163e60becd";
35 data.userType = 2; 36 data.userType = 2;
36 data.appKey = '67bd2ff5e4b0cac8f9a5beea'; 37 // data.appKey = '67bd2ff5e4b0cac8f9a5beea';
38 data.appKey = sysConfigStore().getConfig('appKey');
37 data.validateUri = location.origin == 'http://localhost:9000' ? 'http://localhost:9000/' : location.origin + '/'; 39 data.validateUri = location.origin == 'http://localhost:9000' ? 'http://localhost:9000/' : location.origin + '/';
38 return getTokenPromise.value = getTokenByCode(data).then((res: any) => { 40 return getTokenPromise.value = getTokenByCode(data).then((res: any) => {
39 getTokenPromise.value = null; 41 getTokenPromise.value = null;
......
...@@ -61,6 +61,7 @@ export default ({ mode, command }) => { ...@@ -61,6 +61,7 @@ export default ({ mode, command }) => {
61 build: { 61 build: {
62 outDir: mode === 'product' ? 'dist' : `dist-${mode}`, 62 outDir: mode === 'product' ? 'dist' : `dist-${mode}`,
63 sourcemap: env.VITE_BUILD_SOURCEMAP === 'true', 63 sourcemap: env.VITE_BUILD_SOURCEMAP === 'true',
64 copyPublicDir: true, // 确保 public 目录下的文件被复制到输出目录的根目录
64 }, 65 },
65 define: { 66 define: {
66 __SYSTEM_INFO__: JSON.stringify({ 67 __SYSTEM_INFO__: JSON.stringify({
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!