diff --git a/src/components/Common/PersonCenter/PersonCenter.js b/src/components/Common/PersonCenter/PersonCenter.js index 7d87071..0db2e72 100644 --- a/src/components/Common/PersonCenter/PersonCenter.js +++ b/src/components/Common/PersonCenter/PersonCenter.js @@ -32,6 +32,7 @@ import * as commonServices from '@/services/services'; import commonConfig from '../../../utils/config'; // import SkinChangeModal from './SkinChangeModal'; import MenuSearchPopovor from './MenuSearchPopovor'; +import SwitchCompanyAndLanguage from './SwitchCompanyAndLanguage'; const { TabPane } = Tabs; const FormItem = Form.Item; @@ -383,7 +384,7 @@ class PersonCenter extends Component { const { menuPanel, onAddPane, app } = this.props; return (
- +
{companyName}
+
0} diff --git a/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.js b/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.js new file mode 100644 index 0000000..223feea --- /dev/null +++ b/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.js @@ -0,0 +1,221 @@ +/* eslint-disable */ +import React, { useEffect, useState } from "react"; +import { Button, Dropdown, Spin } from "antd"; +import { DownOutlined, LoadingOutlined } from "@ant-design/icons"; +import * as commonServices from "@/services/services"; +import commonConfig from "@/utils/config"; +import * as commonFunc from "@/components/Common/commonFunc"; +import * as commonUtils from "@/utils/utils"; +import styles from "./index.less"; + +const SwitchCompanyAndLanguageEvent = props => { + const { app } = props; + const { token, userinfo } = app; + + const addState = {}; + const [state, setState] = useState({ language: userinfo.sLanguage === "sChinese" ? "中文" : "EN" }); + + useEffect(() => { + const getComponyList = async () => { + const dataUrl = `${commonConfig.server_host}brand/getBrand/${userinfo.sId}`; + + const dataReturn = (await commonServices.getService(token, dataUrl)).data; + if (dataReturn.code === 1) { + const companyList = dataReturn.dataset.rows[0]; + setState(pre => ({ ...pre, companyList, companyData: companyList.find(item => item.sSubsidiaryId === userinfo.sSubsidiaryId) })); + setTimeout(() => { + const resizeEvent = new Event("resize"); + window.dispatchEvent(resizeEvent); + }, 1000); + } + }; + + getComponyList(); + }, []); + + addState.onChangeCompany = async item => { + if (item.sSubsidiaryId === state.companyData.sSubsidiaryId) return; + + setState(pre => ({ ...pre, companyLoading: true })); + const dataUrl = `${commonConfig.server_host}brand/changeBrand`; + const conditions = { + sBrandsId: item.sBrandsId, + sSubsidiaryId: item.sSubsidiaryId, + }; + const dataReturn = (await commonServices.postValueService(token, conditions, dataUrl)).data; + if (dataReturn.code === 1) { + setState(pre => ({ ...pre, companyData: item })); + const { token, systemData, rxtx, commonConst, gdslogininfo: userinfo, auxiliaryQty, footer, logoImageInfo, isInitPassword } = { + ...app, + ...dataReturn.dataset.rows[0], + }; + + const decimals = {}; + if (commonUtils.isNotEmptyArr(systemData)) { + const dNetPrice = systemData.filter(item => item.sName === "NetPrice")[0]; + const dNumAlign = systemData.filter(item => item.sName === "CkxNumAlign")[0]; + decimals.dNetPrice = Number(dNetPrice.sValue); + decimals.dNetMoney = 2; + decimals.dNumAlign = dNumAlign !== undefined && dNumAlign.sValue !== undefined ? dNumAlign.sValue : 0; + } + + props.dispatch({ + type: "login/login", + payload: { + token, + rxtx, + commonConst, + userinfo, + auxiliaryQty, + dispatch: props.dispatch, + systemData, + decimals, + dateFormat: commonFunc.getDateFormat(systemData), + footer, + logoImageInfo, + isInitPassword, + bChangeLanguage: true, + }, + }); + + setTimeout(() => { + commonUtils.clearStoreDropDownData(); + commonUtils.clearFormStoreDropDownData(); + window.xlyReload(); + }, 1000); + } + + setState(pre => ({ ...pre, companyLoading: false })); + }; + + addState.onChangeLanguage = async () => { + setState(pre => ({ ...pre, btnLoading: true })); + const dataUrl = `${commonConfig.server_host}brand/changeLanguage`; + const { language } = state; + + const dataReturn = (await commonServices.postValueService(token, { sLanguage: language === "中文" ? "sEnglish" : "sChinese" }, dataUrl)).data; + if (dataReturn.code === 1) { + setState(pre => ({ ...pre, language: language === "中文" ? "EN" : "中文" })); + const { token, systemData, rxtx, commonConst, gdslogininfo: userinfo, auxiliaryQty, footer, logoImageInfo, isInitPassword } = { + ...app, + ...dataReturn.dataset.rows[0], + }; + + const decimals = {}; + if (commonUtils.isNotEmptyArr(systemData)) { + const dNetPrice = systemData.filter(item => item.sName === "NetPrice")[0]; + const dNumAlign = systemData.filter(item => item.sName === "CkxNumAlign")[0]; + decimals.dNetPrice = Number(dNetPrice.sValue); + decimals.dNetMoney = 2; + decimals.dNumAlign = dNumAlign !== undefined && dNumAlign.sValue !== undefined ? dNumAlign.sValue : 0; + } + + props.dispatch({ + type: "login/login", + payload: { + token, + rxtx, + commonConst, + userinfo, + auxiliaryQty, + dispatch: props.dispatch, + systemData, + decimals, + dateFormat: commonFunc.getDateFormat(systemData), + footer, + logoImageInfo, + isInitPassword, + bChangeLanguage: true, + }, + }); + + setTimeout(() => { + commonUtils.clearStoreDropDownData(); + commonUtils.clearFormStoreDropDownData(); + window.xlyReload(); + }, 1000); + } + + setState(pre => ({ ...pre, btnLoading: false })); + }; + + return { + ...props, + ...addState, + ...state, + }; +}; + +const SwitchCompanyAndLanguage = baseProps => { + const props = SwitchCompanyAndLanguageEvent(baseProps); + return ( +
+ + {/* */} +
+ ); +}; + +const CompanyComponent = props => { + const { companyList = [], companyData = {}, companyLoading = false } = props; + + const bMutiLine = companyData.sName?.includes("-"); + const sName0 = bMutiLine ? companyData.sName.split("-")[0] : ""; + const sName1 = bMutiLine ? companyData.sName.split("-")[1] : ""; + return ( + !!companyList.length && ( + ({ + ...item, + key: item.sId, + label: item.sName, + onClick: props.onChangeCompany.bind(this, item), + })), + }} + > + + } + > +
+ {bMutiLine ? ( +
+
{sName0}
+
{sName1}
+
+ ) : ( + {companyData.sName} + )} + +
+
+
+ ) + ); +}; + +const LanguageComponent = props => { + const { language, btnLoading } = props; + return ( +
+ {btnLoading ? ( + + ) : ( + + )} +
+ ); +}; + +export default SwitchCompanyAndLanguage; diff --git a/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.less b/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.less new file mode 100644 index 0000000..ce6031c --- /dev/null +++ b/src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.less @@ -0,0 +1,54 @@ +.switchCompanyAndLanguage { + width: auto; + height: 100%; + display: flex; + + :global { + .company { + width: auto; + height: 100%; + white-space: nowrap; + // margin-right: 10px; + cursor: pointer; + display: flex; + gap: 5px; + + .companyMutiLine { + width: auto; + height: 100%; + + >div { + width: auto; + height: 20px; + display: flex; + align-items: center; + justify-content: center; + } + + >div:first-child { + font-size: 12px; + } + } + + span { + font-size: 13px !important; + } + } + + .language { + width: auto; + height: 100%; + + button { + width: 25px; + padding: 0; + color: #FFF; + font-size: 13px; + + &:hover { + color: #1890ff; + } + } + } + } +} \ No newline at end of file diff --git a/src/routes/indexPage.js b/src/routes/indexPage.js index 3b29e3b..dc41c1a 100644 --- a/src/routes/indexPage.js +++ b/src/routes/indexPage.js @@ -1,3 +1,4 @@ +import { useEffect, useState } from 'react'; import { connect } from 'umi'; import { ConfigProvider, Layout } from 'antd-v4'; import zhCN from 'antd-v4/lib/locale-provider/zh_CN'; @@ -11,9 +12,17 @@ import styles from './indexPage.less'; const { Header, Content } = Layout; function IndexPage() { + const [key, setKey] = useState(0); + + useEffect(() => { + window.xlyReload = () => { + setKey(pre => pre + 1); + }; + }, []); + return ( - +