| | |
| | | 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' |
| | |
| | | loading: false, |
| | | disabled: false, |
| | | hidden: false, |
| | | autoMatic: false |
| | | autoMatic: false, |
| | | dict: window.GLOB.dict |
| | | } |
| | | |
| | | UNSAFE_componentWillMount () { |
| | |
| | | */ |
| | | actionTrigger = (triggerId, record, type, lid) => { |
| | | const { BID, btn, selectedData, setting, LID } = this.props |
| | | const { loading, disabled } = this.state |
| | | const { loading, disabled, dict } = this.state |
| | | |
| | | if (loading || disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | | message: setting.supModTip || dict['sup_key_req'] || '需要上级主键值!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | |
| | | this.setState({autoMatic: type === 'autoMatic'}) |
| | | |
| | | let _this = this |
| | | let that = this |
| | | let data = record || selectedData || [] |
| | | |
| | | if (btn.Ot !== 'notRequired' && data.length === 0) { |
| | | // 需要选择行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择行!', |
| | | message: dict['select_row'] || '请选择行!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | // 需要选择单行时,校验数据 |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } 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: '自定义打印数据请设置数据源!', |
| | | message: dict['select_single_row'] || '请选择单行数据!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | let modal = this.state.btnconfig |
| | | if (!modal && btn.modal) { |
| | | modal = this.handleModelConfig(btn.modal) |
| | | modal.uuid = btn.uuid |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | } else if (btn.execMode === 'prompt') { |
| | | this.setState({ loading: true }) |
| | | confirm({ |
| | | title: '确定要执行吗?', |
| | | title: dict['exec_sure'] || '确定要执行吗?', |
| | | okText: dict['ok'] || '确定', |
| | | cancelText: dict['cancel'] || '取消', |
| | | onOk() { |
| | | _this.triggerPrint(data) |
| | | that.triggerPrint(data) |
| | | }, |
| | | onCancel() { |
| | | _this.setState({ loading: false }) |
| | | that.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } else { |
| | |
| | | if (list.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到打印数据!', |
| | | message: window.GLOB.dict['no_data'] || '未获取到打印数据!', |
| | | duration: 5 |
| | | }) |
| | | return false |
| | |
| | | if (!result.ConfigParam) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到打印模板信息!', |
| | | message: window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | |
| | | 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: '', |
| | |
| | | |
| | | try { |
| | | // eslint-disable-next-line |
| | | let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', 'callback', btn.verify.printFunc) |
| | | func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback) |
| | | 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' |
| | |
| | | |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '自定义函数执行错误!', |
| | | message: window.GLOB.dict['func_error'] || '自定义函数执行错误!', |
| | | duration: 5 |
| | | }) |
| | | |
| | | printReject(window.GLOB.dict['func_error'] || '自定义函数执行错误!') |
| | | } |
| | | } |
| | | |
| | |
| | | Promise.all(deffers).then(result => { |
| | | let errorMsg = '' |
| | | result.forEach(res => { |
| | | if (!res.status) { |
| | | if (!res.status && !errorMsg) { |
| | | errorMsg = res |
| | | } |
| | | }) |
| | |
| | | */ |
| | | 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(',') |
| | | |
| | |
| | | _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 custompage = /@pageSize@|@orderBy@/i.test(_dataresource + _customScript + _tailScript) |
| | | let regoptions = [ |
| | | { reg: /@orderBy@/ig, value: btn.verify.setting.order }, |
| | | { reg: /@pageSize@/ig, value: '9999' }, |
| | |
| | | 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)) { |
| | | if (isNaN(val) || val === '') { |
| | | val = 0 |
| | | } |
| | | _initvars.push(`@${_key}=${val}`) |
| | |
| | | |
| | | // 测试系统打印查询语句 |
| | | 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')) |
| | | _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) { |
| | |
| | | let imgs = [] |
| | | |
| | | if (!res.ConfigParam) { |
| | | error = '未获取到打印模板信息!' |
| | | error = window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!' |
| | | } else { |
| | | try { |
| | | configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam))) |
| | |
| | | if (item.Field) { |
| | | fields.push(item.Field) |
| | | // 条码二维码字段不可为空 |
| | | if (item.Type === 'qrcode' || item.Type === 'barcode') { |
| | | if (item.Type === 'barcode') { |
| | | nonEFields.push(item.Field) |
| | | } |
| | | } else if (!item.Value) { |
| | | // 条码二维码内容不可为空 |
| | | if (item.Type === 'barcode') { |
| | | error = '模板中条码/二维码内容不可为空!' |
| | | } |
| | | } |
| | | |
| | |
| | | if (list.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '未获取到打印数据!', |
| | | message: window.GLOB.dict['no_data'] || '未获取到打印数据!', |
| | | duration: 5 |
| | | }) |
| | | this.setState({ loading: false }) |
| | |
| | | Api.postekPrint(param).then(res => { |
| | | if (res.retval === '0') { |
| | | if (params.length === 0) { |
| | | this.execSuccess({ ErrCode: 'S', message: '打印请求已发出。', status: true }) |
| | | this.execSuccess({ ErrCode: 'S', message: window.GLOB.dict['print_out'] || '打印请求已发出。', status: true }) |
| | | } else { |
| | | setTimeout(() => { |
| | | this.loopRFIDPrint(params) |
| | |
| | | |
| | | 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' |
| | |
| | | if (btn.verify.emptyTip === 'false') { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '未获取到打印信息!', |
| | | message: dict['no_data'] || '未获取到打印信息!', |
| | | status: true |
| | | }) |
| | | } else { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '未获取到打印信息!', |
| | | message: dict['no_data'] || '未获取到打印信息!', |
| | | status: false |
| | | }) |
| | | } |
| | |
| | | lackerror.push(`数据中未获取到模板(${err.title})${err.lacks.join('、')} 字段`) |
| | | } |
| | | if (err.emptys.length > 0) { |
| | | emptyerror.push(`数据中模板(${err.title}) ${err.emptys.join('、')} 字段不可为空`) |
| | | emptyerror.push(dict['not_empty'] ? `${err.title}: ${err.emptys.join('、')} ${dict['not_empty']}` : `数据中模板(${err.title}) ${err.emptys.join('、')} 字段不可为空`) |
| | | } |
| | | }) |
| | | |
| | |
| | | if (printerList.length === 0) { |
| | | this.execSuccess({ |
| | | ErrCode: '-1', |
| | | message: '未获取到打印信息!', |
| | | message: dict['no_data'] || '未获取到打印信息!', |
| | | status: true |
| | | }) |
| | | return |
| | |
| | | this.syncMessageSend(printerList, () => { |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | message: dict['print_out'] || '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | }) |
| | |
| | | this.syncMessageSend(printerList, () => { |
| | | this.execSuccess({ |
| | | ErrCode: 'S', |
| | | message: '打印请求已发出。', |
| | | message: dict['print_out'] || '打印请求已发出。', |
| | | status: true |
| | | }) |
| | | }) |
| | |
| | | message: data.message, |
| | | status: false |
| | | }) |
| | | |
| | | printReject(data.message) |
| | | } |
| | | } |
| | | |
| | | socket.onerror = () => { |
| | | this.execError({ |
| | | ErrCode: 'N', |
| | | message: '无法连接到:' + btn.verify.linkUrl, |
| | | message: (dict['un_connect'] || '无法连接到') + ':' + btn.verify.linkUrl, |
| | | status: false |
| | | }) |
| | | } |
| | |
| | | */ |
| | | execSuccess = (res = {}) => { |
| | | const { btn } = this.props |
| | | const { autoMatic, btnconfig } = this.state |
| | | const { autoMatic, btnconfig, dict } = this.state |
| | | |
| | | if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功 |
| | | notification.success({ |
| | | top: 92, |
| | | message: res.message || '执行成功!', |
| | | 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 || '执行成功!' |
| | | title: res.message || dict['exc_success'] || '执行成功!', |
| | | okText: dict['got_it'] || '知道了' |
| | | }) |
| | | } else if (res.ErrCode === '-1') { // 完成后不提示 |
| | | |
| | |
| | | */ |
| | | execError = (res) => { |
| | | const { btn } = this.props |
| | | const { btnconfig, autoMatic } = this.state |
| | | 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 || '执行失败!', |
| | | title: res.message || dict['exc_fail'] || '执行失败!', |
| | | okText: dict['got_it'] || '知道了' |
| | | }) |
| | | } else if (res.ErrCode === 'N' || autoMatic) { |
| | | notification.error({ |
| | | top: 92, |
| | | message: res.message || '执行失败!', |
| | | 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 || '执行失败!', |
| | | 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 || '执行失败!') |
| | | message.error(res.message || dict['exc_fail'] || '执行失败!') |
| | | } |
| | | |
| | | this.setState({ |
| | |
| | | } else { |
| | | _LongParam = updateForm(_LongParam) |
| | | _LongParam = this.handleModelConfig(_LongParam) |
| | | _LongParam.uuid = btn.uuid |
| | | |
| | | this.setState({ |
| | | btnconfig: _LongParam |
| | |
| | | } |
| | | |
| | | modelconfirm = () => { |
| | | const { btnconfig, selines } = this.state |
| | | let _this = this |
| | | const { btnconfig, selines, dict } = this.state |
| | | let that = this |
| | | let result = [] |
| | | let _data = {} |
| | | let BData = {} |
| | |
| | | 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.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') { |
| | | 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') { |
| | |
| | | this.execSubmit(selines, () => {}, result) |
| | | } else { |
| | | confirm({ |
| | | title: '确定要执行吗?', |
| | | title: dict['exec_sure'] || '确定要执行吗?', |
| | | okText: dict['ok'] || '确定', |
| | | cancelText: dict['cancel'] || '取消', |
| | | onOk() { |
| | | _this.triggerPrint(selines, result) |
| | | that.triggerPrint(selines, result) |
| | | }, |
| | | onCancel() { |
| | | _this.setState({ loading: false }) |
| | | that.setState({ loading: false }) |
| | | } |
| | | }) |
| | | } |
| | |
| | | */ |
| | | getModels = () => { |
| | | const { BID, btn } = this.props |
| | | const { btnconfig } = this.state |
| | | const { btnconfig, dict } = this.state |
| | | |
| | | if (!this.state.visible || !btnconfig || !btnconfig.setting) return null |
| | | |
| | |
| | | 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} |