From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 08 五月 2021 14:30:21 +0800 Subject: [PATCH] 2021-05-08 --- src/tabviews/zshare/actionList/normalbutton/index.jsx | 324 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 203 insertions(+), 121 deletions(-) diff --git a/src/tabviews/zshare/actionList/normalbutton/index.jsx b/src/tabviews/zshare/actionList/normalbutton/index.jsx index c9e83ba..de07156 100644 --- a/src/tabviews/zshare/actionList/normalbutton/index.jsx +++ b/src/tabviews/zshare/actionList/normalbutton/index.jsx @@ -6,11 +6,12 @@ import { Button, Modal, notification, message } from 'antd' import Api from '@/api' -import Utils from '@/utils/utils.js' +import Utils, { getSysDefaultSql } 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' import './index.scss' @@ -53,6 +54,8 @@ if (position === 'toolbar') { MKEmitter.addListener('triggerBtnId', this.actionTrigger) + } else if (position === 'form') { + MKEmitter.addListener('triggerFormSubmit', this.actionSubmit) } } @@ -61,6 +64,19 @@ return } MKEmitter.removeListener('triggerBtnId', this.actionTrigger) + MKEmitter.removeListener('triggerFormSubmit', this.actionSubmit) + } + + actionSubmit = (res) => { + const { btn } = this.props + + if (btn.uuid !== res.menuId) return + + this.setState({ + loading: true + }) + + this.execSubmit(this.state.tabledata, () => {}, res.form) } /** @@ -83,7 +99,7 @@ * @description 瑙﹀彂鎸夐挳鎿嶄綔 */ actionTrigger = (triggerId, record) => { - const { setting, Tab, BID, btn, selectedData } = this.props + const { Tab, BID, btn, selectedData } = this.props const { loading } = this.state if ((triggerId && btn.uuid !== triggerId) || loading) return @@ -113,14 +129,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 @@ -178,7 +186,13 @@ return } - if (btn.OpenType === 'prompt') { + if (btn.OpenType === 'formSubmit') { + this.setState({ + tabledata: data + }) + MKEmitter.emit('mkFormSubmit', btn.uuid) + return + } else if (btn.OpenType === 'prompt') { this.updateStatus('start') confirm({ title: this.state.dict['main.action.confirm.tip'], @@ -197,9 +211,14 @@ } else if (btn.OpenType === 'pop') { this.updateStatus('start') + let modal = this.state.btnconfig + if (!modal && btn.modal) { + modal = this.handleModelConfig(btn.modal) + } + this.setState({ tabledata: data, - btnconfig: btn.modal ? btn.modal : this.state.btnconfig + btnconfig: modal }, () => { this.improveAction() }) @@ -231,7 +250,7 @@ let primaryId = '' - if (btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { + if ((btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') && setting.primaryKey) { let ids = data.map(d => { return d[setting.primaryKey] || ''}) ids = ids.filter(Boolean) primaryId = ids.join(',') @@ -239,7 +258,14 @@ if (btn.OpenType === 'prompt' || btn.OpenType === 'exec') { // 鏄惁寮规鎴栫洿鎺ユ墽琛� param.ID = primaryId - param.LText = Utils.getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, '', param, data[0], columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -262,7 +288,7 @@ } param.LText = Utils.formatOptions(param.LText) - } else if (btn.OpenType === 'pop') { // 琛ㄥ崟 + } else if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟 if (btn.sqlType === 'insert') { // 绯荤粺鍑芥暟娣诲姞鏃讹紝鐢熸垚uuid primaryId = '' @@ -274,7 +300,14 @@ } param.ID = primaryId || Utils.getguid() - param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -299,7 +332,14 @@ param.LText = Utils.formatOptions(param.LText) } else { param.ID = primaryId - param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, formdata, param, data[0], columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -354,7 +394,14 @@ if (btn.OpenType === 'prompt' || btn.OpenType === 'exec') { // 鏄惁寮规鎴栫洿鎺ユ墽琛� param.ID = primaryId - param.LText = Utils.getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, '', param, cell, columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -380,7 +427,14 @@ if (btn.sqlType === 'insert') { // 绯荤粺鍑芥暟娣诲姞鏃讹紝鐢熸垚uuid param.ID = Utils.getguid() - param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -396,7 +450,14 @@ param.LText = Utils.formatOptions(param.LText) } else { param.ID = primaryId - param.LText = Utils.getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + + if (retmsg) { + const { sql, callbacksql } = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab, retmsg) // 鏁版嵁婧� + param.LText = sql + param.$callbacksql = callbacksql + } else { + param.LText = getSysDefaultSql(btn, setting, formdata, param, cell, columns, this.props.Tab) // 鏁版嵁婧� + } if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 param.LText = param.LText.replace(/\$@/ig, '/*') @@ -443,15 +504,17 @@ let primaryId = '' - if (btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') { + if ((btn.Ot === 'requiredSgl' || btn.Ot === 'requiredOnce') && setting.primaryKey) { let ids = data.map(d => { return d[setting.primaryKey] || ''}) ids = ids.filter(Boolean) primaryId = ids.join(',') } - param[setting.primaryKey] = primaryId // 璁剧疆涓婚敭鍙傛暟 + if (setting.primaryKey) { + param[setting.primaryKey] = primaryId // 璁剧疆涓婚敭鍙傛暟 + } - if (btn.OpenType === 'pop') { // 琛ㄥ崟 + if (btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') { // 琛ㄥ崟 formdata.forEach(_data => { param[_data.key] = _data.value }) @@ -490,7 +553,9 @@ param[_data.key] = _data.value }) } - param[setting.primaryKey] = primaryId + if (setting.primaryKey) { + param[setting.primaryKey] = primaryId + } if (this.props.menuType === 'HS' && param.func === 's_sDataDictb_TBBack' && param.LTextOut) { // 鍑芥暟 s_sDataDictb_TBBack 浜戠楠岃瘉 param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') @@ -562,7 +627,7 @@ param.BID = this.props.BID } - if (btn.OpenType === 'pop' && formdata) { // 琛ㄥ崟 + if ((btn.OpenType === 'pop' || btn.OpenType === 'formSubmit') && formdata) { // 琛ㄥ崟 formdata.forEach(_data => { param[_data.key] = _data.value }) @@ -638,15 +703,23 @@ loadingNumber: params.length || '' }) + let record = { + BID: param.BID || '', + ID: param.ID || '', + callbacksql: param.$callbacksql || '' + } + + delete param.$callbacksql + Api.genericInterface(param).then(res => { if (res.status) { - if (res.mk_ex_invoke === 'false' && params.length === 0) { + if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length === 0) { this.execSuccess(res) _resolve() - } else if (res.mk_ex_invoke === 'false' && params.length > 0) { + } else if ((res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) && params.length > 0) { this.customLoopRequest(params, _resolve) } else { - this.customOuterRequest(params, res, _resolve) + this.customOuterRequest(params, res, record, _resolve) } } else if (res.ErrCode === 'C' && this.state.checkParam) { const _this = this @@ -657,13 +730,13 @@ return new Promise(resolve => { Api.genericInterface(_this.state.checkParam).then((result) => { if (result.status) { - if (result.mk_ex_invoke === 'false' && params.length === 0) { + if ((result.mk_ex_invoke === 'false' || result.mk_ex_invoke === false) && params.length === 0) { _this.execSuccess(result) _resolve() - } else if (result.mk_ex_invoke === 'false' && params.length > 0) { + } else if ((result.mk_ex_invoke === 'false' || result.mk_ex_invoke === false) && params.length > 0) { _this.customLoopRequest(params, _resolve) } else { - _this.customOuterRequest(params, result, _resolve) + _this.customOuterRequest(params, result, record, _resolve) } } else { _this.execError(result) @@ -696,7 +769,7 @@ /** * @description 鑷畾涔夎姹傚惊鐜墽琛� */ - customOuterRequest = (params, result, _resolve) => { + customOuterRequest = (params, result, record, _resolve) => { const { btn } = this.props let url = '' @@ -722,27 +795,53 @@ param[key] = result[key] }) - Api.directRequest(url, btn.method, param).then(res => { + Api.directRequest(url, btn.method, param, btn.cross).then(res => { if (typeof(res) !== 'object' || Array.isArray(res)) { - this.execError({ErrCode: 'E', message: '鏈煡鐨勮繑鍥炵粨鏋滐紒'}) - _resolve() + let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒' + + if (typeof(res) === 'string') { + error = res.replace(/'/ig, '"') + } + + let result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: error + } + + this.customCallbackRequest(params, result, record, _resolve) } else { res.mk_api_key = mkey - this.customCallbackRequest(params, res, _resolve) + this.customCallbackRequest(params, res, record, _resolve) } - }, () => { - this.updateStatus('over') - _resolve() + }, (e) => { + let result = { + mk_api_key: mkey, + $ErrCode: 'E', + $ErrMesg: e && e.statusText ? e.statusText : '' + } + + this.customCallbackRequest([], result, record, _resolve) }) } /** * @description 鍥炶皟璇锋眰寰幆鎵ц */ - customCallbackRequest = (params, result, _resolve) => { + customCallbackRequest = (params, result, record, _resolve) => { const { btn } = this.props let lines = [] let pre = btn.callbackType === 'script' ? '@' : '' + + let errSql = '' + if (result.$ErrCode === 'E') { + errSql = ` + set @ErrorCode='E' + set @retmsg='${result.$ErrMesg}' + ` + delete result.$ErrCode + delete result.$ErrMesg + } let getDefaultSql = (obj, tb, bid, level) => { let keys = [] @@ -754,6 +853,7 @@ Object.keys(obj).forEach(key => { let val = obj[key] + if (val === null || val === undefined) return if (typeof(val) === 'object') { if (Array.isArray(val)) { val.forEach(item => { @@ -767,7 +867,10 @@ val.$$key = tb + '_' + key subObjs.push(val) } - } else if (val !== null && val !== undefined) { + } else { + if (typeof(val) === 'string') { + val = val.replace(/'/ig, '"') + } keys.push(key) vals.push(`'${val}'`) } @@ -806,12 +909,17 @@ if (btn.callbackType === 'script') { // 浣跨敤鑷畾涔夎剼鏈� param.func = 'sPC_TableData_InUpDe' - if (this.props.BID) { + if (record.BID) { param.BID = this.props.BID } + if (record.ID) { + param.ID = record.ID + } - let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈� - let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈� + let _prevCustomScript = `${record.callbacksql} + ${errSql} + ` + let _backCustomScript = '' btn.verify.cbScripts.forEach(script => { if (script.status === 'false') return @@ -828,6 +936,9 @@ ` } }) + + _backCustomScript += ` + aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` let sql = [...lineMap.values()].map(item => (` ${item.insert} @@ -994,7 +1105,11 @@ 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 + } } // 鍑芥暟 s_sDataDictb_TBBack 浜戠楠岃瘉 @@ -1007,7 +1122,11 @@ 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 + } } } @@ -1102,7 +1221,7 @@ } if (btn.execSuccess !== 'never') { - MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn) + MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess || '', btn) } } @@ -1304,6 +1423,29 @@ }) } + 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 鑾峰彇鎸夐挳閰嶇疆淇℃伅 */ @@ -1350,67 +1492,9 @@ }) this.updateStatus('over') } else { - let roleId = sessionStorage.getItem('role_id') || '' // 瑙掕壊ID - if (_LongParam.groups.length > 0) { - _LongParam.groups.forEach(group => { - group.sublist = group.sublist.map(cell => { - // 鏁版嵁婧恠ql璇彞锛岄澶勭悊锛� 鏉冮檺榛戝悕鍗曞瓧娈佃缃负闅愯棌琛ㄥ崟 - if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') { - let _option = Utils.getSelectQueryOptions(cell) - - if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - _option.sql = _option.sql.replace(/\$@/ig, '/*') - _option.sql = _option.sql.replace(/@\$/ig, '*/') - } else { - _option.sql = _option.sql.replace(/@\$|\$@/ig, '') - } - // 澶栬仈鏁版嵁搴撴浛鎹� - if (window.GLOB.externalDatabase !== null) { - _option.sql = _option.sql.replace(/@db@/ig, window.GLOB.externalDatabase) - } - - 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 - }) - }) - } else { - _LongParam.fields = _LongParam.fields.map(cell => { - // 鏁版嵁婧恠ql璇彞锛岄澶勭悊锛屾潈闄愰粦鍚嶅崟瀛楁璁剧疆涓洪殣钘忚〃鍗� - if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') { - let _option = Utils.getSelectQueryOptions(cell) - - if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 - _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.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 - }) - } - + _LongParam = updateForm(_LongParam) + _LongParam = this.handleModelConfig(_LongParam) + this.setState({ btnconfig: _LongParam }, () => { @@ -1459,17 +1543,10 @@ const { BData } = this.props const { btnconfig, tabledata } = this.state let _this = this - let _fields = [] - - if (btnconfig.groups.length > 0) { - btnconfig.groups.forEach(group => { - _fields = [..._fields, ...group.sublist] - }) - } else { - _fields = btnconfig.fields - } - let result = _fields.map(item => { + let result = [] + btnconfig.fields.forEach(item => { + if (!item.field) return let _readin = item.readin !== 'false' let _initval = item.initval @@ -1496,14 +1573,19 @@ _fieldlen = item.decimal ? item.decimal : 0 } - return { + if (_initval === undefined) { + _initval = '' + } + + result.push({ key: item.field, readonly: item.readonly === 'true', readin: _readin, fieldlen: _fieldlen, + writein: item.writein !== 'false', type: item.type, value: _initval - } + }) }) confirm({ @@ -1604,7 +1686,7 @@ type="link" title={show === 'icon' ? btn.label : ''} loading={loading} - style={btn.btnstyle || style} + style={btn.style || style} icon={show === 'text' ? '' : (btn.icon || '')} onClick={() => {this.actionTrigger()}} >{show === 'icon' && btn.icon ? '' : btn.label}</Button> -- Gitblit v1.8.0