king
2024-08-25 326aa6b3effaccc71cfe0775d47b0f29eb3695a6
src/menu/picturecontroller/index.jsx
@@ -18,7 +18,7 @@
const Video = asyncComponent(() => import('./video'))
const Image = asyncComponent(() => import('@/components/Image'))
class PasteController extends Component {
class SourceController extends Component {
  state = {
    visible: false,
    editvisible: false,
@@ -39,29 +39,42 @@
  }
  trigger = () => {
    let pictures = sessionStorage.getItem('app_pictures')
    let videos = sessionStorage.getItem('app_videos')
    let colorlist = sessionStorage.getItem('app_colors')
    let deffers = []
    if (!pictures) {
      notification.warning({
        top: 92,
        message: '未获取到资源信息,请稍后或刷新重试。',
        duration: 5
      })
      return
    }
    deffers.push(this.getSource('image', 'app_pictures', 0))
    deffers.push(this.getSource('video', 'app_videos', 50))
    deffers.push(this.getSource('color', 'app_colors', 100))
    Promise.all(deffers).then(result => {
      this.open(...result)
    })
  }
    try {
      pictures = JSON.parse(pictures)
      videos = JSON.parse(videos)
      colorlist = JSON.parse(colorlist)
    } catch (e) {
      pictures = []
      videos = []
      colorlist = []
    }
  getSource = (type, sessionName, delay) => {
    return new Promise(resolve => {
      if (window.GLOB[sessionName]) {
        resolve(window.GLOB[sessionName])
      } else {
        let param = {
          func: 's_url_db_adduptdel',
          PageIndex: 0,  // 0 代表全部
          PageSize: 0,   // 0 代表全部
          type: 'search',
          typecharone: type
        }
        setTimeout(() => {
          Api.getCloudConfig(param).then(res => {
            let data = res.data || []
            window.GLOB[sessionName] = data
            resolve(data)
          })
        }, delay)
      }
    })
  }
  open = (pictures, videos, colorlist) => {
    let filpictures = pictures
    let filvideos = videos
@@ -112,12 +125,13 @@
      }).then(result => {
        if (result.status) {
          if (card.typecharone === 'image') {
            sessionStorage.setItem('app_pictures', JSON.stringify(result.data || []))
            window.GLOB.app_pictures = result.data || []
            this.resetPicture(result.data || [])
          } else if (card.typecharone === 'video') {
            sessionStorage.setItem('app_videos', JSON.stringify(result.data || []))
            window.GLOB.app_videos = result.data || []
            this.resetVideo(result.data || [])
          } else if (card.typecharone === 'color') {
            window.GLOB.app_colors = result.data || []
            sessionStorage.setItem('app_colors', JSON.stringify(result.data || []))
            this.resetColor(result.data || [])
          }
@@ -147,7 +161,7 @@
  }
  deleteSource = (item) => {
    const _this = this
    const that = this
    confirm({
      title: '确定删除吗?',
@@ -166,14 +180,15 @@
          }).then(res => {
            if (res.status) {
              if (item.typecharone === 'image') {
                sessionStorage.setItem('app_pictures', JSON.stringify(res.data || []))
                _this.resetPicture(res.data || [])
                window.GLOB.app_pictures = res.data || []
                that.resetPicture(res.data || [])
              } else if (item.typecharone === 'video') {
                sessionStorage.setItem('app_videos', JSON.stringify(res.data || []))
                _this.resetVideo(res.data || [])
                window.GLOB.app_videos = res.data || []
                that.resetVideo(res.data || [])
              } else if (item.typecharone === 'color') {
                window.GLOB.app_colors = res.data || []
                sessionStorage.setItem('app_colors', JSON.stringify(res.data || []))
                _this.resetColor(res.data || [])
                that.resetColor(res.data || [])
              }
            } else {
              notification.warning({
@@ -248,7 +263,7 @@
    const { visible, editvisible, card, filpictures, filvideos, piclist, vidlist, imageKey, videoKey, pageSize, picIndex, vidIndex, colorlist, iconlist } = this.state
    return (
      <div style={{display: 'inline-block'}}>
      <>
        <Button className="mk-border-purple" onClick={this.trigger}><PictureOutlined /> 资源管理</Button>
        <Modal
          wrapClassName="mk-pop-modal picture-control-model"
@@ -376,9 +391,9 @@
        >
          <EditForm card={card} wrappedComponentRef={(inst) => this.editFormRef = inst} inputSubmit={this.save}/>
        </Modal>
      </div>
      </>
    )
  }
}
export default PasteController
export default SourceController