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

refactor: no keywords "any" and "unknown"

This commit is contained in:
pany 2024-11-12 20:10:09 +08:00
parent b3d935cdb0
commit e38525638d
5 changed files with 10 additions and 11 deletions

View File

@ -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

View File

@ -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>>

View File

@ -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")
}
})

View File

@ -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
}

View File

@ -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>