Skip to content

Commit cc65b1d

Browse files
committed
perf: 将 layouts 配置文件迁移到 layouts 目录
1 parent 8a224cc commit cc65b1d

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/layouts/components/Settings/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import { useLayoutMode } from "@/composables/useLayoutMode"
33
import { useSettingsStore } from "@/pinia/stores/settings"
4-
import { removeConfigLayout } from "@/utils/cache/local-storage"
4+
import { removeLayoutsConfig } from "@/utils/cache/local-storage"
55
import { Refresh } from "@element-plus/icons-vue"
66
import { storeToRefs } from "pinia"
77
import { watchEffect } from "vue"
@@ -49,8 +49,8 @@ watchEffect(() => {
4949
})
5050
5151
/** 重置项目配置 */
52-
function resetConfigLayout() {
53-
removeConfigLayout()
52+
function resetLayoutsConfig() {
53+
removeLayoutsConfig()
5454
location.reload()
5555
}
5656
</script>
@@ -65,7 +65,7 @@ function resetConfigLayout() {
6565
<span class="setting-name">{{ settingName }}</span>
6666
<el-switch v-model="settingValue.value" :disabled="!isLeft && settingName === '固定 Header'" />
6767
</div>
68-
<el-button type="danger" :icon="Refresh" @click="resetConfigLayout">
68+
<el-button type="danger" :icon="Refresh" @click="resetLayoutsConfig">
6969
重 置
7070
</el-button>
7171
</div>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { LayoutModeEnum } from "@/constants/app-key"
2-
import { getConfigLayout } from "@/utils/cache/local-storage"
2+
import { getLayoutsConfig } from "@/utils/cache/local-storage"
33

44
/** 项目配置类型 */
5-
export interface LayoutSettings {
6-
/** 是否显示 Settings Panel */
5+
export interface LayoutsConfig {
6+
/** 是否显示设置按钮和面板 */
77
showSettings: boolean
88
/** 布局模式 */
99
layoutMode: LayoutModeEnum
@@ -13,7 +13,7 @@ export interface LayoutSettings {
1313
showLogo: boolean
1414
/** 是否固定 Header */
1515
fixedHeader: boolean
16-
/** 是否显示页脚 Footer */
16+
/** 是否显示页脚 */
1717
showFooter: boolean
1818
/** 是否显示消息通知 */
1919
showNotify: boolean
@@ -34,7 +34,7 @@ export interface LayoutSettings {
3434
}
3535

3636
/** 默认配置 */
37-
const defaultSettings: LayoutSettings = {
37+
const DEFAULT_CONFIG: LayoutsConfig = {
3838
layoutMode: LayoutModeEnum.Left,
3939
showSettings: true,
4040
showTagsView: true,
@@ -52,4 +52,4 @@ const defaultSettings: LayoutSettings = {
5252
}
5353

5454
/** 项目配置 */
55-
export const layoutSettings: LayoutSettings = { ...defaultSettings, ...getConfigLayout() }
55+
export const layoutsConfig: LayoutsConfig = { ...DEFAULT_CONFIG, ...getLayoutsConfig() }

src/pinia/stores/settings.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import type { LayoutSettings } from "@/config/layouts"
1+
import type { LayoutsConfig } from "@/layouts/config"
22
import type { Ref } from "vue"
3-
import { layoutSettings } from "@/config/layouts"
3+
import { layoutsConfig } from "@/layouts/config"
44
import { pinia } from "@/pinia"
5-
import { setConfigLayout } from "@/utils/cache/local-storage"
5+
import { setLayoutsConfig } from "@/utils/cache/local-storage"
66
import { defineStore } from "pinia"
77
import { ref, watch } from "vue"
88

99
type SettingsStore = {
10-
// 使用映射类型来遍历 layoutSettings 对象的键
11-
[Key in keyof LayoutSettings]: Ref<LayoutSettings[Key]>
10+
// 使用映射类型来遍历 LayoutsConfig 对象的键
11+
[Key in keyof LayoutsConfig]: Ref<LayoutsConfig[Key]>
1212
}
1313

1414
type SettingsStoreKey = keyof SettingsStore
1515

1616
export const useSettingsStore = defineStore("settings", () => {
1717
// 状态对象
1818
const state = {} as SettingsStore
19-
// 遍历 layoutSettings 对象的键值对
20-
for (const [key, value] of Object.entries(layoutSettings)) {
19+
// 遍历 LayoutsConfig 对象的键值对
20+
for (const [key, value] of Object.entries(layoutsConfig)) {
2121
// 使用类型断言来指定 key 的类型,将 value 包装在 ref 函数中,创建一个响应式变量
2222
const refValue = ref(value)
2323
// @ts-expect-error ignore
@@ -26,12 +26,12 @@ export const useSettingsStore = defineStore("settings", () => {
2626
watch(refValue, () => {
2727
// 缓存
2828
const settings = getCacheData()
29-
setConfigLayout(settings)
29+
setLayoutsConfig(settings)
3030
})
3131
}
3232
// 获取要缓存的数据:将 state 对象转化为 settings 对象
3333
const getCacheData = () => {
34-
const settings = {} as LayoutSettings
34+
const settings = {} as LayoutsConfig
3535
for (const [key, value] of Object.entries(state)) {
3636
// @ts-expect-error ignore
3737
settings[key as SettingsStoreKey] = value.value

src/utils/cache/local-storage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// 统一处理 localStorage
22

33
import type { ThemeName } from "@/composables/useTheme"
4-
import type { LayoutSettings } from "@/config/layouts"
54
import type { SidebarClosed, SidebarOpened } from "@/constants/app-key"
5+
import type { LayoutsConfig } from "@/layouts/config"
66
import type { TagView } from "@/pinia/stores/tags-view"
77
import { CacheKey } from "@/constants/cache-key"
88

99
// #region 系统布局配置
10-
export function getConfigLayout() {
10+
export function getLayoutsConfig() {
1111
const json = localStorage.getItem(CacheKey.CONFIG_LAYOUT)
12-
return json ? (JSON.parse(json) as LayoutSettings) : null
12+
return json ? (JSON.parse(json) as LayoutsConfig) : null
1313
}
14-
export function setConfigLayout(settings: LayoutSettings) {
14+
export function setLayoutsConfig(settings: LayoutsConfig) {
1515
localStorage.setItem(CacheKey.CONFIG_LAYOUT, JSON.stringify(settings))
1616
}
17-
export function removeConfigLayout() {
17+
export function removeLayoutsConfig() {
1818
localStorage.removeItem(CacheKey.CONFIG_LAYOUT)
1919
}
2020
// #endregion

0 commit comments

Comments
 (0)