xto-fronted 0.4.93 → 0.4.95
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/assets/404-C9Uh6Uu-.css +1 -0
- package/dist/assets/404-zjGLLssH.js +1 -0
- package/dist/assets/_plugin-vue_export-helper-DlAUqK2U.js +1 -0
- package/dist/assets/index-B5xc4gQB.css +1 -0
- package/dist/assets/index-BDgOY6Rp.js +1 -0
- package/dist/assets/index-BIoRANs0.js +1 -0
- package/dist/assets/index-BRR97dc6.js +1 -0
- package/dist/assets/index-Bz0BgZQ1.js +1 -0
- package/dist/assets/index-CAdztNsv.css +1 -0
- package/dist/assets/index-CCXrcISf.css +1 -0
- package/dist/assets/index-CfpZmcpk.css +1 -0
- package/dist/assets/index-CwJSA85U.js +1 -0
- package/dist/assets/index-CwRA10ac.js +1 -0
- package/dist/assets/index-D8NDxq9d.js +1 -0
- package/dist/assets/index-DEB6-Iv_.js +2 -0
- package/dist/assets/index-DM4Ezclc.css +1 -0
- package/dist/assets/index-DYv7nImj.css +1 -0
- package/dist/assets/index-t-2Y0KhA.css +1 -0
- package/dist/assets/vendor-CUVPinTg.js +13 -0
- package/dist/assets/vue-vendor-DeJXJVbN.js +29 -0
- package/dist/assets/xto-base-CL2NKZJJ.css +1 -0
- package/dist/assets/xto-base-PwLGsxxb.js +1 -0
- package/dist/assets/xto-business--V1F5Gwb.css +1 -0
- package/dist/assets/xto-core-CtL4zKiV.js +1 -0
- package/dist/assets/xto-data-MxZsiJgi.css +1 -0
- package/dist/assets/xto-data-bCXQa7fT.js +1 -0
- package/dist/assets/xto-feedback-Bxx38c3P.css +1 -0
- package/dist/assets/xto-feedback-CPydp0kn.js +1 -0
- package/dist/assets/xto-form-Cu6q3VLG.css +1 -0
- package/dist/assets/xto-form-bywohdAf.js +1 -0
- package/dist/assets/xto-layout-BDD6sSlM.css +1 -0
- package/dist/assets/xto-navigation-Bbdpine9.js +1 -0
- package/dist/assets/xto-navigation-XfpyMpEo.css +1 -0
- package/dist/components/Layout/MixTopMenu.vue.d.ts +6 -1
- package/dist/components/Layout/Sidebar.vue.d.ts +2 -0
- package/dist/components/Layout/TopMenu.vue.d.ts +6 -1
- package/dist/components/Layout/index.vue.d.ts +6 -1
- package/dist/{index-D59X6HmM.js → index-3ekBp4iW.js} +2 -2
- package/dist/{index-Cp8kqjtv.js → index-58aI1w0v.js} +2 -2
- package/dist/{index-me_Uu2lk.js → index-A_B_Ap_A.js} +1560 -1590
- package/dist/{index-lJrh5CFc.js → index-B5DLfOYb.js} +23 -23
- package/dist/index-BAmYUT0G.js +189 -0
- package/dist/{index-B4U8Dy2W.js → index-BK4Mut6H.js} +2 -2
- package/dist/index-BRvi9qW-.js +515 -0
- package/dist/index-BVGW4DDQ.js +189 -0
- package/dist/index-BXg94yA2.js +515 -0
- package/dist/index-Bmf0YbVq.js +189 -0
- package/dist/index-C2-a5KSQ.js +4233 -0
- package/dist/index-CAHSv7LK.js +4285 -0
- package/dist/index-CeZ0CSSs.js +641 -0
- package/dist/index-Cf8E7FM1.js +4270 -0
- package/dist/index-CgyQqbdx.js +189 -0
- package/dist/index-ChowNrlU.js +641 -0
- package/dist/index-D25KzR0I.js +479 -0
- package/dist/index-DCBIjLHy.js +515 -0
- package/dist/index-DEYOivza.js +641 -0
- package/dist/index-DReodgBw.js +4233 -0
- package/dist/index-DjERNRXX.js +515 -0
- package/dist/index-LSdsO2Ox.js +479 -0
- package/dist/index-UJixTdep.js +479 -0
- package/dist/index-gBlRG4kk.js +479 -0
- package/dist/index-xWU3J3OH.js +641 -0
- package/dist/index.es.js +1 -1
- package/dist/index.html +28 -0
- package/dist/index.umd.js +8 -8
- package/dist/style.css +1 -1
- package/package.json +91 -91
- package/src/App.vue +48 -48
- package/src/assets/styles/_dark.scss +639 -639
- package/src/assets/styles/_root.scss +183 -183
- package/src/assets/styles/_variables.scss +69 -69
- package/src/assets/styles/index.scss +460 -460
- package/src/components/Layout/MixTopMenu.vue +8 -1
- package/src/components/Layout/Sidebar.vue +200 -198
- package/src/components/Layout/SidebarMenuItem.vue +158 -158
- package/src/components/Layout/TopMenu.vue +1177 -1170
- package/src/components/Layout/index.vue +199 -192
- package/src/composables/useI18n.ts +43 -43
- package/src/index.ts +100 -100
- package/src/router/layoutRoute.ts +59 -59
- package/src/stores/index.ts +15 -15
- package/src/stores/locale.ts +66 -66
- package/src/types/json-bigint.d.ts +18 -18
- package/src/types/xto.d.ts +172 -172
- package/src/utils/request.ts +184 -184
- package/src/views/dashboard/index.vue +545 -545
- package/src/views/error/403.vue +251 -251
- package/src/views/error/404.vue +253 -253
- package/src/views/login/index.vue +586 -586
- package/src/views/system/menu/index.vue +690 -690
- package/src/views/system/role/index.vue +583 -583
- package/src/views/system/user/index.vue +655 -655
package/src/index.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
// 样式
|
|
2
|
-
import './style.scss'
|
|
3
|
-
|
|
4
|
-
// 配置
|
|
5
|
-
import { initAppConfig, getAppId, getClientId, getApiBaseUrl } from './utils/config'
|
|
6
|
-
import type { LocaleCode } from '@xto/core/locale'
|
|
7
|
-
|
|
8
|
-
// XtoConfig 类型定义
|
|
9
|
-
export interface XtoConfig {
|
|
10
|
-
appName?: string
|
|
11
|
-
appId?: string
|
|
12
|
-
clientId?: string
|
|
13
|
-
apiBaseUrl?: string
|
|
14
|
-
indexPath?: string
|
|
15
|
-
loginPath?: string
|
|
16
|
-
locale?: LocaleCode
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 初始化 XTO 应用
|
|
21
|
-
* 在项目入口文件中调用此函数设置应用配置
|
|
22
|
-
* @param config 应用配置
|
|
23
|
-
*/
|
|
24
|
-
export function createXtoApp(config: Partial<XtoConfig>) {
|
|
25
|
-
initAppConfig({
|
|
26
|
-
appId: config.appId,
|
|
27
|
-
clientId: config.clientId,
|
|
28
|
-
apiBaseUrl: config.apiBaseUrl
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// 设置初始语言(如果提供)
|
|
32
|
-
if (config.locale) {
|
|
33
|
-
import('./stores/locale').then(({ useLocaleStore }) => {
|
|
34
|
-
const localeStore = useLocaleStore()
|
|
35
|
-
localeStore.changeLocale(config.locale!)
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
config: {
|
|
41
|
-
appName: config.appName || 'XTO App',
|
|
42
|
-
appId: getAppId(),
|
|
43
|
-
clientId: getClientId(),
|
|
44
|
-
apiBaseUrl: getApiBaseUrl(),
|
|
45
|
-
indexPath: config.indexPath || '/dashboard',
|
|
46
|
-
loginPath: config.loginPath || '/login',
|
|
47
|
-
locale: config.locale || 'zh-CN'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 组件
|
|
53
|
-
export { default as Layout } from './components/Layout/index.vue'
|
|
54
|
-
export { default as Header } from './components/Layout/Header.vue'
|
|
55
|
-
export { default as Sidebar } from './components/Layout/Sidebar.vue'
|
|
56
|
-
export { default as Tabs } from './components/Layout/Tabs.vue'
|
|
57
|
-
export { default as Footer } from './components/Layout/Footer.vue'
|
|
58
|
-
|
|
59
|
-
// 错误页面组件
|
|
60
|
-
export { default as Login } from './views/login/index.vue'
|
|
61
|
-
export { default as NotFound } from './views/error/404.vue'
|
|
62
|
-
export { default as Forbidden } from './views/error/403.vue'
|
|
63
|
-
|
|
64
|
-
// 组合式函数
|
|
65
|
-
export * from './composables/useApp'
|
|
66
|
-
export * from './composables/useAuth'
|
|
67
|
-
export * from './composables/useForm'
|
|
68
|
-
export * from './composables/useTable'
|
|
69
|
-
export * from './composables/useI18n'
|
|
70
|
-
|
|
71
|
-
// 工具函数
|
|
72
|
-
export * from './utils/auth'
|
|
73
|
-
export * from './utils/permission'
|
|
74
|
-
export * from './utils/request'
|
|
75
|
-
export * from './utils/storage'
|
|
76
|
-
export * from './utils/config'
|
|
77
|
-
|
|
78
|
-
// Store
|
|
79
|
-
export * from './stores/app'
|
|
80
|
-
export * from './stores/auth'
|
|
81
|
-
export * from './stores/menu'
|
|
82
|
-
export * from './stores/user'
|
|
83
|
-
export * from './stores/locale'
|
|
84
|
-
|
|
85
|
-
// 路由
|
|
86
|
-
export { default as router, resetRouter } from './router'
|
|
87
|
-
export * from './router/staticRoutes'
|
|
88
|
-
export * from './router/dynamicRoutes'
|
|
89
|
-
export { createLayoutRoute, createRouter } from './router/layoutRoute'
|
|
90
|
-
export { setupRouterGuards } from './router/guards'
|
|
91
|
-
|
|
92
|
-
// API
|
|
93
|
-
export * from './api/auth'
|
|
94
|
-
export * from './api/system'
|
|
95
|
-
export * from './api/user'
|
|
96
|
-
|
|
97
|
-
// 枚举
|
|
98
|
-
export * from './enums'
|
|
99
|
-
|
|
100
|
-
// 指令
|
|
1
|
+
// 样式
|
|
2
|
+
import './style.scss'
|
|
3
|
+
|
|
4
|
+
// 配置
|
|
5
|
+
import { initAppConfig, getAppId, getClientId, getApiBaseUrl } from './utils/config'
|
|
6
|
+
import type { LocaleCode } from '@xto/core/locale'
|
|
7
|
+
|
|
8
|
+
// XtoConfig 类型定义
|
|
9
|
+
export interface XtoConfig {
|
|
10
|
+
appName?: string
|
|
11
|
+
appId?: string
|
|
12
|
+
clientId?: string
|
|
13
|
+
apiBaseUrl?: string
|
|
14
|
+
indexPath?: string
|
|
15
|
+
loginPath?: string
|
|
16
|
+
locale?: LocaleCode
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 初始化 XTO 应用
|
|
21
|
+
* 在项目入口文件中调用此函数设置应用配置
|
|
22
|
+
* @param config 应用配置
|
|
23
|
+
*/
|
|
24
|
+
export function createXtoApp(config: Partial<XtoConfig>) {
|
|
25
|
+
initAppConfig({
|
|
26
|
+
appId: config.appId,
|
|
27
|
+
clientId: config.clientId,
|
|
28
|
+
apiBaseUrl: config.apiBaseUrl
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// 设置初始语言(如果提供)
|
|
32
|
+
if (config.locale) {
|
|
33
|
+
import('./stores/locale').then(({ useLocaleStore }) => {
|
|
34
|
+
const localeStore = useLocaleStore()
|
|
35
|
+
localeStore.changeLocale(config.locale!)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
config: {
|
|
41
|
+
appName: config.appName || 'XTO App',
|
|
42
|
+
appId: getAppId(),
|
|
43
|
+
clientId: getClientId(),
|
|
44
|
+
apiBaseUrl: getApiBaseUrl(),
|
|
45
|
+
indexPath: config.indexPath || '/dashboard',
|
|
46
|
+
loginPath: config.loginPath || '/login',
|
|
47
|
+
locale: config.locale || 'zh-CN'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 组件
|
|
53
|
+
export { default as Layout } from './components/Layout/index.vue'
|
|
54
|
+
export { default as Header } from './components/Layout/Header.vue'
|
|
55
|
+
export { default as Sidebar } from './components/Layout/Sidebar.vue'
|
|
56
|
+
export { default as Tabs } from './components/Layout/Tabs.vue'
|
|
57
|
+
export { default as Footer } from './components/Layout/Footer.vue'
|
|
58
|
+
|
|
59
|
+
// 错误页面组件
|
|
60
|
+
export { default as Login } from './views/login/index.vue'
|
|
61
|
+
export { default as NotFound } from './views/error/404.vue'
|
|
62
|
+
export { default as Forbidden } from './views/error/403.vue'
|
|
63
|
+
|
|
64
|
+
// 组合式函数
|
|
65
|
+
export * from './composables/useApp'
|
|
66
|
+
export * from './composables/useAuth'
|
|
67
|
+
export * from './composables/useForm'
|
|
68
|
+
export * from './composables/useTable'
|
|
69
|
+
export * from './composables/useI18n'
|
|
70
|
+
|
|
71
|
+
// 工具函数
|
|
72
|
+
export * from './utils/auth'
|
|
73
|
+
export * from './utils/permission'
|
|
74
|
+
export * from './utils/request'
|
|
75
|
+
export * from './utils/storage'
|
|
76
|
+
export * from './utils/config'
|
|
77
|
+
|
|
78
|
+
// Store
|
|
79
|
+
export * from './stores/app'
|
|
80
|
+
export * from './stores/auth'
|
|
81
|
+
export * from './stores/menu'
|
|
82
|
+
export * from './stores/user'
|
|
83
|
+
export * from './stores/locale'
|
|
84
|
+
|
|
85
|
+
// 路由
|
|
86
|
+
export { default as router, resetRouter } from './router'
|
|
87
|
+
export * from './router/staticRoutes'
|
|
88
|
+
export * from './router/dynamicRoutes'
|
|
89
|
+
export { createLayoutRoute, createRouter } from './router/layoutRoute'
|
|
90
|
+
export { setupRouterGuards } from './router/guards'
|
|
91
|
+
|
|
92
|
+
// API
|
|
93
|
+
export * from './api/auth'
|
|
94
|
+
export * from './api/system'
|
|
95
|
+
export * from './api/user'
|
|
96
|
+
|
|
97
|
+
// 枚举
|
|
98
|
+
export * from './enums'
|
|
99
|
+
|
|
100
|
+
// 指令
|
|
101
101
|
export { default as permissionDirective } from './directives/permission'
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 布局路由工厂函数
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createRouter as vueCreateRouter, createWebHistory } from 'vue-router'
|
|
6
|
-
import type { RouteRecordRaw, Router } from 'vue-router'
|
|
7
|
-
import Layout from '@/components/Layout/index.vue'
|
|
8
|
-
|
|
9
|
-
interface LayoutRouteOptions {
|
|
10
|
-
indexPath?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface CreateRouterOptions {
|
|
14
|
-
base?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 创建布局路由
|
|
19
|
-
* @param children 子路由配置
|
|
20
|
-
* @param options 配置选项
|
|
21
|
-
* @returns 布局路由配置
|
|
22
|
-
*/
|
|
23
|
-
export function createLayoutRoute(
|
|
24
|
-
children: RouteRecordRaw[],
|
|
25
|
-
options: LayoutRouteOptions = {}
|
|
26
|
-
): RouteRecordRaw {
|
|
27
|
-
const indexPath = options.indexPath || '/dashboard'
|
|
28
|
-
|
|
29
|
-
// 添加 catch-all 路由,让404在Layout内部渲染,保持左侧菜单显示
|
|
30
|
-
const catchAllRoute: RouteRecordRaw = {
|
|
31
|
-
path: '/:pathMatch(.*)*',
|
|
32
|
-
name: 'CatchAll',
|
|
33
|
-
component: () => import('@/views/error/404.vue'),
|
|
34
|
-
meta: {
|
|
35
|
-
title: '404'
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
path: '/',
|
|
41
|
-
name: 'Layout',
|
|
42
|
-
component: Layout,
|
|
43
|
-
redirect: indexPath,
|
|
44
|
-
children: [...children, catchAllRoute]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 创建路由实例
|
|
50
|
-
* @param routes 路由配置数组
|
|
51
|
-
* @param options 配置选项
|
|
52
|
-
* @returns 路由实例
|
|
53
|
-
*/
|
|
54
|
-
export function createRouter(routes: RouteRecordRaw[], options: CreateRouterOptions = {}): Router {
|
|
55
|
-
return vueCreateRouter({
|
|
56
|
-
history: createWebHistory(options.base),
|
|
57
|
-
routes,
|
|
58
|
-
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
59
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* 布局路由工厂函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createRouter as vueCreateRouter, createWebHistory } from 'vue-router'
|
|
6
|
+
import type { RouteRecordRaw, Router } from 'vue-router'
|
|
7
|
+
import Layout from '@/components/Layout/index.vue'
|
|
8
|
+
|
|
9
|
+
interface LayoutRouteOptions {
|
|
10
|
+
indexPath?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface CreateRouterOptions {
|
|
14
|
+
base?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 创建布局路由
|
|
19
|
+
* @param children 子路由配置
|
|
20
|
+
* @param options 配置选项
|
|
21
|
+
* @returns 布局路由配置
|
|
22
|
+
*/
|
|
23
|
+
export function createLayoutRoute(
|
|
24
|
+
children: RouteRecordRaw[],
|
|
25
|
+
options: LayoutRouteOptions = {}
|
|
26
|
+
): RouteRecordRaw {
|
|
27
|
+
const indexPath = options.indexPath || '/dashboard'
|
|
28
|
+
|
|
29
|
+
// 添加 catch-all 路由,让404在Layout内部渲染,保持左侧菜单显示
|
|
30
|
+
const catchAllRoute: RouteRecordRaw = {
|
|
31
|
+
path: '/:pathMatch(.*)*',
|
|
32
|
+
name: 'CatchAll',
|
|
33
|
+
component: () => import('@/views/error/404.vue'),
|
|
34
|
+
meta: {
|
|
35
|
+
title: '404'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
path: '/',
|
|
41
|
+
name: 'Layout',
|
|
42
|
+
component: Layout,
|
|
43
|
+
redirect: indexPath,
|
|
44
|
+
children: [...children, catchAllRoute]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 创建路由实例
|
|
50
|
+
* @param routes 路由配置数组
|
|
51
|
+
* @param options 配置选项
|
|
52
|
+
* @returns 路由实例
|
|
53
|
+
*/
|
|
54
|
+
export function createRouter(routes: RouteRecordRaw[], options: CreateRouterOptions = {}): Router {
|
|
55
|
+
return vueCreateRouter({
|
|
56
|
+
history: createWebHistory(options.base),
|
|
57
|
+
routes,
|
|
58
|
+
scrollBehavior: () => ({ left: 0, top: 0 })
|
|
59
|
+
})
|
|
60
60
|
}
|
package/src/stores/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pinia Store 入口
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createPinia } from 'pinia'
|
|
6
|
-
|
|
7
|
-
const pinia = createPinia()
|
|
8
|
-
|
|
9
|
-
export default pinia
|
|
10
|
-
|
|
11
|
-
// 导出所有 stores
|
|
12
|
-
export * from './user'
|
|
13
|
-
export * from './auth'
|
|
14
|
-
export * from './menu'
|
|
15
|
-
export * from './app'
|
|
1
|
+
/**
|
|
2
|
+
* Pinia Store 入口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createPinia } from 'pinia'
|
|
6
|
+
|
|
7
|
+
const pinia = createPinia()
|
|
8
|
+
|
|
9
|
+
export default pinia
|
|
10
|
+
|
|
11
|
+
// 导出所有 stores
|
|
12
|
+
export * from './user'
|
|
13
|
+
export * from './auth'
|
|
14
|
+
export * from './menu'
|
|
15
|
+
export * from './app'
|
|
16
16
|
export * from './locale'
|
package/src/stores/locale.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 国际化状态管理
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { defineStore } from 'pinia'
|
|
6
|
-
import { ref, computed } from 'vue'
|
|
7
|
-
import { local } from '@/utils/storage'
|
|
8
|
-
import {
|
|
9
|
-
useLocale,
|
|
10
|
-
createLocaleProvider,
|
|
11
|
-
getSupportedLocales,
|
|
12
|
-
type LocaleCode,
|
|
13
|
-
type LocaleMessages
|
|
14
|
-
} from '@xto/core/locale'
|
|
15
|
-
|
|
16
|
-
export type { LocaleCode, LocaleMessages }
|
|
17
|
-
|
|
18
|
-
export const useLocaleStore = defineStore('locale', () => {
|
|
19
|
-
// 从本地存储获取语言设置
|
|
20
|
-
const savedLocale = local.get<LocaleCode>('locale') || 'zh-CN'
|
|
21
|
-
|
|
22
|
-
// 创建国际化提供者
|
|
23
|
-
const provider = createLocaleProvider(savedLocale)
|
|
24
|
-
|
|
25
|
-
// 状态
|
|
26
|
-
const locale = ref<LocaleCode>(savedLocale)
|
|
27
|
-
const locales = getSupportedLocales()
|
|
28
|
-
|
|
29
|
-
// 使用国际化组合式函数
|
|
30
|
-
const { t, messages, setLocale, mergeMessages } = useLocale()
|
|
31
|
-
|
|
32
|
-
// 当前语言名称
|
|
33
|
-
const localeName = computed(() => {
|
|
34
|
-
const found = locales.find(l => l.code === locale.value)
|
|
35
|
-
return found?.name || locale.value
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// 设置语言
|
|
39
|
-
const changeLocale = (code: LocaleCode) => {
|
|
40
|
-
locale.value = code
|
|
41
|
-
setLocale(code)
|
|
42
|
-
local.set('locale', code)
|
|
43
|
-
provider.setLocale(code)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 添加自定义翻译
|
|
47
|
-
const addMessages = (msgs: LocaleMessages) => {
|
|
48
|
-
mergeMessages(msgs)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 初始化
|
|
52
|
-
const initLocale = () => {
|
|
53
|
-
setLocale(savedLocale)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
locale,
|
|
58
|
-
localeName,
|
|
59
|
-
locales,
|
|
60
|
-
messages,
|
|
61
|
-
t,
|
|
62
|
-
changeLocale,
|
|
63
|
-
addMessages,
|
|
64
|
-
initLocale,
|
|
65
|
-
provider
|
|
66
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 国际化状态管理
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { defineStore } from 'pinia'
|
|
6
|
+
import { ref, computed } from 'vue'
|
|
7
|
+
import { local } from '@/utils/storage'
|
|
8
|
+
import {
|
|
9
|
+
useLocale,
|
|
10
|
+
createLocaleProvider,
|
|
11
|
+
getSupportedLocales,
|
|
12
|
+
type LocaleCode,
|
|
13
|
+
type LocaleMessages
|
|
14
|
+
} from '@xto/core/locale'
|
|
15
|
+
|
|
16
|
+
export type { LocaleCode, LocaleMessages }
|
|
17
|
+
|
|
18
|
+
export const useLocaleStore = defineStore('locale', () => {
|
|
19
|
+
// 从本地存储获取语言设置
|
|
20
|
+
const savedLocale = local.get<LocaleCode>('locale') || 'zh-CN'
|
|
21
|
+
|
|
22
|
+
// 创建国际化提供者
|
|
23
|
+
const provider = createLocaleProvider(savedLocale)
|
|
24
|
+
|
|
25
|
+
// 状态
|
|
26
|
+
const locale = ref<LocaleCode>(savedLocale)
|
|
27
|
+
const locales = getSupportedLocales()
|
|
28
|
+
|
|
29
|
+
// 使用国际化组合式函数
|
|
30
|
+
const { t, messages, setLocale, mergeMessages } = useLocale()
|
|
31
|
+
|
|
32
|
+
// 当前语言名称
|
|
33
|
+
const localeName = computed(() => {
|
|
34
|
+
const found = locales.find(l => l.code === locale.value)
|
|
35
|
+
return found?.name || locale.value
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
// 设置语言
|
|
39
|
+
const changeLocale = (code: LocaleCode) => {
|
|
40
|
+
locale.value = code
|
|
41
|
+
setLocale(code)
|
|
42
|
+
local.set('locale', code)
|
|
43
|
+
provider.setLocale(code)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 添加自定义翻译
|
|
47
|
+
const addMessages = (msgs: LocaleMessages) => {
|
|
48
|
+
mergeMessages(msgs)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 初始化
|
|
52
|
+
const initLocale = () => {
|
|
53
|
+
setLocale(savedLocale)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
locale,
|
|
58
|
+
localeName,
|
|
59
|
+
locales,
|
|
60
|
+
messages,
|
|
61
|
+
t,
|
|
62
|
+
changeLocale,
|
|
63
|
+
addMessages,
|
|
64
|
+
initLocale,
|
|
65
|
+
provider
|
|
66
|
+
}
|
|
67
67
|
})
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
declare module 'json-bigint' {
|
|
2
|
-
interface JSONBigintOptions {
|
|
3
|
-
storeAsString?: boolean
|
|
4
|
-
alwaysParseAsBig?: boolean
|
|
5
|
-
useNativeBigInt?: boolean
|
|
6
|
-
protoAction?: 'error' | 'ignore' | 'preserve'
|
|
7
|
-
constructorAction?: 'error' | 'ignore' | 'preserve'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface JSONBigint {
|
|
11
|
-
parse(text: string): any
|
|
12
|
-
stringify(value: any, replacer?: any, space?: string | number): string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function JSONBig(options?: JSONBigintOptions): JSONBigint
|
|
16
|
-
|
|
17
|
-
export = JSONBig
|
|
18
|
-
}
|
|
1
|
+
declare module 'json-bigint' {
|
|
2
|
+
interface JSONBigintOptions {
|
|
3
|
+
storeAsString?: boolean
|
|
4
|
+
alwaysParseAsBig?: boolean
|
|
5
|
+
useNativeBigInt?: boolean
|
|
6
|
+
protoAction?: 'error' | 'ignore' | 'preserve'
|
|
7
|
+
constructorAction?: 'error' | 'ignore' | 'preserve'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface JSONBigint {
|
|
11
|
+
parse(text: string): any
|
|
12
|
+
stringify(value: any, replacer?: any, space?: string | number): string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function JSONBig(options?: JSONBigintOptions): JSONBigint
|
|
16
|
+
|
|
17
|
+
export = JSONBig
|
|
18
|
+
}
|