From 4b18ab4bf4eff4383bd85beb76564dc6aeb1df86 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 26 一月 2021 19:11:26 +0800 Subject: [PATCH] 2021-01-26 --- src/utils/utils-datamanage.js | 209 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 194 insertions(+), 15 deletions(-) diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js index 0022c68..a8e6dbc 100644 --- a/src/utils/utils-datamanage.js +++ b/src/utils/utils-datamanage.js @@ -13,13 +13,12 @@ * @param {Number} pageSize 姣忛〉鏁伴噺 * @param {String} BID 涓婄骇ID * @param {String} menuType 鑿滃崟绫诲瀷锛屾櫘閫氳彍鍗曚笌HS - * @param {Boolean} dataManager 鏁版嵁鏉冮檺 * @return {Object} param */ - static getQueryDataParams (setting, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, dataManager, id) { + static getQueryDataParams (setting, arrFields, search = [], orderBy = '', pageIndex = 1, pageSize = 10, BID, menuType, id) { let param = null - if (setting.interType === 'system' || (setting.interType === 'inner' && !setting.innerFunc)) { + if (setting.interType === 'system' || (setting.interType === 'custom' && setting.requestMode === 'system')) { param = this.getDefaultQueryParam(setting, arrFields, search, orderBy, pageIndex, pageSize, menuType, id) } else { param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, menuType, id) @@ -29,7 +28,7 @@ param.BID = BID } // 鏁版嵁绠$悊鏉冮檺 - if (dataManager) { + if (sessionStorage.getItem('dataM') === 'true') { param.dataM = 'Y' } @@ -53,7 +52,7 @@ param.PageSize = pageSize } - if (setting.interType === 'inner') { + if (setting.interType === 'inner' || (setting.interType === 'custom' && setting.requestMode === 'inner')) { param.func = setting.innerFunc } else { if (menuType === 'HS') { @@ -85,15 +84,25 @@ let param = { func: 'sPC_Get_TableData', obj_name: 'data', + exec_type: 'y', arr_field: arrFields, default_sql: setting.execute ? 'true' : 'false' + } + + let userName = sessionStorage.getItem('User_Name') || '' + let fullName = sessionStorage.getItem('Full_Name') || '' + + if (sessionStorage.getItem('isEditState') === 'true') { + userName = sessionStorage.getItem('CloudUserName') || '' + fullName = sessionStorage.getItem('CloudFullName') || '' } let _dataresource = setting.dataresource let _customScript = '' if (setting.customScript) { - _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' + _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50) + Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}' ${setting.customScript} ` } @@ -126,7 +135,7 @@ value: orderBy }, { reg: new RegExp('@pageSize@', 'ig'), - value: pageSize + value: setting.laypage ? pageSize : '9999' }, { reg: new RegExp('@pageIndex@', 'ig'), value: pageIndex @@ -178,7 +187,7 @@ _customScript = `${_customScript} aaa: if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ ` } } @@ -188,12 +197,13 @@ _customScript && console.info(`${LText ? '' : '/*涓嶆墽琛岄粯璁ql*/\n'}${_customScript}`) LText && console.info(LText) } - + param.custom_script = Utils.formatOptions(_customScript) param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.secretkey = Utils.encrypt(param.LText, param.timestamp) param.DateCount = Utils.formatOptions(DateCount) + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) @@ -205,10 +215,11 @@ /** * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鍚堣鍊肩殑鍙傛暟 */ - static getStatQueryDataParams (setting, statFields, search, orderBy, BID, menuType, dataManager) { + static getStatQueryDataParams (setting, statFields, search, orderBy, BID, menuType) { let param = { func: 'sPC_Get_TableData', obj_name: 'data', + exec_type: 'y', arr_field: statFields.map(col => col.field).join(','), default_sql: setting.execute ? 'true' : 'false' } @@ -292,9 +303,10 @@ param.custom_script = Utils.formatOptions(_customScript) param.LText = Utils.formatOptions(LText) - param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - param.secretkey = Utils.encrypt(param.LText, param.timestamp) param.DateCount = '' + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) @@ -305,10 +317,177 @@ } // 鏁版嵁绠$悊鏉冮檺 - if (dataManager) { + if (sessionStorage.getItem('dataM') === 'true') { param.dataM = 'Y' } return param } + + /** + * @description 鏁版嵁婧愬悕绉帮紝鐢ㄤ簬缁熶竴鏌ヨ + * @param {Object} setting 鏁版嵁婧愯缃� + * @param {String} arrFields 鏌ヨ瀛楁 + * @param {Array} search 鎼滅储鏉′欢 + * @param {String} orderBy 鎺掑簭鏂瑰紡 + * @param {Number} pageIndex 椤电爜 + * @param {Number} pageSize 姣忛〉鏁伴噺 + * @param {String} BID 涓婄骇ID + * @param {String} menuType 鑿滃崟绫诲瀷锛屾櫘閫氳彍鍗曚笌HS + * @return {Object} param + */ + static getPrevQueryParams (setting, search = [], BID, menuType) { + let param = null + + if (setting.procMode !== 'inner') { + param = this.getDefaultPrevQueryParam(setting, search, menuType) + } else { + param = Utils.formatCustomMainSearch(search) + param.func = setting.prevFunc || '' + } + + if (BID) { + param.BID = BID + } + + return param + } + + /** + * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� + */ + static getDefaultPrevQueryParam (setting, search, menuType) { + let param = { + func: 'sPC_TableData_InUpDe', + exec_type: 'y', + script_type: 'Y' + } + + let sql = '' + let userName = sessionStorage.getItem('User_Name') || '' + let fullName = sessionStorage.getItem('Full_Name') || '' + + if (sessionStorage.getItem('isEditState') === 'true') { + userName = sessionStorage.getItem('CloudUserName') || '' + fullName = sessionStorage.getItem('CloudFullName') || '' + } + + setting.preScripts.forEach(item => { + if (item.status === 'false') return + sql += `${item.sql} + ` + }) + + if (sql) { + sql = `/*鍓嶇疆鑴氭湰*/ + declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50) + Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}' + ${sql} + aaa: + if @ErrorCode!='' + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + ` + + let allSearch = Utils.getAllSearchOptions(search) + let regoptions = allSearch.map(item => { + return { + reg: new RegExp('@' + item.key + '@', 'ig'), + value: `'${item.value}'` + } + }) + regoptions.push({ + reg: new RegExp('@userName@', 'ig'), + value: userName + }, { + reg: new RegExp('@fullName@', 'ig'), + value: fullName + }) + + regoptions.forEach(item => { + sql = sql.replace(item.reg, item.value) + }) + + // 娴嬭瘯绯荤粺鎵撳嵃鏌ヨ璇彞 + if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) { + console.info(sql.replace(/\n\s{8}/ig, '\n')) + } + } + + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 + sql = sql.replace(/\$@/ig, '/*') + sql = sql.replace(/@\$/ig, '*/') + } else { + sql = sql.replace(/@\$|\$@/ig, '') + } + + param.LText = Utils.formatOptions(sql) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) + + if (menuType === 'HS') { // 鍑芥暟 sPC_TableData_InUpDe 浜戠楠岃瘉 + param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) + } + + param.menuname = setting.MenuName || '' + + return param + } + + /** + * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁� + */ + static getCallBackQueryParams (setting, sql, errSql) { + let param = { + func: 'sPC_TableData_InUpDe', + exec_type: 'y', + } + let _prevCustomScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) + Select @ErrorCode='',@retmsg='' + ${errSql} + ` + let _backCustomScript = ` + ` + + setting.cbScripts.forEach(script => { + if (script.status === 'false') return + + if (script.position === 'front') { + _prevCustomScript += ` + /* 鑷畾涔夎剼鏈� */ + ${script.sql} + ` + } else { + _backCustomScript += ` + /* 鑷畾涔夎剼鏈� */ + ${script.sql} + ` + } + }) + + _backCustomScript += ` + aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg` + + sql = _prevCustomScript + sql + sql = sql + _backCustomScript + + if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) { + console.info(sql.replace(/\n\s{8}/ig, '\n')) + } + + param.LText = sql + + if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺 + param.LText = param.LText.replace(/\$@/ig, '/*') + param.LText = param.LText.replace(/@\$/ig, '*/') + } else { + param.LText = param.LText.replace(/@\$|\$@/ig, '') + } + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt('', param.timestamp) + param.LText = Utils.formatOptions(param.LText) + param.menuname = setting.MenuName || '' + + return param + } } \ No newline at end of file -- Gitblit v1.8.0