import { post , get , put } from '@/lin/plugins/axios' ; import { saveTokens } from '../utils/token' ; import { store } from '@/store/index' ; import { IUserType } from '@/types/store' ; import { IUserToken , IUserInformation } from '@/types/model' ; export default class User { param { object } data static register ( data ) { return post ( 'cms/user/register' , data , { handleError : true } ) ; } param { string } username param { string } password static async getToken ( username , password ) { const tokens = await post ( 'cms/user/login' , { username , password } ) ; saveTokens ( tokens . access_token , tokens . refresh_token ) ; return tokens ; } /**
     * 获取当前用户信息，并返回User实例
     */ static async getInformation ( ) { const info = await get ( 'cms/user/information' ) ; const storeUser = store . getState ( ) . app . user || { } ; return Object . assign ( { ... storeUser } , info ) ; } /**
     * 获取当前用户信息和所拥有的权限
     */ static async getPermissions ( ) { const info = await get ( 'cms/user/permissions' ) ; const storeUser = store . getState ( ) . app . user || { } ; return Object . assign ( { ... storeUser } , info ) ; } param { string } newPassword param { string } confirmPassword param { string } oldPassword static updatePassword ( { old_password , new_password , confirm_password , } ) { return put ( 'cms/user/change_password' , { new_password , confirm_password , old_password } ) ; } }