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