Skip to content

Commit

Permalink
refactor: 移除不必要的 _ 前缀
Browse files Browse the repository at this point in the history
  • Loading branch information
pany-ang committed Nov 25, 2024
1 parent 1a29248 commit 6f87caf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/layouts/composables/useResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -38,19 +38,19 @@ export function useResize() {

// 在组件挂载前添加窗口大小变化事件监听器
onBeforeMount(() => {
window.addEventListener("resize", _resizeHandler)
window.addEventListener("resize", resizeHandler)
})

// 在组件挂载后根据窗口大小判断设备类型并调整布局
onMounted(() => {
if (_isMobile()) {
if (isMobile()) {
appStore.toggleDevice(DeviceEnum.Mobile)
appStore.closeSidebar(true)
}
})

// 在组件卸载前移除窗口大小变化事件监听器
onBeforeUnmount(() => {
window.removeEventListener("resize", _resizeHandler)
window.removeEventListener("resize", resizeHandler)
})
}
7 changes: 4 additions & 3 deletions src/pinia/stores/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/pinia/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/pinia/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useUserStore = defineStore("user", () => {
token.value = ""
roles.value = []
resetRouter()
_resetTagsView()
resetTagsView()
}

// 重置 Token
Expand All @@ -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()
Expand Down

0 comments on commit 6f87caf

Please sign in to comment.