/* eslint-disable array-callback-return,no-undef,no-unused-vars */ import React, { Component } from 'react'; import { DeleteOutlined, DownOutlined, IdcardOutlined, InfoCircleOutlined, MailOutlined, PoweroffOutlined, QuestionCircleOutlined, EllipsisOutlined, SkinOutlined, SearchOutlined, } from '@ant-design/icons'; import { Form } from '@ant-design/compatible'; // import '@ant-design/compatible/assets/index.css'; import { Button, Input, Modal, Menu, Badge, message, Dropdown, Space, notification, Popover, Tabs } from 'antd-v4'; import styles from '@/routes/indexPage.less'; import config from '@/utils/config'; import * as commonUtils from '@/utils/utils'; import * as commonBusiness from '@/components/Common/commonBusiness'; import * as commonFunc from '@/components/Common/commonFunc';/* 单据业务功能 */ import AntdDraggableModal from '@/components/Common/AntdDraggableModal'; import FaceDetect from '@/components/FaceDetect'; import logoAbout from '@/assets/logo.png'; import prompt from '@/assets/prompt.png'; import newsTone from '@/assets/news.mp3'; import OnlineUser from '@/assets/onlineUser.svg'; import StaticEditTable from '@/components/Common/CommonTable'; import * as commonServices from '@/services/services'; import commonConfig from '../../../utils/config'; import SvgIcon from '../../SvgIcon'; import SkinChangeModal from './SkinChangeModal'; import MenuSearchPopovor from './MenuSearchPopovor'; import SwitchCompanyAndLanguage from './SwitchCompanyAndLanguage'; const { TabPane } = Tabs; const { SubMenu } = Menu; const MenuItemGroup = Menu.ItemGroup; const FormItem = Form.Item; class PersonCenter extends Component { constructor(props) { super(props); this.changePwd = localStorage.getItem(`${commonConfig.prefix}changePwd`) === 'true'; this.state = { sId: props.app.userinfo.sId, dispatch: props.dispatch, userVisible: false, pwdVisible: this.changePwd, addFaceVisible: false, sUserName: props.app.userinfo.sUserName, menuSearchPopoverVisible: false, }; } componentWillMount() { const currentSkin = localStorage.getItem('xly-skin') || 'default'; const oBody = document.querySelector('body'); oBody.setAttribute('data-skin', currentSkin); } componentDidMount() { if (this.changePwd) { message.warn('系统判断密码为初始密码,请修改密码后再操作!', 10); } } componentWillReceiveProps(nextProps) { const { app } = nextProps; if (commonUtils.isNotEmptyObject(app) && commonUtils.isNotEmptyObject(this.props.app.unRead) && commonUtils.isNull(app.unRead.iCount, 0).toString() !== commonUtils.isNull(this.props.app.unRead.iCount, 0).toString()) { /* 当nextProps中的消息大于原来props中的消息数 标明有新消息推送过来 */ const audio = document.getElementById('msgAudio'); if (commonUtils.isNotEmptyObject(audio)) { audio.play(); } } } shouldComponentUpdate(nextProps) { const { pwdVisible } = this.state; const { app: appNew } = nextProps; const { app } = this.props; // 修改密码时,阻止websockt消息推送导致更新 if (pwdVisible && JSON.stringify(appNew) !== JSON.stringify(app)) { return false; } return true; } onSaveFaceSuccess = (e) => { /* 阻止表单提交动作 */ this.setState({ addFaceVisible: false, }); } handleCancellation = (e) => { const { dispatch, sId } = this.state; if (e.key === 'loginOut' || e.key === 'switchAccount') { const url = `${config.server_host}logout`; dispatch({ type: 'app/loginOut', payload: { url, sId, loginOutType: 'loginOut' } }); } else if (e.key === 'setUser') { this.setState({ userVisible: true }); } else if (e.key === 'setPsd') { this.setState({ pwdVisible: true }); } else if (e.key === 'addFace') { this.setState({ addFaceVisible: true }); } else if (e.key === 'resetPwd') { const { sId } = this.state; const url = `${config.server_host}sftlogininfo/updatePasswordUserName/reset?sModelsId=${100}&sId=${sId}`; const value = {}; value.sId = sId; dispatch({ type: 'app/resetPwd', payload: { url, value } }); } else if (e.key === 'mailAndMsg') { const pane = { title: '消息列表', route: '/indexPage/commonList', formId: '15669750700007338351055957774000', key: commonUtils.createSid(), sModelsType: 'commonList/msg', }; dispatch({ type: 'app/addPane', payload: { pane } }); } else if (e.key === 'clearOption') { sessionStorage.clear(); this.clearSocket({ optName: '记录删除' }); commonUtils.clearStoreDropDownData(); } else if (e.key === 'about') { this.handleShowAbout(); } else if (e.key === 'onlineUser') { this.handleShowOnlineUser(); } }; handleShowAbout = async () => { const { app } = this.props; const { token } = app; const configUrl = `${config.server_host}license/getLicense?sModelsId=${100}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const returnData = configReturn.dataset.rows; if (commonUtils.isNotEmptyArr(returnData)) { const aboutInfo = returnData[0]; this.setState({ aboutInfo, aboutVisible: true }); } } else { message.error(configReturn.msg); } }; handleShowNews = (e) => { const { dispatch } = this.state; const pane = { title: '消息列表', route: '/indexPage/commonList', formId: '15669750700007338351055957774000', key: commonUtils.createSid(), sModelsType: 'commonList/msg', }; dispatch({ type: 'app/addPane', payload: { pane } }); }; handleShowMsg = async (e, sFormId) => { const { dispatch } = this.state; const { app } = this.props; const { token } = app; /* 根据getModelById 取对应窗体 */ const paneKey = new Date().getTime().toString(); let sModelsType = ''; let title = '单据页'; let sProcName = ''; let route = '/indexPage/commonBill'; const configUrl = `${commonConfig.server_host}gdsmodule/getGdsmoduleById/${sFormId}?sModelsId=${sFormId}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const dataReturn = configReturn.dataset.rows; if (commonUtils.isNotEmptyArr(dataReturn) && commonUtils.isNotEmptyObject(dataReturn[0])) { const config = dataReturn[0]; sModelsType = commonUtils.isNotEmptyObject(config.sModelType) ? config.sModelType.toString() : ''; title = commonUtils.isNotEmptyObject(config.sMenuName) ? config.sMenuName.toString() : ''; route = commonUtils.isNotEmptyObject(config.sName) ? config.sName.toString() : ''; sProcName = commonUtils.isNotEmptyObject(config.sProcName) ? config.sProcName.toString() : ''; } } else { this.getServiceError(configReturn); } const pane = { formId: sFormId, key: commonUtils.createSid(), route, title, sModelsType, sProcName, }; // const pane = { // title: '消息列表', route: '/indexPage/commonList', formId: sFormId, key: commonUtils.createSid(), sModelsType: 'commonList/msg', // }; dispatch({ type: 'app/addPane', payload: { pane } }); }; handleSubmitPwd = (e) => { /* 阻止表单提交动作 */ e.preventDefault(); this.psdform.validateFields((err, values) => { if (!err) { const { sId } = this.state; values.sId = sId; if (values.sUserPwd !== values.sUserPwdAgain) { message.error('密码输入不一致'); return; } const url = `${config.server_host}sftlogininfo/updatePasswordUserName/update?sModelsId=${100}`; const { dispatch } = this.state; dispatch({ type: 'app/editPwd', payload: { url, value: values, editPwdType: 'window' } }); this.setState({ pwdVisible: false, }); } }); } handleShowModal = () => { this.setState({ visible: true, }); } handleShowOnlineUser = async () => { const { app } = this.props; const { token } = app; const configUrl = `${config.server_host}license/getOnline?sModelsId=${100}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const returnData = configReturn.dataset.rows; if (commonUtils.isNotEmptyArr(returnData)) { const onlineUserData = returnData[0]; this.setState({ onlineUserData, onlineUserVisible: true }); } } else { message.error(configReturn.msg); } } handleSaveOnlineUserState = (onlineUserState) => { this.setState({ onlineUserState }); } // 强制下线用户 handleExitTbRow = (index, record) => { const oThis = this; Modal.confirm({ title: `确定要将用户【${record.sUserName}】强制退出`, async onOk() { const { app } = oThis.props; const { userinfo, token } = app; const { sUserId, sUserLoginType } = record; const { onlineUserData } = oThis.state; const configUrl = `${config.server_host}license/doExit/${sUserId}/${sUserLoginType}`; const configReturn = (await commonServices.getService(token, configUrl)).data; if (configReturn.code === 1) { const iIndex = onlineUserData.data.findIndex(item => item.sUserId === record.sUserId); if (iIndex !== -1) { onlineUserData.data.splice(iIndex, 1); oThis.setState({ onlineUserData }); } message.success(`用户【${record.sUserName}】已下线`); } else { message.error(`用户【${record.sUserName}】强制退出失败`); } }, }); } handleCancel = () => { this.setState({ userVisible: false, pwdVisible: false, aboutVisible: false, addFaceVisible: false, onlineUserVisible: false, skinChangeModalVisible: false, }); }; handleUserForm = (form) => { this.userform = form; } handlePsdForm = (form) => { this.psdform = form; } handleSubmit = (e) => { /* 阻止表单提交动作 */ e.preventDefault(); this.userform.validateFields((err, values) => { if (!err) { const { sId } = this.state; values.sId = sId; const url = `${config.server_host}sftlogininfo/updatePasswordUserName/update?sModelsId=${100}`; const { dispatch } = this.state; dispatch({ type: 'app/editUser', payload: { url, value: values } }); this.setState({ userVisible: false, }); } }); }; handleGetMsg = (content) => { const msgArr = commonUtils.isNotEmptyArr(content) ? content : ''; const divStr = []; if (commonUtils.isNotEmptyArr(msgArr)) { // eslint-disable-next-line no-plusplus for (let i = 0; i < msgArr.length; i++) { const msgObj = msgArr[i]; // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions divStr.push(
this.handleShowMsg(e, msgObj.sFormId)}>{msgObj.sTypeName} {`(${msgObj.iCount})`}
); } } return divStr; } clearSocket = async (params) => { const { app } = this.props; const { token } = app; const returnData = await commonBusiness.clearSocketData({ token, value: params, sModelsId: 100 }); }; handleSetMenuSearchPopoverVisible = (visible) => { this.setState({ menuSearchPopoverVisible: visible }); } updateMenuPanel = () => { // const url = `${config.server_host}business/getBuMenu?sModelsId=100`; // const { token } = this.props.app; // const options = { // method: 'GET', // headers: { // 'Content-Type': 'application/json', // authorization: token, // }, // }; // fetch(url, options).then(response => response.json()).then(async (json) => { // if (json.code === 1) { // console.log(json); // this.setState({ menuPanel: json.dataset.rows }); // // message.success(json.msg); // } else { // message.error(json.msg); // } // }); } render() { const { props, state, unRead } = this; const { sUserName, sType, companyName } = props.app.userinfo; const ModifyUserNserName = commonFunc.showMessage(props.app.commonConst, 'ModifyUserNserName');/* 修改用户名 */ const ModifyPassword = commonFunc.showMessage(props.app.commonConst, 'ModifyPassword');/* 修改密码 */ const InitPassword = commonFunc.showMessage(props.app.commonConst, 'InitPassword');/* 初始化密码 */ const SwitchAccount = commonFunc.showMessage(props.app.commonConst, 'SwitchAccount');/* 切换账号 */ const GetFace = commonUtils.isNotEmptyObject(commonFunc.showMessage(props.app.commonConst, 'GetFace')) ? commonFunc.showMessage(props.app.commonConst, 'GetFace') : '人脸采集';/* 人脸采集 */ const Newsinfo = commonFunc.showMessage(props.app.commonConst, 'Newsinfo');/* 消息 */ const Todo = commonFunc.showMessage(props.app.commonConst, 'Todo');/* Todo待办 */ const aMe = commonFunc.showMessage(props.app.commonConst, '@Me');/* @Me */ const ClearOut = commonFunc.showMessage(props.app.commonConst, 'ClearOut');/* 清空 */ const Help = commonFunc.showMessage(props.app.commonConst, 'Help');/* 帮助 */ const About = commonFunc.showMessage(props.app.commonConst, 'About');/* 关于 */ const ExitLogin = commonFunc.showMessage(props.app.commonConst, 'ExitLogin');/* 退出 */ const sysadmin = commonFunc.showMessage(props.app.commonConst, 'sysadmin');/* 超级管理员 */ const General = commonFunc.showMessage(props.app.commonConst, 'General');/* 普通用户 */ const OnlineUserName = '在线用户'; const sLookAll = commonUtils.isNotEmptyObject(commonFunc.showMessage(props.app.commonConst, 'sLookAll')) ? commonFunc.showMessage(props.app.commonConst, 'sLookAll') : ''; const formItemLayout = { labelCol: { xs: { span: 24 }, sm: { span: 8 }, }, wrapperCol: { xs: { span: 24 }, sm: { span: 12 }, }, }; const tailFormItemLayout = { wrapperCol: { xs: { span: 24, offset: 0, }, sm: { span: 16, offset: 8, }, }, }; const msg = props.app.unRead; const msgObj = commonUtils.isJSON(msg) ? JSON.parse(msg) : {}; const msgData = msgObj.data; /* 推送信息 */ const { menuSearchPopoverVisible, dispatch } = this.state; const { menuPanel, onAddPane, app } = this.props; return (