xto-fronted 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-15Bu0M8D.js +372 -0
- package/dist/index-BGgbfcmf.js +475 -0
- package/dist/index-BO2Zf9u6.js +142 -0
- package/dist/index-BQqo0ZIb.js +345 -0
- package/dist/index-CiuDEfo-.js +142 -0
- package/dist/index-Cqix1YLE.js +1697 -0
- package/dist/index-D3xVcFvg.js +372 -0
- package/dist/index-DLgimJYb.js +1667 -0
- package/dist/index-DqQRSPeF.js +345 -0
- package/dist/index-PRFGBLWt.js +475 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +70 -65
- package/dist/index.umd.js +1 -1
- package/dist/style.css +1 -1
- package/dist/utils/config.d.ts +30 -0
- package/package.json +1 -1
- package/src/api/system.ts +2 -1
- package/src/components/Layout/Sidebar.vue +34 -3
- package/src/env.d.ts +2 -0
- package/src/index.ts +1 -0
- package/src/router/index.ts +2 -1
- package/src/utils/config.ts +81 -0
- package/src/views/login/index.vue +3 -2
package/src/index.ts
CHANGED
package/src/router/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
|
|
6
6
|
import { staticRoutes, errorRoute } from './staticRoutes'
|
|
7
7
|
import { layoutRoute } from './dynamicRoutes'
|
|
8
8
|
import { hasToken } from '@/utils/auth'
|
|
9
|
+
import { getAppId } from '@/utils/config'
|
|
9
10
|
import { useUserStore } from '@/stores/user'
|
|
10
11
|
import { useMenuStore } from '@/stores/menu'
|
|
11
12
|
import { useAppStore } from '@/stores/app'
|
|
@@ -37,7 +38,7 @@ router.beforeEach(async (to, _from, next) => {
|
|
|
37
38
|
const userStore = useUserStore()
|
|
38
39
|
if (!userStore.isLoggedIn) {
|
|
39
40
|
userStore.setUserInfo({
|
|
40
|
-
appId:
|
|
41
|
+
appId: getAppId(),
|
|
41
42
|
userId: '1',
|
|
42
43
|
userName: '管理员',
|
|
43
44
|
departmentName: '技术部',
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用配置(动态设置,避免 import.meta.env 静态替换)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ref } from 'vue'
|
|
6
|
+
|
|
7
|
+
// 配置状态
|
|
8
|
+
const appId = ref<string>('')
|
|
9
|
+
const clientId = ref<string>('')
|
|
10
|
+
const apiBaseUrl = ref<string>('')
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 初始化应用配置
|
|
14
|
+
* 在项目入口文件(main.ts)中调用此函数设置配置
|
|
15
|
+
*/
|
|
16
|
+
export function initAppConfig(config: {
|
|
17
|
+
appId?: string
|
|
18
|
+
clientId?: string
|
|
19
|
+
apiBaseUrl?: string
|
|
20
|
+
}) {
|
|
21
|
+
if (config.appId) {
|
|
22
|
+
appId.value = config.appId
|
|
23
|
+
}
|
|
24
|
+
if (config.clientId) {
|
|
25
|
+
clientId.value = config.clientId
|
|
26
|
+
}
|
|
27
|
+
if (config.apiBaseUrl) {
|
|
28
|
+
apiBaseUrl.value = config.apiBaseUrl
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 获取 AppId
|
|
34
|
+
* 优先使用动态配置,其次使用环境变量
|
|
35
|
+
*/
|
|
36
|
+
export function getAppId(): string {
|
|
37
|
+
if (appId.value) {
|
|
38
|
+
return appId.value
|
|
39
|
+
}
|
|
40
|
+
// 尝试从环境变量获取(使用方项目构建时会注入)
|
|
41
|
+
try {
|
|
42
|
+
return import.meta.env.VITE_APP_ID || ''
|
|
43
|
+
} catch {
|
|
44
|
+
return ''
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 获取 ClientId
|
|
50
|
+
*/
|
|
51
|
+
export function getClientId(): string {
|
|
52
|
+
if (clientId.value) {
|
|
53
|
+
return clientId.value
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
return import.meta.env.VITE_APP_CLIENT_ID || ''
|
|
57
|
+
} catch {
|
|
58
|
+
return ''
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 获取 API 基础路径
|
|
64
|
+
*/
|
|
65
|
+
export function getApiBaseUrl(): string {
|
|
66
|
+
if (apiBaseUrl.value) {
|
|
67
|
+
return apiBaseUrl.value
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return import.meta.env.VITE_API_BASE_URL || ''
|
|
71
|
+
} catch {
|
|
72
|
+
return ''
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 导出响应式引用(供特殊场景直接使用)
|
|
77
|
+
export const appConfig = {
|
|
78
|
+
appId,
|
|
79
|
+
clientId,
|
|
80
|
+
apiBaseUrl
|
|
81
|
+
}
|
|
@@ -6,6 +6,7 @@ import { Form, FormItem, Input, Checkbox } from '@xto/form'
|
|
|
6
6
|
import { Message } from '@xto/feedback'
|
|
7
7
|
import { login } from '@/api/auth'
|
|
8
8
|
import { setTokenInfo } from '@/utils/auth'
|
|
9
|
+
import { getAppId, getClientId } from '@/utils/config'
|
|
9
10
|
|
|
10
11
|
const router = useRouter()
|
|
11
12
|
const route = useRoute()
|
|
@@ -38,8 +39,8 @@ const handleLogin = async () => {
|
|
|
38
39
|
|
|
39
40
|
// 调用登录 API
|
|
40
41
|
const result = await login({
|
|
41
|
-
appId:
|
|
42
|
-
clientId:
|
|
42
|
+
appId: getAppId(),
|
|
43
|
+
clientId: getClientId(),
|
|
43
44
|
uid: formData.uid,
|
|
44
45
|
password: formData.password,
|
|
45
46
|
code: true
|