chore: replace all cn comments of fe to en version by volc api (#320)
This commit is contained in:
@@ -43,13 +43,13 @@ describe('useSyncLocalStorageUid', () => {
|
||||
initialProps: {},
|
||||
});
|
||||
|
||||
// 初始状态:未登录
|
||||
// Initial status: not logged in
|
||||
(useLoginStatus as Mock).mockReturnValue('not_login');
|
||||
(useUserInfo as Mock).mockReturnValue(null);
|
||||
rerender();
|
||||
expect(localStorageService.setUserId).toHaveBeenCalledWith();
|
||||
|
||||
// 切换到登录状态
|
||||
// Switch to login status
|
||||
(useLoginStatus as Mock).mockReturnValue('logined');
|
||||
(useUserInfo as Mock).mockReturnValue(mockUserInfo);
|
||||
rerender();
|
||||
|
||||
@@ -28,11 +28,11 @@ import { type UserInfo } from '../types';
|
||||
import { useUserStore } from '../store/user';
|
||||
|
||||
/**
|
||||
* 用于页面初始化时,检查登录状态,并监听登录态失效的接口报错
|
||||
* 在登录态失效时,会重定向到登录页
|
||||
* @param needLogin 是否需要登录
|
||||
* @param checkLogin 检查登录状态的具体实现
|
||||
* @param goLogin 重定向到登录页的具体实现
|
||||
* It is used to check the login status when the page is initialized, and listen for the interface error if the login status is invalid.
|
||||
* When the login status fails, it will be redirected to the login page
|
||||
* @param needLogin is required
|
||||
* @Param checkLogin Check the specific implementation of login status
|
||||
* @Param goLogin Redirect to login page concrete implementation
|
||||
*/
|
||||
export const useCheckLoginBase = (
|
||||
needLogin: boolean,
|
||||
@@ -54,7 +54,7 @@ export const useCheckLoginBase = (
|
||||
|
||||
useEffect(() => {
|
||||
const isLogined = !!useUserStore.getState().userInfo?.user_id_str;
|
||||
// 当前页面要求登录,登录检查结果为未登录时,重定向回登录页
|
||||
// The current page requires login. If the login check result is not logged in, redirect back to the login page.
|
||||
if (needLogin && isSettled && !isLogined) {
|
||||
memoizedGoLogin();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export const useCheckLoginBase = (
|
||||
}
|
||||
}
|
||||
};
|
||||
// ajax 请求后端接口出现未 授权/登录 时,触发该函数
|
||||
// This function is triggered when the Ajax request backend interface appears not authorized/logged in
|
||||
handleAPIErrorEvent(APIErrorEvent.UNAUTHORIZED, handleUnauthorized);
|
||||
return () => {
|
||||
removeAPIErrorEvent(APIErrorEvent.UNAUTHORIZED, handleUnauthorized);
|
||||
|
||||
@@ -22,8 +22,8 @@ import { type LoginStatus } from '../types';
|
||||
import { useUserStore } from '../store/user';
|
||||
|
||||
/**
|
||||
* @description 用于获取用户登录状态
|
||||
* @returns 登录状态
|
||||
* @Description is used to obtain user login status
|
||||
* @returns login status
|
||||
*/
|
||||
export const useLoginStatus = (): LoginStatus =>
|
||||
useUserStore(state => {
|
||||
@@ -34,21 +34,21 @@ export const useLoginStatus = (): LoginStatus =>
|
||||
});
|
||||
|
||||
/**
|
||||
* @description 用于获取用户信息
|
||||
* @returns 用户信息
|
||||
* @Description is used to obtain user information
|
||||
* @returns user information
|
||||
*/
|
||||
export const useUserInfo = () => useUserStore(state => state.userInfo);
|
||||
|
||||
/**
|
||||
* @description 当前是否为错误状态
|
||||
* @returns 是否为错误状态
|
||||
* @Description Whether it is currently in an error state
|
||||
* @Returns whether it is an error
|
||||
*/
|
||||
export const useHasError = () => useUserStore(state => state.hasError);
|
||||
|
||||
const currentUidLSKey = 'coze_current_uid';
|
||||
/**
|
||||
* 用于打开多页签情况下,探测其它页签下发生的登出事件并在当前触发提示
|
||||
* @param alert 触发提示的具体实现
|
||||
* It is used to detect logout events that occur under other tabs when multiple tabs are opened and trigger a prompt at the current time
|
||||
* @Param alert trigger prompt specific implementation
|
||||
*/
|
||||
export const useAlterOnLogout = (alert: () => void) => {
|
||||
const visibility = useDocumentVisibility();
|
||||
@@ -62,7 +62,7 @@ export const useAlterOnLogout = (alert: () => void) => {
|
||||
useEffect(() => {
|
||||
if (visibility === 'hidden' && isLogined) {
|
||||
const lastUserId = useUserStore.getState().userInfo?.user_id_str;
|
||||
// 登录态下,每次页面从后台回到前台,重新检查一次登录用户是否发生了变化
|
||||
// In the login state, each time the page returns to the foreground from the background, re-check whether the logged in user has changed.
|
||||
return () => {
|
||||
const latestUserId = localStorage.getItem(currentUidLSKey);
|
||||
if (lastUserId !== latestUserId) {
|
||||
@@ -72,7 +72,7 @@ export const useAlterOnLogout = (alert: () => void) => {
|
||||
}
|
||||
}, [visibility, isLogined]);
|
||||
|
||||
// 在登录态变化后,更新本地缓存状态
|
||||
// Update local cache status after login status changes
|
||||
useEffect(() => {
|
||||
if (loginStatus !== 'settling') {
|
||||
localStorage.setItem(
|
||||
|
||||
Reference in New Issue
Block a user