import * as React from "react"; import "./index.scss"; import MiniHeader from './miniHeader' import QuickOperation from "./QuickOperation"; import { Scrollbars } from "react-custom-scrollbars"; import Notification from "../components/common/Notification"; import RightFixed from "./RightFixed"; import { taker, getApiUrl, triggerDispatch } from "../helper"; // import { performance } from '../helper/performance' import PropTypes from 'prop-types'; import '@beisen-cmps/feature-cmps-loader' import { Prop, personItem, RenderTrackHorizontal, RenderTrackVertical } from './propsSetting' import { getUserInfo } from "&/components/helper"; const userAgent = window.navigator.userAgent.toLowerCase(), ios = /iphone|ipod|ipad/.test(userAgent); export default class Honour extends React.Component { static defaultTemplateProps = [ "__background__", "__gridItemMargin__", "__border__" ]; static childContextTypes = { getSelectedUsers: PropTypes.func, updateSelectedUsers: PropTypes.func, getNewAddUserPosition: PropTypes.func, toEmptyNewAddUserPosition: PropTypes.func, showPromptPop: PropTypes.func }; constructor(p: Prop) { super(p); const { channelSetting = [] } = p.data; this.state = { users: [], isfetched:false, currentConten: channelSetting.length ? channelSetting[0].code : "", hideRight:localStorage.getItem('okrPanleRightHide:'+getUserInfo().Id) || false }; } newAddUser = {}; timer: any; state: any; topPosition = 0; getChildContext() { return { getSelectedUsers: this.getSelectedUsers, updateSelectedUsers: this.updateSelectedUsers, getNewAddUserPosition: this.getNewAddUserPosition, toEmptyNewAddUserPosition: this.toEmptyNewAddUserPosition, showPromptPop: this.showPromptPop }; } getSelectedUsers = () => { return this.state.users; }; showPromptPop = (msg = "最多可添加5人!") => { Notification.warning(msg); }; getNewAddUserPosition = () => { return this.newAddUser; }; toEmptyNewAddUserPosition = () => { this.newAddUser = {}; }; updateSelectedUsers = async (userid: number, node?: any) => { const { users } = this.state; if (users.length >= 5) return; const origin = users.filter( (d: personItem) => d.UserId == userid ); if (origin.length) { this.showPromptPop("该用户已在对比列表啦~"); return new Error("添加失败"); } const userIds: any = []; if (node) { const { left, top } = node.getBoundingClientRect(); this.newAddUser = { userid, left, top }; } users.forEach((item: any, i: number) => { userIds.push(item.UserId); }); userIds.push(userid); const url = getApiUrl( "proxy/PostUPaaSCoreGateway/TalentVS/UpdateVsUsers") //要对比的用户ID const body = { userIds: userIds }; const response = await taker(url, "POST", body); if (response.OperationResult) { const newUsers = response.OperationObject || []; this.setState({ users: newUsers }); return newUsers; } else { return new Error("添加失败"); } }; componentWillUnmount() { clearTimeout(this.timer); } componentWillReceiveProps(nextProps: Prop) { const { hisPeers = false, hisSubordinate = false, hisSimilar = false, hisVistors = false } = this.props.data; const { hisPeers: nextHisPeers = false, hisSubordinate: nextHisSubordinate = false, hisSimilar: nextHisSimilar = false, hisVistors: nextHisVistors = false } = nextProps.data; if ( !nextHisPeers && !nextHisSubordinate && !nextHisSimilar && !nextHisVistors && (hisPeers || hisSubordinate || hisSimilar || hisVistors) ) { this.timer = setTimeout( triggerDispatch, 100); } if ( (nextHisPeers || nextHisSubordinate || nextHisSimilar || nextHisVistors) && (!hisPeers && !hisSubordinate && !hisSimilar && !hisVistors) ) { this.timer = setTimeout( triggerDispatch, 100); } } // 添加VS人员 addVs = async (id: number) => { const { users } = this.state; if (users.length >= 5) return; const origin = users.filter( (d: personItem) => d.UserId == id ); if (origin.length) return; const userIds = this.getIds(users); userIds.push(id); this.updateUsers(userIds); }; getIds(users:Array){ let userIds:Array =[] users.forEach((item: any) => { userIds.push(item.UserId); }); return userIds } // 删除VS人员 deleteOneVs = async (id: number) => { const newUsers = this.state.users.filter( (d: personItem) => d.UserId != id ); const userIds = this.getIds(newUsers); this.updateUsers(userIds); }; // 更新对比人信息 updateUsers = async (ids: number[]) => { const url = getApiUrl( "proxy/PostUPaaSCoreGateway/TalentVS/UpdateVsUsers" ); //要对比的用户ID const body = { userIds: ids }; const response = await taker(url, "POST", body); if (response.OperationResult) { const newUsers = response.OperationObject || []; this.setState({ users: newUsers }); } }; changeContent = (code: any) => { this.setState({ currentConten: code }); }; setDefatuleChannel = (defatuleChannel: string) => { this.setState({ currentConten: defatuleChannel }); }; handleToggleRight = () => { localStorage.setItem('okrPanleRightHide:'+getUserInfo().Id,!this.state.hideRight+''); this.setState({ hideRight: !this.state.hideRight }) } // 获取添加vs的人员 async componentDidMount() { const url = getApiUrl( "proxy/GetUPaaSCoreGateway/TalentVS/GetVsUsers"); const response = await taker(url); const users = response && response.OperationObject ? response.OperationObject : []; this.timer = setTimeout(triggerDispatch, 100); this.setState({ users: users, isfetched:true }); // performance(); } render() { const { honorPageOperation, hisPeers = false, hisSubordinate = false, hisSimilar = false, hisVistors = false,} = this.props.data; const { mode,children,workName } = this.props; const { vs = true, relation = true, operation = true } = honorPageOperation || {}; const { users, isfetched,hideRight } = this.state; const rightFixedShow = hisPeers || hisSubordinate || hisSimilar || hisVistors ; const height = this.props.contentHeight > 680? this.props.contentHeight : 680; //如果快捷操作都是关闭的,则不显示底部遮罩 if(!isfetched) return null return
{ rightFixedShow && }
{children}
{honorPageOperation && }
} };