king
2020-03-22 f0602b981659c6d1ff18e8dba4ca1ce89c5f5610
2020-03-22
3个文件已修改
228 ■■■■■ 已修改文件
src/tabviews/zshare/actionList/index.jsx 161 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/zshare/verifycardprint/index.jsx 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/zshare/verifycardprint/index.scss 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tabviews/zshare/actionList/index.jsx
@@ -225,60 +225,10 @@
      formdata[_data.key] = _data.value
    })
    // btn.verify.printFunc = `
    //   let _data = data[0]
    //   _data = JSON.parse(_data)
    //   let socket = new WebSocket(_data.wsaddr)
    //   // 打开Socket
    //   socket.onopen = () => {
    //     notification.success({
    //       top: 92,
    //       message: '打印请求已发出。',
    //       duration: 2
    //     })
    //     socket.send(JSON.stringify(_data.data))
    //   }
    //   // 监听消息
    //   socket.onmessage = (event) => {
    //     let data = ''
    //     if (event.data) {
    //       try {
    //         data = JSON.parse(event.data)
    //       } catch {
    //         notification.warning({
    //           top: 92,
    //           message: event.data,
    //           duration: 10
    //         })
    //         data = ''
    //       }
    //     }
    //     if (data && data.message && !data.status) {
    //       notification.warning({
    //         top: 92,
    //         message: data.message,
    //         duration: 10
    //       })
    //     }
    //   }
    //   socket.onerror = () => {
    //     notification.warning({
    //       top: 92,
    //       message: '无法连接到:' + _data.wsaddr,
    //       duration: 10
    //     })
    //   }
    // `
    if (
      !btn.verify ||
      (btn.verify.printMode === 'normal' && (!btn.verify.Template || !btn.verify.linkUrl)) ||
      (btn.verify.printMode === 'custom' && !btn.verify.printFunc)
      (btn.verify.printMode === 'custom' && (!btn.verify.printFunc || !btn.verify.linkUrl))
    ) {
      notification.warning({
        top: 92,
@@ -412,15 +362,109 @@
    })
  }
  execCustomPrint = (btn, printdata) => {
  execCustomPrint = (item, printlist) => {
    this.setState({loadingUuid: ''})
    if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + item.verify.linkUrl) {
      socket = new WebSocket('ws://' + item.verify.linkUrl)
    } else {
      if (!item.printer) {
        let request  = {
          requestID: '',
          version: '',
          cmd: 'getPrinters'
        }
        socket.send(JSON.stringify(request))
      } else {
        this.setState({loadingUuid: ''})
    try {
      // eslint-disable-next-line
      let func = new Function('data', 'notification', btn.verify.printFunc)  // 最后一个参数当函数体来执行,前面的参数当成函数体的参数。
      func(printdata, notification)
          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
          func(socket, printlist, item.printer, notification)
    } catch (e) {
      console.warn(e)
          notification.warning({
            top: 92,
            message: '自定义函数执行错误!',
            duration: 10
          })
        }
      }
    }
    // 打开Socket
    socket.onopen = () =>{
      if (!item.printer) {
        let request  = {
          requestID: '',
          version: '',
          cmd: 'getPrinters'
        }
        socket.send(JSON.stringify(request))
      } else {
        this.setState({loadingUuid: ''})
        try {
          // eslint-disable-next-line
          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
          func(socket, printlist, item.printer, notification)
        } catch (e) {
          console.warn(e)
          notification.warning({
            top: 92,
            message: '自定义函数执行错误!',
            duration: 10
          })
        }
      }
    }
    // 监听消息
    socket.onmessage = (event) => {
      let data = ''
      if (event.data) {
        try {
          data = JSON.parse(event.data)
        } catch {
          data = ''
          notification.warning({
            top: 92,
            message: event.data,
            duration: 10
          })
          this.setState({loadingUuid: ''})
        }
      }
      if (data && data.cmd === 'getPrinters' && data.status) {
        this.setState({loadingUuid: ''})
        try {
          // eslint-disable-next-line
          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
          func(socket, printlist, data.defaultPrinter, notification)
        } catch (e) {
          console.warn(e)
          notification.warning({
            top: 92,
            message: '自定义函数执行错误!',
            duration: 10
          })
        }
      } else if (data && data.message && !data.status) {
        notification.warning({
          top: 92,
          message: data.message,
          duration: 10
        })
        this.setState({loadingUuid: ''})
      }
    }
    socket.onerror = () => {
      notification.warning({
        top: 92,
        message: '无法连接到:' + item.verify.linkUrl,
        duration: 10
      })
      this.setState({loadingUuid: ''})
    }
  }
@@ -489,8 +533,7 @@
            result.forEach(res => {
              if (res.status) {
                if (btn.verify.printMode === 'custom') {
                  // _list.push(res.data)
                  _list.push('{"status": true,"message": "","ErrCode": "","ErrMesg": "", "wsaddr": "ws://127.0.0.1:13529","wstype": "local/server","data": [{"cmd": "print","requestID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","version": "1.0","task": {"taskID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","preview": false,"printer": "Microsoft Print To PDF", "documents": [{"documentID": "05512003090002A243D8959F","contents": [{"data": {"Bill": "05512003090002","ReturnProduct": ""},"templateURL": "http://css.positecgroup.com/template/warespaceprint01/2020010810525789956968_U000000001.srt","ectype": "jdpop"}]}]}}    ]}')
                  _list.push(res)
                } else {
                  res.data.forEach(_item => {
                    _list.push({data: _item, count: res.printCount})
@@ -590,7 +633,7 @@
        return Api.genericInterface(_callbackparam)
      } else if (response.status) {
        if (btn.verify.printMode === 'custom') {
          _list.push(response.data)
          _list.push(response)
        } else {
          response.data.forEach(_item => {
            _list.push({data: _item, count: response.printCount})
@@ -612,7 +655,7 @@
      if (response.status) {
        if (btn.verify.printMode === 'custom') {
          _list.push(response.data)
          _list.push(response)
        } else {
          response.data.forEach(_item => {
            _list.push({data: _item, count: response.printCount})
@@ -641,7 +684,7 @@
    Api.genericInterface(param).then(res => {
      if (res.status) {
        if (btn.verify.printMode === 'custom') {
          _list.push(res.data)
          _list.push(res)
        } else {
          res.data.forEach(_item => {
            _list.push({data: _item, count: res.printCount})
src/templates/zshare/verifycardprint/index.jsx
@@ -15,6 +15,7 @@
import './index.scss'
const { TabPane } = Tabs
let _printFunc = null
class VerifyCard extends Component {
  static propTpyes = {
@@ -43,8 +44,10 @@
      },
      linkType: _verify.linkType || 'system',
      printMode: _verify.printMode || 'normal',
      printFunc: _verify.printFunc || '// Function(data, notification) // data-打印数据列表,notification-信息提示控件',
      printFunc: _verify.printFunc || '// Function(socket, data, printer, notification) socket-WebSocket 对象,data-打印数据列表,printer-打印机,notification-信息提示控件'
    })
    _printFunc = _verify.printFunc || ''
  }
  componentDidMount() {
@@ -162,7 +165,7 @@
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          let _verify = {...verify, ...values}
          let _verify = {...verify, ...values, printFunc: _printFunc}
          resolve(_verify)
        } else {
@@ -231,6 +234,31 @@
                    )}
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'链接类型'}>
                    {getFieldDecorator('linkType', {
                      initialValue: linkType || 'system'
                    })(
                      <Radio.Group onChange={this.changeLinkType}>
                        <Radio value="system">系统</Radio>
                        <Radio value="custom">自定义</Radio>
                      </Radio.Group>
                    )}
                  </Form.Item>
                </Col>
                <Col span={8}>
                  <Form.Item label={'链接地址'}>
                    {getFieldDecorator('linkUrl', {
                      initialValue: verify.linkUrl || '127.0.0.1:13529',
                      rules: [
                        {
                          required: true,
                          message: this.props.dict['form.required.input'] + '链接地址!'
                        }
                      ]
                    })(<Input placeholder="" autoComplete="off" disabled={linkType === 'system'} />)}
                  </Form.Item>
                </Col>
                {printMode === 'custom' ? <Col span={24}>
                  <Form.Item label={'处理函数'} className="printFunc">
                    {getFieldDecorator('printFunc', {
@@ -251,33 +279,11 @@
                          lineWrapping: true
                        }}
                        onBeforeChange={() => {}}
                        onBlur={(editor) => {
                          _printFunc = editor.getValue()
                        }}
                      />
                    )}
                  </Form.Item>
                </Col> : null}
                {printMode === 'normal' ? <Col span={8}>
                  <Form.Item label={'链接类型'}>
                    {getFieldDecorator('linkType', {
                      initialValue: linkType || 'system'
                    })(
                      <Radio.Group onChange={this.changeLinkType}>
                        <Radio value="system">系统</Radio>
                        <Radio value="custom">自定义</Radio>
                      </Radio.Group>
                    )}
                  </Form.Item>
                </Col> : null}
                {printMode === 'normal' ? <Col span={8}>
                  <Form.Item label={'链接地址'}>
                    {getFieldDecorator('linkUrl', {
                      initialValue: verify.linkUrl || '127.0.0.1:13529',
                      rules: [
                        {
                          required: true,
                          message: this.props.dict['form.required.input'] + '链接地址!'
                        }
                      ]
                    })(<Input placeholder="" autoComplete="off" disabled={linkType === 'system'} />)}
                  </Form.Item>
                </Col> : null }
                {printMode === 'normal' ? <Col span={8}>
src/templates/zshare/verifycardprint/index.scss
@@ -4,6 +4,9 @@
  }
  .ant-tabs-content {
    min-height: 40vh;
    .ant-form-item {
      margin-bottom: 10px;
    }
  }
  .ant-input-disabled {
    color: rgba(0, 0, 0, 0.65);
@@ -36,5 +39,9 @@
  .code-mirror-area {
    font-size : 14px;
    line-height : 25px;
    .CodeMirror {
      height: calc(100vh - 360px);
    }
  }
}