perf: 代码优化 所有的 enum 类型命名
This commit is contained in:
parent
e4d9673a2b
commit
002bbdec8f
@ -1,6 +1,6 @@
|
|||||||
import { watch, onBeforeMount, onMounted, onBeforeUnmount } from "vue"
|
import { watch, onBeforeMount, onMounted, onBeforeUnmount } from "vue"
|
||||||
import { useRoute } from "vue-router"
|
import { useRoute } from "vue-router"
|
||||||
import { useAppStore, DeviceType } from "@/store/modules/app"
|
import { useAppStore, DeviceEnum } from "@/store/modules/app"
|
||||||
|
|
||||||
/** 参考 Bootstrap 的响应式设计 WIDTH = 992 */
|
/** 参考 Bootstrap 的响应式设计 WIDTH = 992 */
|
||||||
const WIDTH = 992
|
const WIDTH = 992
|
||||||
@ -18,7 +18,7 @@ export default () => {
|
|||||||
const _resizeHandler = () => {
|
const _resizeHandler = () => {
|
||||||
if (!document.hidden) {
|
if (!document.hidden) {
|
||||||
const isMobile = _isMobile()
|
const isMobile = _isMobile()
|
||||||
appStore.toggleDevice(isMobile ? DeviceType.Mobile : DeviceType.Desktop)
|
appStore.toggleDevice(isMobile ? DeviceEnum.Mobile : DeviceEnum.Desktop)
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
appStore.closeSidebar(true)
|
appStore.closeSidebar(true)
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ export default () => {
|
|||||||
watch(
|
watch(
|
||||||
() => route.name,
|
() => route.name,
|
||||||
() => {
|
() => {
|
||||||
if (appStore.device === DeviceType.Mobile && appStore.sidebar.opened) {
|
if (appStore.device === DeviceEnum.Mobile && appStore.sidebar.opened) {
|
||||||
appStore.closeSidebar(false)
|
appStore.closeSidebar(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ export default () => {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (_isMobile()) {
|
if (_isMobile()) {
|
||||||
appStore.toggleDevice(DeviceType.Mobile)
|
appStore.toggleDevice(DeviceEnum.Mobile)
|
||||||
appStore.closeSidebar(true)
|
appStore.closeSidebar(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from "vue"
|
import { computed } from "vue"
|
||||||
import { useAppStore, DeviceType } from "@/store/modules/app"
|
import { useAppStore, DeviceEnum } from "@/store/modules/app"
|
||||||
import { useSettingsStore } from "@/store/modules/settings"
|
import { useSettingsStore } from "@/store/modules/settings"
|
||||||
import { AppMain, NavigationBar, Settings, Sidebar, TagsView, RightPanel } from "./components"
|
import { AppMain, NavigationBar, Settings, Sidebar, TagsView, RightPanel } from "./components"
|
||||||
import useResize from "./hooks/useResize"
|
import useResize from "./hooks/useResize"
|
||||||
@ -16,7 +16,7 @@ const classObj = computed(() => {
|
|||||||
hideSidebar: !appStore.sidebar.opened,
|
hideSidebar: !appStore.sidebar.opened,
|
||||||
openSidebar: appStore.sidebar.opened,
|
openSidebar: appStore.sidebar.opened,
|
||||||
withoutAnimation: appStore.sidebar.withoutAnimation,
|
withoutAnimation: appStore.sidebar.withoutAnimation,
|
||||||
mobile: appStore.device === DeviceType.Mobile,
|
mobile: appStore.device === DeviceEnum.Mobile,
|
||||||
showGreyMode: showGreyMode.value,
|
showGreyMode: showGreyMode.value,
|
||||||
showColorWeakness: showColorWeakness.value
|
showColorWeakness: showColorWeakness.value
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { reactive, ref } from "vue"
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { getSidebarStatus, setSidebarStatus } from "@/utils/cache/localStorage"
|
import { getSidebarStatus, setSidebarStatus } from "@/utils/cache/localStorage"
|
||||||
|
|
||||||
export enum DeviceType {
|
export enum DeviceEnum {
|
||||||
Mobile,
|
Mobile,
|
||||||
Desktop
|
Desktop
|
||||||
}
|
}
|
||||||
@ -17,7 +17,7 @@ export const useAppStore = defineStore("app", () => {
|
|||||||
opened: getSidebarStatus() !== "closed",
|
opened: getSidebarStatus() !== "closed",
|
||||||
withoutAnimation: false
|
withoutAnimation: false
|
||||||
})
|
})
|
||||||
const device = ref<DeviceType>(DeviceType.Desktop)
|
const device = ref<DeviceEnum>(DeviceEnum.Desktop)
|
||||||
|
|
||||||
const toggleSidebar = (withoutAnimation: boolean) => {
|
const toggleSidebar = (withoutAnimation: boolean) => {
|
||||||
sidebar.opened = !sidebar.opened
|
sidebar.opened = !sidebar.opened
|
||||||
@ -33,7 +33,7 @@ export const useAppStore = defineStore("app", () => {
|
|||||||
sidebar.withoutAnimation = withoutAnimation
|
sidebar.withoutAnimation = withoutAnimation
|
||||||
setSidebarStatus("closed")
|
setSidebarStatus("closed")
|
||||||
}
|
}
|
||||||
const toggleDevice = (value: DeviceType) => {
|
const toggleDevice = (value: DeviceEnum) => {
|
||||||
device.value = value
|
device.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user