refactor: 代码优化
This commit is contained in:
@@ -42,7 +42,8 @@ export const constantRoutes: Array<RouteRecordRaw> = [
|
||||
name: 'Dashboard',
|
||||
meta: { title: 'dashboard', icon: 'dashboard', affix: true }
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
// 外部链接
|
||||
/*{
|
||||
@@ -95,7 +96,6 @@ export const constantRoutes: Array<RouteRecordRaw> = [
|
||||
},
|
||||
]
|
||||
}*/
|
||||
}
|
||||
]
|
||||
|
||||
// 创建路由
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {PermissionState} from "@/types";
|
||||
import {RouteRecordRaw} from 'vue-router'
|
||||
import {constantRoutes} from '@/router'
|
||||
import {listRoutes} from "@/api/system/menu";
|
||||
import {defineStore} from "pinia";
|
||||
import { PermissionState } from "@/types";
|
||||
import { RouteRecordRaw } from 'vue-router'
|
||||
import { defineStore } from "pinia";
|
||||
import { constantRoutes } from '@/router'
|
||||
import { listRoutes } from "@/api/system/menu";
|
||||
|
||||
const modules = import.meta.glob("../../views/**/**.vue");
|
||||
export const Layout = () => import( '@/layout/index.vue')
|
||||
export const Layout = () => import('@/layout/index.vue')
|
||||
|
||||
const hasPermission = (roles: string[], route: RouteRecordRaw) => {
|
||||
if (route.meta && route.meta.roles) {
|
||||
@@ -24,7 +24,7 @@ const hasPermission = (roles: string[], route: RouteRecordRaw) => {
|
||||
export const filterAsyncRoutes = (routes: RouteRecordRaw[], roles: string[]) => {
|
||||
const res: RouteRecordRaw[] = []
|
||||
routes.forEach(route => {
|
||||
const tmp = {...route} as any
|
||||
const tmp = { ...route } as any
|
||||
if (hasPermission(roles, tmp)) {
|
||||
if (tmp.component == 'Layout') {
|
||||
tmp.component = Layout
|
||||
@@ -47,7 +47,7 @@ export const filterAsyncRoutes = (routes: RouteRecordRaw[], roles: string[]) =>
|
||||
}
|
||||
|
||||
|
||||
const usePermissionStore = defineStore({
|
||||
const usePermissionStore = defineStore({
|
||||
id: "permission",
|
||||
state: (): PermissionState => ({
|
||||
routes: [],
|
||||
@@ -73,6 +73,4 @@ export const filterAsyncRoutes = (routes: RouteRecordRaw[], roles: string[]) =>
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
export default usePermissionStore;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { LoginFormData, UserState } from "@/types";
|
||||
import { localStorage } from "@/utils/storage";
|
||||
import { resetRouter } from "@/router";
|
||||
import { login, logout } from "@/api/login";
|
||||
import { getUserInfo } from "@/api/system/user";
|
||||
import { resetRouter } from "@/router";
|
||||
|
||||
const useUserStore = defineStore({
|
||||
id: "user",
|
||||
@@ -53,8 +53,7 @@ const useUserStore = defineStore({
|
||||
*/
|
||||
getUserInfo() {
|
||||
return new Promise(((resolve, reject) => {
|
||||
getUserInfo().then(response => {
|
||||
const { data } = response
|
||||
getUserInfo().then(({data}) => {
|
||||
if (!data) {
|
||||
return reject('Verification failed, please Login again.')
|
||||
}
|
||||
|
||||
2
src/types/api/system/user.d.ts
vendored
2
src/types/api/system/user.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import { PageQueryParam, PageResult } from "../base"
|
||||
|
||||
/**
|
||||
* 用户信息类型声明
|
||||
* 登录用户类型声明
|
||||
*/
|
||||
export interface UserInfo {
|
||||
nickname: string,
|
||||
|
||||
@@ -276,7 +276,7 @@ import {
|
||||
|
||||
// API依赖
|
||||
import {
|
||||
listUserPages,
|
||||
listUsersPage,
|
||||
getUserFormDetail,
|
||||
deleteUsers,
|
||||
addUser,
|
||||
@@ -451,7 +451,7 @@ function handleStatusChange(row: { [key: string]: any }) {
|
||||
**/
|
||||
function handleQuery() {
|
||||
state.loading = true;
|
||||
listUserPages(state.queryParams).then(({ data }) => {
|
||||
listUsersPage(state.queryParams).then(({ data }) => {
|
||||
state.userList = data.list;
|
||||
state.total = data.total;
|
||||
state.loading = false;
|
||||
|
||||
Reference in New Issue
Block a user