xto-fronted 0.4.18 → 0.4.19

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.
@@ -8,7 +8,7 @@ import { useMenuStore } from '@/stores/menu'
8
8
  import { Icon } from '@xto/base'
9
9
  import { Drawer } from '@xto/feedback'
10
10
 
11
- type LayoutMode = 'sidebar' | 'top'
11
+ type LayoutMode = 'sidebar' | 'top' | 'mix'
12
12
 
13
13
  const route = useRoute()
14
14
  const router = useRouter()
@@ -31,7 +31,8 @@ const greyMode = ref(false)
31
31
  // 布局模式选项
32
32
  const layoutOptions: { value: LayoutMode; label: string; icon: string }[] = [
33
33
  { value: 'sidebar', label: '左侧菜单', icon: 'sidebar-left' },
34
- { value: 'top', label: '顶部菜单', icon: 'menu' }
34
+ { value: 'top', label: '顶部菜单', icon: 'menu' },
35
+ { value: 'mix', label: '混合菜单', icon: 'grid' }
35
36
  ]
36
37
 
37
38
  // 主题色选项
@@ -363,10 +364,19 @@ onUnmounted(() => {
363
364
  <div class="preview-content"></div>
364
365
  </div>
365
366
  </div>
366
- <div v-else class="layout-preview-top">
367
+ <div v-else-if="option.value === 'top'" class="layout-preview-top">
367
368
  <div class="preview-header-full"></div>
368
369
  <div class="preview-content-full"></div>
369
370
  </div>
371
+ <div v-else class="layout-preview-mix">
372
+ <div class="preview-header-mix">
373
+ <div class="preview-mix-left"></div>
374
+ </div>
375
+ <div class="preview-mix-body">
376
+ <div class="preview-mix-aside"></div>
377
+ <div class="preview-mix-content"></div>
378
+ </div>
379
+ </div>
370
380
  </div>
371
381
  <span class="layout-option__label">{{ option.label }}</span>
372
382
  </div>
@@ -821,6 +831,38 @@ onUnmounted(() => {
821
831
  }
822
832
  }
823
833
 
834
+ .layout-preview-mix {
835
+ display: flex;
836
+ flex-direction: column;
837
+ height: 100%;
838
+
839
+ .preview-header-mix {
840
+ height: 25%;
841
+ background-color: var(--color-primary-light-7);
842
+ display: flex;
843
+
844
+ .preview-mix-left {
845
+ width: 30%;
846
+ background-color: var(--color-primary);
847
+ }
848
+ }
849
+
850
+ .preview-mix-body {
851
+ flex: 1;
852
+ display: flex;
853
+
854
+ .preview-mix-aside {
855
+ width: 25%;
856
+ background-color: var(--color-primary-light-8);
857
+ }
858
+
859
+ .preview-mix-content {
860
+ flex: 1;
861
+ background-color: var(--bg-color-page);
862
+ }
863
+ }
864
+ }
865
+
824
866
  .settings-color-options {
825
867
  display: flex;
826
868
  gap: 12px;
@@ -1,105 +1,121 @@
1
- <script setup lang="ts">
2
- import { computed } from 'vue'
3
- import { useAppStore } from '@/stores/app'
4
- import { useMenuStore } from '@/stores/menu'
5
- import Sidebar from './Sidebar.vue'
6
- import Header from './Header.vue'
7
- import TopMenu from './TopMenu.vue'
8
-
9
- const appStore = useAppStore()
10
- const menuStore = useMenuStore()
11
-
12
- const sidebarWidth = computed(() =>
13
- appStore.isCollapsed ? '64px' : '210px'
14
- )
15
-
16
- // 布局模式
17
- const layoutMode = computed(() => appStore.layout)
18
-
19
- // 是否显示左侧菜单
20
- const showSidebar = computed(() => layoutMode.value === 'sidebar')
21
-
22
- // 是否显示顶部菜单(仅 top 模式)
23
- const showTopMenu = computed(() => layoutMode.value === 'top')
24
- </script>
25
-
26
- <template>
27
- <div class="layout" :class="`layout--${layoutMode}`">
28
- <!-- 左侧菜单布局 -->
29
- <aside v-if="showSidebar" class="layout__aside" :style="{ width: sidebarWidth }">
30
- <Sidebar :menu-list="menuStore.menuList" />
31
- </aside>
32
-
33
- <!-- 顶部菜单布局(top 模式) -->
34
- <TopMenu v-if="showTopMenu" />
35
-
36
- <div class="layout__main">
37
- <header class="layout__header">
38
- <Header />
39
- </header>
40
- <main class="layout__content">
41
- <router-view />
42
- </main>
43
- </div>
44
- </div>
45
- </template>
46
-
47
- <style lang="scss" scoped>
48
- .layout {
49
- display: flex;
50
- width: 100%;
51
- height: 100%;
52
-
53
- // 左侧菜单模式
54
- &--sidebar {
55
- flex-direction: row;
56
- }
57
-
58
- // 顶部菜单模式
59
- &--top {
60
- flex-direction: column;
61
-
62
- .layout__aside {
63
- display: none;
64
- }
65
-
66
- .layout__main {
67
- flex: 1;
68
- }
69
- }
70
-
71
- &__aside {
72
- transition: width 0.3s;
73
- overflow: hidden;
74
- flex-shrink: 0;
75
- height: 100%;
76
- }
77
-
78
- &__top-menu {
79
- width: 100%;
80
- height: 50px;
81
- background-color: var(--bg-color);
82
- border-bottom: 1px solid var(--color-border-lighter);
83
- }
84
-
85
- &__main {
86
- display: flex;
87
- flex-direction: column;
88
- overflow: hidden;
89
- height: 100%;
90
- }
91
-
92
- &__header {
93
- height: 50px;
94
- background-color: var(--bg-color);
95
- border-bottom: 1px solid var(--color-border-lighter);
96
- flex-shrink: 0;
97
- }
98
-
99
- &__content {
100
- flex: 1;
101
- overflow: auto;
102
- background-color: var(--bg-color-page);
103
- }
104
- }
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { useAppStore } from '@/stores/app'
4
+ import { useMenuStore } from '@/stores/menu'
5
+ import Sidebar from './Sidebar.vue'
6
+ import Header from './Header.vue'
7
+ import TopMenu from './TopMenu.vue'
8
+
9
+ const appStore = useAppStore()
10
+ const menuStore = useMenuStore()
11
+
12
+ const sidebarWidth = computed(() =>
13
+ appStore.isCollapsed ? '64px' : '210px'
14
+ )
15
+
16
+ // 布局模式
17
+ const layoutMode = computed(() => appStore.layout)
18
+
19
+ // 是否显示左侧菜单
20
+ const showSidebar = computed(() => layoutMode.value === 'sidebar' || layoutMode.value === 'mix')
21
+
22
+ // 是否显示顶部菜单
23
+ const showTopMenu = computed(() => layoutMode.value === 'top')
24
+
25
+ // 混合模式下只显示当前顶部菜单的子菜单
26
+ const mixSubMenus = computed(() => {
27
+ if (layoutMode.value !== 'mix') return menuStore.menuList
28
+ // 混合模式需要根据顶部选中的菜单显示子菜单
29
+ // 这里暂时返回全部菜单,后续可根据实际需求调整
30
+ return menuStore.menuList
31
+ })
32
+ </script>
33
+
34
+ <template>
35
+ <div class="layout" :class="`layout--${layoutMode}`">
36
+ <!-- 左侧菜单布局 -->
37
+ <aside v-if="showSidebar" class="layout__aside" :style="{ width: sidebarWidth }">
38
+ <Sidebar :menu-list="layoutMode === 'mix' ? mixSubMenus : menuStore.menuList" />
39
+ </aside>
40
+
41
+ <!-- 顶部菜单布局 -->
42
+ <div v-if="showTopMenu" class="layout__top-menu">
43
+ <TopMenu />
44
+ </div>
45
+
46
+ <div class="layout__main">
47
+ <header class="layout__header">
48
+ <Header />
49
+ </header>
50
+ <main class="layout__content">
51
+ <router-view />
52
+ </main>
53
+ </div>
54
+ </div>
55
+ </template>
56
+
57
+ <style lang="scss" scoped>
58
+ .layout {
59
+ display: flex;
60
+ width: 100%;
61
+ height: 100%;
62
+
63
+ // 左侧菜单模式
64
+ &--sidebar {
65
+ flex-direction: row;
66
+ }
67
+
68
+ // 顶部菜单模式
69
+ &--top {
70
+ flex-direction: column;
71
+
72
+ .layout__aside {
73
+ display: none;
74
+ }
75
+
76
+ .layout__main {
77
+ flex: 1;
78
+ }
79
+ }
80
+
81
+ // 混合菜单模式
82
+ &--mix {
83
+ flex-direction: row;
84
+ }
85
+
86
+ &__aside {
87
+ transition: width 0.3s;
88
+ overflow: hidden;
89
+ flex-shrink: 0;
90
+ height: 100%;
91
+ }
92
+
93
+ &__top-menu {
94
+ width: 100%;
95
+ height: 50px;
96
+ background-color: var(--bg-color);
97
+ border-bottom: 1px solid var(--color-border-lighter);
98
+ }
99
+
100
+ &__main {
101
+ flex: 1;
102
+ display: flex;
103
+ flex-direction: column;
104
+ overflow: hidden;
105
+ height: 100%;
106
+ }
107
+
108
+ &__header {
109
+ height: 50px;
110
+ background-color: var(--bg-color);
111
+ border-bottom: 1px solid var(--color-border-lighter);
112
+ flex-shrink: 0;
113
+ }
114
+
115
+ &__content {
116
+ flex: 1;
117
+ overflow: auto;
118
+ background-color: var(--bg-color-page);
119
+ }
120
+ }
105
121
  </style>
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
  })