Skip to content

Commit d3b09be

Browse files
committed
perf: 省略 window 前缀
1 parent 05f8cc6 commit d3b09be

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

public/detect-ie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Tip: Simple judgments may not fully cover
2-
if (/MSIE\s|Trident\//.test(window.navigator.userAgent)) {
2+
if (/MSIE\s|Trident\//.test(navigator.userAgent)) {
33
document.body.innerHTML = "<strong>Sorry, this browser is currently not supported. We recommend using the latest version of a modern browser. For example, Chrome/Firefox/Edge.</strong>"
44
}

src/pinia/stores/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const useUserStore = defineStore("user", () => {
3636
token.value = newToken
3737
_setToken(newToken)
3838
// 用刷新页面代替重新登录
39-
window.location.reload()
39+
location.reload()
4040
}
4141

4242
// 登出

src/router/index.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ export const dynamicRoutes: RouteRecordRaw[] = [
197197
meta: {
198198
title: "权限演示",
199199
elIcon: "lock",
200-
roles: ["admin", "editor"], // 可以在根路由中设置角色
200+
// 可以在根路由中设置角色
201+
roles: ["admin", "editor"],
201202
alwaysShow: true
202203
},
203204
children: [
@@ -207,15 +208,18 @@ export const dynamicRoutes: RouteRecordRaw[] = [
207208
name: "PagePermission",
208209
meta: {
209210
title: "页面级",
210-
roles: ["admin"] // 或者在子路由中设置角色
211+
// 或者在子路由中设置角色
212+
roles: ["admin"]
211213
}
212214
},
213215
{
214216
path: "directive",
215217
component: () => import("@/pages/demo/permission/directive.vue"),
216218
name: "DirectivePermission",
217219
meta: {
218-
title: "按钮级" // 如果未设置角色,则表示:该页面不需要权限,但会继承根路由的角色
220+
title: "按钮级",
221+
// 如果未设置角色,则表示:该页面不需要权限,但会继承根路由的角色
222+
roles: undefined
219223
}
220224
}
221225
]
@@ -230,8 +234,8 @@ export const router = createRouter({
230234

231235
/** 重置路由 */
232236
export function resetRouter() {
233-
// 注意:所有动态路由路由必须带有 Name 属性,否则可能会不能完全重置干净
234237
try {
238+
// 注意:所有动态路由路由必须带有 Name 属性,否则可能会不能完全重置干净
235239
router.getRoutes().forEach((route) => {
236240
const { name, meta } = route
237241
if (name && meta.roles?.length) {
@@ -240,7 +244,7 @@ export function resetRouter() {
240244
})
241245
} catch {
242246
// 强制刷新浏览器也行,只是交互体验不是很好
243-
window.location.reload()
247+
location.reload()
244248
}
245249
}
246250

0 commit comments

Comments
 (0)