新增useGetUserInfo
parent
5d28dbeb6f
commit
83241b1254
|
|
@ -0,0 +1,7 @@
|
|||
export type getUserInfoFunction = () => Promise<Record<string, any>>;
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export default function useGetUserInfo(returnType: "array"): [boolean, getUserInfoFunction];
|
||||
export default function useGetUserInfo(returnType?: "object"): { loading: boolean; getDictionary: getUserInfoFunction };
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import { request } from "@cqsjjb/jjb-common-lib/http";
|
||||
import { useState } from "react";
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
function useGetUserInfo(returnType = "object") {
|
||||
// loading状态
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// 获取用户信息
|
||||
const getUserInfo = () => {
|
||||
setLoading(true);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// 发送请求
|
||||
request(
|
||||
"/basic-info/user/getInfo",
|
||||
"get",
|
||||
{},
|
||||
)
|
||||
.then((res) => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (returnType === "array")
|
||||
return [loading, getUserInfo];
|
||||
return { loading, getUserInfo };
|
||||
}
|
||||
|
||||
export default useGetUserInfo;
|
||||
Loading…
Reference in New Issue