Commit a11177bb authored by hewenhao's avatar hewenhao

feat: update

parent 51553d35
......@@ -37,6 +37,17 @@ export function getAccountInfo () {
}))
}
export function updateUserInfo (nickName: string) {
return requestAfterSilentLogin<void, { nickName: string; userId?: number; }>(userInfo => ({
method: 'POST',
url: '/service-idea/stage/user/updateUserInfo',
data: {
nickName,
userId: userInfo?.userId
}
}))
}
export function getSetting () {
return requestAfterSilentLogin<{pointToCard: number}, {}>(() => ({
method: 'GET',
......
......@@ -32,13 +32,15 @@
.avatar {
flex: 1;
.icon {
min-width: 0;
.name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 14PX;
font-weight: 500;
margin-left: 16PX;
width: 32PX;
height: 32PX;
margin-right: 4PX;
border-radius: 16PX;
background-color: #999;
color: #FFFFFF;
}
}
......
......@@ -25,6 +25,7 @@ const MainHeader = () => {
const cardNum = useStoreState(state => state.userModel.cardNum)
const point = useStoreState(state => state.userModel.point)
const userInfo = useStoreState(state => state.userModel.userInfo)
return (
<View className={styles.header}>
......@@ -38,7 +39,7 @@ const MainHeader = () => {
>
<View className={styles.inner} style={innerStyle}>
<View className={styles.avatar}>
<Image src="https://cdn.jkwljy.com/pbb/6gkGHSsPmxc_coeGYahBkelo_2w_/96x96" className={styles.icon}></Image>
<Text className={styles.name}>{userInfo?.nickname ?? ''}</Text>
</View>
<View className={classNames(styles.score, cs.bounce_btn)} onClick={goStore} hoverClass={cs.bounce_btn_hover}>
<Image src={require('../assets/score.png')} className={styles.icon} />
......
import {
action, Action, Thunk, thunk, State
} from 'easy-peasy'
import { getAccountInfo, getSetting } from '@/api'
import { getAccountInfo, getSetting, updateUserInfo } from '@/api'
import type { UserInfo } from '@/types'
import { pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys } from '@/utils/storage'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { AppStoreModel } from '../store-model'
export interface UserModel {
......@@ -14,9 +14,9 @@ export interface UserModel {
point: number;
updateState: Action<UserModel, Partial<State<UserModel>>>;
fetchAccount: Thunk<UserModel, void, void, AppStoreModel>;
updateUserInfo: Action<UserModel, UserInfo>;
setting: { pointToCard: number };
getSetting: Thunk<UserModel, void, void, AppStoreModel>;
updateUserInfo: Thunk<UserModel, string, void, AppStoreModel>;
exchangeItem: Thunk<UserModel, { name: string; num: number; }, void, AppStoreModel>;
}
......@@ -34,6 +34,19 @@ const userModel: UserModel = {
actions.updateState({ setting: { pointToCard: Infinity } })
}
}),
updateUserInfo: thunk(async (actions, nickname, helpers) => {
try {
await updateUserInfo(nickname)
const { userInfo } = helpers.getState()
const current = { ...userInfo, nickname }
updateStorage(StorageKeys.userInfo, current)
actions.updateState({
userInfo: current
})
} catch (err) {
console.log(err)
}
}),
exchangeItem: thunk(async (actions, payload) => {
try {
showLoading({ mask: true, title: '兑换中...' })
......@@ -52,9 +65,6 @@ const userModel: UserModel = {
})
}
}),
updateUserInfo: action((state, user) => {
state.userInfo = user
}),
updateState: action((state, payload) => {
for (const key in payload) {
state[key] = payload[key]
......
......@@ -28,7 +28,7 @@ async function silentLogin () {
updateStorage(StorageKeys.openid, data.openId)
updateStorage(StorageKeys.userInfo, data)
store.getActions().userModel.updateUserInfo(data)
store.getActions().userModel.updateState({ userInfo: data })
setProfile(data.openId, `${data.userId}`)
} catch (silentLoginError) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment