| | |
| | | |
| | | import Api from '@/api' |
| | | import Utils from '@/utils/utils.js' |
| | | import options from '@/store/options.js' |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import asyncSpinComponent from '@/utils/asyncSpinComponent' |
| | | import { updateForm } from '@/utils/utils-update.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | selectedData: PropTypes.any, // 子表中选择数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | MenuID: PropTypes.string, // 菜单ID |
| | | btn: PropTypes.object, // 按钮 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | columns: PropTypes.array, |
| | | disabled: PropTypes.any, // 行按钮禁用 |
| | | } |
| | | |
| | | state = { |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | visible: false, |
| | | formdata: null, |
| | | selines: null, |
| | | btnconfig: null, |
| | | confirmLoading: false, |
| | | loading: false, |
| | | disabled: false, |
| | | hidden: false, |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { btn, selectedData, BData } = this.props |
| | | let disabled = false |
| | | const { btn, selectedData, BData, disabled } = this.props |
| | | |
| | | if (btn.controlField && selectedData && selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | selectedData.forEach(item => { |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | this.setState({hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent') { |
| | | if (!BData || !BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (this.props.disabled || disabled) { |
| | | if (btn.controlField) { |
| | | this.setStatus(btn, selectedData || [], BData, disabled) |
| | | } else if (disabled) { |
| | | this.setState({disabled: true}) |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { btn, selectedData, BData } = this.props |
| | | const { btn } = this.props |
| | | |
| | | let disabled = false |
| | | if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) { |
| | | if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 表格中按钮隐藏控制 |
| | | nextProps.selectedData.forEach(item => { |
| | | let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | disabled = true |
| | | } |
| | | }) |
| | | } |
| | | this.setState({disabled, hidden: disabled && btn.control === 'hidden'}) |
| | | } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) { |
| | | if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | let s = nextProps.BData[btn.controlField] + '' |
| | | if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) { |
| | | this.setState({hidden: true}) |
| | | } else { |
| | | this.setState({hidden: false}) |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (nextProps.disabled || disabled) { |
| | | this.setState({disabled: true}) |
| | | if (btn.controlField) { |
| | | this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled) |
| | | } else { |
| | | this.setState({disabled: false}) |
| | | this.setState({disabled: nextProps.disabled === true}) |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | 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) => { |
| | |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { Tab, BID, btn, selectedData, setting } = this.props |
| | | const { BID, btn, selectedData, setting } = this.props |
| | | const { loading, disabled } = this.state |
| | | |
| | | if (loading || disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | |
| | | // 需要选择行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectline'], |
| | | message: '请选择行!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.confirm.selectSingleLine'], |
| | | message: '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (!['requiredSgl', 'notRequired', 'requiredOnce', 'required'].includes(btn.Ot)) { |
| | | // 数据选择类型校验 |
| | | this.actionSettingError() |
| | | return |
| | | } else if ( |
| | | !btn.verify || |
| | | (btn.verify.printMode === 'normal' && (!btn.verify.Template || !btn.verify.linkUrl)) || |
| | | (btn.verify.printMode === 'custom' && (!btn.verify.printFunc || !btn.verify.linkUrl)) |
| | | ) { |
| | | } else if (!btn.verify || !btn.verify.printMode) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请完善打印验证信息!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (btn.intertype === 'system' && btn.verify.dataType === 'custom' && (!btn.verify.setting || btn.verify.columns.length === 0)) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义打印数据请设置数据源!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | } else if (btn.execMode === 'prompt') { |
| | | this.setState({ loading: true }) |
| | | confirm({ |
| | | title: this.state.dict['main.action.confirm.tip'], |
| | | title: '确定要执行吗?', |
| | | onOk() { |
| | | _this.triggerPrint(data) |
| | | }, |
| | |
| | | } |
| | | } |
| | | |
| | | triggerPrint = (data, formlist = []) => { |
| | | const { btn } = this.props |
| | | |
| | | if (btn.verify.printMode === 'RFID') { |
| | | this.triggerRFIDPrint(data, formlist) |
| | | } else { |
| | | this.triggerNormalPrint(data, formlist) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 触发打印 |
| | | */ |
| | | triggerPrint = (data, formlist = []) => { |
| | | triggerNormalPrint = (data, formlist) => { |
| | | const { btn } = this.props |
| | | let formdata = {} |
| | | let baseCount = 1 |
| | | let baseType = '' |
| | | let baseTemp = btn.verify.Template || '' |
| | | |
| | | formlist.forEach(_data => { |
| | | formdata[_data.key] = _data.value |
| | | |
| | | if (!_data.value) return |
| | | |
| | | if (_data.key.toLowerCase() === 'printcount') { |
| | | baseCount = +_data.value |
| | | } else if (_data.key.toLowerCase() === 'printtype') { |
| | | baseType = _data.value |
| | | } else if (_data.key.toLowerCase() === 'templateid') { |
| | | baseTemp = _data.value |
| | | } |
| | | let _key = _data.key.toLowerCase() |
| | | formdata[_key] = _data.value |
| | | }) |
| | | |
| | | let printlist = [] |
| | | let templates = [] |
| | | |
| | | if (isNaN(baseCount) || baseCount < 1) { |
| | | baseCount = 1 |
| | | } |
| | | |
| | | new Promise(resolve => { |
| | | if (btn.intertype === 'system') { // 使用系统时,直接从表格或表单中选取数据 |
| | | if (btn.intertype === 'system' && btn.verify.dataType !== 'custom') { // 使用系统时,直接从表格或表单中选取数据 |
| | | if (btn.Ot === 'notRequired') { |
| | | let printcell = {} |
| | | |
| | | printcell.printType = baseType |
| | | printcell.printCount = baseCount |
| | | printcell.templateID = baseTemp |
| | | 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 = {...cell, ...formdata} |
| | | let _cell = {} |
| | | |
| | | Object.keys(cell).forEach(key => { |
| | | let _key = key.toLowerCase() |
| | | _cell[_key] = cell[key] |
| | | }) |
| | | |
| | | _cell = {..._cell, ...formdata} |
| | | |
| | | let printcell = {data: [_cell]} |
| | | |
| | | printcell.templateID = baseTemp |
| | | printcell.printType = baseType |
| | | printcell.printCount = 0 |
| | | |
| | | Object.keys(_cell).forEach(key => { |
| | | if (!_cell[key]) return |
| | | |
| | | let _key = key.toLowerCase() |
| | | |
| | | if (_key === 'templateid') { |
| | | printcell.templateID = _cell[key] |
| | | } else if (_key === 'printtype') { |
| | | printcell.printType = _cell[key] |
| | | } else if (_key === 'printcount') { |
| | | printcell.printCount = +_cell[key] |
| | | } |
| | | }) |
| | | 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 = baseCount |
| | | printcell.printCount = 1 |
| | | } |
| | | |
| | | templates.push(printcell.templateID) |
| | |
| | | }) |
| | | } |
| | | |
| | | resolve(true) |
| | | 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) { |
| | | if (!result.next) { |
| | | resolve(false) |
| | | return |
| | | } |
| | | |
| | | // 自定义打印 |
| | | if (btn.verify.printMode === 'custom') { |
| | | result.list.forEach(cell => { |
| | | // 系统打印数据,校验data字段 |
| | | if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return |
| | | |
| | | let templateID = baseTemp |
| | | let printType = baseType |
| | | let printCount = 0 |
| | | |
| | | Object.keys(cell).forEach(key => { |
| | | if (!cell[key]) return |
| | | |
| | | let _key = key.toLowerCase() |
| | | |
| | | if (_key === 'templateid') { |
| | | templateID = cell[key] |
| | | } else if (_key === 'printtype') { |
| | | printType = cell[key] |
| | | } else if (_key === 'printcount') { |
| | | printCount = +cell[key] |
| | | 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 |
| | | } |
| | | |
| | | cell.templateID = templateID |
| | | cell.printType = printType |
| | | cell.printCount = printCount |
| | | result.list.forEach(cell => { |
| | | // 系统打印数据,校验data字段 |
| | | if (!cell.data || cell.data.length === 0) return |
| | | |
| | | if (isNaN(cell.printCount) || cell.printCount < 1) { |
| | | cell.printCount = baseCount |
| | | 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(cell.templateID) |
| | | templates.push(printcell.templateID) |
| | | |
| | | printlist.push(cell) |
| | | printlist.push(printcell) |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | resolve(result.next) |
| | | resolve(true) |
| | | }) |
| | | } |
| | | }).then(res => { |
| | | // 获取打印模板 getTemp |
| | | if (!res) return false |
| | | |
| | | if (btn.verify.printMode === 'custom') { |
| | | this.execCustomPrint(printlist, formdata) |
| | | |
| | | return false |
| | | } |
| | | |
| | | templates = Array.from(new Set(templates)) // 去重 |
| | | |
| | |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | |
| | | Api.getLocalConfig(param).then(result => { |
| | | Api.getSystemCacheConfig(param).then(result => { |
| | | result.tempId = tempId |
| | | resolve(result) |
| | | }) |
| | |
| | | errorMsg = { |
| | | ErrCode: 'N', |
| | | message: _temp.error, |
| | | ErrMesg: _temp.error, |
| | | status: false |
| | | } |
| | | } else { |
| | |
| | | }) |
| | | } |
| | | |
| | | this.execPrint(printlist, _temps, formdata) |
| | | this.execPrint(printlist, _temps) |
| | | }, 500) |
| | | } else { |
| | | this.execPrint(printlist, _temps, formdata) |
| | | 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: '未获取到打印数据!', |
| | | 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: '未获取到打印模板信息!', |
| | | 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) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '', |
| | | ErrMesg: '', |
| | | status: true |
| | | }) |
| | | |
| | |
| | | * @description 获取打印数据 |
| | | */ |
| | | getprintdata = (btn, data, formdata, formlist) => { |
| | | const { setting } = this.props |
| | | const { setting, BID } = this.props |
| | | |
| | | let _list = [] |
| | | return new Promise(resolve => { |
| | | let params = [] |
| | | let param = {} |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | } |
| | | |
| | | if (btn.Ot === 'notRequired') { |
| | | let _param = { ...param, ...formdata } |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'requiredSgl') { |
| | | if (setting.primaryKey) { |
| | | param[setting.primaryKey] = data[0][setting.primaryKey] |
| | | } |
| | | |
| | | let _param = { ...param, ...formdata } |
| | | |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'requiredOnce') { |
| | | if (setting.primaryKey) { |
| | | let ids = data.map(d => { return d[setting.primaryKey]}) |
| | | ids = ids.filter(Boolean) |
| | | ids = ids.join(',') |
| | | if (btn.intertype === 'system' && btn.verify.dataType === 'custom') { |
| | | if (btn.Ot === 'notRequired') { |
| | | let _param = this.getDefaultSql(formlist, null, '') |
| | | |
| | | param[setting.primaryKey] = ids |
| | | } |
| | | |
| | | let _param = { ...param, ...formdata } |
| | | |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'required') { |
| | | params = data.map((cell, index) => { |
| | | let _param = { ...param } |
| | | |
| | | params.push(_param) |
| | | } else if (btn.Ot === 'requiredSgl') { |
| | | let ID = '' |
| | | if (setting.primaryKey) { |
| | | _param[setting.primaryKey] = cell[setting.primaryKey] |
| | | ID = data[0][setting.primaryKey] || '' |
| | | } |
| | | |
| | | let _cell = {} |
| | | if (index !== 0) { |
| | | Object.keys(cell).forEach(key => { |
| | | _cell[key.toLowerCase()] = cell[key] |
| | | }) |
| | | 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(',') |
| | | } |
| | | |
| | | 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 |
| | | 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) |
| | | }) |
| | | return _param |
| | | }) |
| | | } |
| | | } 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') { |
| | | params = params.map(_param => { |
| | | _param.func = btn.innerFunc |
| | | if (btn.intertype === 'inner' || btn.intertype === 'system') { |
| | | if (btn.intertype === 'inner') { |
| | | params = params.map(_param => { |
| | | _param.func = btn.innerFunc |
| | | |
| | | return _param |
| | | }) |
| | | if (btn.recordUser === 'true') { |
| | | _param.username = sessionStorage.getItem('User_Name') || '' |
| | | _param.fullname = sessionStorage.getItem('Full_Name') || '' |
| | | } |
| | | |
| | | return _param |
| | | }) |
| | | } |
| | | |
| | | if (params.length <= 20) { |
| | | let deffers = params.map(par => { |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description 获取默认存储过程请求参数 |
| | | */ |
| | | getDefaultSql = (formlist, data, ID) => { |
| | | const { BID, btn, columns } = this.props |
| | | |
| | | let arrFields = btn.verify.columns.map(col => col.field).join(',') |
| | | |
| | | let param = { |
| | | func: 'sPC_Get_TableData', |
| | | obj_name: 'data', |
| | | exec_type: '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 isDataM = sessionStorage.getItem('dataM') === 'true' |
| | | let regoptions = [ |
| | | { 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: /@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() |
| | | |
| | | if (_vars.includes(_key)) return |
| | | |
| | | _vars.push(_key) |
| | | |
| | | if (form.type === 'number' || form.type === 'rate') { |
| | | let val = form.value |
| | | if (isNaN(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) { |
| | | 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 && console.info(`${btn.logLabel ? `/*${btn.logLabel} 自定义脚本*/\n` : ''}${LText ? '' : '/*不执行默认sql*/\n'}${_customScript}`) |
| | | LText && console.info(`${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.LText = Utils.formatOptions(LText) |
| | | |
| | | 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 => { |
| | | // 内部请求 |
| | |
| | | // 外部请求 |
| | | _outParam = JSON.parse(JSON.stringify(res)) |
| | | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | res.rduri = options.cloudServiceApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | res.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | } |
| | | } 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 |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return Api.genericInterface(res) |
| | | }).then(response => { |
| | | if (!response) return |
| | | if (!response || response.ErrCode === 'LoginError') return |
| | | |
| | | if (btn.callbackFunc) { |
| | | 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 |
| | |
| | | |
| | | return Api.genericInterface(_callbackparam) |
| | | } else if (response.status) { |
| | | |
| | | _list.push(response) |
| | | |
| | | // 一次请求成功,进行下一项请求 |
| | |
| | | _resolve({next: false, list: []}) |
| | | } |
| | | }).then(response => { |
| | | if (!response) return |
| | | if (!response || response.ErrCode === 'LoginError') return |
| | | |
| | | if (response.status) { |
| | | _list.push(response) |
| | |
| | | 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 |
| | | let _field = element.field || '' |
| | | |
| | | if (_field === 'other_field') { |
| | | _field = element.cusfield || '' |
| | |
| | | Name: element.name || '', |
| | | Type: element.type, |
| | | Value: element.value || '', |
| | | Field: _field, |
| | | Left: element.left, |
| | | Top: element.top, |
| | | Field: _field.toLowerCase(), |
| | | Left: element.left + offsetLeft, |
| | | Top: element.top + offsetTop, |
| | | Width: element.width, |
| | | Height: element.height, |
| | | Rotate: element.rotate, |
| | | Rotate: rotate, |
| | | // Rotate: element.rotate, |
| | | BorderSize: element.borderSize / 10, |
| | | BorderColor: element.borderColor, |
| | | Align: element.align, |
| | |
| | | item.ImageWidth = element.imgWidth |
| | | item.ImageHeight = element.imgHeight |
| | | item.Trimming = '' |
| | | if (element.productValue && window.GLOB.systemType === 'production') { |
| | | item.Value = element.productValue |
| | | imgs.push(item.Value) |
| | | } else if (item.Value) { |
| | | imgs.push(item.Value) |
| | | 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 |
| | |
| | | control.push(item) |
| | | }) |
| | | |
| | | let down = false |
| | | |
| | | if (rotate === 90 || rotate === 270) { |
| | | down = true |
| | | } |
| | | |
| | | _configparam = { |
| | | Version: '', |
| | | Title: configParam.name, |
| | |
| | | Description: configParam.remark, |
| | | PrintTempNO: configParam.PrintTempNO, |
| | | PageSetting: { |
| | | Width: configParam.width, |
| | | Height: configParam.height, |
| | | Width: down ? configParam.height : configParam.width, |
| | | Height: down ? configParam.width : configParam.height, |
| | | Left: '0', |
| | | Right: '0', |
| | | Top: '0', |
| | |
| | | return { |
| | | error: error, |
| | | config: _configparam, |
| | | fields: fields, |
| | | nonEFields: nonEFields, |
| | | fields: Array.from(new Set(fields)), |
| | | nonEFields: Array.from(new Set(nonEFields)), |
| | | imgs: imgs |
| | | } |
| | | } |
| | | |
| | | execPrint = (list, template, formdata) => { |
| | | execRfidPrint = (list, template) => { |
| | | const { btn } = this.props |
| | | |
| | | list = list.filter(item => !!item[btn.verify.valueField]) |
| | | |
| | | if (list.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到打印数据!', |
| | | 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: '打印请求已发出。', 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 |
| | | let _errors = [] |
| | | |
| | | |
| | | let defaultPrinter = btn.verify.defaultPrinter || 'lackprinter' |
| | | let printers = {} |
| | | if (btn.verify.printerTypeList && btn.verify.printerTypeList.length > 0) { |
| | |
| | | _datalist.forEach(res => { |
| | | res.data.forEach(_cell => { |
| | | for (let i = 0; i < res.printCount; i++) { |
| | | _data.push({...formdata, ..._cell}) |
| | | _data.push(_cell) |
| | | } |
| | | }) |
| | | }) |
| | | |
| | | let _fields = Array.from(new Set(template[key].fields)) |
| | | let _nonEFields = Array.from(new Set(template[key].nonEFields)) |
| | | let lacks = [] |
| | | let emptys = [] |
| | | |
| | | _data.forEach(d => { |
| | | _fields.forEach(f => { |
| | | template[key].fields.forEach(f => { |
| | | if (!d.hasOwnProperty(f)) { |
| | | lacks.push(f) |
| | | } else if (_nonEFields.includes(f) && !d[f] && d[f] !== 0) { |
| | | } else if (template[key].nonEFields.includes(f) && !d[f] && d[f] !== 0) { |
| | | emptys.push(f) |
| | | } |
| | | }) |
| | | }) |
| | | |
| | | if (lacks.length > 0 || emptys.length > 0) { |
| | | lacks = Array.from(new Set(lacks)) |
| | | emptys = Array.from(new Set(emptys)) |
| | | |
| | | _errors.push({ |
| | | title: template[key].config.Title, |
| | | lacks: lacks, |
| | |
| | | }) |
| | | |
| | | if (list.length === 0) { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '未获取到打印信息!', |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | if (btn.verify.emptyTip === 'false') { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '未获取到打印信息!', |
| | | status: true |
| | | }) |
| | | } else { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '未获取到打印信息!', |
| | | status: false |
| | | }) |
| | | } |
| | | return |
| | | } else if (_errors.length > 0) { |
| | | let lackerror = [] |
| | |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: msg.join(' ; ') + ' !', |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | return |
| | | } |
| | | |
| | | // let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] |
| | | |
| | | if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) { |
| | | socket = new WebSocket('ws://' + btn.verify.linkUrl) |
| | | } else { |
| | | // if (lackItems) { |
| | | // let request = { |
| | | // requestID: '', |
| | | // version: '', |
| | | // cmd: 'getPrinters' |
| | | // } |
| | | // socket.send(JSON.stringify(request)) |
| | | // } else { |
| | | this.syncMessageSend(printerList) |
| | | this.syncMessageSend(printerList) |
| | | |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '', |
| | | ErrMesg: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | // } |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | } |
| | | |
| | | // 打开Socket |
| | | socket.onopen = () =>{ |
| | | // if (lackItems) { |
| | | // let request = { |
| | | // requestID: '', |
| | | // version: '', |
| | | // cmd: 'getPrinters' |
| | | // } |
| | | // socket.send(JSON.stringify(request)) |
| | | // } else { |
| | | this.syncMessageSend(printerList) |
| | | this.syncMessageSend(printerList) |
| | | |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '', |
| | | ErrMesg: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | // } |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | } |
| | | // 监听消息 |
| | | socket.onmessage = (event) => { |
| | |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: event.data, |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | |
| | |
| | | |
| | | // this.execSuccess({ |
| | | // ErrCode: 'S', |
| | | // message: '', |
| | | // ErrMesg: '打印请求已发出。', |
| | | // message: '打印请求已发出。', |
| | | // status: true |
| | | // }) |
| | | // } else if (data && data.message && !data.status) { |
| | |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: data.message, |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | } |
| | |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '无法连接到:' + btn.verify.linkUrl, |
| | | ErrMesg: '', |
| | | status: false |
| | | }) |
| | | } |
| | |
| | | * 4、模态框执行成功后是否关闭 |
| | | * 5、通知主列表刷新 |
| | | */ |
| | | execSuccess = (res) => { |
| | | execSuccess = (res = {}) => { |
| | | const { btn } = this.props |
| | | const { autoMatic } = this.state |
| | | const { autoMatic, btnconfig } = this.state |
| | | |
| | | if ((res && (res.ErrCode === 'S' || !res.ErrCode)) || autoMatic) { // 执行成功 |
| | | if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.ErrMesg || this.state.dict['main.action.confirm.success'], |
| | | message: res.message || '执行成功!', |
| | | duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2 |
| | | }) |
| | | } else if (res && res.ErrCode === 'Y') { // 执行成功 |
| | | } else if (res.ErrCode === 'Y') { // 执行成功 |
| | | Modal.success({ |
| | | title: res.ErrMesg || this.state.dict['main.action.confirm.success'] |
| | | title: res.message || '执行成功!' |
| | | }) |
| | | } else if (res && res.ErrCode === '-1') { // 完成后不提示 |
| | | } else if (res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | | } |
| | | |
| | | if (autoMatic || !btnconfig || btnconfig.setting.finish !== 'unclose') { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: false |
| | | loading: false, |
| | | confirmLoading: false |
| | | }) |
| | | |
| | | if (autoMatic) { |
| | |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | |
| | | const { btn } = this.props |
| | | const { btnconfig, autoMatic } = 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 || res.ErrMesg, |
| | | title: res.message || '执行失败!', |
| | | }) |
| | | } else if (res.ErrCode === 'N' || autoMatic) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || res.ErrMesg, |
| | | message: res.message || '执行失败!', |
| | | 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 || res.ErrMesg, |
| | | message: res.message || '执行失败!', |
| | | duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10 |
| | | }) |
| | | } else if (res.ErrCode === 'NM') { |
| | | message.error(res.message || res.ErrMesg) |
| | | message.error(res.message || '执行失败!') |
| | | } |
| | | |
| | | this.setState({ |
| | | loading: false |
| | | loading: false, |
| | | confirmLoading: false |
| | | }) |
| | | |
| | | if (autoMatic) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 按钮配置信息错误提示 |
| | | */ |
| | | actionSettingError = () => { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['main.action.settingerror'], |
| | | duration: 5 |
| | | }) |
| | | } |
| | | |
| | | handleModelConfig = (config) => { |
| | | let roleId = sessionStorage.getItem('role_id') || '' // 角色ID |
| | | config.fields = config.fields.map(cell => { |
| | |
| | | if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') { |
| | | let _option = Utils.getSelectQueryOptions(cell) |
| | | |
| | | cell.data_sql = Utils.formatOptions(_option.sql) |
| | | cell.base_sql = window.btoa(window.encodeURIComponent(_option.sql)) |
| | | cell.base_sql = _option.sql |
| | | cell.arr_field = _option.field |
| | | } |
| | | |
| | |
| | | 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', |
| | |
| | | * @description 模态框(表单),确认 |
| | | */ |
| | | handleOk = () => { |
| | | const { btnconfig, autoMatic } = this.state |
| | | |
| | | if (!this.formRef) return |
| | | |
| | | this.formRef.handleConfirm().then(res => { |
| | | if (btnconfig.setting.finish !== 'unclose' || autoMatic) { |
| | | this.setState({ |
| | | visible: false |
| | | }) |
| | | } |
| | | this.setState({ confirmLoading: true }) |
| | | this.triggerPrint(this.state.selines, res) |
| | | }) |
| | | } |
| | |
| | | handleCancel = () => { |
| | | this.setState({ |
| | | loading: false, |
| | | visible: false |
| | | visible: false, |
| | | confirmLoading: false |
| | | }) |
| | | } |
| | | |
| | |
| | | |
| | | btnconfig.fields.forEach(item => { |
| | | if (!item.field) return |
| | | let _readin = item.readin !== 'false' |
| | | let _initval = item.initval |
| | | |
| | | if (item.type === 'linkMain' || item.type === 'funcvar') { |
| | | _readin = false |
| | | } |
| | | |
| | | if (item.type === 'linkMain' && BData.hasOwnProperty(item.field.toLowerCase())) { |
| | | _initval = BData[item.field.toLowerCase()] |
| | | } else if (_readin && _data.hasOwnProperty(item.field.toLowerCase())) { |
| | | _initval = _data[item.field.toLowerCase()] |
| | | } else if (item.type === 'date' && _initval) { |
| | | _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD') |
| | | } else if (item.type === 'datemonth' && _initval) { |
| | | _initval = moment().subtract(_initval, 'month').format('YYYY-MM') |
| | | } else if (item.type === 'datetime' && _initval) { |
| | | _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD HH:mm:ss') |
| | | } |
| | | |
| | | let _fieldlen = item.fieldlength || 50 |
| | | if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') { |
| | | _fieldlen = item.fieldlength || 512 |
| | | } else if (item.type === 'number') { |
| | | _fieldlen = item.decimal ? item.decimal : 0 |
| | | } else if (item.type === 'rate') { |
| | | item.rateCount = item.rateCount || 5 |
| | | let allowHalf = item.allowHalf === 'true' |
| | | |
| | | if (allowHalf) { |
| | | _initval = parseFloat(_initval) |
| | | if (_initval % 0.5 !== 0) { |
| | | _initval = parseInt(_initval) |
| | | } |
| | | } else { |
| | | _initval = parseInt(_initval) |
| | | } |
| | | |
| | | if (isNaN(_initval) || _initval < 0) { |
| | | _initval = 0 |
| | | } else if (_initval > item.rateCount) { |
| | | _initval = item.rateCount |
| | | } |
| | | } |
| | | |
| | | if (_initval === undefined) { |
| | | _initval = '' |
| | | } |
| | | |
| | | result.push({ |
| | | let _item = { |
| | | key: item.field, |
| | | readonly: item.readonly === 'true', |
| | | readin: item.readin !== 'false' && item.readin !== 'top', |
| | | fieldlen: _fieldlen, |
| | | fieldlen: item.fieldlength || 50, |
| | | writein: item.writein !== 'false', |
| | | type: item.type, |
| | | value: _initval |
| | | }) |
| | | value: item.initval, |
| | | isconst: item.constant === 'true' |
| | | } |
| | | |
| | | let key = item.field.toLowerCase() |
| | | let _readin = item.readin !== 'false' |
| | | |
| | | 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 { |
| | | _item.value = _item.value.replace(/(^\s*|\s*$)/g, '') |
| | | } |
| | | } |
| | | if (_item.type === 'text' && /@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 (_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: this.state.dict['main.action.confirm.tip'], |
| | | title: '确定要执行吗?', |
| | | onOk() { |
| | | _this.triggerPrint(selines, result) |
| | | }, |
| | |
| | | * @description 显示模态框 |
| | | */ |
| | | getModels = () => { |
| | | const { setting, BID, btn } = this.props |
| | | const { BID, btn } = this.props |
| | | const { btnconfig } = this.state |
| | | |
| | | if (!this.state.visible || !btnconfig || !btnconfig.setting) return null |
| | |
| | | let clickouter = false |
| | | let container = document.body |
| | | |
| | | if ( |
| | | (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || |
| | | (btnconfig.setting.container === 'tab' && btn.ContainerId) |
| | | ) { |
| | | if (btnconfig.setting.container === 'tab' && btn.ContainerId) { |
| | | width = btnconfig.setting.width > 100 ? btnconfig.setting.width : btnconfig.setting.width + '%' |
| | | container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) |
| | | container = () => document.getElementById(btn.ContainerId) |
| | | } |
| | | |
| | | if (btnconfig.setting.clickouter === 'close') { |
| | |
| | | title={title} |
| | | maskClosable={clickouter} |
| | | getContainer={container} |
| | | wrapClassName='action-modal' |
| | | wrapClassName={'action-modal' + (btnconfig.setting.moveable === 'true' ? ' moveable-modal modal-' + btn.uuid : '')} |
| | | visible={this.state.visible} |
| | | confirmLoading={this.state.confirmLoading} |
| | | width={width} |
| | | maskStyle={btnconfig.setting.moveable === 'true' ? {backgroundColor: 'rgba(0, 0, 0, 0.15)'} : null} |
| | | onOk={this.handleOk} |
| | | onCancel={this.handleCancel} |
| | | destroyOnClose |
| | | > |
| | | <MutilForm |
| | | BID={BID} |
| | | dict={this.state.dict} |
| | | action={btnconfig} |
| | | inputSubmit={this.handleOk} |
| | | data={this.state.selines[0]} |
| | |
| | | /> |
| | | </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() { |
| | |
| | | return <> |
| | | <Button |
| | | type={type} |
| | | id={'button' + btn.uuid} |
| | | title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')} |
| | | loading={loading} |
| | | disabled={disabled} |