商品管理列表页优化 实现全屏效果

日常需求:
https://xiaolv.qima-inc.com/#/demand/search?show=true&ids=37128
商品管理页 实现全屏

  1. 通过使用js 的api : element.requestFullScreen()退出全屏:element.exitFullscreen()
    但是在实现过程中会有层级问题;

2.通过操纵dom 的隐藏和显示实现虚拟的全屏

export default class OperatorWrapper extends Component<IFilterHandler> {
  state = {
    // 控制pop框展示
    visible: false,
    // 控制是否是全屏
    isFullScreen: false,
    imgUrlOpen: 'https://img01.yzcdn.cn/upload_files/2021/02/01/FuP3UIzt2XTiDL9HIKc3mzecfyoH.png',
    imgUrlClose: 'https://img01.yzcdn.cn/upload_files/2021/02/01/FnBYCbhSNTGrUcoXXtesMacrXNTr.png',
  };

  exportList = () => {
    const exportDialogId = `export_dialog_${+new Date()}`;
    const dialogParams = {
    });
  };

  componentDidMount() {
    // 是否显示用户引导信息
    const { localStorage } = window;
    // 从localstorage 中获取 isLeadUser;
    const isLeadUser = localStorage.getItem('isLeadUser');
    if (!isLeadUser) this.setState({ visible: true });
    // 监控esc事件
    document.addEventListener('keydown', this.escFunction, false);
  }

  componentWillUnmount() {
    document.removeEventListener('keydown', this.escFunction, false);
  }

  // esc 退出事件
  escFunction = event => {
    if (event.keyCode === 27) {
      this.setState({ isFullScreen: false }, () => {
        this.fullScreen();
      });
    }
  };

  // 显示全屏方法
  fullScreen() {
    const { isFullScreen } = this.state;
    const appHelpContainer: HTMLElement | null = document.getElementById('app-help-container');
    const sharedSider: HTMLElement | null = document.getElementById('shared-sidebar');
    const appHelpButton: HTMLElement | null = document.getElementById('app-help-button');
    const appThirdSidebar: HTMLElement | null = document.getElementById('app-third-sidebar');
    const appContainer: HTMLElement | null = document.getElementById('app-container');
    // 获取商品管理页模块的dom;
    // @ts-ignore
    const app: HTMLElement | null = document.getElementsByClassName('app')[0];

    if (
      appHelpContainer &&
      sharedSider &&
      appHelpButton &&
      appThirdSidebar &&
      appContainer &&
      app
    ) {
      appHelpContainer.style.display = isFullScreen ? 'none' : 'block';
      sharedSider.style.display = isFullScreen ? 'none' : 'block';
      appHelpButton.style.display = isFullScreen ? 'none' : 'block';
      appThirdSidebar.style.display = isFullScreen ? 'none' : 'block';
      appContainer.style.marginLeft = isFullScreen ? '0' : '224px';
      // 获取当前屏幕宽度;
      const { width } = window.screen;
      const curWidth = width + 'px';
      // 设置 商品管理模块的宽度 模拟全屏
      app.style.width = isFullScreen ? curWidth : '100%';
      // 显示弹窗;
      if (isFullScreen) {
        Notify.config({ duration: 2500 });
        Notify.info('按"Esc"键可退出全屏模式');
        this.popClose();
      }
    }
  }

  // 设置全屏
  setFullScreen = () => {
    const { isFullScreen } = this.state;
    this.setState({ isFullScreen: !isFullScreen }, () => {
      this.fullScreen();
    });
  };

  //关闭pop
  popClose = () => {
    const { localStorage } = window;
    // 存储isLeadUser === '1' 到localStorage中;
    localStorage.setItem('isLeadUser', '1');
    this.setState({ visible: false });
  };

  render() {
    const { isFullScreen, imgUrlOpen, imgUrlClose } = this.state;
    const {
      data: { queryType, isLoading },
      onSearchData,
      resetFilterData,
    } = this.props;
    const PopContent = (
      <p>
        点击展示全部字段列
        <Icon style={{ paddingLeft: 8, cursor: 'pointer' }} type="close" onClick={this.popClose} />
      </p>
    );

    return (
      <div className={style.wrapper}>
        >
          重置筛选条件
        </a>
        {/* 全屏icon */}
        <Pop
          trigger="none"
          position="left-center"
          content={PopContent}
          visible={this.state.visible}
        >
          <img
            className={style.fullScreenIcon}
            onClick={this.setFullScreen}
            src={isFullScreen ? imgUrlClose : imgUrlOpen}
            alt="icon"
          />
        </Pop>
      </div>
    );
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值