mirror of
https://github.com/naiyQAQ/fanqie-assistant.git
synced 2026-10-21 01:54:48 +00:00
feat: 缓存用户登录态,减少请求次数
This commit is contained in:
1 parent
03475e1880
commit
dc19d0e5cc
1 file changed
+3
-27
+3
-27
@@ -1,32 +1,6 @@
|
|||||||
import { fetch } from '../config'
|
import { fetch } from '../config'
|
||||||
import { del, read, write } from '../localStorage'
|
import { del, read, write } from '../localStorage'
|
||||||
|
import type { UserInfo, UserState } from '../types'
|
||||||
export interface UserTitle {
|
|
||||||
title: string
|
|
||||||
desc: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UserInfo {
|
|
||||||
id: string
|
|
||||||
username: string
|
|
||||||
avatar: string
|
|
||||||
desc: string
|
|
||||||
age: number
|
|
||||||
// detailed
|
|
||||||
gender?: number // 0: 女 | 1: 男 | 2: 未知/没设置
|
|
||||||
recommend_gender?: number // 0: 女频 | 1: 男频 | 2: 我都爱看
|
|
||||||
fans_num?: number
|
|
||||||
following_num?: number
|
|
||||||
is_author?: boolean
|
|
||||||
author_desc?: string
|
|
||||||
read_book_num?: number
|
|
||||||
read_book_time?: bigint // ms
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface UserState {
|
|
||||||
isLogin: boolean
|
|
||||||
userInfo: UserInfo | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export let userState: UserState = {
|
export let userState: UserState = {
|
||||||
isLogin: false,
|
isLogin: false,
|
||||||
@@ -35,6 +9,7 @@ export let userState: UserState = {
|
|||||||
if (read('userState')) {
|
if (read('userState')) {
|
||||||
userState = read('userState')
|
userState = read('userState')
|
||||||
}
|
}
|
||||||
|
console.log('userState:', userState)
|
||||||
|
|
||||||
export async function getDetailedUserInfo(): Promise<UserInfo | null> {
|
export async function getDetailedUserInfo(): Promise<UserInfo | null> {
|
||||||
if (!userState?.isLogin || !userState?.userInfo) {
|
if (!userState?.isLogin || !userState?.userInfo) {
|
||||||
@@ -66,6 +41,7 @@ export async function getDetailedUserInfo(): Promise<UserInfo | null> {
|
|||||||
// userState.userInfo.titles = data.titles
|
// userState.userInfo.titles = data.titles
|
||||||
return userState.userInfo
|
return userState.userInfo
|
||||||
}
|
}
|
||||||
|
write('userState', userState)
|
||||||
return userState.userInfo
|
return userState.userInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user