|
|
@@ -15,6 +15,8 @@ import {useStore} from 'zustand';
|
|
|
import {userStore} from '@stores';
|
|
|
import {useEffect, useState} from 'react';
|
|
|
import {klona} from 'klona/json';
|
|
|
+import {useQuery} from '@tanstack/react-query';
|
|
|
+import {getUserPower} from '@apis';
|
|
|
|
|
|
const defaultBtnList = [
|
|
|
{
|
|
|
@@ -31,7 +33,7 @@ const defaultBtnList = [
|
|
|
];
|
|
|
|
|
|
export function useBtnList() {
|
|
|
- const {power} = useStore(userStore);
|
|
|
+ const power = useStore(userStore, state => state.power);
|
|
|
|
|
|
const [btnList, setBtnList] = useState(klona(defaultBtnList));
|
|
|
|
|
|
@@ -82,3 +84,31 @@ export function useBtnList() {
|
|
|
|
|
|
return btnList;
|
|
|
}
|
|
|
+
|
|
|
+export function useQueryUserInfo() {
|
|
|
+ const userName = useStore(userStore, state => state.userName);
|
|
|
+
|
|
|
+ const {data} = useQuery({
|
|
|
+ queryKey: [getUserPower.name, userName],
|
|
|
+ enabled: userName.length > 0,
|
|
|
+ async queryFn() {
|
|
|
+ const data = await getUserPower(userName);
|
|
|
+
|
|
|
+ if (data.code === '200' && data.data.length > 0)
|
|
|
+ return data.data[0].power;
|
|
|
+
|
|
|
+ return '';
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const setPower = useStore(userStore, state => state.setPower);
|
|
|
+
|
|
|
+ useEffect(
|
|
|
+ function () {
|
|
|
+ if (data && data.length > 0) {
|
|
|
+ setPower(data);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [data, setPower],
|
|
|
+ );
|
|
|
+}
|