refactor: API类型声明优化调整
Former-commit-id: 0ae696c2e872fa90feba0c5df9a92391c02d3e0b
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AppState } from '@/types/store/app';
|
||||
import { AppState } from './types';
|
||||
import { localStorage } from '@/utils/storage';
|
||||
import { defineStore } from 'pinia';
|
||||
import { getLanguage } from '@/lang/index';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PermissionState } from '@/types/store/permission';
|
||||
import { PermissionState } from './types';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { defineStore } from 'pinia';
|
||||
import { constantRoutes } from '@/router';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { SettingState } from '@/types/store/setting';
|
||||
import { SettingState } from './types';
|
||||
import defaultSettings from '../../settings';
|
||||
import { localStorage } from '@/utils/storage';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { TagsViewState } from '@/types/store/tagsview';
|
||||
import { TagsViewState } from './types';
|
||||
|
||||
const useTagsViewStore = defineStore({
|
||||
id: 'tagsView',
|
||||
|
||||
41
src/store/modules/types.ts
Normal file
41
src/store/modules/types.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
|
||||
|
||||
export interface AppState {
|
||||
device: string;
|
||||
sidebar: {
|
||||
opened: boolean;
|
||||
withoutAnimation: boolean;
|
||||
};
|
||||
language: string;
|
||||
size: string;
|
||||
}
|
||||
|
||||
export interface PermissionState {
|
||||
routes: RouteRecordRaw[];
|
||||
addRoutes: RouteRecordRaw[];
|
||||
}
|
||||
|
||||
export interface SettingState {
|
||||
theme: string;
|
||||
tagsView: boolean;
|
||||
fixedHeader: boolean;
|
||||
showSettings: boolean;
|
||||
sidebarLogo: boolean;
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
token: string;
|
||||
nickname: string;
|
||||
avatar: string;
|
||||
roles: string[];
|
||||
perms: string[];
|
||||
}
|
||||
|
||||
export interface TagView extends Partial<RouteLocationNormalized> {
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface TagsViewState {
|
||||
visitedViews: TagView[];
|
||||
cachedViews: string[];
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { LoginFormData } from '@/types/api/user';
|
||||
import { UserState } from '@/types/store/user';
|
||||
import { UserState } from './types';
|
||||
|
||||
import { localStorage } from '@/utils/storage';
|
||||
import { login, logout } from '@/api/auth';
|
||||
import { loginApi, logoutApi } from '@/api/auth';
|
||||
import { getUserInfo } from '@/api/user';
|
||||
|
||||
import { resetRouter } from '@/router';
|
||||
import { LoginForm } from '@/api/auth/types';
|
||||
|
||||
const useUserStore = defineStore({
|
||||
id: 'user',
|
||||
@@ -22,12 +21,12 @@ const useUserStore = defineStore({
|
||||
this.$reset();
|
||||
},
|
||||
/**
|
||||
* 登录 login
|
||||
* 登录
|
||||
*/
|
||||
login(loginData: LoginFormData) {
|
||||
const { username, password } = loginData;
|
||||
login(data: LoginForm) {
|
||||
const { username, password } = data;
|
||||
return new Promise((resolve, reject) => {
|
||||
login({
|
||||
loginApi({
|
||||
grant_type: 'password',
|
||||
username: username.trim(),
|
||||
password: password
|
||||
@@ -65,7 +64,6 @@ const useUserStore = defineStore({
|
||||
resolve(data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('error', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -76,7 +74,7 @@ const useUserStore = defineStore({
|
||||
*/
|
||||
logout() {
|
||||
return new Promise((resolve, reject) => {
|
||||
logout()
|
||||
logoutApi()
|
||||
.then(() => {
|
||||
localStorage.remove('token');
|
||||
this.RESET_STATE();
|
||||
|
||||
Reference in New Issue
Block a user