|  | @@ -1,6 +1,8 @@
 | 
	
		
			
				|  |  |  import { defineStore } from 'pinia';
 | 
	
		
			
				|  |  | +import { store } from '@/store';
 | 
	
		
			
				|  |  |  import { ACCESS_TOKEN, CURRENT_USER, IM_TOKEN } from '@/store/mutation-types';
 | 
	
		
			
				|  |  |  import { storage } from '@/utils/storage';
 | 
	
		
			
				|  |  | +import { userLogin, getUserInfo } from '@/api/user';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export interface IUserState {
 | 
	
		
			
				|  |  |    token: string;
 | 
	
	
		
			
				|  | @@ -51,30 +53,25 @@ export const useUserStore = defineStore('user-store', {
 | 
	
		
			
				|  |  |      // 登录
 | 
	
		
			
				|  |  |      async login(userInfo: any) {
 | 
	
		
			
				|  |  |        try {
 | 
	
		
			
				|  |  | -        if (userInfo.username !== 'admin' || userInfo.password !== '123456') {
 | 
	
		
			
				|  |  | -          return Promise.reject({ msg: '用户名或密码错误' });
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        // const response = (await login(userInfo)) as any;
 | 
	
		
			
				|  |  | -        // const { data, code } = response;
 | 
	
		
			
				|  |  | -        // if (code === ResultEnum.SUCCESS) {
 | 
	
		
			
				|  |  | +        const { data } = await userLogin(userInfo);
 | 
	
		
			
				|  |  |          const ex = 7 * 24 * 60 * 60 * 1000;
 | 
	
		
			
				|  |  | -        storage.set(ACCESS_TOKEN, 'bearer test1121121212121212', ex);
 | 
	
		
			
				|  |  | +        storage.set(
 | 
	
		
			
				|  |  | +          ACCESS_TOKEN,
 | 
	
		
			
				|  |  | +          data.token_type + ' ' + data.access_token,
 | 
	
		
			
				|  |  | +          ex
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +        storage.get(IM_TOKEN, data.imToken);
 | 
	
		
			
				|  |  |          storage.set(
 | 
	
		
			
				|  |  |            CURRENT_USER,
 | 
	
		
			
				|  |  |            {
 | 
	
		
			
				|  |  | -            name: '王天奇',
 | 
	
		
			
				|  |  | -            avatar: ''
 | 
	
		
			
				|  |  | +            userId: data.userId
 | 
	
		
			
				|  |  |            },
 | 
	
		
			
				|  |  |            ex
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  | -        //   this.setToken(data.token_type + ' ' + data.access_token);
 | 
	
		
			
				|  |  | -        //   this.setImToken(data.imToken);
 | 
	
		
			
				|  |  | -        //   this.setUserInfo(data);
 | 
	
		
			
				|  |  | -        // }
 | 
	
		
			
				|  |  | -        this.setToken('bearer test1121121212121212');
 | 
	
		
			
				|  |  | +        this.setToken(data.token_type + ' ' + data.access_token);
 | 
	
		
			
				|  |  | +        this.setImToken(data.imToken);
 | 
	
		
			
				|  |  |          this.setUserInfo({
 | 
	
		
			
				|  |  | -          name: '王天奇',
 | 
	
		
			
				|  |  | -          avatar: ''
 | 
	
		
			
				|  |  | +          userId: data.userId
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          return Promise.resolve();
 | 
	
		
			
				|  |  |        } catch (e) {
 | 
	
	
		
			
				|  | @@ -83,10 +80,9 @@ export const useUserStore = defineStore('user-store', {
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 获取用户信息
 | 
	
		
			
				|  |  | -    getInfo() {
 | 
	
		
			
				|  |  | +    async getInfo() {
 | 
	
		
			
				|  |  |        // const that = this;
 | 
	
		
			
				|  |  |        return new Promise((resolve, reject) => {
 | 
	
		
			
				|  |  | -        // getUserInfo()
 | 
	
		
			
				|  |  |          //   .then(res => {
 | 
	
		
			
				|  |  |          //     const result = res.data;
 | 
	
		
			
				|  |  |          //     this..setUserInfo(result);
 | 
	
	
		
			
				|  | @@ -97,6 +93,9 @@ export const useUserStore = defineStore('user-store', {
 | 
	
		
			
				|  |  |          //     reject(error);
 | 
	
		
			
				|  |  |          //   });
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  | +          // getUserInfo().then((res: any) => {
 | 
	
		
			
				|  |  | +          //   console.log(res, 'res');
 | 
	
		
			
				|  |  | +          // });
 | 
	
		
			
				|  |  |            resolve(true);
 | 
	
		
			
				|  |  |          } catch {
 | 
	
		
			
				|  |  |            reject();
 | 
	
	
		
			
				|  | @@ -108,12 +107,13 @@ export const useUserStore = defineStore('user-store', {
 | 
	
		
			
				|  |  |      async logout() {
 | 
	
		
			
				|  |  |        this.setUserInfo('');
 | 
	
		
			
				|  |  |        storage.remove(ACCESS_TOKEN);
 | 
	
		
			
				|  |  | +      storage.remove(CURRENT_USER);
 | 
	
		
			
				|  |  |        return Promise.resolve('');
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // Need to be used outside the setup
 | 
	
		
			
				|  |  | -// export function useUserStoreWidthOut() {
 | 
	
		
			
				|  |  | -//   return useUserStore(store);
 | 
	
		
			
				|  |  | -// }
 | 
	
		
			
				|  |  | +export function useUserStoreWidthOut() {
 | 
	
		
			
				|  |  | +  return useUserStore(store);
 | 
	
		
			
				|  |  | +}
 |