import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import moment from 'moment'
|
import { is, fromJS } from 'immutable'
|
import { Button, Modal, notification, message } from 'antd'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import asyncSpinComponent from '@/utils/asyncSpinComponent'
|
import { updateForm } from '@/utils/utils-update.js'
|
import UtilsDM from '@/utils/utils-datamanage.js'
|
import MKEmitter from '@/utils/events.js'
|
import MkIcon from '@/components/mk-icon'
|
// import './index.scss'
|
|
const MutilForm = asyncSpinComponent(() => import('@/tabviews/zshare/mutilform'))
|
const { confirm } = Modal
|
let socket = null
|
|
class PrintButton extends Component {
|
static propTpyes = {
|
BID: PropTypes.string, // 主表ID
|
BData: PropTypes.any, // 主表数据
|
selectedData: PropTypes.any, // 子表中选择数据
|
MenuID: PropTypes.string, // 菜单ID
|
btn: PropTypes.object, // 按钮
|
setting: PropTypes.any, // 页面通用设置
|
columns: PropTypes.array,
|
disabled: PropTypes.any, // 行按钮禁用
|
}
|
|
state = {
|
visible: false,
|
formdata: null,
|
selines: null,
|
btnconfig: null,
|
confirmLoading: false,
|
loading: false,
|
disabled: false,
|
hidden: false,
|
autoMatic: false,
|
dict: window.GLOB.dict
|
}
|
|
UNSAFE_componentWillMount () {
|
const { btn, selectedData, BData, disabled } = this.props
|
|
if (btn.controlField) {
|
this.setStatus(btn, selectedData || [], BData, disabled)
|
} else if (disabled) {
|
this.setState({disabled: true})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
const { btn } = this.props
|
|
MKEmitter.addListener('triggerBtnId', this.actionTrigger)
|
|
if (btn.autoMatic) {
|
MKEmitter.addListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
|
}
|
}
|
|
UNSAFE_componentWillReceiveProps (nextProps) {
|
const { btn } = this.props
|
|
if (btn.controlField) {
|
this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
|
} else {
|
this.setState({disabled: nextProps.disabled === true})
|
}
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
|
MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit)
|
}
|
|
setStatus = (btn, data, BData, disprop) => {
|
let disabled = false
|
let hidden = false
|
|
if (btn.control !== 'parent') {
|
if (data.length > 0) {
|
data.forEach(item => {
|
let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
|
if (btn.controlVals.includes(s) || item.$lock) {
|
disabled = true
|
}
|
})
|
} else if (btn.controlVals.includes('')) {
|
disabled = true
|
}
|
} else {
|
if (!BData || !BData.hasOwnProperty(btn.controlField)) {
|
hidden = true
|
} else {
|
let s = BData[btn.controlField] + ''
|
if (btn.controlVals.includes(s)) {
|
hidden = true
|
}
|
}
|
}
|
|
if (disabled && btn.control === 'hidden') {
|
hidden = true
|
}
|
|
if (disprop) {
|
disabled = true
|
}
|
|
this.setState({hidden, disabled})
|
}
|
|
triggerBtnPopSubmit = (id) => {
|
const { btn } = this.props
|
|
if (btn.uuid !== id) return
|
|
this.handleOk()
|
}
|
|
/**
|
* @description 触发按钮操作
|
*/
|
actionTrigger = (triggerId, record, type, lid) => {
|
const { BID, btn, selectedData, setting, LID } = this.props
|
const { loading, disabled, dict } = this.state
|
|
if (loading || disabled) return
|
if (triggerId && btn.uuid !== triggerId) return
|
if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
|
|
if (setting.supModule && !BID) {
|
notification.warning({
|
top: 92,
|
message: setting.supModTip || dict['sup_key_req'] || '需要上级主键值!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({autoMatic: type === 'autoMatic'})
|
|
let that = this
|
let data = record || selectedData || []
|
|
if (btn.Ot !== 'notRequired' && data.length === 0) {
|
// 需要选择行时,校验数据
|
notification.warning({
|
top: 92,
|
message: dict['select_row'] || '请选择行!',
|
duration: 5
|
})
|
return
|
} else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
|
// 需要选择单行时,校验数据
|
notification.warning({
|
top: 92,
|
message: dict['select_single_row'] || '请选择单行数据!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
selines: data
|
})
|
|
if (btn.execMode === 'pop') {
|
let modal = this.state.btnconfig
|
if (!modal && btn.modal) {
|
modal = this.handleModelConfig(btn.modal)
|
modal.uuid = btn.uuid
|
}
|
|
this.setState({
|
loading: true,
|
btnconfig: modal
|
}, () => {
|
this.improveAction()
|
})
|
} else if (btn.execMode === 'prompt') {
|
this.setState({ loading: true })
|
confirm({
|
title: dict['exec_sure'] || '确定要执行吗?',
|
okText: dict['ok'] || '确定',
|
cancelText: dict['cancel'] || '取消',
|
onOk() {
|
that.triggerPrint(data)
|
},
|
onCancel() {
|
that.setState({ loading: false })
|
}
|
})
|
} else {
|
this.triggerPrint(data)
|
}
|
|
if (window.GLOB.systemType === 'production') {
|
MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '标签打印'})
|
}
|
}
|
|
triggerPrint = (data, formlist = []) => {
|
const { btn } = this.props
|
|
if (btn.verify.printMode === 'RFID') {
|
this.triggerRFIDPrint(data, formlist)
|
} else {
|
this.triggerNormalPrint(data, formlist)
|
}
|
}
|
|
/**
|
* @description 触发打印
|
*/
|
triggerNormalPrint = (data, formlist) => {
|
const { btn } = this.props
|
let formdata = {}
|
|
formlist.forEach(_data => {
|
let _key = _data.key.toLowerCase()
|
formdata[_key] = _data.value
|
})
|
|
let printlist = []
|
let templates = []
|
|
new Promise(resolve => {
|
if (btn.intertype === 'system' && btn.verify.dataType !== 'custom') { // 使用系统时,直接从表格或表单中选取数据
|
if (btn.Ot === 'notRequired') {
|
let printcell = {}
|
|
printcell.printType = formdata.printtype || ''
|
printcell.printCount = +(formdata.printcount || 1)
|
printcell.templateID = formdata.templateid || btn.verify.Template || ''
|
|
printcell.data = [formdata]
|
|
if (isNaN(printcell.printCount) || printcell.printCount < 1) {
|
printcell.printCount = 1
|
}
|
|
templates.push(printcell.templateID)
|
|
printlist.push(printcell)
|
} else {
|
data.forEach(cell => {
|
let _cell = {}
|
|
Object.keys(cell).forEach(key => {
|
let _key = key.toLowerCase()
|
|
if (/^\$/.test(_key)) return
|
|
_cell[_key] = cell[key]
|
})
|
|
_cell = {..._cell, ...formdata}
|
|
let printcell = {data: [_cell]}
|
|
printcell.printType = _cell.printtype || ''
|
printcell.printCount = +(_cell.printcount || 1)
|
printcell.templateID = _cell.templateid || btn.verify.Template || ''
|
|
if (isNaN(printcell.printCount) || printcell.printCount < 1) {
|
printcell.printCount = 1
|
}
|
|
templates.push(printcell.templateID)
|
|
printlist.push(printcell)
|
})
|
}
|
|
if (btn.verify.printMode === 'custom') {
|
this.execCustomPrint(printlist, formdata)
|
resolve(false)
|
} else {
|
resolve(true)
|
}
|
} else {
|
this.getprintdata(btn, data, formdata, formlist).then(result => {
|
if (!result.next) {
|
resolve(false)
|
return
|
}
|
|
// 自定义打印
|
if (btn.verify.printMode === 'custom') {
|
result.list.forEach(cell => {
|
Object.keys(cell).forEach(key => {
|
let _key = key.toLowerCase()
|
if (['printtype', 'printcount'].includes(_key)) {
|
cell[_key] = cell[key]
|
}
|
})
|
cell.printType = cell.printtype || ''
|
cell.printCount = +(cell.printcount || 1)
|
})
|
this.execCustomPrint(result.list, formdata)
|
resolve(false)
|
return
|
}
|
|
result.list.forEach(cell => {
|
// 系统打印数据,校验data字段
|
if (!cell.data || cell.data.length === 0) return
|
|
Object.keys(cell).forEach(key => {
|
let _key = key.toLowerCase()
|
if (['templateid', 'printtype', 'printcount'].includes(_key)) {
|
cell[_key] = cell[key]
|
}
|
})
|
|
cell.data.forEach(item => {
|
let _item = {...formdata}
|
|
_item.printtype = cell.printtype || ''
|
_item.printcount = cell.printcount || 1
|
_item.templateid = cell.templateid || ''
|
|
Object.keys(item).forEach(key => {
|
let _key = key.toLowerCase()
|
_item[_key] = item[key]
|
})
|
|
let printcell = {data: [_item]}
|
|
printcell.printType = _item.printtype || ''
|
printcell.printCount = +(_item.printcount || 1)
|
printcell.templateID = _item.templateid || btn.verify.Template || ''
|
|
if (isNaN(printcell.printCount) || printcell.printCount < 1) {
|
printcell.printCount = 1
|
}
|
|
templates.push(printcell.templateID)
|
|
printlist.push(printcell)
|
})
|
})
|
|
resolve(true)
|
})
|
}
|
}).then(res => {
|
// 获取打印模板 getTemp
|
if (!res) return false
|
|
templates = Array.from(new Set(templates)) // 去重
|
|
let deffers = templates.map(tempId => {
|
return new Promise(resolve => {
|
let param = {
|
func: 's_PrintTemplateMGetData',
|
Type: 'Y',
|
// ID: tempId, // 添加模板时,保存及查询使用模板参数
|
PrintTempNO: tempId
|
}
|
|
if (window.GLOB.mainSystemApi) { // 从单点登录服务器取打印配置信息
|
param.rduri = window.GLOB.mainSystemApi
|
}
|
|
Api.getSystemCacheConfig(param).then(result => {
|
result.tempId = tempId
|
resolve(result)
|
})
|
})
|
})
|
|
return Promise.all(deffers)
|
}).then(result => {
|
if (!result) return
|
|
let errorMsg = ''
|
let _temps = {}
|
let images = []
|
|
result.forEach(res => {
|
if (res.status && !errorMsg) {
|
let _temp = this.getPrintConfigParam(res)
|
|
if (_temp.error) {
|
errorMsg = {
|
ErrCode: 'N',
|
message: _temp.error,
|
status: false
|
}
|
} else {
|
images = [...images, ..._temp.imgs]
|
_temps[res.tempId] = _temp
|
}
|
} else if (!errorMsg) {
|
errorMsg = res
|
}
|
})
|
|
if (!errorMsg) {
|
if (images.length > 0) {
|
let errorUrls = []
|
images.forEach(url => {
|
let img = new Image()
|
img.onerror = () => {
|
errorUrls.push(url)
|
}
|
img.src = url
|
})
|
|
setTimeout(() => {
|
if (errorUrls.length > 0) {
|
notification.warning({
|
top: 92,
|
message: '模板中图片 ' + errorUrls.join(',') + ' 已失效!',
|
duration: 5
|
})
|
Object.keys(_temps).forEach(key => {
|
_temps[key].config.ReportHeader.Control = _temps[key].config.ReportHeader.Control.map(item => {
|
if (item.Type === 'image' && errorUrls.includes(item.Value)) {
|
item.Value = ''
|
}
|
return item
|
})
|
})
|
}
|
|
this.execPrint(printlist, _temps)
|
}, 500)
|
} else {
|
this.execPrint(printlist, _temps)
|
}
|
} else {
|
this.execError(errorMsg)
|
}
|
})
|
}
|
|
/**
|
* @description 触发RFID打印
|
*/
|
triggerRFIDPrint = (data, formlist) => {
|
const { btn } = this.props
|
let formdata = {}
|
let list = []
|
|
formlist.forEach(_data => {
|
formdata[_data.key] = _data.value
|
})
|
|
new Promise(resolve => {
|
if (btn.intertype === 'system' && btn.verify.dataType !== 'custom') { // 使用系统时,直接从表格或表单中选取数据
|
if (btn.Ot === 'notRequired') {
|
if (formlist.length > 0) {
|
list = [formdata]
|
}
|
} else {
|
data.forEach(cell => {
|
let _cell = {...cell, ...formdata}
|
list.push(_cell)
|
})
|
}
|
|
resolve(true)
|
} else {
|
this.getprintdata(btn, data, formdata, formlist).then(result => {
|
if (result.next) {
|
result.list.forEach(cell => {
|
// 系统打印数据,校验data字段
|
if (!cell.data || cell.data.length === 0) return
|
|
cell.data.forEach(m => {
|
let _cell = {...m, ...formdata}
|
list.push(_cell)
|
})
|
})
|
}
|
|
resolve(result.next)
|
})
|
}
|
}).then(res => {
|
// 获取打印模板 getTemp
|
if (!res) return false
|
|
if (list.length === 0) {
|
notification.warning({
|
top: 92,
|
message: window.GLOB.dict['no_data'] || '未获取到打印数据!',
|
duration: 5
|
})
|
return false
|
}
|
|
let param = {
|
func: 's_PrintTemplateMGetData',
|
Type: 'Y',
|
// ID: tempId, // 添加模板时,保存及查询使用模板参数
|
PrintTempNO: btn.verify.Template
|
}
|
|
if (window.GLOB.mainSystemApi) { // 从单点登录服务器取打印配置信息
|
param.rduri = window.GLOB.mainSystemApi
|
}
|
|
return Api.getSystemCacheConfig(param)
|
}).then(result => {
|
if (!result || result.ErrCode === 'LoginError') {
|
this.setState({ loading: false })
|
return
|
}
|
|
if (!result.ConfigParam) {
|
notification.warning({
|
top: 92,
|
message: window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!',
|
duration: 5
|
})
|
this.setState({ loading: false })
|
} else {
|
let configParam = ''
|
try {
|
configParam = JSON.parse(window.decodeURIComponent(window.atob(result.ConfigParam)))
|
} catch (e) {
|
configParam = ''
|
}
|
|
if (!configParam) {
|
notification.warning({
|
top: 92,
|
message: '打印模板解析错误!',
|
duration: 5
|
})
|
this.setState({ loading: false })
|
} else {
|
this.execRfidPrint(list, configParam)
|
}
|
}
|
})
|
}
|
|
/**
|
* @description 自定义打印,解析自定义js
|
*/
|
execCustomPrint = (printlist, formdata) => {
|
const { btn } = this.props
|
|
let callback = null
|
let printReject = null
|
let skip = false
|
let send = false
|
|
let data = fromJS({
|
data: printlist,
|
form: formdata
|
}).toJS()
|
|
if (!window.GLOB.errorLog) {
|
printReject = (msg) => {
|
if (send) return
|
|
send = true
|
data.message = msg
|
|
window.mkInfo(JSON.stringify(data))
|
}
|
} else {
|
printReject = (msg) => {
|
if (send) return
|
|
send = true
|
data.message = msg
|
|
let param = {
|
func: 's_special_error_note_log',
|
api_url: btn.logLabel,
|
error_code: 507,
|
error_time: moment().format('YYYY-MM-DD HH:mm:ss'),
|
api_param: JSON.stringify(data)
|
}
|
Api.genericInterface(param)
|
}
|
}
|
|
if (/callback\(\)/.test(btn.verify.printFunc)) {
|
callback = () => {
|
if (skip) return
|
skip = true
|
|
this.execSuccess({
|
ErrCode: '-1',
|
message: '',
|
status: true
|
})
|
}
|
} else {
|
this.execSuccess({
|
ErrCode: '-1',
|
message: '',
|
status: true
|
})
|
}
|
|
try {
|
// eslint-disable-next-line
|
let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', 'callback', 'printReject', btn.verify.printFunc)
|
func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback, printReject)
|
|
// 自定义打印示例
|
// let defaultPrinter = printer.defaultPrinter || 'lackprinter'
|
// let printers = {}
|
// let getuuid = () => {
|
// let uuid = []
|
// let _options = '0123456789abcdefghigklmnopqrstuv'
|
// for (let i = 0; i < 32; i++) {
|
// uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
|
// }
|
// return uuid.join('')
|
// }
|
// if (printer.printerTypeList && printer.printerTypeList.length > 0) {
|
// printer.printerTypeList.forEach(cell => {
|
// if (cell.printer) {
|
// printers[cell.Value] = cell.printer
|
// }
|
// })
|
// }
|
|
// let jdList = [];
|
// let jdNewList = [];
|
// let otherList = [];
|
// let _map = new Map()
|
// data.forEach(m => {
|
// if (!m.print_data || m.print_data.length === 0) return
|
|
// m.print_data.forEach(n => {
|
// if (n.InsideBill) {
|
// if (_map.has(n.InsideBill)) {
|
// return
|
// }
|
// _map.set(n.InsideBill, true)
|
// }
|
// if (n.CustomData) {
|
// n.CustomData = JSON.parse(n.CustomData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
|
// }
|
|
// if (n.hasOwnProperty('StdTemplate')) {
|
// jdNewList.push(n);
|
// return
|
// } else if (!n.PrintData) {
|
// return
|
// }
|
|
// n.PrintData = JSON.parse(n.PrintData.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))
|
// n.PrintData.data = {...form, ...n.PrintData.data}
|
|
// if (n.PrintData.ectype === 'jdpop') {
|
// jdList.push(n)
|
// } else {
|
// otherList.push(n)
|
// }
|
// })
|
// })
|
|
// if (jdList.length === 0 && otherList.length === 0 && jdNewList.length === 0) {
|
// notification.warning({
|
// top: 92,
|
// message: '无打印数据!',
|
// duration: 5
|
// })
|
// return
|
// }
|
|
// let execPrint = (list, linkUrl, type) => {
|
// let printdata = {};
|
// let printerList = [];
|
|
// if (type === 'jd') {
|
// printerList = list.map(m => {
|
// let _printer = defaultPrinter;
|
|
// if (m.printType && printers[m.printType]) {
|
// _printer = printers[m.printType];
|
// }
|
|
// return {
|
// orderType: "print",
|
// parameters: {
|
// printName: _printer === 'lackprinter' ? '' : _printer,
|
// tempUrl: m.StdTemplate,
|
// customTempUrl: m.CusTemplate,
|
// customData: [m.CustomData],
|
// printData: [m.PrintData]
|
// }
|
// }
|
// })
|
// } else {
|
// list.forEach(res => {
|
// let _printer = defaultPrinter
|
|
// if (res.printType && printers[res.printType]) {
|
// _printer = printers[res.printType]
|
// }
|
|
// printdata[_printer] = printdata[_printer] || []
|
|
// printdata[_printer].push(res)
|
// })
|
|
// Object.keys(printdata).forEach(printer => {
|
// let _documents = []
|
// printdata[printer].forEach(item => {
|
// let _cell = {
|
// documentID: getuuid(),
|
// contents: []
|
// }
|
|
// if (item.PrintData) {
|
// _cell.contents.push(item.PrintData)
|
// }
|
// if (item.CustomData) {
|
// _cell.contents.push(item.CustomData)
|
// }
|
|
// _documents.push(_cell)
|
// })
|
// printerList.push({
|
// cmd: 'print',
|
// requestID: '',
|
// version: '',
|
// task: {
|
// taskID: getuuid(),
|
// preview: false,
|
// printer: printer === 'lackprinter' ? '' : printer,
|
// documents: _documents
|
// }
|
// })
|
// })
|
// }
|
|
// let socket = new WebSocket('ws://' + linkUrl)
|
|
// // 打开Socket
|
// socket.onopen = () =>{
|
// printerList.forEach((cell, i) => {
|
// setTimeout(() => {
|
// socket.send(JSON.stringify(cell).replace(/\\r/g,"\r").replace(/\\n/g,"\n"))
|
// }, 1000 * i)
|
// });
|
|
// notification.success({
|
// top: 92,
|
// message: '打印请求已发出。',
|
// duration: 2
|
// })
|
// }
|
// // 监听消息
|
// socket.onmessage = (event) => {
|
// let data = ''
|
|
// if (event.data) {
|
// try {
|
// data = JSON.parse(event.data)
|
// } catch (e) {
|
// 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: '无法连接到:' + linkUrl,
|
// duration: 10
|
// })
|
// }
|
// }
|
|
// if (jdNewList.length > 0) {
|
// execPrint(jdNewList, '127.0.0.1:9113', 'jd');
|
// }
|
// if (jdList.length > 0) {
|
// execPrint(jdList, '127.0.0.1:13529')
|
// }
|
// if (otherList.length > 0) {
|
// execPrint(otherList, '127.0.0.1:13528')
|
// }
|
} catch (e) {
|
console.warn(e)
|
|
notification.warning({
|
top: 92,
|
message: window.GLOB.dict['func_error'] || '自定义函数执行错误!',
|
duration: 5
|
})
|
|
printReject(window.GLOB.dict['func_error'] || '自定义函数执行错误!')
|
}
|
}
|
|
/**
|
* @description 获取打印数据
|
*/
|
getprintdata = (btn, data, formdata, formlist) => {
|
const { setting, BID } = this.props
|
|
let _list = []
|
return new Promise(resolve => {
|
let params = []
|
|
if (btn.intertype === 'system' && btn.verify.dataType === 'custom') {
|
if (btn.Ot === 'notRequired') {
|
let _param = this.getDefaultSql(formlist, null, '')
|
|
params.push(_param)
|
} else if (btn.Ot === 'requiredSgl') {
|
let ID = ''
|
if (setting.primaryKey) {
|
ID = data[0][setting.primaryKey] || ''
|
}
|
|
let _param = this.getDefaultSql(formlist, data[0], ID)
|
|
params.push(_param)
|
} else if (btn.Ot === 'requiredOnce') {
|
let ID = ''
|
|
if (setting.primaryKey) {
|
let ids = data.map(d => { return d[setting.primaryKey]})
|
ids = ids.filter(Boolean)
|
ID = ids.join(',')
|
}
|
|
let _param = this.getDefaultSql(formlist, data[0], ID)
|
|
params.push(_param)
|
} else if (btn.Ot === 'required') {
|
params = data.map(cell => {
|
let ID = ''
|
if (setting.primaryKey) {
|
ID = cell[setting.primaryKey] || ''
|
}
|
|
return this.getDefaultSql(formlist, cell, ID)
|
})
|
}
|
} else {
|
if (btn.Ot === 'notRequired') {
|
let _param = { ...formdata }
|
|
if (BID) {
|
_param.BID = BID
|
}
|
|
params.push(_param)
|
} else if (btn.Ot === 'requiredSgl') {
|
let _param = { ...formdata }
|
|
if (setting.primaryKey) {
|
_param[setting.primaryKey] = data[0][setting.primaryKey]
|
}
|
|
if (BID) {
|
_param.BID = BID
|
}
|
|
params.push(_param)
|
} else if (btn.Ot === 'requiredOnce') {
|
let _param = { ...formdata }
|
|
if (setting.primaryKey) {
|
let ids = data.map(d => { return d[setting.primaryKey]})
|
ids = ids.filter(Boolean)
|
ids = ids.join(',')
|
|
_param[setting.primaryKey] = ids
|
}
|
|
if (BID) {
|
_param.BID = BID
|
}
|
|
params.push(_param)
|
} else if (btn.Ot === 'required') {
|
params = data.map((cell, index) => {
|
let _param = {}
|
|
if (setting.primaryKey) {
|
_param[setting.primaryKey] = cell[setting.primaryKey]
|
}
|
|
if (BID) {
|
_param.BID = BID
|
}
|
|
let _cell = {}
|
if (index !== 0) {
|
Object.keys(cell).forEach(key => {
|
_cell[key.toLowerCase()] = cell[key]
|
})
|
}
|
|
formlist.forEach(_data => {
|
if (index !== 0 && _data.readin && _cell.hasOwnProperty(_data.key.toLowerCase())) {
|
_param[_data.key] = _cell[_data.key.toLowerCase()]
|
} else {
|
_param[_data.key] = _data.value
|
}
|
})
|
return _param
|
})
|
}
|
}
|
|
if (btn.intertype === 'inner' || btn.intertype === 'system') {
|
if (btn.intertype === 'inner') {
|
params = params.map(_param => {
|
_param.func = btn.innerFunc
|
|
if (btn.recordUser === 'true') {
|
_param.username = sessionStorage.getItem('User_Name') || ''
|
_param.fullname = sessionStorage.getItem('Full_Name') || ''
|
}
|
if (btn.dataM === 'true') {
|
_param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : ''
|
}
|
|
return _param
|
})
|
}
|
|
if (params.length <= 20) {
|
let deffers = params.map(par => {
|
return new Promise(resolve => {
|
Api.genericInterface(par).then(res => {
|
resolve(res)
|
})
|
})
|
})
|
Promise.all(deffers).then(result => {
|
let errorMsg = ''
|
result.forEach(res => {
|
if (!res.status && !errorMsg) {
|
errorMsg = res
|
}
|
})
|
if (!errorMsg) {
|
resolve({next: true, list: result})
|
} else {
|
this.execError(errorMsg)
|
resolve({next: false, list: []})
|
}
|
})
|
} else {
|
this.printInnerLoopRequest(params, btn, _list, resolve)
|
}
|
} else {
|
this.printOuterLoopRequest(params, btn, _list, resolve)
|
}
|
})
|
}
|
|
/**
|
* @description 获取默认存储过程请求参数
|
*/
|
getDefaultSql = (formlist, data, ID) => {
|
const { BID, btn, columns } = this.props
|
|
if (window.backend && window.GLOB.CacheData.has('sql_' + btn.uuid)) {
|
let setting = {...btn.verify.setting}
|
setting.interType = 'system'
|
setting.uuid = btn.uuid
|
|
let _param = UtilsDM.getQueryDataParams(setting, [], setting.order, 1, 9999, BID, ID)
|
let item = window.GLOB.CacheData.get('sql_' + btn.uuid)
|
|
_param.data[0].exps = _param.data[0].exps.filter(n => n.key !== 'mk_search')
|
let formkeys = []
|
|
formlist.forEach(form => {
|
if (!item.reps.includes(form.key)) return
|
|
formkeys.push(form.key)
|
|
let val = form.value
|
if (form.type === 'number' || form.type === 'rate') {
|
if (isNaN(val) || val === '') {
|
val = 0
|
}
|
} else if (['date', 'datemonth'].includes(form.type)) {
|
val = val || '1949-10-01'
|
}
|
|
_param.data[0].exps.push({
|
key: 'mk_' + form.key + '_mk',
|
value: val
|
})
|
})
|
|
if (data && columns && columns.length > 0) {
|
let datavars = {}
|
|
Object.keys(data).forEach(key => {
|
datavars[key.toLowerCase()] = data[key]
|
})
|
|
columns.forEach(col => {
|
if (!item.reps.includes(col.field) || formkeys.includes(col.field)) return
|
if (!col.datatype) return
|
|
let _key = col.field.toLowerCase()
|
let _val = datavars.hasOwnProperty(_key) ? datavars[_key] : ''
|
|
if (/^date/ig.test(col.datatype) && !_val) {
|
_val = '1949-10-01'
|
}
|
|
_param.data[0].exps.push({
|
key: 'mk_' + col.field + '_mk',
|
value: _val
|
})
|
})
|
}
|
|
return _param
|
}
|
|
let arrFields = btn.verify.columns.map(col => col.field).join(',')
|
|
let param = {
|
func: 'sPC_Get_TableData',
|
obj_name: 'data',
|
exec_type: window.GLOB.execType || 'y',
|
arr_field: arrFields,
|
default_sql: btn.verify.setting.defaultSql
|
}
|
|
if (BID) {
|
param.BID = BID
|
}
|
if (ID) {
|
param.ID = ID
|
}
|
|
let userName = sessionStorage.getItem('User_Name') || ''
|
let fullName = sessionStorage.getItem('Full_Name') || ''
|
let RoleID = sessionStorage.getItem('role_id') || ''
|
let departmentcode = sessionStorage.getItem('departmentcode') || ''
|
let organization = sessionStorage.getItem('organization') || ''
|
let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
|
let nation = sessionStorage.getItem('nation') || ''
|
let province = sessionStorage.getItem('province') || ''
|
let city = sessionStorage.getItem('city') || ''
|
let district = sessionStorage.getItem('district') || ''
|
let address = sessionStorage.getItem('address') || ''
|
|
let _dataresource = btn.verify.setting.dataresource
|
let _customScript = ''
|
let _tailScript = ''
|
btn.verify.scripts && btn.verify.scripts.forEach(script => {
|
if (script.status === 'false') return
|
if (script.position !== 'back') {
|
_customScript += `
|
${script.sql}
|
`
|
} else {
|
_tailScript += `
|
${script.sql}
|
`
|
}
|
})
|
|
if (btn.verify.setting.defaultSql === 'false') {
|
_dataresource = ''
|
}
|
|
let custompage = false
|
|
if (/order\s+by\s+sort_id\s*$/i.test(_dataresource)) {
|
custompage = true
|
} else if (/@pageSize@|@orderBy@|@mk_total/i.test(_dataresource + _customScript + _tailScript)) {
|
custompage = true
|
}
|
|
let isDataM = sessionStorage.getItem('dataM') === 'true'
|
let regoptions = [
|
{ reg: /@orderBy@/ig, value: btn.verify.setting.order },
|
{ reg: /@pageSize@/ig, value: '9999' },
|
{ reg: /@pageIndex@/ig, value: '1'},
|
{ reg: /@ID@/ig, value: `'${ID}'`},
|
{ reg: /@BID@/ig, value: `'${BID || ''}'`},
|
{ reg: /@LoginUID@/ig, value: `'${sessionStorage.getItem('LoginUID') || ''}'`},
|
{ reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
|
{ reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
|
{ reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
|
{ reg: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
|
{ reg: /@typename@/ig, value: `'admin'`},
|
{ reg: /\$@/ig, value: isDataM ? '/*' : ''},
|
{ reg: /@\$/ig, value: isDataM ? '*/' : ''},
|
{ reg: /@datam@/ig, value: isDataM ? `'Y'` : `''`},
|
]
|
|
regoptions.forEach(item => {
|
_dataresource = _dataresource.replace(item.reg, item.value)
|
_customScript = _customScript.replace(item.reg, item.value)
|
_tailScript = _tailScript.replace(item.reg, item.value)
|
})
|
|
if (/\s/.test(_dataresource)) {
|
_dataresource = '(' + _dataresource + ') tb'
|
}
|
|
let initsql = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100)
|
Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
|
`
|
|
let _vars = []
|
let _initvars = []
|
let _declare = []
|
// 获取字段键值对
|
formlist.forEach(form => {
|
let _key = form.key.toLowerCase()
|
|
_vars.push(_key)
|
|
if (form.type === 'number' || form.type === 'rate') {
|
let val = form.value
|
if (isNaN(val) || val === '') {
|
val = 0
|
}
|
_initvars.push(`@${_key}=${val}`)
|
} else if (['date', 'datemonth'].includes(form.type)) {
|
_initvars.push(`@${_key}='${form.value || '1949-10-01'}'`)
|
} else {
|
_initvars.push(`@${_key}='${form.value}'`)
|
}
|
|
if (form.fieldlen && form.fieldlen > 4000) {
|
form.fieldlen = 'max'
|
}
|
|
let _type = `nvarchar(${form.fieldlen})`
|
|
if (form.type.match(/date/ig)) {
|
_type = 'datetime'
|
} else if (form.type === 'number') {
|
_type = `decimal(18,${form.fieldlen})`
|
} else if (form.type === 'rate') {
|
_type = `decimal(18,2)`
|
}
|
|
_declare.push(`@${_key} ${_type}`)
|
})
|
|
if (_declare.length > 0) {
|
initsql += `/* 表单变量 */
|
Declare ${_declare.join(',')}
|
select ${_initvars.join(',')}
|
`
|
|
_declare = []
|
_initvars = []
|
}
|
|
if (data && columns && columns.length > 0) {
|
let datavars = {}
|
|
Object.keys(data).forEach(key => {
|
datavars[key.toLowerCase()] = data[key]
|
})
|
|
columns.forEach(col => {
|
if (!col.field || !col.datatype) return
|
|
let _key = col.field.toLowerCase()
|
|
if (_vars.includes(_key)) return
|
|
let _val = datavars.hasOwnProperty(_key) ? datavars[_key] : ''
|
|
if (/^date/ig.test(col.datatype) && !_val) {
|
_val = '1949-10-01'
|
}
|
|
_initvars.push(`@${_key}='${_val}'`)
|
_declare.push(`@${_key} ${col.datatype}`)
|
})
|
}
|
|
if (_declare.length > 0) {
|
initsql += `/* 显示列变量 */
|
Declare ${_declare.join(',')}
|
select ${_initvars.join(',')}
|
`
|
}
|
|
if (_customScript) {
|
_customScript = `${initsql}
|
${_customScript}
|
`
|
}
|
|
let LText = ''
|
|
if (_dataresource) {
|
if (custompage) {
|
LText = `/*system_query*/select ${arrFields} from ${_dataresource} `
|
} else {
|
LText = `/*system_query*/select ${arrFields} from (select ${arrFields} ,ROW_NUMBER() over(order by ${btn.verify.setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
|
}
|
}
|
|
if (_customScript) {
|
if (LText) {
|
LText = `${LText}
|
${_tailScript}
|
aaa:
|
if @ErrorCode!=''
|
insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
|
`
|
} else {
|
_customScript = `${_customScript}
|
${_tailScript}
|
aaa:
|
if @ErrorCode!=''
|
insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
|
`
|
}
|
} else if (_tailScript) {
|
LText = `${initsql}
|
${LText}
|
${_tailScript}
|
aaa:
|
if @ErrorCode!=''
|
insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
|
`
|
} else {
|
LText = `${initsql}
|
${LText}
|
`
|
}
|
|
// 测试系统打印查询语句
|
if (window.GLOB.debugger === true) {
|
_customScript && window.mkInfo(`${btn.logLabel ? `/*${btn.logLabel} 自定义脚本*/\n` : ''}${LText ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
|
LText && window.mkInfo(`${btn.logLabel ? `/*${btn.logLabel} 数据源*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
|
}
|
|
if (btn.logLabel) {
|
param.menuname = btn.logLabel
|
}
|
|
param.custom_script = Utils.formatOptions(_customScript, param.exec_type)
|
param.LText = Utils.formatOptions(LText, param.exec_type)
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt('', param.timestamp)
|
|
param.username = userName
|
param.fullname = fullName
|
|
if (window.GLOB.probation) {
|
param.s_debug_type = 'Y'
|
}
|
|
return param
|
}
|
|
/**
|
* @description 外部请求循环执行
|
*/
|
printOuterLoopRequest = (params, btn, _list, _resolve) => {
|
let param = params.shift()
|
let _outParam = null
|
let ver_token = false
|
|
new Promise(resolve => {
|
// 内部请求
|
if (btn.innerFunc) {
|
param.func = btn.innerFunc
|
// 存在内部函数时,数据预处理
|
Api.genericInterface(param).then(res => {
|
if (res.status) {
|
delete res.ErrCode
|
delete res.ErrMesg
|
delete res.message
|
delete res.status
|
|
// 使用处理后的数据调用外部接口
|
let keys = Object.keys(res) // 提交外部接口前,添加BID
|
if (this.props.BID && keys.filter(key => key.toLowerCase() === 'bid').length === 0) {
|
res.BID = this.props.BID
|
}
|
|
resolve(res)
|
} else {
|
this.execError(res)
|
resolve(false)
|
_resolve({next: false, list: []})
|
}
|
})
|
} else {
|
resolve(param)
|
}
|
}).then(res => {
|
if (!res) return
|
// 外部请求
|
_outParam = JSON.parse(JSON.stringify(res))
|
|
if (btn.sysInterface === 'true') {
|
if (window.GLOB.mainSystemApi) {
|
res.rduri = window.GLOB.mainSystemApi
|
}
|
} else if (btn.sysInterface === 'external') {
|
if (window.GLOB.systemType === 'production') {
|
res.$token = btn.exProInterface || ''
|
} else {
|
res.$token = btn.exInterface || ''
|
}
|
ver_token = true
|
} else {
|
if (window.GLOB.systemType === 'production' && btn.proInterface) {
|
res.rduri = btn.proInterface
|
} else {
|
res.rduri = btn.interface
|
}
|
|
let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
|
if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) {
|
res.$login = true
|
}
|
}
|
|
if (btn.outerFunc) {
|
res.func = btn.outerFunc
|
}
|
|
return Api.genericInterface(res)
|
}).then(response => {
|
if (!response || response.ErrCode === 'LoginError') return
|
|
if (ver_token && response.ErrCode === 'token_error') {
|
response.ErrCode = 'E'
|
this.execError(response)
|
_resolve({next: false, list: []})
|
} else if (btn.callbackFunc) {
|
// 存在回调函数时,调用
|
delete response.message
|
delete response.status
|
|
response.func = btn.callbackFunc
|
|
let _callbackparam = {..._outParam, ...response}
|
|
return Api.genericInterface(_callbackparam)
|
} else if (response.status) {
|
_list.push(response)
|
|
// 一次请求成功,进行下一项请求
|
if (params.length === 0) {
|
_resolve({next: true, list: _list})
|
} else {
|
this.printOuterLoopRequest(params, btn, _list, _resolve)
|
}
|
} else {
|
this.execError(response)
|
_resolve({next: false, list: []})
|
}
|
}).then(response => {
|
if (!response || response.ErrCode === 'LoginError') return
|
|
if (response.status) {
|
_list.push(response)
|
|
// 一次请求成功,进行下一项请求
|
if (params.length === 0) {
|
_resolve({next: true, list: _list})
|
} else {
|
this.printOuterLoopRequest(params, btn, _list, _resolve)
|
}
|
} else {
|
this.execError(response)
|
_resolve({next: false, list: []})
|
}
|
})
|
}
|
|
/**
|
* @description 内部请求循环执行
|
*/
|
printInnerLoopRequest = (params, btn, _list, _resolve) => {
|
let param = params.shift()
|
|
Api.genericInterface(param).then(res => {
|
if (res.status) {
|
_list.push(res)
|
|
if (params.length === 0) {
|
_resolve({next: true, list: _list})
|
} else {
|
this.printInnerLoopRequest(params, btn, _list, _resolve)
|
}
|
} else {
|
this.execError(res)
|
_resolve({next: false, list: []})
|
}
|
})
|
}
|
|
getPrintConfigParam = (res) => {
|
let error = '' // 错误信息
|
let configParam = '' // 模板配置信息
|
let _configparam = '' // 打印配置信息
|
let fields = [] // 模板中所需字段
|
let nonEFields = [] // 非空字段
|
let imgs = []
|
|
if (!res.ConfigParam) {
|
error = window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!'
|
} else {
|
try {
|
configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam)))
|
} catch (e) {
|
configParam = ''
|
}
|
|
if (!configParam) {
|
error = '打印模板解析错误!'
|
} else {
|
let control = []
|
let rotate = configParam.rotate || 0
|
let offsetTop = 0
|
let offsetLeft = 0
|
|
if (rotate === 90) {
|
offsetTop = configParam.width - configParam.height
|
} else if (rotate === 270) {
|
offsetLeft = configParam.height - configParam.width
|
}
|
|
configParam.elements.forEach(element => {
|
let _field = element.field || ''
|
|
if (_field === 'other_field') {
|
_field = element.cusfield || ''
|
}
|
|
let item = {
|
Name: element.name || '',
|
Type: element.type,
|
Value: element.value || '',
|
Field: _field.toLowerCase(),
|
Left: element.left + offsetLeft,
|
Top: element.top + offsetTop,
|
Width: element.width,
|
Height: element.height,
|
Rotate: rotate,
|
// Rotate: element.rotate,
|
BorderSize: element.borderSize / 10,
|
BorderColor: element.borderColor,
|
Align: element.align,
|
VerticalAlign: element.vertialAlign,
|
BackColor: element.background,
|
ForeColor: 'black'
|
}
|
|
if (!item.Width || !item.Height) {
|
item.Type = 'line'
|
item.Value = ''
|
item.Field = ''
|
item.FontFamily = element.fontFamily || ''
|
item.FontSize = element.fontSize || ''
|
item.FontStyle = (!element.fontWeight || element.fontWeight === 'normal') ? 'regular' : element.fontWeight
|
item.Padding = 0
|
item.Trimming = ''
|
if (!item.Width) {
|
item.Width = item.BorderSize
|
item.Left = item.Left - item.Width + 0.1
|
} else if (!item.Height) {
|
item.Height = item.BorderSize
|
item.Top = item.Top - item.Height + 0.1
|
}
|
item.BackColor = element.borderColor
|
item.BorderSize = 0
|
} else if (item.Type === 'image') {
|
item.ImageWidth = element.imgWidth
|
item.ImageHeight = element.imgHeight
|
item.Trimming = ''
|
if (!item.Field) {
|
if (element.productValue && window.GLOB.systemType === 'production') {
|
item.Value = element.productValue
|
imgs.push(item.Value)
|
} else if (item.Value) {
|
imgs.push(item.Value)
|
}
|
}
|
} else if (item.Type === 'text') {
|
item.FontFamily = element.fontFamily
|
item.FontSize = element.fontSize
|
item.FontStyle = element.fontWeight === 'normal' ? 'regular' : element.fontWeight
|
item.Padding = element.padding / 2
|
item.Trimming = ''
|
} else if (item.Type === 'barcode') {
|
item.BarcodeType = element.barcodeType
|
item.BarcodeWidth = element.barcodeWidth
|
item.BarcodeHeight = element.barcodeHeight
|
item.BarcodeLabel = element.barcodeLabel
|
item.LabelSize = element.fontSize
|
} else if (item.Type === 'qrcode') {
|
item.Type = 'barcode'
|
item.BarcodeType = element.qrcodeType
|
item.BarcodeWidth = element.qrcodeWidth
|
item.BarcodeHeight = element.qrcodeWidth
|
item.BarcodeLabel = false
|
}
|
|
if (item.Field) {
|
fields.push(item.Field)
|
// 条码二维码字段不可为空
|
if (item.Type === 'barcode') {
|
nonEFields.push(item.Field)
|
}
|
} else if (!item.Value) {
|
// 条码二维码内容不可为空
|
if (item.Type === 'barcode') {
|
error = '模板中条码/二维码内容不可为空!'
|
}
|
}
|
|
control.push(item)
|
})
|
|
let down = false
|
|
if (rotate === 90 || rotate === 270) {
|
down = true
|
}
|
|
_configparam = {
|
Version: '',
|
Title: configParam.name,
|
Author: sessionStorage.getItem('UserID'),
|
Description: configParam.remark,
|
PrintTempNO: configParam.PrintTempNO,
|
PageSetting: {
|
Width: down ? configParam.height : configParam.width,
|
Height: down ? configParam.width : configParam.height,
|
Left: '0',
|
Right: '0',
|
Top: '0',
|
Bottom: '0',
|
Landscape: false
|
},
|
PageHeader: [],
|
ReportHeader: {
|
Control: control
|
},
|
ReportFooter: [],
|
PageFooter: []
|
}
|
}
|
}
|
|
return {
|
error: error,
|
config: _configparam,
|
fields: Array.from(new Set(fields)),
|
nonEFields: Array.from(new Set(nonEFields)),
|
imgs: imgs
|
}
|
}
|
|
execRfidPrint = (list, template) => {
|
const { btn } = this.props
|
|
list = list.filter(item => !!item[btn.verify.valueField])
|
|
if (list.length === 0) {
|
notification.warning({
|
top: 92,
|
message: window.GLOB.dict['no_data'] || '未获取到打印数据!',
|
duration: 5
|
})
|
this.setState({ loading: false })
|
return
|
}
|
|
let width = template.width
|
let height = template.height
|
let gap = template.gap || 0
|
let mm = 12
|
|
if (btn.verify.DPI === '203') {
|
mm = 8
|
} else if (btn.verify.DPI === '600') {
|
mm = 24
|
}
|
|
let items = []
|
template.elements.forEach(element => {
|
if (!['text', 'barcode', 'qrcode'].includes(element.type)) return
|
|
let _field = element.field
|
|
if (_field === 'other_field') {
|
_field = element.cusfield || ''
|
}
|
|
let item = {
|
type: element.type,
|
value: element.value || '',
|
field: _field
|
}
|
|
if (item.type === 'text') {
|
let size = Math.floor(4 * mm * (element.fontSize || 12) / 12)
|
let fontWeight = 400
|
if (element.fontWeight === 'bold') {
|
fontWeight = 600
|
} else if (element.fontWeight === 'bolder') {
|
fontWeight = 800
|
} else if (element.fontWeight === 'lighter') {
|
fontWeight = 300
|
}
|
item.draw = `${element.left * mm},${element.top * mm},${size},0,${element.fontFamily || '微软雅黑'},${element.align === 'center' ? 5 : 1},${fontWeight},0,0,0,`
|
} else if (item.type === 'barcode') {
|
let codeType = 1
|
if (element.barcodeType === 'EAN13') {
|
codeType = 'E30'
|
}
|
let narrowWidth = element.narrowWidth || 2
|
let horizontal = element.narrowWidth || 2
|
let vertical = Math.ceil(element.barcodeHeight * mm)
|
|
item.draw = `${element.left * mm},${element.top * mm},0,${codeType},${narrowWidth},${horizontal},${vertical},${element.barcodeLabel === 'true' ? 'B' : 'N'},`
|
} else if (item.type === 'qrcode') {
|
let r = Math.ceil(element.qrcodeWidth / 2)
|
|
item.draw = `${element.left * mm},${element.top * mm},0,0,0,${r},0,0,8,`
|
}
|
|
items.push(item)
|
})
|
|
let ip = '192.168.1.2'
|
let params = list.map(cell => {
|
let array = []
|
let value = cell[btn.verify.valueField]
|
|
if (btn.verify.linkType !== 'USB') {
|
array.push({PTK_Connect_Timer: `${ip},${btn.verify.port},5`}); // 打开打印机网络端口
|
} else {
|
array.push({PTK_OpenUSBPort: btn.verify.port}); // 打开打印机USB端口
|
}
|
|
array.push({PTK_ClearBuffer: ''}); // 清空缓存
|
array.push({PTK_SetDirection: 'B'}); // 设置打印方向
|
array.push({PTK_SetLabelHeight: height * mm + ',' + gap * mm + ',' + 0 + ',' + false}); // 设置标签高度、间隙及偏移
|
array.push({PTK_SetLabelWidth: width * mm}); // 设置标签宽度
|
array.push({PTK_SetRFID: '0,0,0,0,0'}); // UHF RFID打印设置
|
array.push({PTK_RWRFIDLabel: '1,0,0,4,1,' + value});
|
|
items.forEach(m => {
|
let val = ''
|
if (m.field) {
|
val = cell[m.field]
|
} else {
|
val = m.value
|
}
|
|
if (!val && val !== 0) return
|
|
if (m.type === 'text') {
|
array.push({PTK_DrawText_TrueType: m.draw + val});
|
} else if (m.type === 'barcode') {
|
array.push({PTK_DrawBarcode: m.draw + val});
|
} else if (m.type === 'qrcode') {
|
array.push({PTK_DrawBar2D_QR: m.draw + val});
|
}
|
})
|
|
array.push({PTK_PrintLabel: '1,1'});
|
array.push({PTK_CloseUSBPort: ''}); // 关闭USB通讯端口
|
|
return {
|
reqParam: '1',
|
printparams: JSON.stringify(array)
|
}
|
})
|
|
this.loopRFIDPrint(params)
|
}
|
|
loopRFIDPrint = (params) => {
|
let param = params.shift()
|
|
Api.postekPrint(param).then(res => {
|
if (res.retval === '0') {
|
if (params.length === 0) {
|
this.execSuccess({ ErrCode: 'S', message: window.GLOB.dict['print_out'] || '打印请求已发出。', status: true })
|
} else {
|
setTimeout(() => {
|
this.loopRFIDPrint(params)
|
}, 200)
|
}
|
} else {
|
if (res.retval === '30021') {
|
res.msg = res.msg.replace(/PTK_ClearBuffer[\s\S]*/, '')
|
}
|
|
this.execError({ErrCode: 'N', message: res.msg})
|
}
|
})
|
}
|
|
execPrint = (list, template) => {
|
const { btn } = this.props
|
const { dict } = this.state
|
|
let printReject = null
|
let send = false
|
|
let data = fromJS({
|
data: list,
|
template: template
|
}).toJS()
|
|
if (!window.GLOB.errorLog) {
|
printReject = (msg) => {
|
if (send) return
|
|
send = true
|
data.message = msg
|
|
window.mkInfo(JSON.stringify(data))
|
}
|
} else {
|
printReject = (msg) => {
|
if (send) return
|
|
send = true
|
data.message = msg
|
|
let param = {
|
func: 's_special_error_note_log',
|
api_url: btn.logLabel,
|
error_code: 507,
|
error_time: moment().format('YYYY-MM-DD HH:mm:ss'),
|
api_param: JSON.stringify(data)
|
}
|
Api.genericInterface(param)
|
}
|
}
|
|
let _errors = []
|
|
let defaultPrinter = btn.verify.defaultPrinter || 'lackprinter'
|
let printers = {}
|
if (btn.verify.printerTypeList && btn.verify.printerTypeList.length > 0) {
|
btn.verify.printerTypeList.forEach(cell => {
|
if (cell.printer) {
|
printers[cell.Value] = cell.printer
|
}
|
})
|
}
|
|
let printdata = {}
|
|
list.forEach(res => {
|
let _printer = defaultPrinter
|
|
if (res.printType && printers[res.printType]) {
|
_printer = printers[res.printType]
|
}
|
|
printdata[_printer] = printdata[_printer] || []
|
|
printdata[_printer].push(res)
|
})
|
|
let printerList = []
|
|
Object.keys(printdata).forEach(printer => {
|
Object.keys(template).forEach(key => {
|
let _datalist = printdata[printer].filter(cell => cell.templateID === key)
|
|
if (_datalist.length === 0) return
|
|
let _data = []
|
_datalist.forEach(res => {
|
res.data.forEach(_cell => {
|
for (let i = 0; i < res.printCount; i++) {
|
_data.push(_cell)
|
}
|
})
|
})
|
|
let lacks = []
|
let emptys = []
|
|
_data.forEach(d => {
|
template[key].fields.forEach(f => {
|
if (!d.hasOwnProperty(f)) {
|
lacks.push(f)
|
} else if (template[key].nonEFields.includes(f) && !d[f] && d[f] !== 0) {
|
emptys.push(f)
|
}
|
})
|
})
|
|
if (lacks.length > 0 || emptys.length > 0) {
|
_errors.push({
|
title: template[key].config.Title,
|
lacks: lacks,
|
emptys: emptys
|
})
|
}
|
|
let results = []
|
let num = 100
|
for(let i = 0, len = _data.length; i < len; i += num){
|
results.push(_data.slice(i, i + num))
|
}
|
|
results.forEach(result => {
|
let _cell = {
|
documentID: Utils.getuuid(),
|
contents: [
|
{
|
data: result,
|
templateURL: JSON.stringify(template[key].config)
|
}
|
]
|
}
|
|
printerList.push({
|
cmd: 'print',
|
requestID: Utils.getuuid(),
|
version: Utils.getuuid(),
|
task: {
|
taskID: Utils.getuuid(),
|
preview: false,
|
printer: printer === 'lackprinter' ? '' : printer,
|
documents: [_cell]
|
}
|
})
|
})
|
})
|
})
|
|
if (list.length === 0) {
|
if (btn.verify.emptyTip === 'false') {
|
this.execSuccess({
|
ErrCode: '-1',
|
message: dict['no_data'] || '未获取到打印信息!',
|
status: true
|
})
|
} else {
|
this.execError({
|
ErrCode: 'N',
|
message: dict['no_data'] || '未获取到打印信息!',
|
status: false
|
})
|
}
|
return
|
} else if (_errors.length > 0) {
|
let lackerror = []
|
let emptyerror = []
|
|
_errors.forEach(err => {
|
if (err.lacks.length > 0) {
|
lackerror.push(`数据中未获取到模板(${err.title})${err.lacks.join('、')} 字段`)
|
}
|
if (err.emptys.length > 0) {
|
emptyerror.push(dict['not_empty'] ? `${err.title}: ${err.emptys.join('、')} ${dict['not_empty']}` : `数据中模板(${err.title}) ${err.emptys.join('、')} 字段不可为空`)
|
}
|
})
|
|
let msg = []
|
if (lackerror.length > 0) {
|
msg.push(lackerror.join(' ; '))
|
}
|
|
if (emptyerror.length > 0) {
|
msg.push(emptyerror.join(' ; '))
|
}
|
|
this.execError({
|
ErrCode: 'N',
|
message: msg.join(' ; ') + ' !',
|
status: false
|
})
|
return
|
}
|
|
if (printerList.length === 0) {
|
this.execSuccess({
|
ErrCode: '-1',
|
message: dict['no_data'] || '未获取到打印信息!',
|
status: true
|
})
|
return
|
}
|
|
if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) {
|
socket = new WebSocket('ws://' + btn.verify.linkUrl)
|
} else {
|
this.syncMessageSend(printerList, () => {
|
this.execSuccess({
|
ErrCode: 'S',
|
message: dict['print_out'] || '打印请求已发出。',
|
status: true
|
})
|
})
|
}
|
|
// 打开Socket
|
socket.onopen = () =>{
|
this.syncMessageSend(printerList, () => {
|
this.execSuccess({
|
ErrCode: 'S',
|
message: dict['print_out'] || '打印请求已发出。',
|
status: true
|
})
|
})
|
}
|
// 监听消息
|
socket.onmessage = (event) => {
|
let data = ''
|
|
if (event.data) {
|
try {
|
data = JSON.parse(event.data)
|
} catch (e) {
|
this.execError({
|
ErrCode: 'N',
|
message: event.data,
|
status: false
|
})
|
|
data = ''
|
}
|
}
|
|
// if (data && data.cmd === 'getPrinters' && data.status) {
|
// printerList = printerList.map(cell => {
|
// if (cell.task.printer === 'lackprinter') {
|
// cell.task.printer = data.defaultPrinter
|
// }
|
// return cell
|
// })
|
|
// this.syncMessageSend(printerList)
|
|
// this.execSuccess({
|
// ErrCode: 'S',
|
// message: '打印请求已发出。',
|
// status: true
|
// })
|
// } else if (data && data.message && !data.status) {
|
if (data && data.message && !data.status) {
|
this.execError({
|
ErrCode: 'N',
|
message: data.message,
|
status: false
|
})
|
|
printReject(data.message)
|
}
|
}
|
|
socket.onerror = () => {
|
this.execError({
|
ErrCode: 'N',
|
message: (dict['un_connect'] || '无法连接到') + ':' + btn.verify.linkUrl,
|
status: false
|
})
|
}
|
}
|
|
syncMessageSend = (list, callback) => {
|
let param = list.shift()
|
|
if (socket) {
|
try {
|
socket.send(JSON.stringify(param))
|
} catch(e) {
|
console.warn('打印请求发送失败!')
|
}
|
}
|
|
if (list.length > 0) {
|
setTimeout(() => {
|
this.syncMessageSend(list, callback)
|
}, 3000)
|
} else {
|
callback()
|
}
|
}
|
|
/**
|
* @description 操作成功后处理
|
* 1、excel导出,成功后取消导出按钮加载中状态
|
* 2、状态码为 S 时,显示成功信息后系统默认信息
|
* 3、状态码为 -1 时,不显示任何信息
|
* 4、模态框执行成功后是否关闭
|
* 5、通知主列表刷新
|
*/
|
execSuccess = (res = {}) => {
|
const { btn } = this.props
|
const { autoMatic, btnconfig, dict } = this.state
|
|
if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功
|
notification.success({
|
top: 92,
|
message: res.message || dict['exc_success'] || '执行成功!',
|
duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
|
})
|
} else if (res.ErrCode === 'Y') { // 执行成功
|
Modal.success({
|
title: res.message || dict['exc_success'] || '执行成功!',
|
okText: dict['got_it'] || '知道了'
|
})
|
} else if (res.ErrCode === '-1') { // 完成后不提示
|
|
}
|
|
if (autoMatic || !btnconfig || btnconfig.setting.finish !== 'unclose') {
|
this.setState({
|
visible: false
|
})
|
}
|
|
this.setState({
|
loading: false,
|
confirmLoading: false
|
})
|
|
if (autoMatic) {
|
MKEmitter.emit('autoExecOver', btn.uuid, 'success')
|
return
|
}
|
|
if (btn.execSuccess !== 'never') {
|
MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines)
|
}
|
|
if (btn.execSuccess === 'popclose' && btn.$tabId) { // 标签关闭刷新
|
MKEmitter.emit('refreshPopButton', btn.$tabId)
|
}
|
}
|
|
/**
|
* @description 操作失败后处理
|
* 1、状态码为 E、N、F、NM 时,显示相应提示信息
|
* 2、excel导出,失败后取消导出按钮加载中状态
|
* 3、通知主列表刷新
|
*/
|
execError = (res) => {
|
const { btn } = this.props
|
const { btnconfig, autoMatic, dict } = this.state
|
|
if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) {
|
res.ErrCode = 'E'
|
}
|
|
if (res.ErrCode === 'E' && !autoMatic) {
|
Modal.error({
|
title: res.message || dict['exc_fail'] || '执行失败!',
|
okText: dict['got_it'] || '知道了'
|
})
|
} else if (res.ErrCode === 'N' || autoMatic) {
|
notification.error({
|
top: 92,
|
message: res.message || dict['exc_fail'] || '执行失败!',
|
duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
|
})
|
} else if (res.ErrCode === 'F') {
|
notification.error({
|
className: 'notification-custom-error',
|
top: 92,
|
message: res.message || dict['exc_fail'] || '执行失败!',
|
duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
|
})
|
} else if (res.ErrCode === 'NM') {
|
message.error(res.message || dict['exc_fail'] || '执行失败!')
|
}
|
|
this.setState({
|
loading: false,
|
confirmLoading: false
|
})
|
|
if (autoMatic) {
|
MKEmitter.emit('autoExecOver', btn.uuid, 'error')
|
return
|
}
|
|
if (res.ErrCode === '-2') return
|
|
if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) {
|
MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus)
|
}
|
|
if (btn.execError !== 'never') {
|
MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
|
}
|
}
|
|
handleModelConfig = (config) => {
|
let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
|
config.fields = config.fields.map(cell => {
|
// 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
|
if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
|
let _option = Utils.getSelectQueryOptions(cell)
|
|
cell.base_sql = _option.sql
|
cell.arr_field = _option.field
|
}
|
|
// 字段权限黑名单
|
if (!cell.blacklist || cell.blacklist.length === 0) return cell
|
if (cell.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
|
cell.hidden = 'true'
|
}
|
|
return cell
|
})
|
return config
|
}
|
|
/**
|
* @description 获取按钮配置信息
|
*/
|
improveAction = () => {
|
const { btn } = this.props
|
const { btnconfig, autoMatic } = this.state
|
|
if (btnconfig) {
|
if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 如果表单以是否框展示
|
this.modelconfirm()
|
} else {
|
this.setState({
|
visible: true
|
})
|
|
if (btnconfig.setting.display === 'modal' && btnconfig.setting.moveable === 'true') {
|
setTimeout(() => {
|
this.setMove()
|
}, 100)
|
}
|
}
|
} else if (!btn.$old) {
|
notification.warning({
|
top: 92,
|
message: '未获取到按钮配置信息!',
|
duration: 5
|
})
|
this.setState({ loading: false })
|
} else {
|
Api.getCacheConfig({
|
func: 'sPC_Get_LongParam',
|
MenuID: btn.uuid
|
}).then(res => {
|
let _LongParam = ''
|
|
if (res.status && res.LongParam) {
|
try {
|
_LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_LongParam = ''
|
}
|
}
|
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
this.setState({ loading: false })
|
} else if (!_LongParam || (btn.execMode === 'pop' && _LongParam.type !== 'Modal')) {
|
notification.warning({
|
top: 92,
|
message: '未获取到按钮配置信息!',
|
duration: 5
|
})
|
this.setState({ loading: false })
|
} else {
|
_LongParam = updateForm(_LongParam)
|
_LongParam = this.handleModelConfig(_LongParam)
|
_LongParam.uuid = btn.uuid
|
|
this.setState({
|
btnconfig: _LongParam
|
}, () => {
|
if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 如果表单以是否框展示
|
this.modelconfirm()
|
} else {
|
this.setState({
|
visible: true
|
})
|
}
|
})
|
}
|
})
|
}
|
}
|
|
/**
|
* @description 模态框(表单),确认
|
*/
|
handleOk = () => {
|
if (!this.formRef) return
|
|
this.formRef.handleConfirm().then(res => {
|
this.setState({ confirmLoading: true })
|
this.triggerPrint(this.state.selines, res)
|
})
|
}
|
|
/**
|
* @description 模态框(表单),取消
|
*/
|
handleCancel = () => {
|
this.setState({
|
loading: false,
|
visible: false,
|
confirmLoading: false
|
})
|
}
|
|
modelconfirm = () => {
|
const { btnconfig, selines, dict } = this.state
|
let that = this
|
let result = []
|
let _data = {}
|
let BData = {}
|
|
if (selines[0]) {
|
Object.keys(selines[0]).forEach(key => {
|
_data[key.toLowerCase()] = selines[0][key]
|
})
|
}
|
if (this.props.BData) {
|
Object.keys(this.props.BData).forEach(key => {
|
BData[key.toLowerCase()] = this.props.BData[key]
|
})
|
}
|
|
btnconfig.fields.forEach(item => {
|
if (!item.field) return
|
|
let _item = {
|
key: item.field,
|
readin: item.readin !== 'false' && item.readin !== 'top',
|
fieldlen: item.fieldlength || 50,
|
writein: item.writein !== 'false',
|
type: item.type,
|
value: item.initval,
|
isconst: item.constant === 'true'
|
}
|
|
let key = item.field.toLowerCase()
|
let _readin = item.readin !== 'false'
|
|
if (item.type === 'linkMain' && item.verifyVal === 'true') {
|
_item.$verify = true
|
_item.label = item.label
|
}
|
if (_item.type === 'date') { // 时间兼容
|
_item.precision = item.precision || 'day'
|
} else if (_item.type === 'datetime') {
|
_item.type = 'date'
|
_item.precision = 'second'
|
} else if (['funcvar', 'linkMain'].includes(_item.type)) {
|
_readin = false
|
_item.readin = false
|
} else if (['select', 'link', 'radio'].includes(_item.type)) { // 选中第一项
|
if (/^\s*\$first\s*$/.test(_item.value)) {
|
_item.value = ''
|
|
if (item.resourceType === '0' && item.options[0] && item.options[0].Value) {
|
_item.value = item.options[0].Value
|
}
|
}
|
}
|
|
if (_item.type === 'funcvar') {
|
_item.value = ''
|
} else if (_item.type === 'linkMain' && BData.hasOwnProperty(key)) {
|
_item.value = BData[key]
|
} else if (_readin && _data.hasOwnProperty(key)) {
|
_item.value = _data[key]
|
} else if (_item.type === 'date' && _item.value) {
|
_item.value = moment().subtract(_item.value, 'days').format(_item.precision === 'day' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss')
|
} else if (_item.type === 'datemonth' && _item.value) {
|
_item.value = moment().subtract(_item.value, 'month').format('YYYY-MM')
|
}
|
|
_item.value = _item.value === undefined ? '' : _item.value
|
|
if (_item.type === 'number' || item.declare === 'decimal') {
|
_item.type = 'number'
|
_item.fieldlen = item.decimal || 0
|
} else if (['text', 'textarea', 'linkMain'].includes(_item.type)) {
|
_item.value = _item.value + ''
|
_item.value = _item.value.replace(/\t+|\v+/g, '') // 去除制表符
|
|
if (item.interception !== 'false') { // 去除首尾空格
|
if (item.interception === 'func') {
|
try {
|
// eslint-disable-next-line
|
let func = new Function('value', 'data', item.func)
|
_item.value = func(_item.value, _data)
|
_item.value = _item.value !== undefined ? _item.value : ''
|
} catch (e) {
|
console.warn(e)
|
_item.value = ''
|
}
|
} else if (item.interception === 'charTure') {
|
let str = _item.value.replace(/(^\s*|\s*$)/g, '')
|
let result = ''
|
for (let i = 0 ; i < str.length; i++) {
|
let code = str.charCodeAt(i)
|
if (code >= 65281 && code <= 65373) {
|
result += String.fromCharCode(str.charCodeAt(i) - 65248)
|
} else if (code === 12288) {
|
result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32)
|
} else {
|
result += str.charAt(i)
|
}
|
}
|
_item.value = result
|
} else {
|
_item.value = _item.value.replace(/(^\s*|\s*$)/g, '')
|
}
|
}
|
if (_item.type === 'text') {
|
if (/@appkey@|@SessionUid@|@bid@/ig.test(_item.value)) { // 特殊字段替换
|
_item.value = _item.value.replace(/^(\s*)@appkey@(\s*)$/ig, window.GLOB.appkey).replace(/^(\s*)@SessionUid@(\s*)$/ig, (localStorage.getItem('SessionUid') || '')).replace(/^(\s*)@bid@(\s*)$/ig, (this.props.BID || ''))
|
}
|
if (/@currentYear@/ig.test(_item.value)) { // 系统变量替换
|
_item.value = _item.value.replace(/@currentYear@/ig, moment().format('YYYY'))
|
}
|
}
|
if (_item.type === 'text' && item.lenControl && item.lenControl !== 'limit') {
|
if (item.lenControl === 'left') {
|
_item.value = _item.value.substr(0, item.fieldlength)
|
} else {
|
_item.value = _item.value.slice(-item.fieldlength)
|
}
|
}
|
} else if (_item.type === 'datemonth') {
|
_item.type = 'text'
|
} else if (_item.type === 'date') {
|
_item.type = item.declareType === 'nvarchar(50)' ? 'text' : 'date'
|
} else if (_item.type === 'switch' || _item.type === 'check') {
|
if (_readin) {
|
_item.value = _item.value === item.openVal ? item.openVal : item.closeVal
|
} else {
|
if (item.initval === true) {
|
_item.value = item.openVal
|
} else {
|
_item.value = item.closeVal
|
}
|
}
|
} else if (_item.type === 'rate') {
|
let count = item.rateCount || 5
|
_item.value = parseInt(_item.value)
|
|
if (isNaN(_item.value) || _item.value < 0) {
|
_item.value = 0
|
} else if (_item.value > count) {
|
_item.value = count
|
}
|
}
|
|
result.push(_item)
|
})
|
|
if (btnconfig.setting.display === 'exec') {
|
this.execSubmit(selines, () => {}, result)
|
} else {
|
confirm({
|
title: dict['exec_sure'] || '确定要执行吗?',
|
okText: dict['ok'] || '确定',
|
cancelText: dict['cancel'] || '取消',
|
onOk() {
|
that.triggerPrint(selines, result)
|
},
|
onCancel() {
|
that.setState({ loading: false })
|
}
|
})
|
}
|
}
|
|
/**
|
* @description 显示模态框
|
*/
|
getModels = () => {
|
const { BID, btn } = this.props
|
const { btnconfig, dict } = this.state
|
|
if (!this.state.visible || !btnconfig || !btnconfig.setting) return null
|
|
let title = btn.label
|
let width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + 'vw'
|
let clickouter = false
|
let container = document.body
|
|
if (btnconfig.setting.container === 'tab' && btn.ContainerId) {
|
width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%'
|
container = () => document.getElementById(btn.ContainerId)
|
}
|
|
if (btnconfig.setting.clickouter === 'close') {
|
clickouter = true
|
}
|
|
if (btnconfig.setting.icon) {
|
title = <>
|
<span className={'mk-modal-icon-' + btnconfig.setting.iconType} style={{background: btnconfig.setting.iconColor || 'unset', color: btnconfig.setting.iconColor || 'inherit'}}><MkIcon type={btnconfig.setting.icon}/></span>
|
{title}
|
</>
|
}
|
|
return (
|
<Modal
|
title={title}
|
maskClosable={clickouter}
|
getContainer={container}
|
wrapClassName={'action-modal' + (btnconfig.setting.moveable === 'true' ? ' moveable-modal modal-' + btn.uuid : '')}
|
visible={this.state.visible}
|
confirmLoading={this.state.confirmLoading}
|
width={width}
|
okText={dict['ok'] || '确定'}
|
cancelText={dict['cancel'] || '取消'}
|
maskStyle={btnconfig.setting.moveable === 'true' ? {backgroundColor: 'rgba(0, 0, 0, 0.15)'} : null}
|
onOk={this.handleOk}
|
onCancel={this.handleCancel}
|
destroyOnClose
|
>
|
<MutilForm
|
BID={BID}
|
action={btnconfig}
|
inputSubmit={this.handleOk}
|
data={this.state.selines[0]}
|
BData={this.props.BData}
|
wrappedComponentRef={(inst) => this.formRef = inst}
|
/>
|
</Modal>
|
)
|
}
|
|
setMove = () => {
|
const { btn } = this.props
|
let wrap = document.getElementsByClassName('modal-' + btn.uuid)[0]
|
|
if (!wrap) return
|
|
let node = wrap.getElementsByClassName('ant-modal-header')[0]
|
|
if (!node) return
|
|
node.onmousedown = function(e) {
|
let orileft = 0
|
let oritop = 0
|
let oleft = e.clientX
|
let otop = e.clientY
|
|
if (node.parentNode.style.left) {
|
orileft = parseFloat(node.parentNode.style.left)
|
}
|
if (node.parentNode.style.top) {
|
oritop = parseFloat(node.parentNode.style.top)
|
}
|
|
document.onmousemove = function(e) {
|
let left = e.clientX - oleft
|
let top = e.clientY - otop
|
|
node.parentNode.style.left = (orileft + left) + 'px'
|
node.parentNode.style.top = (oritop + top) + 'px'
|
}
|
}
|
|
document.onmouseup = function() {
|
document.onmousemove = null
|
}
|
}
|
|
render() {
|
const { btn } = this.props
|
const { loading, disabled, hidden } = this.state
|
|
if (hidden) return null
|
|
let label = ''
|
|
if (btn.show === 'link') {
|
label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
|
} else if (btn.show === 'icon') {
|
label = !loading ? <MkIcon type={btn.icon} /> : null
|
} else {
|
label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span>
|
}
|
|
return <>
|
<Button
|
type="link"
|
id={'button' + btn.uuid}
|
title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
|
loading={loading}
|
disabled={disabled}
|
style={btn.style || null}
|
className={btn.hover || ''}
|
onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
|
>{label}</Button>
|
<span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span>
|
</>
|
}
|
}
|
|
export default PrintButton
|