-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1056 from chat2db/dev
Dev
- Loading branch information
Showing
10 changed files
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { queryCurUser } from '@/store/user' | ||
|
||
/** 初始化登陆的信息 */ | ||
const initLoginInfo = () => { | ||
queryCurUser(); | ||
}; | ||
|
||
export default initLoginInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { StoreApi } from 'zustand'; | ||
import { UseBoundStoreWithEqualityFn, createWithEqualityFn } from 'zustand/traditional'; | ||
import { devtools } from 'zustand/middleware'; | ||
import { shallow } from 'zustand/shallow'; | ||
import { IUserVO } from '@/typings/user'; | ||
import { getUser } from '@/service/user'; | ||
|
||
export interface IUserStore { | ||
curUser?: IUserVO | null; | ||
} | ||
|
||
const initUserStore: IUserStore = { | ||
curUser: null, | ||
}; | ||
|
||
/** | ||
* 用户 store | ||
*/ | ||
export const useUserStore: UseBoundStoreWithEqualityFn<StoreApi<IUserStore>> = createWithEqualityFn( | ||
devtools(() => initUserStore), | ||
shallow, | ||
); | ||
|
||
/** | ||
* | ||
* @param curUser 设置当前用户 | ||
*/ | ||
|
||
export const setCurUser = (curUser: IUserVO) => { | ||
useUserStore.setState({ curUser }); | ||
}; | ||
|
||
/** | ||
* 获取当前用户 | ||
*/ | ||
|
||
export const queryCurUser = async () => { | ||
// null 表示在padding,返回 void 0(undefined)表示未登录 | ||
const curUser = await getUser() || void 0; | ||
useUserStore.setState({ curUser }); | ||
// 向cookie中写入当前用户id | ||
const date = new Date('2030-12-30 12:30:00').toUTCString(); | ||
document.cookie = `CHAT2DB.USER_ID=${curUser?.id};Expires=${date}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters