Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 11:29:20 +08:00

refactor: 移除不必要的 _ 前缀

This commit is contained in:
pany 2024-11-25 19:02:36 +08:00
parent 1a2924861d
commit 6f87caf262
4 changed files with 18 additions and 17 deletions

View File

@ -14,18 +14,18 @@ export function useResize() {
const appStore = useAppStore()
const { listenerRouteChange } = useRouteListener()
// 用于判断当前设备是否为移动端
const _isMobile = () => {
// 用于判断当前设备是否为移动端
const isMobile = () => {
const rect = document.body.getBoundingClientRect()
return rect.width - 1 < MAX_MOBILE_WIDTH
}
// 用于处理窗口大小变化事件
const _resizeHandler = () => {
const resizeHandler = () => {
if (!document.hidden) {
const isMobile = _isMobile()
appStore.toggleDevice(isMobile ? DeviceEnum.Mobile : DeviceEnum.Desktop)
isMobile && appStore.closeSidebar(true)
const _isMobile = isMobile()
appStore.toggleDevice(_isMobile ? DeviceEnum.Mobile : DeviceEnum.Desktop)
_isMobile && appStore.closeSidebar(true)
}
}
@ -38,12 +38,12 @@ export function useResize() {
// 在组件挂载前添加窗口大小变化事件监听器
onBeforeMount(() => {
window.addEventListener("resize", _resizeHandler)
window.addEventListener("resize", resizeHandler)
})
// 在组件挂载后根据窗口大小判断设备类型并调整布局
onMounted(() => {
if (_isMobile()) {
if (isMobile()) {
appStore.toggleDevice(DeviceEnum.Mobile)
appStore.closeSidebar(true)
}
@ -51,6 +51,6 @@ export function useResize() {
// 在组件卸载前移除窗口大小变化事件监听器
onBeforeUnmount(() => {
window.removeEventListener("resize", _resizeHandler)
window.removeEventListener("resize", resizeHandler)
})
}

View File

@ -35,15 +35,16 @@ export const usePermissionStore = defineStore("permission", () => {
// 根据角色生成可访问的 Routes可访问的路由 = 常驻路由 + 有访问权限的动态路由)
const setRoutes = (roles: string[]) => {
const accessedRoutes = filterDynamicRoutes(dynamicRoutes, roles)
_set(accessedRoutes)
set(accessedRoutes)
}
// 所有路由 = 所有常驻路由 + 所有动态路由
const setAllRoutes = () => {
_set(dynamicRoutes)
set(dynamicRoutes)
}
const _set = (accessedRoutes: RouteRecordRaw[]) => {
// 统一设置
const set = (accessedRoutes: RouteRecordRaw[]) => {
routes.value = constantRoutes.concat(accessedRoutes)
addRoutes.value = routeSettings.thirdLevelRouteCache ? flatMultiLevelRoutes(accessedRoutes) : accessedRoutes
}

View File

@ -25,12 +25,12 @@ export const useSettingsStore = defineStore("settings", () => {
// 监听每个响应式变量
watch(refValue, () => {
// 缓存
const settings = _getCacheData()
const settings = getCacheData()
setConfigLayout(settings)
})
}
// 获取要缓存的数据:将 state 对象转化为 settings 对象
const _getCacheData = () => {
const getCacheData = () => {
const settings = {} as LayoutSettings
for (const [key, value] of Object.entries(state)) {
// @ts-expect-error ignore

View File

@ -47,7 +47,7 @@ export const useUserStore = defineStore("user", () => {
token.value = ""
roles.value = []
resetRouter()
_resetTagsView()
resetTagsView()
}
// 重置 Token
@ -57,8 +57,8 @@ export const useUserStore = defineStore("user", () => {
roles.value = []
}
// 重置 Visited Views 和 Cached Views
const _resetTagsView = () => {
// 重置 Visited Views 和 Cached Views
const resetTagsView = () => {
if (!settingsStore.cacheTagsView) {
tagsViewStore.delAllVisitedViews()
tagsViewStore.delAllCachedViews()