king
2021-07-18 2850799963a5bff04aeeb9eb73dc4eb91a0dc165
src/views/appmanage/index.jsx
@@ -19,6 +19,7 @@
const Header = asyncComponent(() => import('@/mob/header'))
const MutilForm = asyncComponent(() => import('./mutilform'))
const TransForm = asyncComponent(() => import('./transform'))
const ScriptForm = asyncComponent(() => import('./scriptform'))
const SubMutilForm = asyncComponent(() => import('./submutilform'))
let base_url = ''
@@ -81,9 +82,10 @@
        title: '操作',
        key: 'action',
        align: 'center',
        width: '230px',
        render: (text, record) => (
          <div>
            <Button type="link" onClick={() => this.setState({ selectTran: record, transVisible: 'edit' })} style={{color: '#8E44AD'}}>修改</Button>
          <div onClick={() => this.forbid = true}>
            <Button type="link" onClick={() => this.setState({ editTran: record, transVisible: 'edit' })} style={{color: '#8E44AD'}}>修改</Button>
            <Button type="link" onClick={() => this.deleteTran(record)} style={{color: '#ff4d4f'}}>删除</Button>
            <Button type="link" onClick={() => this.enableTran(record)} style={{color: '#26C281'}}>启用</Button>
          </div>
@@ -94,9 +96,23 @@
    translist: [],
    tranSearchKey: '',
    selectTran: null,
    editTran: null,
    transIndex: 1,
    transTotal: 0
    transTotal: 0,
    scriptcolumns: [
      { title: '关键字', dataIndex: 'KeyWords', key: 'KeyWords', align: 'left' },
      { title: '描述', dataIndex: 'Remark', key: 'Remark', align: 'left' },
      { title: '类型', dataIndex: 'TypeName', key: 'TypeName', align: 'left' },
      { title: '排序', dataIndex: 'Sort', key: 'Sort', align: 'left' },
    ],
    scriptVisible: false,
    scriptlist: [],
    scriptSearchKey: '',
    scriptIndex: 1,
    scriptTotal: 0,
  }
  forbid = false
  UNSAFE_componentWillMount() {
    document.body.className = ''
@@ -138,7 +154,10 @@
      if (result.status) {
        this.setState({
          loading: false,
          translist: result.data
          translist: result.data,
          selectTran: null,
          scriptlist: [],
          transTotal: result.total
        })
      } else {
        this.setState({
@@ -153,6 +172,72 @@
    })
  }
  getScriptList = () => {
    const { scriptSearchKey, scriptIndex, selectTran } = this.state
    if (!selectTran || !selectTran.ID) {
      notification.warning({
        top: 92,
        message: '缺少传输号ID!',
        duration: 3
      })
      return
    }
    let param = {
      func: 's_get_sVersionDetail',
      dataM: 'Y',
      PageSize: 10,
      PageIndex: scriptIndex,
      OrderCol: 'Sort desc',
      BID: selectTran.ID,
    }
    if (scriptSearchKey) {
      param.TypeName = scriptSearchKey
      param.KeyWords = scriptSearchKey
      param.Remark = scriptSearchKey
    }
    this.setState({
      loading: true
    })
    Api.getCloudConfig(param).then(result => {
      if (result.status) {
        this.setState({
          loading: false,
          scriptlist: result.data,
          scriptTotal: result.total,
          selectScriptKeys: []
        })
      } else {
        this.setState({
          loading: false
        })
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
      }
    })
  }
  scriptSearch = (value) => {
    this.setState({scriptSearchKey: value, scriptIndex: 1}, () => {
      this.getScriptList()
    })
  }
  changeScriptTable = (pagination) => {
    this.setState({
      scriptIndex: pagination.current
    }, () => {
      this.getScriptList()
    })
  }
  changeTable = (pagination) => {
    this.setState({
      transIndex: pagination.current
@@ -162,13 +247,13 @@
  }
  tranSearch = (value) => {
    this.setState({tranSearchKey: value}, () => {
    this.setState({tranSearchKey: value, transIndex: 1}, () => {
      this.getTransList()
    })
  }
  submitTrans = () => {
    const { transVisible, selectTran } = this.state
    const { transVisible, editTran } = this.state
    this.transRef.handleConfirm().then(res => {
      this.setState({
@@ -184,7 +269,7 @@
      } else {
        param.func = 's_sVersion_upt'
        param.ProgramName = res.ProgramName
        param.ID = selectTran.ID
        param.ID = editTran.ID
      }
      Api.getCloudConfig(param).then(result => {
@@ -217,6 +302,49 @@
    })
  }
  submitScript = () => {
    // const { selectTran } = this.state
    this.scriptRef.handleConfirm().then(res => {
      this.setState({
        confirmloading: true
      })
      // let param = {}
      // s_sVersionDetail_Add
      // s_sVersionDetail_CloudAdd
      // Api.getCloudConfig(param).then(result => {
      //   if (result.status) {
      //     notification.success({
      //       top: 92,
      //       message: '操作成功!',
      //       duration: 3
      //     })
      //     this.setState({
      //       scriptIndex: 1,
      //       confirmloading: false,
      //       scriptVisible: false
      //     }, () => {
      //       this.getScriptList()
      //     })
      //   } else {
      //     this.setState({
      //       confirmloading: false
      //     })
      //     notification.warning({
      //       top: 92,
      //       message: result.message,
      //       duration: 5
      //     })
      //   }
      // }, () => {
      //   this.setState({
      //     confirmloading: false
      //   })
      // })
    })
  }
  deleteTran = (record) => {
    const _this = this
@@ -235,10 +363,6 @@
                top: 92,
                message: '操作成功!',
                duration: 3
              })
              _this.setState({
                selectTran: null,
              })
              _this.getTransList()
            } else {
@@ -276,10 +400,6 @@
                top: 92,
                message: '操作成功!',
                duration: 3
              })
              _this.setState({
                selectTran: record,
              })
              _this.getTransList()
            } else {
@@ -322,6 +442,10 @@
          return item
        })
        if (!selectApp && applist[0]) {
          selectApp = applist[0]
        }
        
        this.setState({
          loading: false,
@@ -495,11 +619,113 @@
    this.setState({ selectApp })
  }
  onTransChange = selectedRowKeys => {
    const { translist } = this.state
    let selectTran = translist.filter(item => item.ID === selectedRowKeys[0])[0]
  onScriptChange = selectedRowKeys => {
    this.setState({ selectScriptKeys: selectedRowKeys })
  }
    this.setState({ selectTran })
  onScriptSelect = (record) => {
    const { selectScriptKeys } = this.state
    if (selectScriptKeys.includes(record.ID)) {
      this.setState({ selectScriptKeys: selectScriptKeys.filter(key => key !== record.ID) })
    } else {
      this.setState({ selectScriptKeys: [...selectScriptKeys, record.ID]})
    }
  }
  deleteScripts = () => {
    const { selectScriptKeys, selectTran } = this.state
    if (selectScriptKeys.length === 0) {
      notification.warning({
        top: 92,
        message: '请选择要删除的脚本!',
        duration: 3
      })
      return
    }
    let params = selectScriptKeys.map(key => {
      return {
        func: 's_sVersionDetail_del',
        BID: selectTran.ID,
        ID: key
      }
    })
    const _this = this
    confirm({
      content: '确定要执行吗?',
      onOk() {
        return new Promise(resolve => {
          let deffers = params.map((param, i) => {
            return new Promise(resolve => {
              setTimeout(() => {
                Api.getCloudConfig(param).then(res => {
                  resolve(res)
                }, () => {
                  resolve({status: false, message: '删除失败!'})
                })
              }, i * 150)
            })
          })
          Promise.all(deffers).then(result => {
            let errorMsg = ''
            result.forEach(res => {
              if (!res.status) {
                errorMsg = res.message
              }
            })
            if (errorMsg) {
              notification.warning({
                top: 92,
                message: errorMsg,
                duration: 3
              })
            } else {
              notification.success({
                top: 92,
                message: '执行成功。',
                duration: 3
              })
              _this.setState({
                scriptIndex: 1
              }, () => {
                _this.getScriptList()
              })
            }
            resolve()
          })
        })
      },
      onCancel() {}
    })
  }
  onTransChange = selectedRowKeys => {
    const { translist, selectTran } = this.state
    let _selectTran = translist.filter(item => item.ID === selectedRowKeys[0])[0]
    this.setState({ selectTran: _selectTran })
    if (!selectTran || selectTran.ID !== _selectTran.ID) {
      this.setState({ scriptIndex: 1 }, () => {
        this.getScriptList()
      })
    }
  }
  onTransSelect = (record) => {
    const { selectTran } = this.state
    this.setState({ selectTran: record })
    if (!selectTran || selectTran.ID !== record.ID) {
      this.setState({ scriptIndex: 1 }, () => {
        this.getScriptList()
      })
    }
  }
  /**
@@ -661,7 +887,7 @@
  }
  render () {
    const { loading, visible, subVisible, columns, transcolumns, applist, translist, transVisible, selectApp, selectTran, selectSubApp } = this.state
    const { loading, visible, subVisible, columns, transcolumns, applist, translist, transVisible, selectApp, selectTran, selectSubApp, scriptVisible, scriptlist, scriptcolumns, selectScriptKeys } = this.state
    return (
      <div className="mk-app-manage">
@@ -669,8 +895,7 @@
          <Header view="manage" />
          {loading ?
            <div className="loading-mask">
              <div className="ant-spin-blur"></div>
              <Spin />
              <Spin size="large" />
            </div> : null
          }
          <div className="view-wrap">
@@ -700,32 +925,41 @@
                  pagination={{
                    current: this.state.transIndex,
                    pageSize: 10,
                    total: this.state.transTotal || 0
                    total: this.state.transTotal || 0,
                    showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
                  }}
                  rowSelection={{ type: 'radio', selectedRowKeys: selectTran ? [selectTran.ID] : [], onChange: this.onTransChange }}
                  onRow={(record) => ({ onClick: () => this.setState({ selectTran: record })})}
                  onRow={(record) => ({ onClick: () => {
                    if (this.forbid) {
                      this.forbid = false
                      return
                    }
                    this.onTransSelect(record)
                  }})}
                  onChange={this.changeTable}
                />
              </div>
              {/* <div className={'script-table' + (this.state.transTotal <= 10 ? ' no-footer' : '')}>
              {selectTran ? <div className="script-table">
                <div className="app-action">
                  <Button className="mk-green" onClick={() => this.setState({ scriptVisible: 'plus' })}>添加脚本</Button>
                  <Search placeholder="综合搜索" onSearch={value => this.scriptSearch(value)} enterButton />
                  <Button className="mk-green" onClick={() => this.setState({ scriptVisible: true })}>添加脚本</Button>
                  <Button className="mk-danger" onClick={this.deleteScripts} style={{marginLeft: '15px'}}>删除</Button>
                  <Search placeholder="综合搜索" defaultValue={this.state.scriptSearchKey} onSearch={value => this.scriptSearch(value)} enterButton />
                </div>
                <Table
                  rowKey="ID"
                  columns={transcolumns}
                  dataSource={translist}
                  columns={scriptcolumns}
                  dataSource={scriptlist}
                  pagination={{
                    current: this.state.transIndex,
                    current: this.state.scriptIndex,
                    pageSize: 10,
                    total: this.state.transTotal || 0
                    total: this.state.scriptTotal || 0,
                    showTotal: (total, range) => `${range[0]}-${range[1]} 共 ${total} 条`
                  }}
                  rowSelection={{ type: 'radio', selectedRowKeys: selectTran ? [selectTran.ID] : [], onChange: this.onTransChange }}
                  onRow={(record) => ({ onClick: () => this.setState({ selectTran: record })})}
                  onChange={this.changeTable}
                  rowSelection={{ type: 'checkbox', selectedRowKeys: selectScriptKeys, onChange: this.onScriptChange }}
                  onRow={(record) => ({ onClick: () => this.onScriptSelect(record)})}
                  onChange={this.changeScriptTable}
                />
              </div> */}
              </div> : null}
            </div>
            <div className="right-view">
              {selectApp ? <div className="app-title">{selectApp.remark}</div> : null}
@@ -813,8 +1047,8 @@
            title={'编辑应用'}
            width={'600px'}
            maskClosable={false}
            visible={!!visible}
            onCancel={() => this.setState({visible: false})}
            visible={visible !== false}
            onCancel={() => this.setState({visible: false, confirmloading: false})}
            confirmLoading={this.state.confirmloading}
            onOk={this.submitCard}
            cancelText="取消"
@@ -827,22 +1061,36 @@
            title={transVisible === 'plus' ? '添加传输号' : '编辑传输号'}
            width={'600px'}
            maskClosable={false}
            visible={!!transVisible}
            onCancel={() => this.setState({transVisible: false})}
            visible={transVisible !== false}
            onCancel={() => this.setState({transVisible: false, confirmloading: false})}
            confirmLoading={this.state.confirmloading}
            onOk={this.submitTrans}
            cancelText="取消"
            okText="确定"
            destroyOnClose
          >
            <TransForm type={transVisible} card={transVisible === 'edit' ? selectTran : ''} wrappedComponentRef={(inst) => this.transRef = inst} inputSubmit={this.submitTrans} />
            <TransForm type={transVisible} card={transVisible === 'edit' ? this.state.editTran : ''} wrappedComponentRef={(inst) => this.transRef = inst} inputSubmit={this.submitTrans} />
          </Modal>
          <Modal
            title={'添加脚本'}
            width={750}
            maskClosable={false}
            visible={scriptVisible}
            onCancel={() => this.setState({scriptVisible: false, confirmloading: false})}
            confirmLoading={this.state.confirmloading}
            onOk={this.submitScript}
            cancelText="取消"
            okText="确定"
            destroyOnClose
          >
            <ScriptForm applist={applist} wrappedComponentRef={(inst) => this.scriptRef = inst} inputSubmit={this.submitScript} />
          </Modal>
          <Modal
            title={'编辑子应用'}
            width={'850px'}
            maskClosable={false}
            visible={!!subVisible}
            onCancel={() => this.setState({subVisible: false})}
            visible={subVisible !== false}
            onCancel={() => this.setState({subVisible: false, confirmloading: false})}
            confirmLoading={this.state.confirmloading}
            onOk={this.submitSubCard}
            cancelText="取消"