✨ feat(登录登出): 已完成用户使用账号密码登录登出
This commit is contained in:
+8
-6
@@ -122,6 +122,7 @@ export const useRequest = (
|
||||
}
|
||||
|
||||
const stateRef = useRef({ ...params })
|
||||
console.log('stateRef==>', stateRef)
|
||||
const [state, setState] = useState({ ...stateRef.current })
|
||||
const { removeToken, removeSessionKey, removeUserInfo } = useUserInfo()
|
||||
const { login } = useLoginRequest()
|
||||
@@ -152,11 +153,11 @@ export const useRequest = (
|
||||
},
|
||||
...(options.method?.toUpperCase() == 'GET'
|
||||
? {
|
||||
data: stateRef.current.query,
|
||||
}
|
||||
data: stateRef.current.query,
|
||||
}
|
||||
: {
|
||||
data: options.type?.toUpperCase() == 'FORMDATA' ? qs.stringify(stateRef.current.query) : stateRef.current.query,
|
||||
}),
|
||||
data: options.type?.toUpperCase() == 'FORMDATA' ? qs.stringify(stateRef.current.query) : stateRef.current.query,
|
||||
}),
|
||||
}
|
||||
const result = await Taro.request(q as any)
|
||||
const { statusCode } = result
|
||||
@@ -196,10 +197,11 @@ export const useRequest = (
|
||||
}
|
||||
stateRef.current.error = false
|
||||
stateRef.current.loading = false
|
||||
setState(() => ({ ...stateRef.current }))
|
||||
setState(() => ({...stateRef.current}))
|
||||
console.log('request result stateRef', stateRef.current)
|
||||
console.log('request result state', state)
|
||||
return stateRef.current
|
||||
}
|
||||
|
||||
return {
|
||||
fetchData,
|
||||
state,
|
||||
|
||||
+20
-13
@@ -1,40 +1,47 @@
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import { CLEAR_SESSIONKEY, SET_USERINFO, SET_TOKEN, SET_SESSIONKEY, CLEAR_USERINFO, CLEAR_TOKEN, SET_ADMINUSERINFO, SET_SORTCODE } from '@/constants/userInfo'
|
||||
import { DataParam, UserParam, UserAdminParam, SortCodeParam } from '@/reducers/userInfo'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { UserInfoActionType } from '@/constants/userInfo'
|
||||
import { DataParam, UserParam, UserAdminParam, SortCodeParam, UserInfoAction } from '@/reducers/userInfo'
|
||||
import { Dispatch } from 'redux'
|
||||
import { useSelector } from '@/reducers/hooks'
|
||||
export default () => {
|
||||
const userInfo = useSelector((state: DataParam) => state.userInfo) as DataParam
|
||||
const dispatch = useDispatch()
|
||||
const userInfo = useSelector((state) => state.userInfoData)
|
||||
const dispatch = useDispatch<Dispatch<UserInfoAction>>()
|
||||
|
||||
const setToken = (token: string) => {
|
||||
dispatch({ type: SET_TOKEN, data: { token } })
|
||||
// @ts-ignore
|
||||
dispatch({ type: UserInfoActionType.SET_TOKEN, data: { token } })
|
||||
}
|
||||
|
||||
const setSessionKey = (sessionkey: string) => {
|
||||
dispatch({ type: SET_SESSIONKEY, data: { session_key: sessionkey } })
|
||||
// @ts-ignore
|
||||
dispatch({ type: UserInfoActionType.SET_SESSIONKEY, data: { session_key: sessionkey } })
|
||||
}
|
||||
|
||||
const setUserInfo = (userInfo: UserParam) => {
|
||||
dispatch({ type: SET_USERINFO, data: { userInfo } })
|
||||
// @ts-ignore
|
||||
dispatch({ type: UserInfoActionType.SET_USERINFO, data: { userInfo } })
|
||||
}
|
||||
|
||||
const setAdminUserInfo = (adminUserInfo: UserAdminParam) => {
|
||||
dispatch({ type: SET_ADMINUSERINFO, data: { adminUserInfo } })
|
||||
// @ts-ignore
|
||||
dispatch({ type: UserInfoActionType.SET_ADMINUSERINFO, data: { adminUserInfo } })
|
||||
}
|
||||
|
||||
const setSortCode = (sortCode: SortCodeParam) => {
|
||||
dispatch({ type: SET_SORTCODE, data: { sort_code: sortCode } })
|
||||
// @ts-ignore
|
||||
dispatch({ type: UserInfoActionType.SET_SORTCODE, data: { sort_code: sortCode } })
|
||||
}
|
||||
|
||||
const removeUserInfo = () => {
|
||||
dispatch({ type: CLEAR_USERINFO })
|
||||
dispatch({ type: UserInfoActionType.CLEAR_USERINFO })
|
||||
}
|
||||
|
||||
const removeToken = () => {
|
||||
dispatch({ type: CLEAR_TOKEN })
|
||||
dispatch({ type: UserInfoActionType.CLEAR_TOKEN })
|
||||
}
|
||||
|
||||
const removeSessionKey = () => {
|
||||
dispatch({ type: CLEAR_SESSIONKEY })
|
||||
dispatch({ type: UserInfoActionType.CLEAR_SESSIONKEY })
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user