From da64ab0923bf8817fc8599a6e37b953ce38f64c8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 27 八月 2023 18:37:36 +0800 Subject: [PATCH] 2023-08-27 --- src/templates/zshare/createinterface/index.jsx | 373 +++++++++++++++++++++++++++++++++-------------------- 1 files changed, 231 insertions(+), 142 deletions(-) diff --git a/src/templates/zshare/createinterface/index.jsx b/src/templates/zshare/createinterface/index.jsx index 89a9089..b5d117a 100644 --- a/src/templates/zshare/createinterface/index.jsx +++ b/src/templates/zshare/createinterface/index.jsx @@ -1,16 +1,17 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' +import { fromJS } from 'immutable' import { Button, notification, Modal } from 'antd' import moment from 'moment' import MutilForm from './mutilform' import Utils from '@/utils/utils.js' +import { updateForm } from '@/utils/utils-update.js' import Api from '@/api' import './index.scss' -class CreateFunc extends Component { +class CreateInterface extends Component { static propTypes = { - dict: PropTypes.object, // 瀛楀吀椤� trigger: PropTypes.func } @@ -168,10 +169,10 @@ required: true, options: [{ value: 'Y', - text: this.props.dict['model.true'] + text: '鏄�' }, { value: 'N', - text: this.props.dict['model.false'] + text: '鍚�' }] }, { type: 'radio', @@ -181,10 +182,10 @@ required: true, options: [{ value: 'Y', - text: this.props.dict['model.true'] + text: '鏄�' }, { value: 'N', - text: this.props.dict['model.false'] + text: '鍚�' }] }] }) @@ -195,7 +196,6 @@ if (type === 'out') { this.FormRef.handleConfirm().then(res => { - this.setState({ type: '', loading: true, @@ -208,7 +208,6 @@ }) } else { this.FormRef.handleConfirm().then(res => { - this.setState({ type: '', btn: null, @@ -217,7 +216,11 @@ visible: false, param: null }) - + + if (res.TryType === 'Y' && res.array_name) { + res.Return = 'N' + } + this.createBtnInterfaceExec({...param, ...res}, config, btn) }) } @@ -253,11 +256,11 @@ delete param.hidden - let _mainParam = JSON.parse(JSON.stringify(param)) + let _mainParam = fromJS(param).toJS() new Promise(resolve => { // 鑾峰彇浜戠瀛樺偍杩囩▼淇℃伅 - Api.getLocalConfig(param).then(result => { + Api.genericInterface(param).then(result => { if (!result.status) { notification.warning({ top: 92, @@ -272,12 +275,7 @@ }).then(res => { if (res === false) return res - if (window.GLOB.mainSystemApi) { - _mainParam.rduri = window.GLOB.mainSystemApi - - return Api.getLocalConfig(_mainParam) - } - return 'success' + return Api.getCloudConfig(_mainParam) }).then(result => { if (result === false || result === 'success') return result @@ -335,15 +333,16 @@ Ltextgridparam: '', Ltexttableparam: '', Ltext: '', - menuType: menu.type + menuType: menu.type, + systemType: window.GLOB.sysType } this.setState({ type: 'inner', param: param, visible: true, - btn: JSON.parse(JSON.stringify(btn)), - config: JSON.parse(JSON.stringify(config)), + btn: fromJS(btn).toJS(), + config: fromJS(config).toJS(), formlist: [{ type: 'text', key: 'KunName', @@ -360,7 +359,7 @@ type: 'radio', key: 'TryType', label: '浜嬪姟', - initval: 'N', + initval: 'Y', required: true, options: [{ value: 'Y', @@ -374,6 +373,7 @@ key: 'Return', label: '鍥炴墽', initval: 'N', + tooltip: '褰撻�夋嫨闇�瑕佷簨鍔★紝涓斿~鍏ヤ簡鏁扮粍鍚嶇О鏃讹紝灏嗕笉瀛樺湪鍥炴墽淇℃伅銆�', required: true, options: [{ value: 'Y', @@ -382,6 +382,13 @@ value: 'N', text: '涓嶉渶瑕�' }] + }, { + type: 'text', + key: 'array_name', + label: '鏁扮粍鍚嶇О', + initval: menu.menuNo + btn.uuid.substr(-4), + tooltip: '鎵归噺鎿嶄綔鏃讹紝闇�瑕佸~鍐欐暟缁勫悕绉般��', + required: false }] }) } @@ -398,7 +405,7 @@ new Promise(resolve => { if (btn.OpenType === 'pop') { - Api.getSystemConfig({ + Api.getCloudConfig({ func: 'sPC_Get_LongParam', MenuID: btn.uuid }).then(result => { @@ -414,20 +421,14 @@ _LongParam = '' } } - let fields = [] if (_LongParam && _LongParam.type === 'Modal') { - if (_LongParam.groups.length > 0) { - _LongParam.groups.forEach(group => { - fields = [...fields, ...group.sublist] - }) - } else { - fields = _LongParam.fields - } + _LongParam = updateForm(_LongParam) } - if (fields && fields.length > 0) { - formlist = fields.map(cell => { + if (_LongParam && _LongParam.fields.length > 0) { + _LongParam.fields.forEach(cell => { + if (!cell.field) return let _fieldlen = cell.fieldlength || 50 if (cell.type === 'textarea' || cell.type === 'fileupload' || cell.type === 'multiselect') { @@ -444,6 +445,7 @@ fieldlen: _fieldlen, key: cell.field, required: cell.required === 'true' ? 'required' : '', + writein: cell.writein !== 'false', value: cell.initval || '' } @@ -453,6 +455,8 @@ _fieldtype = 'datetime' } else if (_field.type === 'number') { _fieldtype = `decimal(18,${_fieldlen})` + } else if (_field.type === 'rate') { + _fieldtype = `decimal(18,2)` } _field.fieldtype = _fieldtype @@ -462,7 +466,7 @@ _field.value = '' } - return _field + formlist.push(_field) }) } resolve(true) @@ -550,9 +554,9 @@ delete param.menuType - _mainParam = JSON.parse(JSON.stringify(param)) + _mainParam = fromJS(param).toJS() - return Api.getLocalConfig(param) + return Api.genericInterface(param) }).then(res => { if (res === false) return res @@ -569,14 +573,9 @@ }).then(res => { if (res === false) return res - if (window.GLOB.mainSystemApi) { - _mainParam.rduri = window.GLOB.mainSystemApi - - return Api.getLocalConfig(_mainParam) - } - return 'success' + return Api.getCloudConfig(_mainParam) }).then(res => { - if (res === false || res === 'success') return res + if (res === false) return res if (!res.status) { notification.warning({ @@ -608,12 +607,37 @@ let primaryKey = setting.primaryKey || 'id' let columns = config.columns.filter(col => !!col.field) let verify = btn.verify || {} + + let _initCustomScript = '' // 鍒濆鍖栬剼鏈� + let _prevCustomScript = '' // 榛樿sql鍓嶆墽琛岃剼鏈� + let _backCustomScript = '' // 榛樿sql鍚庢墽琛岃剼鏈� + + verify.scripts && verify.scripts.forEach(item => { + if (item.status === 'false') return + + if (item.position === 'init') { + _initCustomScript += ` + /* 鑷畾涔夎剼鏈� */ + ${item.sql} + ` + } else if (item.position === 'front') { + _prevCustomScript += ` + /* 鑷畾涔夎剼鏈� */ + ${item.sql} + ` + } else { + _backCustomScript += ` + /* 鑷畾涔夎剼鏈� */ + ${item.sql} + ` + } + }) + // 闇�瑕佸0鏄庣殑鍙橀噺闆� let _vars = ['tbid', 'errorcode', 'retmsg', 'billcode', 'bvoucher', 'fibvoucherdate', 'fiyear', 'username', 'fullname', 'modulardetailcode'] // 绯荤粺鍙橀噺澹版槑涓庤缃垵濮嬪�� - let _sql = `Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50) - ` + let _sql = '' let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦 let _initfields = [] @@ -639,6 +663,8 @@ _type = 'datetime' } else if (form.type === 'number') { _type = `decimal(18,${form.fieldlen})` + } else if (form.type === 'rate') { + _type = `decimal(18,2)` } _declarefields.push(`@${_key} ${_type}`) @@ -676,9 +702,14 @@ // 鍙橀噺澹版槑 _declarefields = _declarefields.join(',') if (_declarefields) { - _sql += `,${_declarefields} - ` + _declarefields = ',' + _declarefields } + _sql = `/* 绯荤粺鐢熸垚 */ + Declare @tbid nvarchar(50),@ErrorCode nvarchar(50),@retmsg nvarchar(4000),@BillCode nvarchar(50),@BVoucher nvarchar(50),@FIBVoucherDate nvarchar(50), @FiYear nvarchar(50), @UserName nvarchar(50),@FullName nvarchar(50),@ModularDetailCode nvarchar(50)${_declarefields} + + select @UserName='',@FullName='' + select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@ + ` // 鍙橀噺璧嬪�� if (_initfields.length > 0) { @@ -686,10 +717,10 @@ ` } - if (_initcolumnfields.length > 0) { - _sql += `select ${_initcolumnfields.join(',')} from ${setting.dataresource} where ${primaryKey}=@ID@ - ` - } + // if (_initcolumnfields.length > 0) { + // _sql += `select ${_initcolumnfields.join(',')} from (${setting.dataresource})tb where ${primaryKey}=@ID@ + // ` + // } // 鍘婚櫎绂佺敤鐨勯獙璇� if (verify.contrasts) { @@ -709,25 +740,48 @@ } // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁 - _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='' + _sql += `select @BVoucher='',@FIBVoucherDate='',@FiYear='',@ErrorCode='',@retmsg='', @BillCode='', @ModularDetailCode='' ` + + if (_initCustomScript) { + _sql += _initCustomScript + } // 鍚敤璐︽湡楠岃瘉 if (verify.accountdate === 'true') { - _sql += `exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT + _sql += ` + /* 璐︽湡楠岃瘉 */ + exec s_FIBVoucherDateCheck @ErrorCode=@ErrorCode OUTPUT,@retmsg=@retmsg OUTPUT if @ErrorCode!='' GOTO aaa ` } // 澶辨晥楠岃瘉锛屾坊鍔犳暟鎹椂涓嶇敤 - if (btn.sqlType !== 'insert' && verify.invalid === 'true') { + if (btn.sqlType !== 'insert' && verify.invalid === 'true' && setting.dataresource) { let datasource = setting.dataresource - if (/\s/.test(datasource)) { // 鎷兼帴鍒悕 + if (/\s/.test(datasource) && !/tb$/.test(datasource)) { // 鎷兼帴鍒悕 datasource = '(' + datasource + ') tb' } - _sql += `select @tbid='', @ErrorCode='',@retmsg='' + // 鑷畾涔夎剼鏈� + if (setting.interType === 'system' && setting.scripts && setting.scripts.length > 0) { + let _customScript = '' + setting.scripts.forEach(item => { + if (item.status === 'false') return + _customScript += ` + ${item.sql} + ` + }) + _sql += ` + /* 鏁版嵁婧愯嚜瀹氫箟鑴氭湰锛岃娉ㄦ剰鍙橀噺瀹氫箟鏄惁閲嶅 */ + ${_customScript} + ` + } + + _sql += ` + /* 澶辨晥楠岃瘉 */ + select @tbid='', @ErrorCode='',@retmsg='' select @tbid=${primaryKey} from ${datasource} where ${primaryKey} =@${primaryKey}@ If @tbid='' Begin @@ -740,11 +794,76 @@ // 姣旇緝楠岃瘉 if (verify.contrasts && verify.contrasts.length > 0) { verify.contrasts.forEach(item => { - _sql += `If ${item.frontfield} ${item.operator} ${item.backfield} + _sql += ` + /* 姣旇緝楠岃瘉 */ + If ${item.frontfield} ${item.operator} ${item.backfield} Begin select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' goto aaa end + ` + }) + } + + // 鑷畾涔夐獙璇� + if (verify.customverifys && verify.customverifys.length > 0) { + verify.customverifys.forEach(item => { + _sql += ` + /* 鑷畾涔夐獙璇� */ + select @tbid='', @ErrorCode='',@retmsg='' + select top 1 @tbid='X' from (${item.sql}) a + If @tbid ${item.result === 'true' ? '!=' : '='}'' + Begin + select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' + goto aaa + end + ` + }) + } + + // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級 + if (verify.billcodes && verify.billcodes.length > 0) { + verify.billcodes.forEach(item => { + let _ModularDetailCode = '' + let _lpline = '' + if (item.TypeCharOne === 'Lp') { + if (item.linkField === 'BID' && BID) { // 鏇挎崲bid + _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@BID@,48)` + } else { + _lpline = `set @ModularDetailCode= 'Lp'+ right('${item.mark || btn.uuid}'+@${item.linkField}@,48)` + } + _ModularDetailCode = '@ModularDetailCode' + } else if (item.TypeCharOne === 'BN') { + + _ModularDetailCode = `'${item.TypeCharOne + '@' + item.linkField}@'` + } else { + _ModularDetailCode = `'${item.ModularDetailCode}'` + } + + let _declare = '' + let _key = item.field.toLowerCase() + + if (!_vars.includes(_key)) { + _declare = `Declare @${_key} nvarchar(50)` + _vars.push(_key) + } + + _sql += ` + /* 鍗曞彿鐢熸垚 */ + ${_declare} + select @BillCode='', @${_key}='', @ModularDetailCode='' + ${_lpline} + exec s_get_BillCode + @ModularDetailCode=${_ModularDetailCode}, + @Type=${item.Type}, + @TypeCharOne='${item.TypeCharOne}', + @TypeCharTwo ='${item.TypeCharTwo}', + @BillCode =@BillCode output, + @ErrorCode =@ErrorCode output, + @retmsg=@retmsg output + if @ErrorCode!='' + goto aaa + set @${_key}=@BillCode ` }) } @@ -782,65 +901,6 @@ ` }) } - - // 鑷畾涔夐獙璇� - if (verify.customverifys && verify.customverifys.length > 0) { - verify.customverifys.forEach(item => { - _sql += `select @tbid='', @ErrorCode='',@retmsg='' - select top 1 @tbid='X' from (${item.sql}) a - If @tbid ${item.result === 'true' ? '!=' : '='}'' - Begin - select @ErrorCode='${item.errorCode}',@retmsg='${item.errmsg}' - goto aaa - end - ` - }) - } - - // 鍗曞彿鐢熸垚锛屼娇鐢ㄤ笂绾d锛圔ID锛夋垨鍒楄〃鏁版嵁锛屽0鏄庡彉閲忥紙妫�楠岋級 - if (verify.billcodes && verify.billcodes.length > 0) { - verify.billcodes.forEach(item => { - let _ModularDetailCode = '' - let _lpline = '' - if (item.TypeCharOne === 'Lp') { - if (item.linkField === 'BID' && BID) { // 鏇挎崲bid - _lpline = `set @ModularDetailCode= 'Lp'+ right('${btn.uuid}'+@BID@,48)` - } else { - _lpline = `set @ModularDetailCode= 'Lp'+ right('${btn.uuid}'+@${item.linkField}@,48)` - } - _ModularDetailCode = '@ModularDetailCode' - } else if (item.TypeCharOne === 'BN') { - - _ModularDetailCode = `'${item.TypeCharOne + '@' + item.linkField}@'` - } else { - _ModularDetailCode = `'${item.ModularDetailCode}'` - } - - let _declare = '' - let _key = item.field.toLowerCase() - - if (!_vars.includes(_key)) { - _declare = `Declare @${_key} nvarchar(50)` - _vars.push(_key) - } - - _sql += `${_declare} - select @BillCode='', @${_key}='', @ModularDetailCode='' - ${_lpline} - exec s_get_BillCode - @ModularDetailCode=${_ModularDetailCode}, - @Type=${item.Type}, - @TypeCharOne='${item.TypeCharOne}', - @TypeCharTwo ='${item.TypeCharTwo}', - @BillCode =@BillCode output, - @ErrorCode =@ErrorCode output, - @retmsg=@retmsg output - if @ErrorCode!='' - goto aaa - set @${_key}=@BillCode - ` - }) - } let hasvoucher = false @@ -869,6 +929,10 @@ ` } + if (_prevCustomScript) { + _sql += _prevCustomScript + } + let _actionType = null let receiptKeys = [] // 鍥炴墽瀛楁 @@ -888,18 +952,18 @@ receiptKeys.push('bid') } - // 鐢ㄤ簬鍙栫敤鎴蜂俊鎭� - let _user = `select @UserName=UserName,@FullName=FullName from SUsers where UID=@UserID@ - ` - + let _insertsql = '' + let _updatesql = '' // 娣诲姞銆佷慨鏀广�侀�昏緫鍒犻櫎銆佺墿鐞嗗垹闄� - if (_actionType === 'insert') { + if (_actionType === 'insert' || _actionType === 'insertOrUpdate') { let keys = [] let values = [] formlist.forEach(item => { + if (item.writein === false) return + keys.push(item.key.toLowerCase()) - values.push('@' + item.key + '@') + values.push('@' + item.key) }) if (!keys.includes(primaryKey.toLowerCase())) { @@ -926,16 +990,20 @@ keys = keys.join(',') values = values.join(',') - _sql += _user - _sql += `insert into ${btn.sql} (${keys}) select ${values};` - } else if (_actionType === 'update') { + _insertsql = ` + /* 榛樿sql */ + insert into ${btn.sql} (${keys}) select ${values};` + } + + if (_actionType === 'update' || _actionType === 'audit' || _actionType === 'insertOrUpdate') { let _form = [] let _arr = [] formlist.forEach(item => { - _arr.push(item.key.toLowerCase()) + if (item.writein === false) return - _form.push(item.key + `=@${item.key}@`) + _arr.push(item.key.toLowerCase()) + _form.push(item.key + `=@${item.key}`) }) if (!_arr.includes('modifydate')) { @@ -943,6 +1011,9 @@ } if (!_arr.includes('modifyuserid')) { _form.push('modifyuserid=@userid@') + } + if (!_arr.includes('modifyuser')) { + _form.push('modifyuser=@username') } if (hasvoucher) { if (!_arr.includes('bvoucher')) { @@ -967,9 +1038,32 @@ } _form = _form.join(',') - _sql += `update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKey}@;` + _updatesql = ` + /* 榛樿sql */ + update ${btn.sql} set ${_form} where ${primaryKey}=@${primaryKey}@;` + } + + if (_actionType === 'insert') { + _sql += _insertsql + } else if (_actionType === 'update' || _actionType === 'audit') { + _sql += _updatesql + } else if (_actionType === 'insertOrUpdate') { + _sql += ` + select @tbid='' + select @tbid='X' from ${btn.sql} where ${primaryKey}=@ID@ + if @tbid='' + begin + ${_insertsql} + end + else + begin + ${_updatesql} + end + ` } else if (_actionType === 'LogicDelete') { // 閫昏緫鍒犻櫎 - _sql += `update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuserid=@userid@ where ${primaryKey}=@${primaryKey}@;` + _sql += ` + /* 榛樿sql */ + update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuser=@username,modifystaff=@fullname,modifyuserid=@userid@ where ${primaryKey}=@${primaryKey}@;` } else if (_actionType === 'delete') { // 鐗╃悊鍒犻櫎 let _msg = '' @@ -982,18 +1076,14 @@ } }) } - _sql += _user - _sql += `insert into snote (remark,createuserid,CreateUser,CreateStaff) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKey}@,@userid@,@username,@fullname delete ${btn.sql} where ${primaryKey}=@${primaryKey}@;` + _sql += ` + /* 榛樿sql */ + insert into snote (remark,createuserid,CreateUser,CreateStaff) select '鍒犻櫎琛�:${btn.sql} 鏁版嵁: ${_msg}${primaryKey}='+@${primaryKey}@,@userid@,@username,@fullname + delete ${btn.sql} where ${primaryKey}=@${primaryKey}@;` } - // 鎷兼帴鑷畾涔夎剼鏈� - if (verify.scripts && verify.scripts.length > 0) { - let _scripts = '' - verify.scripts.forEach(item => { - _scripts += ` - ${item.sql}` - }) - _sql += `${_scripts}` + if (_backCustomScript) { + _sql += _backCustomScript } let _ltext = '' @@ -1020,11 +1110,11 @@ onClick={this.props.trigger} loading={this.state.loading} > - {this.props.dict['header.menu.interface.create']} + 鍒涘缓鎺ュ彛 </Button> {/* 鎺ュ彛閫夐」 */} <Modal - title={this.props.dict['header.menu.interface.create']} + title="鍒涘缓鎺ュ彛" visible={this.state.visible} width={500} maskClosable={false} @@ -1033,7 +1123,6 @@ destroyOnClose > <MutilForm - dict={this.props.dict} formlist={this.state.formlist} wrappedComponentRef={(inst) => this.FormRef = inst} /> @@ -1043,4 +1132,4 @@ } } -export default CreateFunc +export default CreateInterface -- Gitblit v1.8.0