xto-fronted 0.4.18 → 0.4.20

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/src/stores/app.ts CHANGED
@@ -1,181 +1,163 @@
1
- /**
2
- * 应用状态
3
- */
4
-
5
- import { defineStore } from 'pinia'
6
- import { ref, computed, watch } from 'vue'
7
- import { local } from '@/utils/storage'
8
-
9
- export type ThemeMode = 'light' | 'dark'
10
- export type LayoutMode = 'sidebar' | 'top'
11
-
12
- // 支持的布局模式列表
13
- const SUPPORTED_LAYOUTS: LayoutMode[] = ['sidebar', 'top']
14
-
15
- export const useAppStore = defineStore('app', () => {
16
- // 状态
17
- const appName = ref<string>(local.get<string>('appName') || 'XTO App')
18
- const indexPath = ref<string>(local.get<string>('indexPath') || '/dashboard')
19
- const isDark = ref<boolean>(local.get<boolean>('isDark') || false)
20
- const theme = ref<ThemeMode>(local.get<ThemeMode>('theme') || 'light')
21
-
22
- // 布局模式:读取localStorage,如果是不支持的值则默认sidebar
23
- const savedLayout = local.get<string>('layout')
24
- const layout = ref<LayoutMode>(
25
- SUPPORTED_LAYOUTS.includes(savedLayout as LayoutMode)
26
- ? (savedLayout as LayoutMode)
27
- : 'sidebar'
28
- )
29
- const isCollapsed = ref<boolean>(local.get<boolean>('isCollapsed') || false)
30
- const showTabs = ref<boolean>(local.get<boolean>('showTabs') ?? true)
31
- const showFooter = ref<boolean>(local.get<boolean>('showFooter') ?? true)
32
- const showBreadcrumb = ref<boolean>(local.get<boolean>('showBreadcrumb') ?? true)
33
- const primaryColor = ref<string>(local.get<string>('primaryColor') || '#409eff')
34
- const cachedViews = ref<string[]>([])
35
-
36
- // 计算属性
37
- const themeClass = computed(() => (isDark.value ? 'dark' : 'light'))
38
-
39
- // 设置应用名称
40
- const setAppName = (name: string) => {
41
- appName.value = name
42
- local.set('appName', name)
43
- }
44
-
45
- // 设置默认首页路径
46
- const setIndexPath = (path: string) => {
47
- indexPath.value = path
48
- local.set('indexPath', path)
49
- }
50
-
51
- // 切换主题
52
- const toggleTheme = () => {
53
- isDark.value = !isDark.value
54
- theme.value = isDark.value ? 'dark' : 'light'
55
- updateTheme()
56
- }
57
-
58
- // 设置主题
59
- const setTheme = (mode: ThemeMode) => {
60
- theme.value = mode
61
- isDark.value = mode === 'dark'
62
- updateTheme()
63
- }
64
-
65
- // 更新主题
66
- const updateTheme = () => {
67
- const html = document.documentElement
68
- if (isDark.value) {
69
- html.classList.add('dark')
70
- } else {
71
- html.classList.remove('dark')
72
- }
73
- local.set('isDark', isDark.value)
74
- local.set('theme', theme.value)
75
- }
76
-
77
- // 切换菜单折叠
78
- const toggleCollapse = () => {
79
- isCollapsed.value = !isCollapsed.value
80
- local.set('isCollapsed', isCollapsed.value)
81
- }
82
-
83
- // 设置布局
84
- const setLayout = (mode: LayoutMode) => {
85
- if (!SUPPORTED_LAYOUTS.includes(mode)) {
86
- mode = 'sidebar'
87
- }
88
- layout.value = mode
89
- local.set('layout', mode)
90
- }
91
-
92
- // 切换标签页
93
- const toggleTabs = () => {
94
- showTabs.value = !showTabs.value
95
- local.set('showTabs', showTabs.value)
96
- }
97
-
98
- // 切换底部
99
- const toggleFooter = () => {
100
- showFooter.value = !showFooter.value
101
- local.set('showFooter', showFooter.value)
102
- }
103
-
104
- // 切换面包屑
105
- const toggleBreadcrumb = () => {
106
- showBreadcrumb.value = !showBreadcrumb.value
107
- local.set('showBreadcrumb', showBreadcrumb.value)
108
- }
109
-
110
- // 设置主题色
111
- const setPrimaryColor = (color: string) => {
112
- primaryColor.value = color
113
- document.documentElement.style.setProperty('--color-primary', color)
114
- local.set('primaryColor', color)
115
- }
116
-
117
- // 添加缓存页面
118
- const addCachedView = (name: string) => {
119
- if (!cachedViews.value.includes(name)) {
120
- cachedViews.value.push(name)
121
- }
122
- }
123
-
124
- // 移除缓存页面
125
- const removeCachedView = (name: string) => {
126
- const index = cachedViews.value.indexOf(name)
127
- if (index > -1) {
128
- cachedViews.value.splice(index, 1)
129
- }
130
- }
131
-
132
- // 清除缓存页面
133
- const clearCachedViews = () => {
134
- cachedViews.value = []
135
- }
136
-
137
- // 初始化主题
138
- const initTheme = () => {
139
- updateTheme()
140
- if (primaryColor.value !== '#409eff') {
141
- document.documentElement.style.setProperty('--color-primary', primaryColor.value)
142
- }
143
- // 清除无效的layout设置,确保使用支持的布局模式
144
- if (!SUPPORTED_LAYOUTS.includes(layout.value)) {
145
- layout.value = 'sidebar'
146
- local.set('layout', 'sidebar')
147
- }
148
- }
149
-
150
- // 监听主题变化
151
- watch(isDark, updateTheme)
152
-
153
- return {
154
- appName,
155
- indexPath,
156
- isDark,
157
- theme,
158
- layout,
159
- isCollapsed,
160
- showTabs,
161
- showFooter,
162
- showBreadcrumb,
163
- primaryColor,
164
- cachedViews,
165
- themeClass,
166
- setAppName,
167
- setIndexPath,
168
- toggleTheme,
169
- toggleCollapse,
170
- setTheme,
171
- setLayout,
172
- toggleTabs,
173
- toggleFooter,
174
- toggleBreadcrumb,
175
- setPrimaryColor,
176
- addCachedView,
177
- removeCachedView,
178
- clearCachedViews,
179
- initTheme
180
- }
1
+ /**
2
+ * 应用状态
3
+ */
4
+
5
+ import { defineStore } from 'pinia'
6
+ import { ref, computed, watch } from 'vue'
7
+ import { local } from '@/utils/storage'
8
+
9
+ export type ThemeMode = 'light' | 'dark'
10
+ export type LayoutMode = 'sidebar' | 'top' | 'mix'
11
+
12
+ export const useAppStore = defineStore('app', () => {
13
+ // 状态
14
+ const appName = ref<string>(local.get<string>('appName') || 'XTO App')
15
+ const indexPath = ref<string>(local.get<string>('indexPath') || '/dashboard')
16
+ const isDark = ref<boolean>(local.get<boolean>('isDark') || false)
17
+ const theme = ref<ThemeMode>(local.get<ThemeMode>('theme') || 'light')
18
+ const layout = ref<LayoutMode>(local.get<LayoutMode>('layout') || 'sidebar')
19
+ const isCollapsed = ref<boolean>(local.get<boolean>('isCollapsed') || false)
20
+ const showTabs = ref<boolean>(local.get<boolean>('showTabs') ?? true)
21
+ const showFooter = ref<boolean>(local.get<boolean>('showFooter') ?? true)
22
+ const showBreadcrumb = ref<boolean>(local.get<boolean>('showBreadcrumb') ?? true)
23
+ const primaryColor = ref<string>(local.get<string>('primaryColor') || '#409eff')
24
+ const cachedViews = ref<string[]>([])
25
+
26
+ // 计算属性
27
+ const themeClass = computed(() => (isDark.value ? 'dark' : 'light'))
28
+
29
+ // 设置应用名称
30
+ const setAppName = (name: string) => {
31
+ appName.value = name
32
+ local.set('appName', name)
33
+ }
34
+
35
+ // 设置默认首页路径
36
+ const setIndexPath = (path: string) => {
37
+ indexPath.value = path
38
+ local.set('indexPath', path)
39
+ }
40
+
41
+ // 切换主题
42
+ const toggleTheme = () => {
43
+ isDark.value = !isDark.value
44
+ theme.value = isDark.value ? 'dark' : 'light'
45
+ updateTheme()
46
+ }
47
+
48
+ // 设置主题
49
+ const setTheme = (mode: ThemeMode) => {
50
+ theme.value = mode
51
+ isDark.value = mode === 'dark'
52
+ updateTheme()
53
+ }
54
+
55
+ // 更新主题
56
+ const updateTheme = () => {
57
+ const html = document.documentElement
58
+ if (isDark.value) {
59
+ html.classList.add('dark')
60
+ } else {
61
+ html.classList.remove('dark')
62
+ }
63
+ local.set('isDark', isDark.value)
64
+ local.set('theme', theme.value)
65
+ }
66
+
67
+ // 切换菜单折叠
68
+ const toggleCollapse = () => {
69
+ isCollapsed.value = !isCollapsed.value
70
+ local.set('isCollapsed', isCollapsed.value)
71
+ }
72
+
73
+ // 设置布局
74
+ const setLayout = (mode: LayoutMode) => {
75
+ layout.value = mode
76
+ local.set('layout', mode)
77
+ }
78
+
79
+ // 切换标签页
80
+ const toggleTabs = () => {
81
+ showTabs.value = !showTabs.value
82
+ local.set('showTabs', showTabs.value)
83
+ }
84
+
85
+ // 切换底部
86
+ const toggleFooter = () => {
87
+ showFooter.value = !showFooter.value
88
+ local.set('showFooter', showFooter.value)
89
+ }
90
+
91
+ // 切换面包屑
92
+ const toggleBreadcrumb = () => {
93
+ showBreadcrumb.value = !showBreadcrumb.value
94
+ local.set('showBreadcrumb', showBreadcrumb.value)
95
+ }
96
+
97
+ // 设置主题色
98
+ const setPrimaryColor = (color: string) => {
99
+ primaryColor.value = color
100
+ document.documentElement.style.setProperty('--color-primary', color)
101
+ local.set('primaryColor', color)
102
+ }
103
+
104
+ // 添加缓存页面
105
+ const addCachedView = (name: string) => {
106
+ if (!cachedViews.value.includes(name)) {
107
+ cachedViews.value.push(name)
108
+ }
109
+ }
110
+
111
+ // 移除缓存页面
112
+ const removeCachedView = (name: string) => {
113
+ const index = cachedViews.value.indexOf(name)
114
+ if (index > -1) {
115
+ cachedViews.value.splice(index, 1)
116
+ }
117
+ }
118
+
119
+ // 清除缓存页面
120
+ const clearCachedViews = () => {
121
+ cachedViews.value = []
122
+ }
123
+
124
+ // 初始化主题
125
+ const initTheme = () => {
126
+ updateTheme()
127
+ if (primaryColor.value !== '#409eff') {
128
+ document.documentElement.style.setProperty('--color-primary', primaryColor.value)
129
+ }
130
+ }
131
+
132
+ // 监听主题变化
133
+ watch(isDark, updateTheme)
134
+
135
+ return {
136
+ appName,
137
+ indexPath,
138
+ isDark,
139
+ theme,
140
+ layout,
141
+ isCollapsed,
142
+ showTabs,
143
+ showFooter,
144
+ showBreadcrumb,
145
+ primaryColor,
146
+ cachedViews,
147
+ themeClass,
148
+ setAppName,
149
+ setIndexPath,
150
+ toggleTheme,
151
+ toggleCollapse,
152
+ setTheme,
153
+ setLayout,
154
+ toggleTabs,
155
+ toggleFooter,
156
+ toggleBreadcrumb,
157
+ setPrimaryColor,
158
+ addCachedView,
159
+ removeCachedView,
160
+ clearCachedViews,
161
+ initTheme
162
+ }
181
163
  })