Skip to content

Let's use AI to Earn!

feat: 登录逻辑优化调整

gaoSir64ef06e36399
diff --git a/src/icp/account.ts b/src/icp/account.ts
index 85a47b30..2b36ffcd 100644
--- a/src/icp/account.ts
+++ b/src/icp/account.ts
@@ -67,7 +67,6 @@ export async function icpGetAccountList() {
return res;
} catch (error) {
console.error('获取账户列表失败', error);
- throw error;
}
}
@@ -81,7 +80,6 @@ export async function icpGetAccountListByIds(ids: number[]) {
return res;
} catch (error) {
console.error('获取账户列表失败', error);
- throw error;
}
}
diff --git a/src/layout/LayoutBody.tsx b/src/layout/LayoutBody.tsx
index d632a477..11ecc414 100644
--- a/src/layout/LayoutBody.tsx
+++ b/src/layout/LayoutBody.tsx
@@ -7,7 +7,11 @@ export const LayoutBody = () => {
const userStore = useUserStore();
useEffect(() => {
- userStore.getUserInfo();
+ if (userStore.token) {
+ userStore.getUserInfo();
+ } else {
+ userStore.logout();
+ }
}, []);
// 添加键盘事件监听
diff --git a/src/store/user.ts b/src/store/user.ts
index 20ab3e9a..4efe1f0e 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -13,7 +13,7 @@ export interface IUserStore {
const state: IUserStore = {
userInfo: undefined,
- token: '123',
+ token: '',
overdueTime: 0,
// 是否开始刷新token,防止多次调用
refreshTokenLoading: false,
diff --git a/src/views/account/components/AccountSidebar.tsx b/src/views/account/components/AccountSidebar.tsx
index b61c9616..a00b553c 100644
--- a/src/views/account/components/AccountSidebar.tsx
+++ b/src/views/account/components/AccountSidebar.tsx
@@ -110,8 +110,8 @@ const AccountSidebar = memo(
*/
const getAccountList = async () => {
try {
- const result: AccountInfo[] = await icpGetAccountList();
- setAccountList(result);
+ const result = await icpGetAccountList();
+ setAccountList(result || []);
} catch (error) {
console.error('获取账户列表失败', error);
message.error('获取账户列表失败');
diff --git a/src/views/publish/children/drafts/item.tsx b/src/views/publish/children/drafts/item.tsx
index 004f45ff..e0977623 100644
--- a/src/views/publish/children/drafts/item.tsx
+++ b/src/views/publish/children/drafts/item.tsx
@@ -52,7 +52,7 @@ export default forwardRef<PubItemRef>((props, ref) => {
async function getAccountListByIds(ids: number[]) {
const res = await icpGetAccountListByIds(ids);
- setAccountList(res);
+ setAccountList(res || []);
}
async function delPubRecord() {
diff --git a/src/views/publish/children/pubRecord/page.tsx b/src/views/publish/children/pubRecord/page.tsx
index ed61085e..ea856d84 100644
--- a/src/views/publish/children/pubRecord/page.tsx
+++ b/src/views/publish/children/pubRecord/page.tsx
@@ -107,6 +107,7 @@ export default function Page() {
useEffect(() => {
icpGetAccountList().then((res) => {
+ if (!res) return;
res.map((v) => {
accountMap.current.set(v.id, v);
});
diff --git a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
index 5588bec6..9fc59d01 100644
--- a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
+++ b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
@@ -101,6 +101,7 @@ const PlatChoose = memo(
const getAccountList = () => {
icpGetAccountList().then((res) => {
+ if (!res) return;
setAccountMap((prevMap) => {
const newMap = new Map(prevMap);
Array.from(AccountPlatInfoMap).map(([key, value]) => {