From bde2916433c7830e2879e6524e32b9f6c8bd0bab Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 02 一月 2022 16:31:32 +0800 Subject: [PATCH] 2022-01-02 --- src/tabviews/zshare/actionList/printbutton/index.jsx | 828 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 595 insertions(+), 233 deletions(-) diff --git a/src/tabviews/zshare/actionList/printbutton/index.jsx b/src/tabviews/zshare/actionList/printbutton/index.jsx index d2af58f..0e0ceb7 100644 --- a/src/tabviews/zshare/actionList/printbutton/index.jsx +++ b/src/tabviews/zshare/actionList/printbutton/index.jsx @@ -11,7 +11,10 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import asyncSpinComponent from '@/utils/asyncSpinComponent' -import './index.scss' +import { updateForm } from '@/utils/utils-update.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 @@ -28,26 +31,49 @@ btn: PropTypes.object, // 鎸夐挳 setting: PropTypes.any, // 椤甸潰閫氱敤璁剧疆 ContainerId: PropTypes.any, // tab椤甸潰ID锛岀敤浜庡脊绐楁帶鍒� - updateStatus: PropTypes.func, // 鎸夐挳鐘舵�佹洿鏂� - triggerBtn: PropTypes.any, + disabled: PropTypes.any, // 琛屾寜閽鐢� } state = { dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, visible: false, formdata: null, - tabledata: null, + selines: null, btnconfig: null, loading: false, - loadingNumber: '' + disabled: false, + hidden: false, + loadingNumber: '', + autoMatic: false } - /** - * @description 澶栭儴瑙﹀彂鎸夐挳鐐瑰嚮 - */ - UNSAFE_componentWillReceiveProps(nextProps) { - if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.button.uuid === this.props.btn.uuid) { - this.actionTrigger(nextProps.triggerBtn.data) + UNSAFE_componentWillMount () { + const { btn, selectedData, BData } = this.props + let disabled = false + + if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� + selectedData.forEach(item => { + let s = 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) { + this.setState({disabled: true}) } } @@ -55,46 +81,92 @@ return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } - /** - * @description 鎸夐挳鐘舵�佹敼鍙� - */ - updateStatus = (type) => { - if (type === 'start') { - this.setState({ - loading: true - }) - this.props.updateStatus('start') - } else if (type === 'over') { - this.setState({ - loading: false - }) - this.props.updateStatus('over') + componentDidMount () { + const { btn } = this.props + + MKEmitter.addListener('triggerBtnId', this.actionTrigger) + + if (btn.autoMatic) { + MKEmitter.addListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit) } + } + + UNSAFE_componentWillReceiveProps (nextProps) { + const { btn, selectedData, BData } = 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] + '' + 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}) + } else { + this.setState({disabled: false}) + } + } + + componentWillUnmount () { + this.setState = () => { + return + } + MKEmitter.removeListener('triggerBtnId', this.actionTrigger) + MKEmitter.removeListener('triggerBtnPopSubmit', this.triggerBtnPopSubmit) + } + + triggerBtnPopSubmit = (id) => { + const { btn } = this.props + + if (btn.uuid !== id) return + + this.handleOk() } /** * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ - actionTrigger = (record) => { - const { setting, Tab, BID, btn, selectedData } = this.props + actionTrigger = (triggerId, record, type) => { + const { Tab, BID, btn, selectedData, setting } = this.props + const { loading, disabled } = this.state - if (Tab && Tab.supMenu && !BID) { + if ((triggerId && btn.uuid !== triggerId) || loading || disabled) return + + if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { notification.warning({ top: 92, message: '闇�瑕佷笂绾т富閿�硷紒', duration: 5 }) return + } else if (type === 'linkbtn' && selectedData && selectedData.length === 1) { + if (record[0].$Index !== selectedData[0].$Index) { + return + } } + this.setState({autoMatic: type === 'autoMatic'}) + let _this = this - let data = [] - - if (record) { // 琛ㄦ牸涓Е鍙戞寜閽� - data = [record] - } else { - data = selectedData || [] - } + let data = record || selectedData || [] if (btn.Ot !== 'notRequired' && data.length === 0) { // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾暟鎹� @@ -109,14 +181,6 @@ notification.warning({ top: 92, message: this.state.dict['main.action.confirm.selectSingleLine'], - duration: 5 - }) - return - } else if (!setting.primaryKey) { - // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾槸鍚﹁缃富閿� - notification.warning({ - top: 92, - message: '鏈缃富閿紒', duration: 5 }) return @@ -137,26 +201,39 @@ return } + this.setState({ + selines: data + }) + if (btn.execMode === 'pop') { - this.updateStatus('start') + let modal = this.state.btnconfig + if (!modal && btn.modal) { + modal = this.handleModelConfig(btn.modal) + } + this.setState({ - tabledata: data + loading: true, + btnconfig: modal }, () => { this.improveAction() }) } else if (btn.execMode === 'prompt') { - this.updateStatus('start') + this.setState({ loading: true }) confirm({ title: this.state.dict['main.action.confirm.tip'], onOk() { _this.triggerPrint(data) }, onCancel() { - _this.updateStatus('over') + _this.setState({ loading: false }) } }) } else { this.triggerPrint(data) + } + + if (window.GLOB.systemType === 'production') { + MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '鏍囩鎵撳嵃'}) } } @@ -173,17 +250,17 @@ let printlist = [] let templates = [] - let printCount = 1 + let printCount = +(formdata.printCount || formdata.PrintCount || formdata.printcount || formdata.Printcount || 1) - if (formdata.printCount && typeof(formdata.printCount) === 'number' && formdata.printCount >= 1) { - printCount = formdata.printCount + if (isNaN(printCount) || printCount < 1) { + printCount = 1 } new Promise(resolve => { - if (btn.intertype === 'inner' && !btn.innerFunc) { + if (btn.intertype === 'system') { // 浣跨敤绯荤粺鏃讹紝鐩存帴浠庤〃鏍兼垨琛ㄥ崟涓�夊彇鏁版嵁 let printcell = {} - printcell.printType = formdata.printType || '' + printcell.printType = formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' printcell.printCount = printCount printcell.templateID = btn.verify.Template || '' @@ -207,12 +284,13 @@ // 绯荤粺鎵撳嵃鏁版嵁锛屾牎楠宒ata瀛楁 if (btn.verify.printMode !== 'custom' && (!cell.data || cell.data.length === 0)) return - cell.templateID = cell.templateID || btn.verify.Template - cell.printType = cell.printType || formdata.printType || '' + cell.templateID = cell.templateID || cell.TemplateID || cell.Templateid || cell.templateid || btn.verify.Template + cell.printType = cell.printType || cell.PrintType || cell.printtype || cell.Printtype || formdata.printType || formdata.PrintType || formdata.printtype || formdata.Printtype || '' - let _printCount = printCount - if (cell.printCount && typeof(cell.printCount) === 'number' && cell.printCount >= 1) { - _printCount = cell.printCount + let _printCount = +(cell.printCount || cell.PrintCount || cell.printcount || cell.Printcount || 0) + + if (isNaN(_printCount) || _printCount < 1) { + _printCount = printCount } cell.printCount = _printCount @@ -264,6 +342,7 @@ let errorMsg = '' let _temps = {} + let images = [] result.forEach(res => { if (res.status && !errorMsg) { @@ -277,6 +356,7 @@ status: false } } else { + images = [...images, ..._temp.imgs] _temps[res.tempId] = _temp } } else if (!errorMsg) { @@ -285,7 +365,38 @@ }) if (!errorMsg) { - this.execPrint(printlist, _temps, formdata) + 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, formdata) + }, 500) + } else { + this.execPrint(printlist, _temps, formdata) + } } else { this.execError(errorMsg) } @@ -307,15 +418,207 @@ try { // eslint-disable-next-line - let func = new Function('data', 'form', 'printer', 'notification', btn.verify.printFunc) - func(printlist, formdata, btn.verify, notification) + let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc) + func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) + + // 鑷畾涔夋墦鍗扮ず渚� + // 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) try { // eslint-disable-next-line - let evalfunc = eval('(true && function (data, form, printer, notification) {' + btn.verify.printFunc + '})') - evalfunc(printlist, formdata, btn.verify, notification) + let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})') + evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType) } catch (error) { console.warn(error) notification.warning({ @@ -346,17 +649,21 @@ let _param = { ...param, ...formdata } params.push(_param) } else if (btn.Ot === 'requiredSgl') { - param[setting.primaryKey] = data[0][setting.primaryKey] + if (setting.primaryKey) { + param[setting.primaryKey] = data[0][setting.primaryKey] + } let _param = { ...param, ...formdata } params.push(_param) } else if (btn.Ot === 'requiredOnce') { - let ids = data.map(d => { return d[setting.primaryKey]}) - ids = ids.filter(Boolean) - ids = ids.join(',') - - param[setting.primaryKey] = ids + if (setting.primaryKey) { + let ids = data.map(d => { return d[setting.primaryKey]}) + ids = ids.filter(Boolean) + ids = ids.join(',') + + param[setting.primaryKey] = ids + } let _param = { ...param, ...formdata } @@ -364,7 +671,10 @@ } else if (btn.Ot === 'required') { params = data.map((cell, index) => { let _param = { ...param } - _param[setting.primaryKey] = cell[setting.primaryKey] + + if (setting.primaryKey) { + _param[setting.primaryKey] = cell[setting.primaryKey] + } formlist.forEach(_data => { if (index !== 0 && _data.readin && cell.hasOwnProperty(_data.key)) { @@ -459,13 +769,21 @@ if (btn.sysInterface === 'true' && options.cloudServiceApi) { res.rduri = options.cloudServiceApi } else if (btn.sysInterface !== 'true') { - res.rduri = btn.interface + if (window.GLOB.systemType === 'production' && btn.proInterface) { + res.rduri = btn.proInterface + } else { + res.rduri = btn.interface + } } } else { if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { res.rduri = window.GLOB.mainSystemApi } else if (btn.sysInterface !== 'true') { - res.rduri = btn.interface + if (window.GLOB.systemType === 'production' && btn.proInterface) { + res.rduri = btn.proInterface + } else { + res.rduri = btn.interface + } } } @@ -548,6 +866,7 @@ let _configparam = '' // 鎵撳嵃閰嶇疆淇℃伅 let fields = [] // 妯℃澘涓墍闇�瀛楁 let nonEFields = [] // 闈炵┖瀛楁 + let imgs = [] if (!res.ConfigParam) { error = '鏈幏鍙栧埌鎵撳嵃妯℃澘淇℃伅锛�' @@ -561,7 +880,6 @@ if (!configParam) { error = '鎵撳嵃妯℃澘瑙f瀽閿欒锛�' } else { - let control = configParam.elements.map(element => { let _field = element.field @@ -608,6 +926,12 @@ 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) + } } else if (item.Type === 'text') { item.FontFamily = element.fontFamily item.FontSize = element.fontSize @@ -668,7 +992,8 @@ error: error, config: _configparam, fields: fields, - nonEFields: nonEFields + nonEFields: nonEFields, + imgs: imgs } } @@ -767,7 +1092,7 @@ task: { taskID: Utils.getuuid(), preview: false, - printer: printer, + printer: printer === 'lackprinter' ? '' : printer, documents: [_cell] } }) @@ -814,19 +1139,19 @@ return } - let lackItems = printerList.filter(cell => cell.task.printer === 'lackprinter')[0] + // 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 { + // if (lackItems) { + // let request = { + // requestID: '', + // version: '', + // cmd: 'getPrinters' + // } + // socket.send(JSON.stringify(request)) + // } else { this.syncMessageSend(printerList) this.execSuccess({ @@ -835,19 +1160,19 @@ ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', status: true }) - } + // } } // 鎵撳紑Socket socket.onopen = () =>{ - if (lackItems) { - let request = { - requestID: '', - version: '', - cmd: 'getPrinters' - } - socket.send(JSON.stringify(request)) - } else { + // if (lackItems) { + // let request = { + // requestID: '', + // version: '', + // cmd: 'getPrinters' + // } + // socket.send(JSON.stringify(request)) + // } else { this.syncMessageSend(printerList) this.execSuccess({ @@ -856,7 +1181,7 @@ ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', status: true }) - } + // } } // 鐩戝惉娑堟伅 socket.onmessage = (event) => { @@ -865,7 +1190,7 @@ if (event.data) { try { data = JSON.parse(event.data) - } catch { + } catch (e) { this.execError({ ErrCode: 'N', message: event.data, @@ -877,23 +1202,24 @@ } } - if (data && data.cmd === 'getPrinters' && data.status) { - printerList = printerList.map(cell => { - if (cell.task.printer === 'lackprinter') { - cell.task.printer = data.defaultPrinter - } - return cell - }) + // 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.syncMessageSend(printerList) - this.execSuccess({ - ErrCode: 'S', - message: '', - ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', - status: true - }) - } else if (data && data.message && !data.status) { + // this.execSuccess({ + // ErrCode: 'S', + // message: '', + // ErrMesg: '鎵撳嵃璇锋眰宸插彂鍑恒��', + // status: true + // }) + // } else if (data && data.message && !data.status) { + if (data && data.message && !data.status) { this.execError({ ErrCode: 'N', message: data.message, @@ -934,8 +1260,9 @@ */ execSuccess = (res) => { const { btn } = this.props + const { autoMatic } = this.state - if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛 + if ((res && res.ErrCode === 'S') || autoMatic) { // 鎵ц鎴愬姛 notification.success({ top: 92, message: res.ErrMesg || this.state.dict['main.action.confirm.success'], @@ -948,12 +1275,19 @@ } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず } - + this.setState({ loading: false }) - this.props.updateStatus('refresh', btn.execSuccess) + if (autoMatic) { + MKEmitter.emit('autoExecOver', btn.uuid, 'success') + return + } + + if (btn.execSuccess !== 'never') { + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines) + } } /** @@ -964,12 +1298,13 @@ */ execError = (res) => { const { btn } = this.props + const { btnconfig, autoMatic } = this.state - if (res.ErrCode === 'E') { + if (res.ErrCode === 'E' && !autoMatic) { Modal.error({ title: res.message || res.ErrMesg, }) - } else if (res.ErrCode === 'N') { + } else if (res.ErrCode === 'N' || autoMatic) { notification.error({ top: 92, message: res.message || res.ErrMesg, @@ -990,7 +1325,18 @@ loading: false }) - this.props.updateStatus('refresh', btn.execError) + if (autoMatic) { + MKEmitter.emit('autoExecOver', btn.uuid, 'error') + 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) + } } /** @@ -1004,15 +1350,38 @@ }) } + handleModelConfig = (config) => { + let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID + config.fields = config.fields.map(cell => { + // 鏁版嵁婧恠ql璇彞锛岄澶勭悊锛屾潈闄愰粦鍚嶅崟瀛楁璁剧疆涓洪殣钘忚〃鍗� + 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.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 } = this.state + const { btnconfig, autoMatic } = this.state if (btnconfig) { - if (btnconfig.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず + if (!autoMatic && (btnconfig.setting.display === 'prompt' || btnconfig.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず this.modelconfirm() } else { this.setState({ @@ -1041,83 +1410,22 @@ message: res.message, duration: 5 }) - this.updateStatus('over') - } else if (!_LongParam || (btn.OpenType === 'pop' && _LongParam.type !== 'Modal')) { + this.setState({ loading: false }) + } else if (!_LongParam || (btn.execMode === 'pop' && _LongParam.type !== 'Modal')) { notification.warning({ top: 92, message: '鏈幏鍙栧埌鎸夐挳閰嶇疆淇℃伅锛�', duration: 5 }) - this.updateStatus('over') + this.setState({ loading: false }) } else { - if (_LongParam.groups.length > 0) { - _LongParam.groups.forEach(group => { - group.sublist = group.sublist.map(cell => { - // 鏁版嵁婧恠ql璇彞锛岄澶勭悊 - if (['select', 'link', 'multiselect'].includes(cell.type) && cell.resourceType === '1') { - let _option = Utils.getSelectQueryOptions(cell) - - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 - _option.sql = _option.sql.replace(/\$@/ig, '/*') - _option.sql = _option.sql.replace(/@\$/ig, '*/') - } else { - _option.sql = _option.sql.replace(/@\$|\$@/ig, '') - } - - cell.data_sql = Utils.formatOptions(_option.sql) - cell.arr_field = _option.field - } - - // 瀛楁鏉冮檺榛戝悕鍗� - if (!cell.blacklist || cell.blacklist.length === 0) return cell - - let _black = cell.blacklist.filter(v => { - return this.props.permRoles.indexOf(v) !== -1 - }) - - if (_black.length > 0) { - cell.hidden = 'true' - } - - return cell - }) - }) - } else { - _LongParam.fields = _LongParam.fields.map(cell => { - // 鏁版嵁婧恠ql璇彞锛岄澶勭悊 - if (['select', 'link', 'multiselect'].includes(cell.type) && cell.resourceType === '1') { - let _option = Utils.getSelectQueryOptions(cell) - - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 - _option.sql = _option.sql.replace(/\$@/ig, '/*') - _option.sql = _option.sql.replace(/@\$/ig, '*/') - } else { - _option.sql = _option.sql.replace(/@\$|\$@/ig, '') - } - - cell.data_sql = Utils.formatOptions(_option.sql) - cell.arr_field = _option.field - } - - // 瀛楁鏉冮檺榛戝悕鍗� - if (!cell.blacklist || cell.blacklist.length === 0) return cell - - let _black = cell.blacklist.filter(v => { - return this.props.permRoles.indexOf(v) !== -1 - }) - - if (_black.length > 0) { - cell.hidden = 'true' - } - - return cell - }) - } + _LongParam = updateForm(_LongParam) + _LongParam = this.handleModelConfig(_LongParam) this.setState({ btnconfig: _LongParam }, () => { - if (_LongParam.setting.display === 'prompt') { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず + if (!autoMatic && (_LongParam.setting.display === 'prompt' || _LongParam.setting.display === 'exec')) { // 濡傛灉琛ㄥ崟浠ユ槸鍚︽灞曠ず this.modelconfirm() } else { this.setState({ @@ -1134,11 +1442,17 @@ * @description 妯℃�佹锛堣〃鍗曪級锛岀‘璁� */ handleOk = () => { + const { btnconfig, autoMatic } = this.state + + if (!this.formRef) return + this.formRef.handleConfirm().then(res => { - this.setState({ - visible: false - }) - this.triggerPrint(this.state.tabledata, res) + if (btnconfig.setting.finish !== 'unclose' || autoMatic) { + this.setState({ + visible: false + }) + } + this.triggerPrint(this.state.selines, res) }) } @@ -1147,26 +1461,19 @@ */ handleCancel = () => { this.setState({ + loading: false, visible: false }) - this.updateStatus('over') } modelconfirm = () => { const { BData } = this.props - const { btnconfig, tabledata } = this.state + const { btnconfig, selines } = this.state let _this = this - let _fields = [] + let result = [] - if (btnconfig.groups.length > 0) { - btnconfig.groups.forEach(group => { - _fields = [..._fields, ...group.sublist] - }) - } else { - _fields = btnconfig.fields - } - - let result = _fields.map(item => { + btnconfig.fields.forEach(item => { + if (!item.field) return let _readin = item.readin !== 'false' let _initval = item.initval @@ -1176,8 +1483,8 @@ if (item.type === 'linkMain' && BData && BData.hasOwnProperty(item.field)) { _initval = BData[item.field] - } else if (_readin && tabledata[0] && tabledata[0].hasOwnProperty(item.field)) { - _initval = tabledata[0][item.field] + } else if (_readin && selines[0] && selines[0].hasOwnProperty(item.field)) { + _initval = selines[0][item.field] } else if (item.type === 'date' && _initval) { _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD') } else if (item.type === 'datemonth' && _initval) { @@ -1191,34 +1498,60 @@ _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 + } } - return { + if (_initval === undefined) { + _initval = '' + } + + result.push({ key: item.field, readonly: item.readonly === 'true', - readin: _readin, + readin: item.readin !== 'false' && item.readin !== 'top', fieldlen: _fieldlen, type: item.type, value: _initval - } + }) }) - confirm({ - title: this.state.dict['main.action.confirm.tip'], - onOk() { - _this.triggerPrint(tabledata, result) - }, - onCancel() { - _this.updateStatus('over') - } - }) + if (btnconfig.setting.display === 'exec') { + this.execSubmit(selines, () => {}, result) + } else { + confirm({ + title: this.state.dict['main.action.confirm.tip'], + onOk() { + _this.triggerPrint(selines, result) + }, + onCancel() { + _this.setState({ loading: false }) + } + }) + } } /** * @description 鏄剧ず妯℃�佹 */ getModels = () => { - const { setting, BID } = this.props + const { setting, BID, btn } = this.props const { btnconfig } = this.state if (!this.state.visible || !btnconfig || !btnconfig.setting) return null @@ -1228,9 +1561,12 @@ let clickouter = false let container = document.body - if (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) { + if ( + (setting.tabType === 'main' && btnconfig.setting.container === 'tab' && this.props.ContainerId) || + (btnconfig.setting.container === 'tab' && btn.ContainerId) + ) { width = btnconfig.setting.width + '%' - container = () => document.getElementById(this.props.ContainerId) + container = () => document.getElementById(this.props.ContainerId || btn.ContainerId) } if (btnconfig.setting.clickouter === 'close') { @@ -1255,7 +1591,7 @@ menuType={this.props.menuType} action={btnconfig} inputSubmit={this.handleOk} - data={this.state.tabledata[0]} + data={this.state.selines[0]} BData={this.props.BData} wrappedComponentRef={(inst) => this.formRef = inst} /> @@ -1265,31 +1601,57 @@ render() { const { btn, show } = this.props - const { loadingNumber, loading } = this.state + const { loadingNumber, loading, disabled, hidden } = this.state - return ( - <div className="mk-btn-wrap"> - {!show ? <Button - className={'mk-btn mk-' + btn.class} + if (hidden) return null + + if (show === 'actionList') { + return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> + <Button icon={btn.icon} - onClick={() => {this.actionTrigger()}} loading={loading} - >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button> : null} - {show === 'icon' ? <Button className="action-cell" icon={btn.icon || 'dash'} loading={loading} onClick={() => {this.actionTrigger()}}></Button> : null} - {show === 'text' ? <Button className="action-cell" loading={loading} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null} - {show === 'all' ? <Button className="action-cell" icon={btn.icon || ''} loading={loading} onClick={() => {this.actionTrigger()}}>{btn.label}</Button> : null} + disabled={disabled} + className={'mk-btn mk-' + btn.class} + onClick={() => {this.actionTrigger()}} + >{loadingNumber ? `(${loadingNumber})` : '' + btn.label}</Button> {this.getModels()} </div> - ) + } else { // icon銆乼ext銆� all 鍗$墖 + let label = '' + let icon = '' + + if (show === 'button') { + label = btn.label + icon = btn.icon || '' + } else if (show === 'link') { + label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span> + icon = '' + } else if (show === 'icon') { + icon = btn.icon || '' + // } else if (show === 'text') { + } else { + label = btn.label + } + + return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}> + <Button + type="link" + title={show === 'icon' ? btn.label : ''} + loading={loading} + disabled={disabled} + style={btn.style} + icon={icon} + onClick={() => {this.actionTrigger()}} + >{label}</Button> + {this.getModels()} + </div> + } } } const mapStateToProps = (state) => { return { - tabviews: state.tabviews, - menuType: state.editLevel, - permRoles: state.permRoles, - dataManager: state.dataManager + menuType: state.editLevel } } -- Gitblit v1.8.0