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 | 1033 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 972 insertions(+), 61 deletions(-) diff --git a/src/templates/zshare/createinterface/index.jsx b/src/templates/zshare/createinterface/index.jsx index aab31f6..b5d117a 100644 --- a/src/templates/zshare/createinterface/index.jsx +++ b/src/templates/zshare/createinterface/index.jsx @@ -1,53 +1,44 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Button, notification } from 'antd' +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 } state = { + type: '', + param: null, loading: false, + visible: false, + config: null, + btn: null } - exec = (menu, config) => { - let _grid = [] - let _fields = [] + /** + * @description 瑙﹀彂鍒涘缓璇绘暟鎹帴鍙� + * @param { object } menu 鑿滃崟绫诲瀷锛堜笁绾ц彍鍗曟垨鏍囩椤碉級銆佽彍鍗旾D銆佽彍鍗曞弬鏁般�佽彍鍗曞悕绉� + * @param { object } config 鑿滃崟閰嶇疆淇℃伅 + */ + triggerOutInterface = (menu, config) => { + let _search = [] let _index = 1 - config.columns.forEach(item => { - if (!item.field || item.type === 'colspan') return - - let _type = `nvarchar(${item.fieldlength || 50})` - - if (item.type === 'number') { - _type = `decimal(18,${item.decimal ? item.decimal : 0})` - } else if (item.type === 'picture' || item.type === 'textarea') { - _type = `nvarchar(${item.fieldlength || 512})` - } - - _grid.push(item.field) - _fields.push(`select '${item.field}' as gridfield,'${_type}' as fieldtype,'${item.label}' as label,'${_index}' as Sort`) - _index++ - }) - - let _search = [] - _index = 1 - if (menu.type !== 'main') { + // 瀛愯〃椤甸潰澧炲姞BID瀛楁锛屾暟鎹簮涓娇鐢ㄤ簡@BID@鏃讹紝BID绫诲瀷涓哄繀浼� if (config.setting.dataresource && /@BID@/ig.test(config.setting.dataresource)) { _search.push(`select 'BID' as searchfield,'BID' as label,'0' as Sort,'' as defaultvalue,'required' as DefaultType`) - _index++ } else { _search.push(`select 'BID' as searchfield,'BID' as label,'0' as Sort,'' as defaultvalue,'' as DefaultType`) - _index++ } } @@ -120,46 +111,161 @@ } }) + let _customScript = '' + config.setting.scripts && config.setting.scripts.forEach(script => { + if (script.status !== 'false') { + _customScript += ` + ${script.sql} + ` + } + }) + + if (_customScript) { + _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' + ${_customScript} + ` + } + let param = { func: 's_get_para_for_out', Menuid: menu.MenuID, Menuname: menu.menuName, Menuno: menu.menuNo, - Ltextgridparam: _fields.join(' union all '), + PageType: 'Y', Ltextsearchparam: _search.join(' union all '), AppendWhere: config.setting.queryType === 'query' ? searchText.join(' AND ') : '', - Ltextgrid: _grid.join(','), WhereType: config.setting.queryType === 'statistics' ? 'Statistics' : 'query', + custom_script: _customScript, + default_sql: config.setting.default || 'true', OrderCol: config.setting.order } param.Ltextsearchparam = Utils.formatOptions(param.Ltextsearchparam) param.AppendWhere = Utils.formatOptions(param.AppendWhere) - - param.Ltextgridparam = Utils.formatOptions(param.Ltextgridparam) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' - param.secretkey = Utils.encrypt(param.Ltextgridparam, param.timestamp) + param.custom_script = Utils.formatOptions(param.custom_script) this.setState({ - loading: true - }) - - return new Promise(resolve => { - this.createExec(resolve, param) + type: 'out', + param: param, + config: config, + visible: true, + formlist: [{ + type: 'text', + key: 'Menuname', + label: '鎺ュ彛鍚嶇О', + initval: menu.menuName, + required: true + }, { + type: 'text', + key: 'Menuno', + label: '鎺ュ彛鍑芥暟', + initval: menu.menuNo, + required: true + }, { + type: 'radio', + key: 'PageType', + label: '鏄惁鍒嗛〉', + initval: 'Y', + required: true, + options: [{ + value: 'Y', + text: '鏄�' + }, { + value: 'N', + text: '鍚�' + }] + }, { + type: 'radio', + key: 'hidden', + label: '杩斿洖闅愯棌瀛楁', + initval: 'N', + required: true, + options: [{ + value: 'Y', + text: '鏄�' + }, { + value: 'N', + text: '鍚�' + }] + }] }) } + + confirmInterface = () => { + const { type, param, btn, config } = this.state + + if (type === 'out') { + this.FormRef.handleConfirm().then(res => { + this.setState({ + type: '', + loading: true, + visible: false, + config: null, + param: null + }) + + this.createExecOutInterface({...param, ...res}, config) + }) + } else { + this.FormRef.handleConfirm().then(res => { + this.setState({ + type: '', + btn: null, + config: null, + loading: true, + visible: false, + param: null + }) + + if (res.TryType === 'Y' && res.array_name) { + res.Return = 'N' + } + + this.createBtnInterfaceExec({...param, ...res}, config, btn) + }) + } + } - createExec = (_resolve, param) => { - let _mainParam = JSON.parse(JSON.stringify(param)) + createExecOutInterface = (param, config) => { + let _grid = [] + let _fields = [] + let _index = 1 + + config.columns.forEach(item => { + if (!item.field || item.type === 'colspan') return + if (param.hidden !== 'Y' && item.Hide === 'true') return + + let _type = `nvarchar(${item.fieldlength || 50})` + + if (item.type === 'number') { + _type = `decimal(18,${item.decimal ? item.decimal : 0})` + } else if (item.type === 'picture' || item.type === 'textarea') { + _type = `nvarchar(${item.fieldlength || 512})` + } + + _grid.push(item.field) + _fields.push(`select '${item.field}' as gridfield,'${_type}' as fieldtype,'${item.label}' as label,'${_index}' as Sort`) + _index++ + }) + + param.Ltextgrid = _grid.join(',') + param.Ltextgridparam = _fields.join(' union all ') + param.Ltextgridparam = Utils.formatOptions(param.Ltextgridparam) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt(param.Ltextgridparam, param.timestamp) + + delete param.hidden + + 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, message: result.message, - duration: 10 + duration: 5 }) resolve(false) } else { @@ -169,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 @@ -182,7 +283,7 @@ notification.warning({ top: 92, message: result.message, - duration: 10 + duration: 5 }) return false } else { @@ -190,15 +291,12 @@ } }).then(res => { // 缁撴灉澶勭悊 - if (res === false) { - _resolve('error') - } else { + if (res !== false) { notification.success({ top: 92, message: '鍒涘缓鎴愬姛', duration: 2 }) - _resolve('success') } this.setState({ @@ -207,18 +305,831 @@ }) } + /** + * @description 瑙﹀彂鍒涘缓鍐欏叆鎺ュ彛锛堟寜閽級 + */ + triggerInInterface = (btn, config, menu) => { + if (!['pop', 'exec', 'prompt'].includes(btn.OpenType) || btn.funcType || btn.intertype !== 'system') { + notification.warning({ + top: 92, + message: '鎵撳紑鏂瑰紡涓� 寮圭獥锛堣〃鍗曪級銆佹彁绀烘鎴栫洿鎺ユ墽琛岋紝涓旀帴鍙g被鍨嬩负绯荤粺鏃讹紝鎵嶅彲浠ュ垱寤烘帴鍙o紒', + duration: 5 + }) + return + } else if (btn.Ot === 'requiredOnce') { + notification.warning({ + top: 92, + message: '澶氳鎷兼帴鏃讹紝涓嶆敮鎸佸垱寤烘帴鍙o紒', + duration: 5 + }) + return + } + + let param = { + func: 's_get_para_for_in', + Menuid: btn.uuid, + KunName: menu.menuName + '-' + btn.label, + KunNo: menu.menuNo + '_' + btn.sqlType, + Ltextgridparam: '', + Ltexttableparam: '', + Ltext: '', + menuType: menu.type, + systemType: window.GLOB.sysType + } + + this.setState({ + type: 'inner', + param: param, + visible: true, + btn: fromJS(btn).toJS(), + config: fromJS(config).toJS(), + formlist: [{ + type: 'text', + key: 'KunName', + label: '鎺ュ彛鍚嶇О', + initval: param.KunName, + required: true + }, { + type: 'text', + key: 'KunNo', + label: '鎺ュ彛鍑芥暟', + initval: param.KunNo, + required: true + }, { + type: 'radio', + key: 'TryType', + label: '浜嬪姟', + initval: 'Y', + required: true, + options: [{ + value: 'Y', + text: '闇�瑕�' + }, { + value: 'N', + text: '涓嶉渶瑕�' + }] + }, { + type: 'radio', + key: 'Return', + label: '鍥炴墽', + initval: 'N', + tooltip: '褰撻�夋嫨闇�瑕佷簨鍔★紝涓斿~鍏ヤ簡鏁扮粍鍚嶇О鏃讹紝灏嗕笉瀛樺湪鍥炴墽淇℃伅銆�', + required: true, + options: [{ + value: 'Y', + text: '闇�瑕�' + }, { + value: 'N', + text: '涓嶉渶瑕�' + }] + }, { + type: 'text', + key: 'array_name', + label: '鏁扮粍鍚嶇О', + initval: menu.menuNo + btn.uuid.substr(-4), + tooltip: '鎵归噺鎿嶄綔鏃讹紝闇�瑕佸~鍐欐暟缁勫悕绉般��', + required: false + }] + }) + } + + /** + * @description 鎵ц鎺ュ彛鍒涘缓 + */ + createBtnInterfaceExec = (param, config, btn) => { + let formlist = [] + let receipt = param.Return === 'Y' + let _mainParam = null + + delete param.Return + + new Promise(resolve => { + if (btn.OpenType === 'pop') { + Api.getCloudConfig({ + func: 'sPC_Get_LongParam', + MenuID: btn.uuid + }).then(result => { + if (result.status && result.LongParam) { + let _LongParam = '' + + // 瑙f瀽閰嶇疆锛屼慨鏀规ā鎬佹鏍囬鍚嶇О + if (result.LongParam) { + try { + _LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) + } catch (e) { + console.warn('Parse Failure') + _LongParam = '' + } + } + + if (_LongParam && _LongParam.type === 'Modal') { + _LongParam = updateForm(_LongParam) + } + + 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') { + _fieldlen = cell.fieldlength || 512 + } else if (cell.type === 'number') { + _fieldlen = cell.decimal ? cell.decimal : 0 + } + + let _field = { + type: cell.type, + label: cell.label, + readonly: cell.readonly, + readin: cell.readin !== 'false', + fieldlen: _fieldlen, + key: cell.field, + required: cell.required === 'true' ? 'required' : '', + writein: cell.writein !== 'false', + value: cell.initval || '' + } + + let _fieldtype = `nvarchar(${_fieldlen})` + + if (_field.type.match(/date/ig)) { + _fieldtype = 'datetime' + } else if (_field.type === 'number') { + _fieldtype = `decimal(18,${_fieldlen})` + } else if (_field.type === 'rate') { + _fieldtype = `decimal(18,2)` + } + + _field.fieldtype = _fieldtype + + if (cell.type === 'funcvar') { + _field.readin = false + _field.value = '' + } + + formlist.push(_field) + }) + } + resolve(true) + } else if (!result.status) { + notification.warning({ + top: 92, + message: result.message, + duration: 5 + }) + resolve(false) + } else { + notification.warning({ + top: 92, + message: '璇峰畬鍠勮〃鍗曚俊鎭紒', + duration: 5 + }) + resolve(false) + } + }) + } + }).then(res => { + if (res === false) return res + + let _keys = [] + param.Ltexttableparam = formlist.map((item, index) => { + _keys.push(item.key.toLowerCase()) + + return `select '${item.key}' as searchfield,'${item.label}' as label,'${index + 2}' as Sort, '${item.fieldtype}' as fieldtype,'${item.required}' as requiredtype,'${item.value}' as defaultvalue` + }) + + if (param.menuType !== 'main' && !_keys.includes('bid')) { + _keys.push('bid') + param.Ltexttableparam.unshift(`select 'BID' as searchfield,'BID' as label,'0' as Sort,'nvarchar(50)' as fieldtype,'required' as requiredtype,'' as defaultvalue`) + } + + if (btn.Ot !== 'notRequired' && !_keys.includes('id')) { + param.Ltexttableparam.unshift(`select 'ID' as searchfield,'ID' as label,'1' as Sort,'nvarchar(50)' as fieldtype,'required' as requiredtype,'' as defaultvalue`) + } + + param.Ltexttableparam = param.Ltexttableparam.join(' union all ') + + if (receipt) { + let _keys = [] + + param.Ltextgridparam = formlist.map((item, index) => { + _keys.push(item.key.toLowerCase()) + + return `select '${item.key}' as gridfield, '${item.fieldtype}' as fieldtype,'${item.label}' as label,'${index + 2}' as Sort` + }) + + if (param.menuType !== 'main' && !_keys.includes('bid')) { + _keys.push('bid') + param.Ltextgridparam.unshift(`select 'BID' as gridfield,'nvarchar(50)' as fieldtype,'BID' as label,'0' as Sort`) + } + + if (!_keys.includes(config.setting.primaryKey.toLowerCase())) { + _keys.push(config.setting.primaryKey.toLowerCase()) + param.Ltextgridparam.unshift(`select '${config.setting.primaryKey}' as gridfield,'nvarchar(50)' as fieldtype,'${config.setting.primaryKey}' as label,'1' as Sort`) + } + + if (btn.verify && btn.verify.voucher && btn.verify.voucher.enabled && btn.Ot !== 'notRequired') { + if (!_keys.includes('bvoucher')) { + param.Ltextgridparam.unshift(`select 'bvoucher' as gridfield,'nvarchar(50)' as fieldtype,'bvoucher' as label,'30' as Sort`) + } + if (!_keys.includes('fibvoucherdate')) { + param.Ltextgridparam.unshift(`select 'fibvoucherdate' as gridfield,'nvarchar(50)' as fieldtype,'fibvoucherdate' as label,'31' as Sort`) + } + if (!_keys.includes('fiyear')) { + param.Ltextgridparam.unshift(`select 'fiyear' as gridfield,'nvarchar(50)' as fieldtype,'fiyear' as label,'32' as Sort`) + } + } + + param.Ltextgridparam = param.Ltextgridparam.join(' union all ') + } + + let BID = param.menuType !== 'main' ? '@BID@' : '' + + param.Ltextgridparam = Utils.formatOptions(param.Ltextgridparam) + param.Ltexttableparam = Utils.formatOptions(param.Ltexttableparam) + + param.Ltext = this.getInterfaceSysDefaultSql(btn, config, formlist, receipt, BID) + param.Ltext = Utils.formatOptions(param.Ltext) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt(param.Ltext, param.timestamp) + + delete param.menuType + + _mainParam = fromJS(param).toJS() + + return Api.genericInterface(param) + }).then(res => { + if (res === false) return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + return false + } else { + return true + } + }).then(res => { + if (res === false) return res + + return Api.getCloudConfig(_mainParam) + }).then(res => { + if (res === false) return res + + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + return false + } else { + return 'success' + } + }).then(res => { + + if (res === 'success') { + notification.success({ + top: 92, + message: '鍒涘缓鎴愬姛', + duration: 2 + }) + } + this.setState({ + loading: false + }) + }) + } + + getInterfaceSysDefaultSql = (btn, config, formlist, receipt, BID) => { + let setting = config.setting + 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 = '' + + let _initvars = [] // 宸茶祴鍊煎瓧娈甸泦 + let _initfields = [] + let _initcolumnfields = [] + let _declarefields = [] + + // 鑾峰彇瀛楁閿�煎 + formlist.forEach(form => { + let _key = form.key.toLowerCase() + + if (!_initvars.includes(_key)) { + _initvars.push(_key) + + _initfields.push(`@${_key}=@${_key}@`) + } + + if (!_vars.includes(_key)) { + _vars.push(_key) + + 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)` + } + + _declarefields.push(`@${_key} ${_type}`) + } + }) + + // 娣诲姞鏁版嵁涓瓧娈碉紝琛ㄥ崟鍊间紭鍏�(鎸夐挳涓嶉�夎鏃惰烦杩�) + if (btn.Ot !== 'notRequired') { + columns.forEach(col => { + let _key = col.field.toLowerCase() + + if (!_initvars.includes(_key)) { + _initvars.push(_key) + + _initcolumnfields.push(`@${_key}=${_key}`) + } + + if (!_vars.includes(_key)) { + _vars.push(_key) + + let _type = `nvarchar(${col.fieldlength || 50})` + + if (col.type === 'number') { + let _length = col.decimal ? col.decimal : 0 + _type = `decimal(18,${_length})` + } else if (col.type === 'picture' || col.type === 'textarea') { + _type = `nvarchar(${col.fieldlength || 512})` + } + + _declarefields.push(`@${_key} ${_type}`) + } + }) + } + + // 鍙橀噺澹版槑 + _declarefields = _declarefields.join(',') + if (_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) { + _sql += `select ${_initfields.join(',')} + ` + } + + // if (_initcolumnfields.length > 0) { + // _sql += `select ${_initcolumnfields.join(',')} from (${setting.dataresource})tb where ${primaryKey}=@ID@ + // ` + // } + + // 鍘婚櫎绂佺敤鐨勯獙璇� + if (verify.contrasts) { + verify.contrasts = verify.contrasts.filter(item => item.status !== 'false') + } + if (verify.uniques) { + verify.uniques = verify.uniques.filter(item => item.status !== 'false') + } + if (verify.customverifys) { + verify.customverifys = verify.customverifys.filter(item => item.status !== 'false') + } + if (verify.billcodes) { + verify.billcodes = verify.billcodes.filter(item => item.status !== 'false') + } + if (verify.scripts) { + verify.scripts = verify.scripts.filter(item => item.status !== 'false') + } + + // 鍒濆鍖栧嚟璇佸強鐢ㄦ埛淇℃伅瀛楁 + _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 + if @ErrorCode!='' + GOTO aaa + ` + } + + // 澶辨晥楠岃瘉锛屾坊鍔犳暟鎹椂涓嶇敤 + if (btn.sqlType !== 'insert' && verify.invalid === 'true' && setting.dataresource) { + let datasource = setting.dataresource + if (/\s/.test(datasource) && !/tb$/.test(datasource)) { // 鎷兼帴鍒悕 + datasource = '(' + datasource + ') tb' + } + + // 鑷畾涔夎剼鏈� + 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 + select @ErrorCode='E',@retmsg='鏁版嵁宸插け鏁�' + goto aaa + end + ` + } + + // 姣旇緝楠岃瘉 + if (verify.contrasts && verify.contrasts.length > 0) { + verify.contrasts.forEach(item => { + _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 + ` + }) + } + + // 鍞竴鎬ч獙璇侊紝蹇呴』瀛樺湪琛ㄥ崟锛堣〃鍗曞瓨鍦ㄦ椂锛屼富閿潎涓哄崟鍊硷級,蹇呴』濉啓鏁版嵁婧� + if (formlist.length > 0 && verify.uniques && verify.uniques.length > 0) { + verify.uniques.forEach(item => { + let _fieldValue = [] // 琛ㄥ崟閿�煎field=value + let _value = [] // 琛ㄥ崟鍊硷紝鐢ㄤ簬閿欒鎻愮ず + let _labels = item.fieldlabel.split(',') // 琛ㄥ崟鎻愮ず鏂囧瓧 + let arr = [] // 楠岃瘉涓婚敭 + + item.field.split(',').forEach((_field, index) => { + _fieldValue.push(`${_field}=@${_field}@`) + _value.push(`${_labels[index] || ''}锛�'+@${_field}@+'`) + arr.push(_field.toLowerCase()) + }) + + let _verifyType = '' + if (item.verifyType === 'logic') { + _verifyType = ' and deleted=0' + } + + if (!arr.includes(primaryKey.toLowerCase())) { + _fieldValue.push(`${primaryKey} !=@${primaryKey}@`) + } + + _sql += `select @tbid='', @ErrorCode='',@retmsg='' + select @tbid='X' from ${btn.sql} where ${_fieldValue.join(' and ')}${_verifyType} + If @tbid!='' + Begin + select @ErrorCode='${item.errorCode}',@retmsg='${_value.join(', ')} 宸插瓨鍦�' + goto aaa + end + ` + }) + } + + let hasvoucher = false + + // 鍑瘉-鏄剧ず鍒椾腑閫夊彇,蹇呴』閫夎 + if (verify.voucher && verify.voucher.enabled && btn.Ot !== 'notRequired') { + let _voucher = verify.voucher + + hasvoucher = true + + _sql += `exec s_BVoucher_Create + @Bill =@${_voucher.linkField}@', + @BVoucherType ='${_voucher.BVoucherType}', + @VoucherTypeOne ='${_voucher.VoucherTypeOne}', + @VoucherTypeTwo ='${_voucher.VoucherTypeTwo}', + @Type =${_voucher.Type}, + @UserID=@UserID@, + @Username=@Username, + @FullName=@FullName, + @BVoucher =@BVoucher OUTPUT , + @FIBVoucherDate =@FIBVoucherDate OUTPUT , + @FiYear =@FiYear OUTPUT , + @ErrorCode =@ErrorCode OUTPUT, + @retmsg=@retmsg OUTPUT + if @ErrorCode!='' + GOTO aaa + ` + } + + if (_prevCustomScript) { + _sql += _prevCustomScript + } + + let _actionType = null + let receiptKeys = [] // 鍥炴墽瀛楁 + + if (verify.default !== 'false') { // 鍒ゆ柇鏄惁浣跨敤榛樿sql + _actionType = btn.sqlType + } + + formlist.forEach(item => { + receiptKeys.push(item.key.toLowerCase()) + }) + + if (!receiptKeys.includes(primaryKey.toLowerCase())) { + receiptKeys.push(primaryKey.toLowerCase()) + } + + if (!receiptKeys.includes('bid') && BID) { + receiptKeys.push('bid') + } + + let _insertsql = '' + let _updatesql = '' + // 娣诲姞銆佷慨鏀广�侀�昏緫鍒犻櫎銆佺墿鐞嗗垹闄� + 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) + }) + + if (!keys.includes(primaryKey.toLowerCase())) { + keys.push(primaryKey.toLowerCase()) + values.push(`@${primaryKey}@`) + } + + if (!keys.includes('createuserid')) { + keys.push('createuserid') + values.push('@userid@') + } + if (!keys.includes('createuser')) { + keys.push('createuser') + values.push('@username') + } + if (!keys.includes('createstaff')) { + keys.push('createstaff') + values.push('@fullname') + } + if (!keys.includes('bid') && BID) { + keys.push('bid') + values.push('@BID@') + } + + keys = keys.join(',') + values = values.join(',') + _insertsql = ` + /* 榛樿sql */ + insert into ${btn.sql} (${keys}) select ${values};` + } + + if (_actionType === 'update' || _actionType === 'audit' || _actionType === 'insertOrUpdate') { + let _form = [] + let _arr = [] + + formlist.forEach(item => { + if (item.writein === false) return + + _arr.push(item.key.toLowerCase()) + _form.push(item.key + `=@${item.key}`) + }) + + if (!_arr.includes('modifydate')) { + _form.push('modifydate=getdate()') + } + if (!_arr.includes('modifyuserid')) { + _form.push('modifyuserid=@userid@') + } + if (!_arr.includes('modifyuser')) { + _form.push('modifyuser=@username') + } + if (hasvoucher) { + if (!_arr.includes('bvoucher')) { + _arr.push('bvoucher') + receiptKeys.push('bvoucher') + _form.push('BVoucher=@BVoucher') + } + if (!_arr.includes('fibvoucherdate')) { + _arr.push('fibvoucherdate') + receiptKeys.push('fibvoucherdate') + _form.push('FIBVoucherDate=@FIBVoucherDate') + } + if (!_arr.includes('fiyear')) { + _arr.push('fiyear') + receiptKeys.push('fiyear') + _form.push('FiYear=@FiYear') + } + } + + if (!_arr.includes(primaryKey)) { + _arr.push(primaryKey) + } + + _form = _form.join(',') + _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 += ` + /* 榛樿sql */ + update ${btn.sql} set deleted=1,modifydate=getdate(),modifyuser=@username,modifystaff=@fullname,modifyuserid=@userid@ where ${primaryKey}=@${primaryKey}@;` + + } else if (_actionType === 'delete') { // 鐗╃悊鍒犻櫎 + let _msg = '' + if (columns.length > 0) { + let _index = 0 + columns.forEach(col => { + if (col.Hide !== 'true' && _index < 4) { + _msg += col.label + `=@${col.field}@,` + _index++ + } + }) + } + _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 (_backCustomScript) { + _sql += _backCustomScript + } + + let _ltext = '' + if (receipt) { + _ltext = `select obj_name='data',prm_field='${receiptKeys.join(',')}',str_field='', + arr_field='',tabid='',parid='',sub_name='',sub_field='' + select ${receiptKeys.map(key => `@${key}@ as ${key}`).join(',')} + ` + _ltext = Utils.formatOptions(_ltext) + } + + _sql += ` + aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg,'${_ltext}' as Ltext` + + return _sql + } + render() { return ( - <Button - className="mk-btn mk-green" - onClick={this.props.trigger} - loading={this.state.loading} - > - {this.props.dict['header.menu.interface.create']} - </Button> + <div style={{display: 'inline-block', marginRight: '8px'}}> + <Button + className="mk-btn mk-green" + onClick={this.props.trigger} + loading={this.state.loading} + > + 鍒涘缓鎺ュ彛 + </Button> + {/* 鎺ュ彛閫夐」 */} + <Modal + title="鍒涘缓鎺ュ彛" + visible={this.state.visible} + width={500} + maskClosable={false} + onOk={this.confirmInterface} + onCancel={() => {this.setState({visible: false})}} + destroyOnClose + > + <MutilForm + formlist={this.state.formlist} + wrappedComponentRef={(inst) => this.FormRef = inst} + /> + </Modal> + </div> ) } } -export default CreateFunc +export default CreateInterface -- Gitblit v1.8.0