From de3d0ef8d89838bc9f05fa7f944d80af022b2414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Tue, 22 Mar 2022 00:08:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 4 ++-- src/store/modules/permission.ts | 18 ++++++++---------- src/store/modules/user.ts | 5 ++--- src/types/api/system/user.d.ts | 2 +- src/views/system/user/index.vue | 4 ++-- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index fa80bed7..6d9d3ce2 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -42,7 +42,8 @@ export const constantRoutes: Array = [ name: 'Dashboard', meta: { title: 'dashboard', icon: 'dashboard', affix: true } } - ] + ] + } // 外部链接 /*{ @@ -95,7 +96,6 @@ export const constantRoutes: Array = [ }, ] }*/ - } ] // 创建路由 diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 20699c73..2a4ece30 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -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; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 868cb237..4b5f9556 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -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.') } diff --git a/src/types/api/system/user.d.ts b/src/types/api/system/user.d.ts index b9031a55..70823948 100644 --- a/src/types/api/system/user.d.ts +++ b/src/types/api/system/user.d.ts @@ -1,7 +1,7 @@ import { PageQueryParam, PageResult } from "../base" /** - * 用户信息类型声明 + * 登录用户类型声明 */ export interface UserInfo { nickname: string, diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 2a27fd5f..0f301135 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -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;