| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, Spin, Empty } from 'antd' |
| | | import { Button, Modal, notification, Spin, Empty, Tooltip } from 'antd' |
| | | |
| | | import Api from '@/api' |
| | | import MKEmitter from '@/utils/events.js' |
| | |
| | | components: null, // 组件集合 |
| | | revertLoading: false, // 恢复默认设置 |
| | | confirmLoading: false, // 自定义设置模态框加载中 |
| | | dict: window.GLOB.dict, |
| | | lang: sessionStorage.getItem('lang') |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | }) |
| | | } else if (!links.includes(item.verify.linkUrl)) { |
| | | links.push(item.verify.linkUrl) |
| | | } |
| | | }) |
| | | |
| | | let socket = null |
| | | socket = new WebSocket('ws://' + item.verify.linkUrl) |
| | | if (links.length === 0) return |
| | | |
| | | let defers = links.map(link => { |
| | | return new Promise((resolve) => { |
| | | let socket = new WebSocket('ws://' + link) |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | let request = { |
| | |
| | | }) |
| | | } |
| | | |
| | | window.GLOB.UserCacheMap.set(item.verify.linkUrl, _printers) |
| | | } else if (data && data.cmd === 'getPrinters') { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: data.message, |
| | | duration: 5 |
| | | }) |
| | | resolve({status: true, printers: _printers}) |
| | | } else if (data && data.cmd === 'getPrinters' && data.message) { |
| | | resolve({status: false, printers: null, message: data.message}) |
| | | } |
| | | } |
| | | |
| | | socket.onerror = () => { |
| | | let tool = item.verify.linkUrl |
| | | if (item.verify.linkUrl === '127.0.0.1:13529') { |
| | | let tool = link |
| | | |
| | | if (link === '127.0.0.1:13529') { |
| | | tool = '明科通讯组件' |
| | | } else if (item.verify.linkUrl === '127.0.0.1:13528') { |
| | | } else if (link === '127.0.0.1:13528') { |
| | | tool = 'CAINIAO打印组件' |
| | | } |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '无法连接到: ' + tool, |
| | | duration: 5 |
| | | }) |
| | | |
| | | resolve({status: false, printers: null, message: '无法连接到: ' + tool}) |
| | | |
| | | } |
| | | }) |
| | | }) |
| | | |
| | | Promise.all(defers).then(results => { |
| | | let res = results.filter(item => item.status)[0] |
| | | if (res) { |
| | | links.forEach(link => { |
| | | window.GLOB.UserCacheMap.set(link, res.printers) |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: results[0].message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { components, visible } = this.state |
| | | const { components, visible, dict, lang } = this.state |
| | | |
| | | if (window.GLOB.mkHS || window.GLOB.sysType !== 'local') return null |
| | | |
| | | return ( |
| | | <div className="tool-wrap"> |
| | | <Button icon="setting" shape="circle" onClick={this.trigger}/> |
| | | <Tooltip placement="left" title={dict['custom_settings'] || '自定义设置'}> |
| | | <Button icon="setting" shape="circle" onClick={this.trigger}/> |
| | | </Tooltip> |
| | | <Modal |
| | | wrapClassName="custom-setting-modal" |
| | | title={'自定义设置'} |
| | | title={dict['custom_settings'] || '自定义设置'} |
| | | maskClosable={false} |
| | | width={950} |
| | | visible={visible} |
| | | onCancel={() => { this.setState({ visible: false }) }} |
| | | footer={[ |
| | | <Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>恢复默认设置</Button>, |
| | | <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>取消</Button>, |
| | | <Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>提交</Button> |
| | | <Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>{dict['restore_default'] || '恢复默认设置'}</Button>, |
| | | <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{dict['cancel'] || '取消'}</Button>, |
| | | <Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>{dict['submit'] || '提交'}</Button> |
| | | ]} |
| | | destroyOnClose |
| | | > |
| | | <div className="tip">注:行级按钮快捷键设置无效。</div> |
| | | {lang !== 'en-US' ? <div className="tip">注:行级按钮快捷键设置无效。</div> : null} |
| | | {components && components.length > 0 ? components.map(item => ( |
| | | <div key={item.uuid}> |
| | | <p className="component-title">{item.title}</p> |