Skip to content

Commit e496096

Browse files
feat(Component): Setting component add copy button
1 parent ff4dd3a commit e496096

File tree

9 files changed

+142
-20
lines changed

9 files changed

+142
-20
lines changed

src/components/Setting/src/Setting.vue

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ElDrawer, ElDivider } from 'element-plus'
2+
import { ElDrawer, ElDivider, ElButton, ElMessage } from 'element-plus'
33
import { ref, unref, computed, watch } from 'vue'
44
import { useI18n } from '@/hooks/web/useI18n'
55
import { ThemeSwitch } from '@/components/ThemeSwitch'
@@ -10,6 +10,8 @@ import { trim, setCssVar } from '@/utils'
1010
import ColorRadioPicker from './components/ColorRadioPicker.vue'
1111
import InterfaceDisplay from './components/InterfaceDisplay.vue'
1212
import LayoutRadioPicker from './components/LayoutRadioPicker.vue'
13+
import { useCache } from '@/hooks/web/useCache'
14+
import { useClipboard } from '@vueuse/core'
1315
1416
const appStore = useAppStore()
1517
@@ -100,6 +102,84 @@ watch(
100102
}
101103
}
102104
)
105+
106+
// 拷贝
107+
const copyConfig = async () => {
108+
const { copy, copied } = useClipboard({
109+
source: `
110+
// 面包屑
111+
breadcrumb: ${appStore.getBreadcrumb},
112+
// 面包屑图标
113+
breadcrumbIcon: ${appStore.getBreadcrumbIcon},
114+
// 折叠图标
115+
hamburger: ${appStore.getHamburger},
116+
// 全屏图标
117+
screenfull: ${appStore.getScreenfull},
118+
// 尺寸图标
119+
size: ${appStore.getSize},
120+
// 多语言图标
121+
locale: ${appStore.getLocale},
122+
// 标签页
123+
tagsView: ${appStore.getTagsView},
124+
// logo
125+
logo: ${appStore.getLogo},
126+
// 固定header
127+
fixedHeader: ${appStore.getFixedHeader},
128+
// 灰色模式
129+
greyMode: ${appStore.getGreyMode},
130+
// layout布局
131+
layout: '${appStore.getLayout}',
132+
// 暗黑模式
133+
isDark: ${appStore.getIsDark},
134+
// 组件尺寸
135+
currentSize: '${appStore.getCurrentSize}',
136+
// 主题相关
137+
theme: {
138+
// 主题色
139+
elColorPrimary: '${appStore.getTheme.elColorPrimary}',
140+
// 左侧菜单边框颜色
141+
leftMenuBorderColor: '${appStore.getTheme.leftMenuBorderColor}',
142+
// 左侧菜单背景颜色
143+
leftMenuBgColor: '${appStore.getTheme.leftMenuBgColor}',
144+
// 左侧菜单浅色背景颜色
145+
leftMenuBgLightColor: '${appStore.getTheme.leftMenuBgLightColor}',
146+
// 左侧菜单选中背景颜色
147+
leftMenuBgActiveColor: '${appStore.getTheme.leftMenuBgActiveColor}',
148+
// 左侧菜单收起选中背景颜色
149+
leftMenuCollapseBgActiveColor: '${appStore.getTheme.leftMenuCollapseBgActiveColor}',
150+
// 左侧菜单字体颜色
151+
leftMenuTextColor: '${appStore.getTheme.leftMenuTextColor}',
152+
// 左侧菜单选中字体颜色
153+
leftMenuTextActiveColor: '${appStore.getTheme.leftMenuTextActiveColor}',
154+
// logo字体颜色
155+
logoTitleTextColor: '${appStore.getTheme.logoTitleTextColor}',
156+
// logo边框颜色
157+
logoBorderColor: '${appStore.getTheme.logoBorderColor}',
158+
// 头部背景颜色
159+
topHeaderBgColor: '${appStore.getTheme.topHeaderBgColor}',
160+
// 头部字体颜色
161+
topHeaderTextColor: '${appStore.getTheme.topHeaderTextColor}',
162+
// 头部悬停颜色
163+
topHeaderHoverColor: '${appStore.getTheme.topHeaderHoverColor}',
164+
// 头部边框颜色
165+
topToolBorderColor: '${appStore.getTheme.topToolBorderColor}'
166+
}
167+
`
168+
})
169+
await copy()
170+
if (unref(copied)) {
171+
ElMessage.success(t('setting.copySuccess'))
172+
}
173+
}
174+
175+
// 清空缓存
176+
const clear = () => {
177+
const { wsCache } = useCache()
178+
wsCache.delete('layout')
179+
wsCache.delete('theme')
180+
wsCache.delete('isDark')
181+
window.location.reload()
182+
}
103183
</script>
104184

105185
<template>
@@ -181,6 +261,16 @@ watch(
181261
<!-- 界面显示 -->
182262
<ElDivider>{{ t('setting.interfaceDisplay') }}</ElDivider>
183263
<InterfaceDisplay />
264+
265+
<ElDivider />
266+
<div>
267+
<ElButton type="primary" class="w-full" @click="copyConfig">{{ t('setting.copy') }}</ElButton>
268+
</div>
269+
<div class="mt-5px">
270+
<ElButton type="danger" class="w-full" @click="clear">
271+
{{ t('setting.clearAndReset') }}
272+
</ElButton>
273+
</div>
184274
</ElDrawer>
185275
</template>
186276

src/components/TabMenu/src/TabMenu.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export default defineComponent({
3737
(routers: AppRouteRecordRaw[]) => {
3838
initTabMap(routers)
3939
filterMenusPath(routers, routers)
40-
console.log(tabPathMap)
4140
},
4241
{
4342
immediate: true,

src/config/app.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ export interface AppState {
1515
tagsView: boolean
1616
logo: boolean
1717
fixedHeader: boolean
18-
fixedMenu: boolean
1918
greyMode: boolean
20-
19+
pageLoading: boolean
2120
layout: LayoutType
2221
title: string
2322
userInfo: string
@@ -29,6 +28,12 @@ export interface AppState {
2928
}
3029

3130
export const appModules: AppState = {
31+
userInfo: 'userInfo', // 登录信息存储字段-建议每个项目换一个字段,避免与其他项目冲突
32+
sizeMap: ['default', 'large', 'small'],
33+
mobile: false, // 是否是移动端
34+
title: 'ButterflyAdmin', // 标题
35+
pageLoading: false, // 路由跳转loading
36+
3237
breadcrumb: true, // 面包屑
3338
breadcrumbIcon: true, // 面包屑图标
3439
collapse: false, // 折叠菜单
@@ -39,16 +44,11 @@ export const appModules: AppState = {
3944
tagsView: true, // 标签页
4045
logo: true, // logo
4146
fixedHeader: true, // 固定toolheader
42-
fixedMenu: false, // 固定切割菜单
4347
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
4448

4549
layout: wsCache.get('layout') || 'classic', // layout布局
46-
title: 'ButterflyAdmin', // 标题
47-
userInfo: 'userInfo', // 登录信息存储字段-建议每个项目换一个字段,避免与其他项目冲突
4850
isDark: wsCache.get('isDark') || false, // 是否是暗黑模式
4951
currentSize: wsCache.get('default') || 'default', // 组件尺寸
50-
sizeMap: ['default', 'large', 'small'],
51-
mobile: false, // 是否是移动端
5252
theme: wsCache.get('theme') || {
5353
// 主题色
5454
elColorPrimary: '#409eff',

src/hooks/web/usePageLoading.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useAppStoreWithOut } from '@/store/modules/app'
2+
3+
const appStore = useAppStoreWithOut()
4+
5+
export const usePageLoading = () => {
6+
const loadStart = () => {
7+
appStore.setPageLoading(true)
8+
}
9+
10+
const loadDone = () => {
11+
appStore.setPageLoading(false)
12+
}
13+
14+
return {
15+
loadStart,
16+
loadDone
17+
}
18+
}

src/layout/components/useRenderLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { ElScrollbar } from 'element-plus'
1010

1111
const appStore = useAppStore()
1212

13+
const pageLoading = computed(() => appStore.getPageLoading)
14+
1315
// 标签页
1416
const tagsView = computed(() => appStore.getTagsView)
1517

@@ -60,6 +62,7 @@ export const useRenderLayout = () => {
6062
style="transition: all var(--transition-time-02);"
6163
>
6264
<ElScrollbar
65+
v-loading={pageLoading.value}
6366
class={[
6467
'v-content',
6568
{
@@ -119,6 +122,7 @@ export const useRenderLayout = () => {
119122
style="transition: all var(--transition-time-02);"
120123
>
121124
<ElScrollbar
125+
v-loading={pageLoading.value}
122126
class={[
123127
'v-content',
124128
{
@@ -161,6 +165,7 @@ export const useRenderLayout = () => {
161165
</div>
162166
<div class="v-app-right h-full w-full">
163167
<ElScrollbar
168+
v-loading={pageLoading.value}
164169
class={[
165170
'v-content',
166171
{
@@ -212,6 +217,7 @@ export const useRenderLayout = () => {
212217
style="transition: all var(--transition-time-02);"
213218
>
214219
<ElScrollbar
220+
v-loading={pageLoading.value}
215221
class={[
216222
'v-content',
217223
{
@@ -232,7 +238,7 @@ export const useRenderLayout = () => {
232238
!collapse.value && fixedHeader.value
233239
}
234240
]}
235-
style="transition: all var(--transition-time-02);"
241+
style="transition: width var(--transition-time-02), left var(--transition-time-02);"
236242
></TagsView>
237243
) : undefined}
238244

src/locales/en.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export default {
3838
greyMode: 'Grey mode',
3939
fixedHeader: 'Fixed header',
4040
headerTheme: 'Header theme',
41-
cutMenu: 'Cut Menu'
41+
cutMenu: 'Cut Menu',
42+
copy: 'Copy',
43+
clearAndReset: 'Clear cache and reset',
44+
copySuccess: 'Copy success'
4245
},
4346
size: {
4447
default: 'Default',

src/locales/zh-CN.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export default {
3838
greyMode: '灰色模式',
3939
fixedHeader: '固定头部',
4040
headerTheme: '头部主题',
41-
cutMenu: '切割菜单'
41+
cutMenu: '切割菜单',
42+
copy: '拷贝',
43+
clearAndReset: '清除缓存并且重置',
44+
copySuccess: '拷贝成功'
4245
},
4346
size: {
4447
default: '默认',

src/permission.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { RouteRecordRaw } from 'vue-router'
55
import { useTitle } from '@/hooks/web/useTitle'
66
import { useNProgress } from '@/hooks/web/useNProgress'
77
import { usePermissionStoreWithOut } from '@/store/modules/permission'
8+
import { usePageLoading } from '@/hooks/web/usePageLoading'
89

910
const permissionStore = usePermissionStoreWithOut()
1011

@@ -14,10 +15,13 @@ const { wsCache } = useCache()
1415

1516
const { start, done } = useNProgress()
1617

18+
const { loadStart, loadDone } = usePageLoading()
19+
1720
const whiteList = ['/login'] // 不重定向白名单
1821

1922
router.beforeEach(async (to, from, next) => {
2023
start()
24+
loadStart()
2125
if (wsCache.get(appStore.getUserInfo)) {
2226
if (to.path === '/login') {
2327
next({ path: '/' })
@@ -48,4 +52,5 @@ router.beforeEach(async (to, from, next) => {
4852
router.afterEach((to) => {
4953
useTitle(to?.meta?.title as string)
5054
done() // 结束Progress
55+
loadDone()
5156
})

src/store/modules/app.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ export const useAppStore = defineStore({
4242
getFixedHeader(): boolean {
4343
return this.fixedHeader
4444
},
45-
getFixedMenu(): boolean {
46-
return this.fixedMenu
47-
},
4845
getGreyMode(): boolean {
4946
return this.greyMode
5047
},
51-
48+
getPageLoading(): boolean {
49+
return this.pageLoading
50+
},
5251
getLayout(): LayoutType {
5352
return this.layout
5453
},
@@ -105,13 +104,12 @@ export const useAppStore = defineStore({
105104
setFixedHeader(fixedHeader: boolean) {
106105
this.fixedHeader = fixedHeader
107106
},
108-
setFixedMenu(fixedMenu: boolean) {
109-
this.fixedMenu = fixedMenu
110-
},
111107
setGreyMode(greyMode: boolean) {
112108
this.greyMode = greyMode
113109
},
114-
110+
setPageLoading(pageLoading: boolean) {
111+
this.pageLoading = pageLoading
112+
},
115113
setLayout(layout: LayoutType) {
116114
if (this.mobile && layout !== 'classic') {
117115
ElMessage.warning('移动端模式下不支持切换其他布局')

0 commit comments

Comments
 (0)