import React, { CSSProperties } from "react"; import { Avatar, Col, Dropdown, Menu, MenuProps, Row, Tooltip } from "antd"; import { LoginOutlined, LogoutOutlined, UserOutlined } from "@ant-design/icons"; import { UserInfo } from "../../tmpl/interface"; import HcserviceV3 from "../../tmpl/hcservice-v3"; import HCDataSource from "../../tmpl/hc-data-source"; import UserInfoBar from "./userinfo-bar"; import ResetPassword from "./reset-password"; import { LocaleContext } from "../../locale/LocaleProvider"; import { LocaleType } from "../../locale/langMp"; import Units from "../../units"; //const confirm = Modal.confirm; interface UserBarProps { backgroudColor?: string; showUserInfo?: boolean; showChangePassword?: boolean; menu?: MenuProps; } interface UserBarState extends UserInfo { context: Array; } class UserBar extends React.PureComponent { state = { id: undefined, name: undefined, roles: [], context: undefined, cleanCachable: false, gtmplSourceId: undefined, changePasswordable: undefined, changePersonalInfoable: undefined, viewPersonalInfoable: undefined, }; static contextType = LocaleContext; context: React.ContextType; static defaultProps = { backgroudColor: "#4a5f74", showUserInfo: true, showChangePassword: true, }; async componentDidMount() { let userInfo: UserInfo = await Units.getUserInfo(); //查询 上下文配置信息 let context = await HcserviceV3.getContextSourceValue(); // console.log('context', context); this.setState({ context, ...userInfo, }); } cleanCache = () => { let { roles } = this.state; let loading = document.getElementById("ajaxLoading"); loading.style.display = "block"; HCDataSource.reload(roles); loading.style.display = "none"; }; getContext = () => { let { context } = this.state; const { translate } = this.context; if (context) { console.log("context", context); return ( <> {context.map((c) => { return ( {c.label} : {c.content} ); })} ); } return translate("${无}"); }; toSetContext = () => { window.location.hash = "#/context-setter"; }; getTitle = () => { const { name, context } = this.state; return ( <>

{name}

{context ? context.map((con) => { return (

{con.label} : {con.content}

); }) : null} ); }; render() { const { backgroudColor, showUserInfo, showChangePassword, menu, } = this.props; const { name, context, cleanCachable, gtmplSourceId, changePasswordable, changePersonalInfoable, viewPersonalInfoable, id, } = this.state; const { translate, changeLocale, locale, availableLang } = this.context; const syyy: CSSProperties = { "--message-bar-backgroupd": backgroudColor, } as CSSProperties; const items: MenuProps["items"] = []; const langItems = availableLang.map((lang) => ({ label: ( changeLocale(lang as LocaleType)} style={locale === lang ? { color: backgroudColor } : {}}> { lang } ), key: lang, })) langItems.unshift({ label: ( changeLocale("zh")} style={locale === "zh" ? { color: backgroudColor } : {}} > 中文 ), key: "zh", }); items.push({ key: "locale", label: translate("${切换语言}"), children: langItems, }); if (name) { showUserInfo && viewPersonalInfoable ? items.push({ key: "1", label: ( ), }) : null; context && context.length > 0 ? items.push({ key: "2", label: ( {translate("${全局配置}")} ), }) : null; showChangePassword && changePasswordable ? items.push({ key: "3", label: , }) : null; cleanCachable ? items.push({ key: "4", label: ( {translate("${清空缓存}")} ), }) : null; items.push({ key: "5", label: ( {translate("${退出}")} ), }); } else { items.push({ key: "2", label: ( {translate("${登录}")} ), }); } return ( <>
{/**/} {/*} size={{ xs: 8, sm: 16, md: 24, lg: 32, xl: 40, xxl: 48 }}>*/} {/**/} {/**/} {/**/} } size="large" > {/*{name ?name.substring(0,1).toUpperCase():null}*/} {/*{name && name.length>=8?name.substring(0,5)+'...':name}*/}
); } } export default UserBar;