Skip to content

Commit f64a716

Browse files
KAICharles7c
authored andcommitted
feat: 新增应用配置开关属性,迁移主题配置至 src/config/setting.ts,新增色弱模式与哀悼模式
1 parent 4b5536a commit f64a716

File tree

10 files changed

+130
-39
lines changed

10 files changed

+130
-39
lines changed

.env.development

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ VITE_API_WS_URL = 'ws://localhost:8000'
1212
VITE_BASE = '/'
1313

1414
# 是否开启开发者工具
15-
VITE_OPEN_DEVTOOLS = false
15+
VITE_OPEN_DEVTOOLS = false
16+
17+
# 应用配置面板
18+
VITE_APP_SETTING = true

.env.production

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ VITE_API_BASE_URL = 'https://api.continew.top'
88
VITE_API_WS_URL = 'wss://api.continew.top'
99

1010
# 地址前缀
11-
VITE_BASE = '/'
11+
VITE_BASE = '/'
12+
13+
# 应用配置面板
14+
VITE_APP_SETTING = false

.env.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ VITE_API_BASE_URL = 'http://localhost:8000'
1313
VITE_BASE = '/test'
1414

1515
# 是否开启开发者工具
16-
VITE_OPEN_DEVTOOLS = true
16+
VITE_OPEN_DEVTOOLS = true
17+
18+
# 应用配置面板
19+
VITE_APP_SETTING = false

src/config/setting.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/config/setting.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const defaultSettings: App.AppSettings = {
2+
theme: 'light',
3+
themeColor: '#165DFF',
4+
tab: true,
5+
tabMode: 'card-gutter',
6+
animate: false,
7+
animateMode: 'zoom-fade',
8+
menuCollapse: true,
9+
menuAccordion: true,
10+
menuDark: false,
11+
copyrightDisplay: true,
12+
layout: 'left',
13+
enableColorWeaknessMode: false,
14+
enableMourningMode: false,
15+
}
16+
// 根据环境返回配置
17+
export const getSettings = (): App.AppSettings => {
18+
return defaultSettings
19+
}

src/layout/components/HeaderRightBar/SettingDrawer.vue

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<template>
22
<a-drawer v-model:visible="visible" title="项目配置" width="300px" unmount-on-close :footer="false">
33
<a-space :size="15" direction="vertical" fill>
4-
<a-divider orientation="center">系统布局</a-divider>
5-
<a-row justify="center">
4+
<a-alert v-if="settingOpen" :show-icon="false" type="info">
5+
「复制配置」按钮,并将配置粘贴到 src/config/settings.ts 文件中。
6+
</a-alert>
7+
<a-divider v-if="settingOpen" orientation="center">系统布局</a-divider>
8+
<a-row v-if="settingOpen" justify="center">
69
<a-space>
710
<a-badge>
811
<template #content>
@@ -35,9 +38,9 @@
3538
></ColorPicker>
3639
</a-row>
3740

38-
<a-divider orientation="center">界面显示</a-divider>
41+
<a-divider v-if="settingOpen" orientation="center">界面显示</a-divider>
3942

40-
<a-descriptions :column="1" :align="{ value: 'right' }" :value-style="{ paddingRight: 0 }">
43+
<a-descriptions v-if="settingOpen" :column="1" :align="{ value: 'right' }" :value-style="{ paddingRight: 0 }">
4144
<a-descriptions-item label="页签显示">
4245
<a-switch v-model="appStore.tab" />
4346
</a-descriptions-item>
@@ -70,24 +73,44 @@
7073
<a-descriptions-item label="水印">
7174
<a-switch v-model="appStore.isOpenWatermark" />
7275
</a-descriptions-item>
73-
<a-descriptions-item v-if="appStore.isOpenWatermark" label="水印信息">
76+
<a-descriptions-item label="水印信息">
7477
<a-input v-model="appStore.watermark" placeholder="留空则显示用户名" />
7578
</a-descriptions-item>
7679
</a-descriptions>
80+
81+
<a-divider orientation="center">其它</a-divider>
82+
<a-descriptions :column="1" :align="{ value: 'right' }" :value-style="{ paddingRight: 0 }">
83+
<a-descriptions-item label="色弱模式">
84+
<a-switch v-model="appStore.enableColorWeaknessMode" />
85+
</a-descriptions-item>
86+
<a-descriptions-item v-if="settingOpen" label="哀悼模式">
87+
<a-switch v-model="appStore.enableMourningMode" />
88+
</a-descriptions-item>
89+
</a-descriptions>
90+
<a-space v-if="settingOpen" direction="vertical" fill>
91+
<a-button type="primary" long @click="copySettings">
92+
<template #icon>
93+
<icon-copy />
94+
</template>
95+
复制配置
96+
</a-button>
97+
</a-space>
7798
</a-space>
7899
</a-drawer>
79100
</template>
80101

81102
<script setup lang="ts">
82103
import { ColorPicker } from 'vue-color-kit'
83104
import 'vue-color-kit/dist/vue-color-kit.css'
105+
import { useClipboard } from '@vueuse/core'
106+
import { Message } from '@arco-design/web-vue'
84107
import LayoutItem from './components/LayoutItem.vue'
85108
import { useAppStore } from '@/stores'
86109
87110
defineOptions({ name: 'SettingDrawer' })
88111
const appStore = useAppStore()
89112
const visible = ref(false)
90-
113+
const settingOpen = JSON.parse(import.meta.env.VITE_APP_SETTING)
91114
const tabModeList: App.TabItem[] = [
92115
{ label: '卡片', value: 'card' },
93116
{ label: '间隔卡片', value: 'card-gutter' },
@@ -138,6 +161,36 @@ const changeColor = (colorObj: ColorObj) => {
138161
appStore.setThemeColor(colorObj.hex)
139162
}
140163
164+
// 复制配置
165+
const copySettings = () => {
166+
const settings: App.AppSettings = {
167+
theme: 'light',
168+
themeColor: appStore.themeColor,
169+
tab: appStore.tab,
170+
tabMode: appStore.tabMode,
171+
animate: appStore.animate,
172+
animateMode: appStore.animateMode,
173+
menuCollapse: appStore.menuCollapse,
174+
menuAccordion: appStore.menuAccordion,
175+
menuDark: appStore.menuDark,
176+
copyrightDisplay: appStore.copyrightDisplay,
177+
layout: appStore.layout,
178+
isOpenWatermark: appStore.isOpenWatermark,
179+
watermark: appStore.watermark,
180+
enableColorWeaknessMode: appStore.enableColorWeaknessMode,
181+
enableMourningMode: appStore.enableMourningMode,
182+
}
183+
184+
const settingJson = JSON.stringify(settings, null, 2)
185+
const { isSupported, copy } = useClipboard({ source: settingJson })
186+
if (isSupported) {
187+
copy(settingJson)
188+
Message.success({ content: '复制成功!' })
189+
} else {
190+
Message.error({ content: '请检查浏览器权限是否开启' })
191+
}
192+
}
193+
141194
defineExpose({ open })
142195
</script>
143196

src/layout/components/HeaderRightBar/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import { isMobile } from '@/utils'
8080
import { getToken } from '@/utils/auth'
8181
8282
defineOptions({ name: 'HeaderRight' })
83-
8483
let socket: WebSocket
8584
onBeforeUnmount(() => {
8685
if (socket) {

src/stores/modules/app.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { defineStore } from 'pinia'
22
import { computed, reactive, toRefs } from 'vue'
33
import { generate, getRgbStr } from '@arco-design/color'
44
import { type BasicConfig, listSiteOptionDict } from '@/apis'
5-
import defaultSettings from '@/config/setting.json'
5+
import { getSettings } from '@/config/setting'
66

77
const storeSetup = () => {
88
// App配置
9-
const settingConfig = reactive({ ...defaultSettings }) as App.SettingConfig
9+
const settingConfig = reactive({ ...getSettings() }) as App.AppSettings
1010
// 页面切换动画类名
1111
const transitionName = computed(() => (settingConfig.animate ? settingConfig.animateMode : ''))
1212

@@ -81,6 +81,27 @@ const storeSetup = () => {
8181
document.title = config.SITE_TITLE || ''
8282
document.querySelector('link[rel="shortcut icon"]')?.setAttribute('href', config.SITE_FAVICON || '/favicon.ico')
8383
}
84+
// 监听 色弱模式 和 哀悼模式
85+
watch([
86+
() => settingConfig.enableMourningMode,
87+
() => settingConfig.enableColorWeaknessMode,
88+
], ([mourningMode, colorWeaknessMode]) => {
89+
const filters = [] as string[]
90+
if (mourningMode) {
91+
filters.push('grayscale(100%)')
92+
}
93+
if (colorWeaknessMode) {
94+
filters.push('invert(80%)')
95+
}
96+
// 如果没有任何滤镜条件,移除 `filter` 样式
97+
if (filters.length === 0) {
98+
document.documentElement.style.removeProperty('filter')
99+
} else {
100+
document.documentElement.style.setProperty('filter', filters.join(' '))
101+
}
102+
}, {
103+
immediate: true,
104+
})
84105

85106
const getFavicon = () => {
86107
return siteConfig.SITE_FAVICON

src/types/app.d.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
declare namespace App {
2-
/** 系统配置 */
3-
interface SettingConfig {
4-
theme: 'light' | 'dark' // 主题
5-
themeColor: string // 主题色
6-
tab: boolean // 是否显示页签
7-
tabMode: TabType // 页签风格
8-
animate: boolean // 是否显示动画
9-
animateMode: AnimateType // 动画类名
10-
menuCollapse: boolean // 左侧菜单折叠状态
11-
menuAccordion: boolean // 左侧菜单手风琴效果
12-
copyrightDisplay: boolean // 是否显示底部版权信息
13-
menuDark: boolean // 菜单深色模式
2+
interface AppSettings {
3+
theme: 'light' | 'dark'
4+
themeColor: string
5+
tab: boolean
6+
tabMode: 'card' | 'card-gutter' | 'rounded'
7+
animate: boolean
8+
animateMode: 'zoom-fade' | 'slide-dynamic-origin' | 'fade-slide' | 'fade' | 'fade-bottom' | 'fade-scale'
9+
menuCollapse: boolean
10+
menuAccordion: boolean
11+
menuDark: boolean
12+
copyrightDisplay: boolean
1413
layout: 'left' | 'mix'
15-
isOpenWatermark: boolean // 是否开启水印
16-
watermark: string // 水印
14+
isOpenWatermark?: boolean
15+
watermark?: string
16+
enableColorWeaknessMode?: boolean
17+
enableMourningMode?: boolean
1718
}
19+
1820
/** 导航页签的样式类型 */
1921
type TabType = 'card' | 'card-gutter' | 'rounded'
2022
interface TabItem {

src/types/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface ImportMetaEnv {
55
readonly VITE_API_PREFIX: string
66
readonly VITE_API_BASE_URL: string
77
readonly VITE_BASE: string
8+
readonly VITE_APP_SETTING: string
89
}
910

1011
interface ImportMeta {

0 commit comments

Comments
 (0)