import * as React from 'react'; import { taker, getApiUrl, getByteLen, getToUserId } from '&/helper'; import './index.scss'; import ConfirmPop from '&/components/common/popLayerConfirm'; import Mount from './Mount'; interface EditPopProps { editCancel: Function; editSure: Function, defaultValue: string } class EditPop extends React.Component { state = { inputVlaue: this.props.defaultValue, error: '' } channelNameChange = (e: React.ChangeEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); let value = e.target.value let len = getByteLen(value).len; this.setState( { inputVlaue: String(value), error: len > 20 ? '不能超过10个字' : len == 0 ? '页签名称不能为空' : '' } ) } editSure = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { editSure } = this.props; const { inputVlaue, error } = this.state; if (inputVlaue) { if (!error) { editSure(inputVlaue); } } else { this.setState({ error: '页签名称不能为空' }) } } editCancel = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { editCancel, defaultValue } = this.props; editCancel(); this.setState({ inputVlaue: defaultValue, error: '' }) } handleWrapClick = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); } render() { const { inputVlaue, error } = this.state; return (
名称  
{error}
) } } interface ChannelItemProps { index: number; name: string; inCheck: boolean; onClick: (data: any) => (e: React.MouseEvent) => void; changeOrder: Function; deleteChanel: Function; canDelete: boolean; canSort: boolean; editChannel: Function } interface ChannelItemState { isEditing: boolean } class ChannelItem extends React.Component { state = { isEditing: false } handleEdit = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); this.setState({ isEditing: true }) } editSure = (newValue: string) => { const { editChannel, index } = this.props; editChannel(newValue, index) this.setState({ isEditing: false }) } editCancle = () => { this.setState({ isEditing: false }) } handleInputChange = (e: React.ChangeEvent) => { } render() { const { index, inCheck, name, canDelete, canSort, changeOrder, deleteChanel, onClick } = this.props; const { isEditing } = this.state; return (
  • { isEditing ? :
    {name} { canDelete ? : } { canSort && }
    }
  • ) } } interface Props { data: any, update: Function } interface State { isFetching: boolean; channelData: any[]; popShow: boolean; showDeleteConfirm: boolean; deleteConfirmLeft: number; deleteConfirmTop: number; deleteIndex: number; } export default class ChannelSetting extends React.Component{ constructor(props: Props) { super(props); this.state = { isFetching: true, channelData: [], popShow: false, showDeleteConfirm: false, deleteConfirmLeft: 0, deleteConfirmTop: 0, deleteIndex: 0 } this.getData() } getData = async () => { const { data, update } = this.props; const url = getApiUrl(`proxy/GetUPaaSCoreGateway/TalentHonor/GetAppItems?code=Tabs&toUserId=${getToUserId()}`); const ChannelRes = await taker(url); let newChannelData: any[] = []; if (ChannelRes && ChannelRes.Code === 200 && ChannelRes.OperationObject) { const channelResData = ChannelRes.OperationObject.map((item: any) => { return { name: item.Title, code: item.IsIframe ? `${item.Code}__ISIFRAME` : item.Code, isSystem: true, inCheck: true } }) if (data !== undefined) { data.forEach((item: any) => { if (!item.isSystem) newChannelData.push(item); if (channelResData.find((i: any) => { return i.code == item.code })) newChannelData.push(item); }) } channelResData.forEach((item: any) => { if (!newChannelData.find((i: any) => { return i.code == item.code })) newChannelData.push(item) }) } // if (res.Code !== 200) return; // const resData = res.OperationObject.map((item: any) => { // return { // name: item.Title, // code: item.Code, // isSystem: true, // inCheck: true // } // }) // const channelData: any[] = []; // resData.forEach((item: any) => { // const oldData = data ? data.find((i: any) => { // return i.isSystem && i.name == item.name // }) : null; // channelData.push(oldData ? oldData : item) // }); // if (data) { // data.forEach((item: any) => { // if (!item.isSystem) { // channelData.push(item) // } // }) // } update(newChannelData); this.setState({ isFetching: false, channelData: newChannelData }) } checkboxListChange = (data: any) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { channelData } = this.state, { update } = this.props, newChannelData: any = []; const checked = channelData.filter(item => item.inCheck); // 至少一个选中 if (checked.length == 1 && checked[0].code == data.code) return; channelData.forEach(item => { newChannelData.push({ name: item.name, code: item.code, isSystem: item.isSystem, inCheck: item.code == data.code ? !data.inCheck : item.inCheck }) }) this.setState({ channelData: newChannelData }) update(newChannelData) } changeOrder = (index: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation() const { channelData } = this.state, { update } = this.props, channelLen = channelData.length; let newChannelData: any[] = []; const prev = index - 1 <= 0 ? [] : channelData.slice(0, index - 1); let next = []; newChannelData = newChannelData.concat(prev); if (index) { newChannelData.push(channelData[index]) newChannelData.push(channelData[index - 1]) next = index + 1 == channelLen ? [] : channelData.slice(index + 1); } else { newChannelData.push(channelData[index + 1]) newChannelData.push(channelData[index]) next = index + 2 == channelLen ? [] : channelData.slice(index + 2); } newChannelData = newChannelData.concat(next); update(newChannelData) this.setState({ channelData: newChannelData }) } deleteChanel = (index: number) => (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); const { left, top } = e.currentTarget.getBoundingClientRect(); this.setState({ showDeleteConfirm: true, deleteConfirmLeft: left - 340, deleteConfirmTop: top - 90, deleteIndex: index }) } confirmOnSure = () => { const { update } = this.props; const { channelData, deleteIndex } = this.state; const channelDataLen = channelData.length; let newChannelData: any[] = []; if (deleteIndex) { newChannelData = channelData.slice(0, deleteIndex); const next = deleteIndex + 1 == channelDataLen ? [] : channelData.slice(deleteIndex + 1) newChannelData = newChannelData.concat(next); } else { newChannelData = channelData.slice(1); } update(newChannelData) // this.mountClose && this.mountClose() this.setState({ channelData: newChannelData, showDeleteConfirm: false }) } confirmOnClose = () => { // this.mountClose && this.mountClose() this.setState({ showDeleteConfirm: false }) } // mountClose: Function; // mountTriggerClose = (fn: any) => { // this.mountClose = fn // } addNewChannel = (e: React.MouseEvent) => { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation() this.setState({ popShow: true }) } editChannel = (value: string, index: number) => { const { channelData } = this.state; const { update } = this.props; let newChannelData = channelData.map((item: any, i: number) => { if (i == index) { return Object.assign({}, { ...item }, { name: value }) } return item; }) update(newChannelData) this.setState({ channelData: newChannelData }) } addNewChannelSure = (value: string) => { const { channelData } = this.state; const { update } = this.props; const newAddChannelData = { name: value, code: String(new Date().getTime()), isSystem: false, inCheck: true } const newChannelData = channelData.concat(newAddChannelData); update(newChannelData) this.setState({ popShow: false, channelData: newChannelData }) } addNewChannelCancel = () => { this.setState({ popShow: false }) } render() { const { isFetching, channelData, popShow, showDeleteConfirm, deleteConfirmLeft, deleteConfirmTop } = this.state; const channelLen = channelData.length; const confirmMountStyle = `position: absolute;left: ${deleteConfirmLeft}px;top:${deleteConfirmTop}px;`; return
    { showDeleteConfirm ? : null } { !isFetching &&
      { channelData.map((item: any, index: number) => { return ( 1} canDelete={!item.isSystem} changeOrder={this.changeOrder} deleteChanel={this.deleteChanel} editChannel={this.editChannel} /> ) }) }
    } +新增 { popShow && }
    } }