import TemplateContainer from '@/pages/TemplateContainer'; import { UserInfo } from '@/services/services/user'; import { RedoOutlined } from '@ant-design/icons'; import { useModel } from '@umijs/max'; import { Avatar, Badge, Button, Card, Col, FloatButton, Input, message, Modal, Row, Spin, Tag } from 'antd'; import React, { useEffect, useState } from 'react'; import UserCenterUserInfo from './UserCenterUserInfo'; import UserCenterAgentMessage from './UserCenterAgentMessage'; import { useSoftStore } from '@/store/software'; import { SoftwareControl } from '@/services/services/software'; import UserSoftwareInfo from './UserSoftwareInfo'; const UserCenter: React.FC = () => { const { initialState, setInitialState } = useModel('@@initialState'); const [messageApi, messageHolder] = message.useMessage(); const [modalApi, modalHolder] = Modal.useModal(); const [badgeCount, setBadgeCount] = useState(0); const { setTopSpinTip, setTopSpinning } = useSoftStore(); const [userAgentUserInfo, setUserAgentUserInfo] = useState(); useEffect(() => { if (initialState?.currentUser?.id) { // 初始化加载用户信息 setTopSpinning(true); setTopSpinTip("正在获取用户信息。。。"); UserInfo.GetUserInfo(initialState?.currentUser?.id).then(async (res) => { setInitialState({ ...initialState, currentUser: res }); localStorage.setItem('userInfo', JSON.stringify(res)); let agentInfo = await UserInfo.GetUserAgentInfo(); setUserAgentUserInfo(agentInfo); }).catch((error) => { messageApi.error(error.message); }).finally(() => { setTopSpinning(false); }) // 加载当前用户可申请的的软件控制权限 SoftwareControl.GetUserSoftwareControlCount(initialState?.currentUser?.id).then((res) => { setBadgeCount(res); }).catch((error) => { messageApi.error(error.message); }) } }, []) /** * 申请用户软件控制权限 */ async function ApplyUserSoftwareControlHandle() { let userID = initialState?.currentUser?.id; if (!userID) { messageApi.error("用户信息不存在"); return; } // 重新获取用户关联信息 const userCanApplyCount = await SoftwareControl.GetUserSoftwareControlCount(userID); if (userCanApplyCount <= 0) { messageApi.warning("您已经没有可申请的软件控制权限了"); return; } // 开始调用申请接口 setTopSpinning(true); setTopSpinTip("正在申请软件控制权限。。。"); try { await SoftwareControl.ApplyUserSoftwareControl(userID); // 提示成功 messageApi.success("申请成功"); setBadgeCount(0); } catch (error: any) { messageApi.error(error.message); } finally { setTopSpinning(false); } } /** * 显示软件控制权限 */ async function ShowSoftwareControlHandle() { modalApi.info({ title: "用户软件控制权限", content: , width: 800, footer: null, closable: true, }); } function renderTitie() { return (
{initialState?.currentUser?.userName?.substring(0, 1)}
{"ID: " + initialState?.currentUser?.id} {initialState?.currentUser?.userName}
{initialState?.currentUser?.roleNames?.map((item: any) => { return {item} })}
) } return (
可激活总数
{initialState?.currentUser?.allDeviceCount}
余换绑次数
{initialState?.currentUser?.freeCount}
代理分成
{(initialState?.currentUser?.agentPercent ?? 0.5) * 100}%
邀请码
{initialState?.currentUser?.affiliateCode}
软件控制权限
{ badgeCount > 0 ? : }
{modalHolder} {messageHolder}
); }; export default UserCenter;