Commit e36427d3e8e177d571864f039500cca3b86e5e86

Authored by zhangzzzz
1 parent 252adbfc

同步切换系统功能;

src/components/Common/PersonCenter/PersonCenter.js
... ... @@ -32,6 +32,7 @@ import * as commonServices from '@/services/services';
32 32 import commonConfig from '../../../utils/config';
33 33 // import SkinChangeModal from './SkinChangeModal';
34 34 import MenuSearchPopovor from './MenuSearchPopovor';
  35 +import SwitchCompanyAndLanguage from './SwitchCompanyAndLanguage';
35 36  
36 37 const { TabPane } = Tabs;
37 38 const FormItem = Form.Item;
... ... @@ -383,7 +384,7 @@ class PersonCenter extends Component {
383 384 const { menuPanel, onAddPane, app } = this.props;
384 385 return (
385 386 <div className={styles.dropdownContainer} id="pcDropdwonContainer">
386   - <Space align="baseline">
  387 + <Space align="baseline" style={{ display: 'flex', alignItems: 'center' }}>
387 388 <div style={{ display: 'none' }} className={styles.dropdownDiv}>{companyName}</div>
388 389 <div
389 390 className="sysSearchInput"
... ... @@ -417,6 +418,7 @@ class PersonCenter extends Component {
417 418 />
418 419 </Popover>
419 420 </div>
  421 + <SwitchCompanyAndLanguage {...props} />
420 422 <div
421 423 className="sysNewBox"
422 424 onFocus={() => 0}
... ...
src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.js 0 → 100644
  1 +/* eslint-disable */
  2 +import React, { useEffect, useState } from "react";
  3 +import { Button, Dropdown, Spin } from "antd";
  4 +import { DownOutlined, LoadingOutlined } from "@ant-design/icons";
  5 +import * as commonServices from "@/services/services";
  6 +import commonConfig from "@/utils/config";
  7 +import * as commonFunc from "@/components/Common/commonFunc";
  8 +import * as commonUtils from "@/utils/utils";
  9 +import styles from "./index.less";
  10 +
  11 +const SwitchCompanyAndLanguageEvent = props => {
  12 + const { app } = props;
  13 + const { token, userinfo } = app;
  14 +
  15 + const addState = {};
  16 + const [state, setState] = useState({ language: userinfo.sLanguage === "sChinese" ? "中文" : "EN" });
  17 +
  18 + useEffect(() => {
  19 + const getComponyList = async () => {
  20 + const dataUrl = `${commonConfig.server_host}brand/getBrand/${userinfo.sId}`;
  21 +
  22 + const dataReturn = (await commonServices.getService(token, dataUrl)).data;
  23 + if (dataReturn.code === 1) {
  24 + const companyList = dataReturn.dataset.rows[0];
  25 + setState(pre => ({ ...pre, companyList, companyData: companyList.find(item => item.sSubsidiaryId === userinfo.sSubsidiaryId) }));
  26 + setTimeout(() => {
  27 + const resizeEvent = new Event("resize");
  28 + window.dispatchEvent(resizeEvent);
  29 + }, 1000);
  30 + }
  31 + };
  32 +
  33 + getComponyList();
  34 + }, []);
  35 +
  36 + addState.onChangeCompany = async item => {
  37 + if (item.sSubsidiaryId === state.companyData.sSubsidiaryId) return;
  38 +
  39 + setState(pre => ({ ...pre, companyLoading: true }));
  40 + const dataUrl = `${commonConfig.server_host}brand/changeBrand`;
  41 + const conditions = {
  42 + sBrandsId: item.sBrandsId,
  43 + sSubsidiaryId: item.sSubsidiaryId,
  44 + };
  45 + const dataReturn = (await commonServices.postValueService(token, conditions, dataUrl)).data;
  46 + if (dataReturn.code === 1) {
  47 + setState(pre => ({ ...pre, companyData: item }));
  48 + const { token, systemData, rxtx, commonConst, gdslogininfo: userinfo, auxiliaryQty, footer, logoImageInfo, isInitPassword } = {
  49 + ...app,
  50 + ...dataReturn.dataset.rows[0],
  51 + };
  52 +
  53 + const decimals = {};
  54 + if (commonUtils.isNotEmptyArr(systemData)) {
  55 + const dNetPrice = systemData.filter(item => item.sName === "NetPrice")[0];
  56 + const dNumAlign = systemData.filter(item => item.sName === "CkxNumAlign")[0];
  57 + decimals.dNetPrice = Number(dNetPrice.sValue);
  58 + decimals.dNetMoney = 2;
  59 + decimals.dNumAlign = dNumAlign !== undefined && dNumAlign.sValue !== undefined ? dNumAlign.sValue : 0;
  60 + }
  61 +
  62 + props.dispatch({
  63 + type: "login/login",
  64 + payload: {
  65 + token,
  66 + rxtx,
  67 + commonConst,
  68 + userinfo,
  69 + auxiliaryQty,
  70 + dispatch: props.dispatch,
  71 + systemData,
  72 + decimals,
  73 + dateFormat: commonFunc.getDateFormat(systemData),
  74 + footer,
  75 + logoImageInfo,
  76 + isInitPassword,
  77 + bChangeLanguage: true,
  78 + },
  79 + });
  80 +
  81 + setTimeout(() => {
  82 + commonUtils.clearStoreDropDownData();
  83 + commonUtils.clearFormStoreDropDownData();
  84 + window.xlyReload();
  85 + }, 1000);
  86 + }
  87 +
  88 + setState(pre => ({ ...pre, companyLoading: false }));
  89 + };
  90 +
  91 + addState.onChangeLanguage = async () => {
  92 + setState(pre => ({ ...pre, btnLoading: true }));
  93 + const dataUrl = `${commonConfig.server_host}brand/changeLanguage`;
  94 + const { language } = state;
  95 +
  96 + const dataReturn = (await commonServices.postValueService(token, { sLanguage: language === "中文" ? "sEnglish" : "sChinese" }, dataUrl)).data;
  97 + if (dataReturn.code === 1) {
  98 + setState(pre => ({ ...pre, language: language === "中文" ? "EN" : "中文" }));
  99 + const { token, systemData, rxtx, commonConst, gdslogininfo: userinfo, auxiliaryQty, footer, logoImageInfo, isInitPassword } = {
  100 + ...app,
  101 + ...dataReturn.dataset.rows[0],
  102 + };
  103 +
  104 + const decimals = {};
  105 + if (commonUtils.isNotEmptyArr(systemData)) {
  106 + const dNetPrice = systemData.filter(item => item.sName === "NetPrice")[0];
  107 + const dNumAlign = systemData.filter(item => item.sName === "CkxNumAlign")[0];
  108 + decimals.dNetPrice = Number(dNetPrice.sValue);
  109 + decimals.dNetMoney = 2;
  110 + decimals.dNumAlign = dNumAlign !== undefined && dNumAlign.sValue !== undefined ? dNumAlign.sValue : 0;
  111 + }
  112 +
  113 + props.dispatch({
  114 + type: "login/login",
  115 + payload: {
  116 + token,
  117 + rxtx,
  118 + commonConst,
  119 + userinfo,
  120 + auxiliaryQty,
  121 + dispatch: props.dispatch,
  122 + systemData,
  123 + decimals,
  124 + dateFormat: commonFunc.getDateFormat(systemData),
  125 + footer,
  126 + logoImageInfo,
  127 + isInitPassword,
  128 + bChangeLanguage: true,
  129 + },
  130 + });
  131 +
  132 + setTimeout(() => {
  133 + commonUtils.clearStoreDropDownData();
  134 + commonUtils.clearFormStoreDropDownData();
  135 + window.xlyReload();
  136 + }, 1000);
  137 + }
  138 +
  139 + setState(pre => ({ ...pre, btnLoading: false }));
  140 + };
  141 +
  142 + return {
  143 + ...props,
  144 + ...addState,
  145 + ...state,
  146 + };
  147 +};
  148 +
  149 +const SwitchCompanyAndLanguage = baseProps => {
  150 + const props = SwitchCompanyAndLanguageEvent(baseProps);
  151 + return (
  152 + <div className={styles.switchCompanyAndLanguage}>
  153 + <CompanyComponent {...props} />
  154 + {/* <LanguageComponent {...props} /> */}
  155 + </div>
  156 + );
  157 +};
  158 +
  159 +const CompanyComponent = props => {
  160 + const { companyList = [], companyData = {}, companyLoading = false } = props;
  161 +
  162 + const bMutiLine = companyData.sName?.includes("-");
  163 + const sName0 = bMutiLine ? companyData.sName.split("-")[0] : "";
  164 + const sName1 = bMutiLine ? companyData.sName.split("-")[1] : "";
  165 + return (
  166 + !!companyList.length && (
  167 + <Dropdown
  168 + trigger={["click"]}
  169 + menu={{
  170 + items: companyList.map(item => ({
  171 + ...item,
  172 + key: item.sId,
  173 + label: item.sName,
  174 + onClick: props.onChangeCompany.bind(this, item),
  175 + })),
  176 + }}
  177 + >
  178 + <Spin
  179 + spinning={companyLoading}
  180 + indicator={
  181 + <LoadingOutlined
  182 + style={{
  183 + fontSize: 24,
  184 + }}
  185 + spin
  186 + />
  187 + }
  188 + >
  189 + <div className="company">
  190 + {bMutiLine ? (
  191 + <div className="companyMutiLine">
  192 + <div>{sName0}</div>
  193 + <div>{sName1}</div>
  194 + </div>
  195 + ) : (
  196 + <span>{companyData.sName}</span>
  197 + )}
  198 + <DownOutlined />
  199 + </div>
  200 + </Spin>
  201 + </Dropdown>
  202 + )
  203 + );
  204 +};
  205 +
  206 +const LanguageComponent = props => {
  207 + const { language, btnLoading } = props;
  208 + return (
  209 + <div className="language">
  210 + {btnLoading ? (
  211 + <LoadingOutlined style={{ fontSize: 16 }} />
  212 + ) : (
  213 + <Button type="link" onClick={props.onChangeLanguage}>
  214 + {language}
  215 + </Button>
  216 + )}
  217 + </div>
  218 + );
  219 +};
  220 +
  221 +export default SwitchCompanyAndLanguage;
... ...
src/components/Common/PersonCenter/SwitchCompanyAndLanguage/index.less 0 → 100644
  1 +.switchCompanyAndLanguage {
  2 + width: auto;
  3 + height: 100%;
  4 + display: flex;
  5 +
  6 + :global {
  7 + .company {
  8 + width: auto;
  9 + height: 100%;
  10 + white-space: nowrap;
  11 + // margin-right: 10px;
  12 + cursor: pointer;
  13 + display: flex;
  14 + gap: 5px;
  15 +
  16 + .companyMutiLine {
  17 + width: auto;
  18 + height: 100%;
  19 +
  20 + >div {
  21 + width: auto;
  22 + height: 20px;
  23 + display: flex;
  24 + align-items: center;
  25 + justify-content: center;
  26 + }
  27 +
  28 + >div:first-child {
  29 + font-size: 12px;
  30 + }
  31 + }
  32 +
  33 + span {
  34 + font-size: 13px !important;
  35 + }
  36 + }
  37 +
  38 + .language {
  39 + width: auto;
  40 + height: 100%;
  41 +
  42 + button {
  43 + width: 25px;
  44 + padding: 0;
  45 + color: #FFF;
  46 + font-size: 13px;
  47 +
  48 + &:hover {
  49 + color: #1890ff;
  50 + }
  51 + }
  52 + }
  53 + }
  54 +}
0 55 \ No newline at end of file
... ...
src/routes/indexPage.js
  1 +import { useEffect, useState } from 'react';
1 2 import { connect } from 'umi';
2 3 import { ConfigProvider, Layout } from 'antd-v4';
3 4 import zhCN from 'antd-v4/lib/locale-provider/zh_CN';
... ... @@ -11,9 +12,17 @@ import styles from &#39;./indexPage.less&#39;;
11 12 const { Header, Content } = Layout;
12 13  
13 14 function IndexPage() {
  15 + const [key, setKey] = useState(0);
  16 +
  17 + useEffect(() => {
  18 + window.xlyReload = () => {
  19 + setKey(pre => pre + 1);
  20 + };
  21 + }, []);
  22 +
14 23 return (
15 24 <ConfigProvider locale={zhCN}>
16   - <Layout>
  25 + <Layout key={key}>
17 26 <Header className={styles.header}>
18 27 <div className={styles.headerRight}>
19 28 <div className={styles.personCenter}>
... ...