Skip to content

Commit

Permalink
refactor: no keywords "any" and "unknown"
Browse files Browse the repository at this point in the history
  • Loading branch information
pany-ang committed Nov 12, 2024
1 parent b3d935c commit e385256
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/config/white-list.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { type RouteLocationNormalized } from "vue-router"
import { type RouteLocationNormalized, type RouteRecordNameGeneric } from "vue-router"

/** 免登录白名单(匹配路由 path) */
const whiteListByPath: string[] = ["/login"]

/** 免登录白名单(匹配路由 name) */
const whiteListByName: string[] = []
const whiteListByName: RouteRecordNameGeneric[] = []

/** 判断是否在白名单 */
const isWhiteList = (to: RouteLocationNormalized) => {
// path 和 name 任意一个匹配上即可
return whiteListByPath.indexOf(to.path) !== -1 || whiteListByName.indexOf(to.name as any) !== -1
return whiteListByPath.indexOf(to.path) !== -1 || whiteListByName.indexOf(to.name) !== -1
}

export default isWhiteList
2 changes: 1 addition & 1 deletion src/hooks/useFullscreenLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface LoadingInstance {
}

interface UseFullscreenLoading {
<T extends (...args: any[]) => ReturnType<T>>(
<T extends (...args: Parameters<T>) => ReturnType<T>>(
fn: T,
options?: LoadingOptions
): (...args: Parameters<T>) => Promise<ReturnType<T>>
Expand Down
5 changes: 2 additions & 3 deletions src/router/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ router.beforeEach(async (to, _from, next) => {
routeSettings.dynamic ? permissionStore.setRoutes(roles) : permissionStore.setAllRoutes()
// 将 "有访问权限的动态路由" 添加到 Router 中
permissionStore.addRoutes.forEach((route) => router.addRoute(route))
// 确保添加路由已完成
// 设置 replace: true, 因此导航将不会留下历史记录
next({ ...to, replace: true })
} catch (err: any) {
} catch (error) {
// 过程中发生任何错误,都直接重置 Token,并重定向到登录页面
userStore.resetToken()
ElMessage.error(err.message || "路由守卫过程发生错误")
ElMessage.error((error as Error).message || "路由守卫过程发生错误")
next("/login")
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/utils/validate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/** 判断是否为数组 */
export const isArray = (arg: unknown) => {
export const isArray = <T>(arg: T) => {
return Array.isArray ? Array.isArray(arg) : Object.prototype.toString.call(arg) === "[object Array]"
}

/** 判断是否为字符串 */
export const isString = (str: unknown) => {
export const isString = <T>(str: T) => {
return typeof str === "string" || str instanceof String
}

Expand Down
4 changes: 2 additions & 2 deletions src/views/hook-demo/use-fullscreen-loading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const querySuccess = async () => {
const queryError = async () => {
try {
await useFullscreenLoading(getErrorApi, options)()
} catch (err: any) {
ElMessage.error(err.message)
} catch (error) {
ElMessage.error((error as Error).message)
}
}
</script>
Expand Down

0 comments on commit e385256

Please sign in to comment.