提交 de3d0ef8 编写于 作者: 郝先瑞

refactor: 代码优化

上级 88ee9c7d
......@@ -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> = [
},
]
}*/
}
]
// 创建路由
......
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;
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.')
}
......
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册