king
16 小时以前 b09b821ef36fd1ea979e9a5daa98e95732ac81d5
src/components/mkIcon/index.jsx
@@ -46,12 +46,8 @@
  }
  componentDidMount() {
    if (!window.GLOB.designView) {
      if (sessionStorage.getItem('systemIcons')) {
        this.setState({cusicons: JSON.parse(sessionStorage.getItem('systemIcons'))})
      } else {
        this.getIcons()
      }
    if (!window.GLOB.designView && window.GLOB.systemIcons) {
      this.setState({cusicons: window.GLOB.systemIcons})
    }
  }
@@ -65,28 +61,50 @@
  }
  getIcons = () => {
    Api.getSystemConfig({ func: 's_get_icons' }).then(res => {
    const { selectIcon } = this.state
    Api.getCloudConfig({ func: 's_get_icons' }).then(res => {
      if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
        sessionStorage.setItem('systemIcons', JSON.stringify([]))
        return
      } else if (!res.data) {
        window.GLOB.systemIcons = []
        return
      }
      let icons = res.data.map(item => {
      let icons = (res.data || []).map(item => {
        item.icon_svg = window.decodeURIComponent(window.atob(item.icon_svg))
        return item
      })
      sessionStorage.setItem('systemIcons', JSON.stringify(icons))
      window.GLOB.systemIcons = icons
      this.setState({cusicons: icons})
      if (icons.length > 0 && selectIcon && /<svg/.test(selectIcon)) {
        setTimeout(() => {
          let node = document.getElementById('mk-custom-tab')
          node && node.click()
        }, 200)
      }
    })
  }
  trigger = () => {
    const { selectIcon, cusicons } = this.state
    this.setState({visible: true})
    if (!window.GLOB.designView && !window.GLOB.systemIcons) {
      this.getIcons()
    } else if (cusicons.length > 0 && selectIcon && /<svg/.test(selectIcon)) {
      setTimeout(() => {
        let node = document.getElementById('mk-custom-tab')
        node && node.click()
      }, 200)
    }
  }
  render() {
@@ -95,7 +113,7 @@
    return (
      <div className="mk-icon-box">
        {selectIcon ? <MkIcon type={selectIcon}/> : <span style={{color: '#bcbcbc'}}>请选择</span>}
        <MkIcon className="trigger" onClick={() => this.setState({visible: true})} type="swap"/>
        <MkIcon className="trigger" onClick={this.trigger} type="swap"/>
        {allowClear && selectIcon ? <CloseCircleFilled className="close" onClick={() => this.checkIcon('')}/> : null}
        <Modal
          wrapClassName="mk-pop-modal mk-icon-wrap"
@@ -118,13 +136,13 @@
              </Row>
            </TabPane>
            <TabPane tab={
              <span className="tab-control">
              <span className="tab-control" id="mk-custom-tab">
                <RedoOutlined onClick={(e) => {this.getIcons()}}/>
                自定义
              </span>
            } key="scripts">
              <Row>
                {cusicons.map(icon => <Col key={icon.id} span={4} onClick={() => this.checkIcon(icon.icon_svg)}>
                {cusicons.map(icon => <Col className={icon.icon_svg === selectIcon ? 'active' : ''} key={icon.id} span={4} onClick={() => this.checkIcon(icon.icon_svg)}>
                  <MkIcon type={icon.icon_svg} />
                </Col>)}
              </Row>