From c10fc10d5fd307a7b334bcde6af5c1175aaa0410 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 28 八月 2024 17:47:28 +0800 Subject: [PATCH] 2024-08-28 --- src/index.js | 1 src/utils/utils-datamanage.js | 302 ++++++++++++++++---- src/views/tabledesign/index.jsx | 42 ++ src/tabviews/basetable/index.jsx | 26 src/utils/utils-custom.js | 250 ++++++++--------- src/views/menudesign/index.jsx | 42 ++ src/utils/utils.js | 138 +++++++++ src/templates/sharecomponent/searchcomponent/searchform/index.jsx | 2 8 files changed, 570 insertions(+), 233 deletions(-) diff --git a/src/index.js b/src/index.js index 8c25e14..36ff7ed 100644 --- a/src/index.js +++ b/src/index.js @@ -346,6 +346,7 @@ } if (config.systemRun === 'backend') { + GLOB.debugger = false Object.defineProperty(window, 'backend', { writable: false, value: true diff --git a/src/tabviews/basetable/index.jsx b/src/tabviews/basetable/index.jsx index 3ef6c7c..c613378 100644 --- a/src/tabviews/basetable/index.jsx +++ b/src/tabviews/basetable/index.jsx @@ -174,19 +174,19 @@ window.GLOB.CacheData.set(MenuID, urlparam) - // if (window.backend && config.allSqls) { - // let keys = Object.keys(urlparam) - // config.allSqls.forEach(item => { - // if (item.type === 'datasource') { - // item.urlkeys = keys - // item.urlparam = urlparam - // if (config.flow_code) { - // item.works_flow_code = config.flow_code - // } - // } - // window.GLOB.CacheData.set('sql_' + item.uuid, item) - // }) - // } + if (window.backend && config.allSqls) { + let keys = Object.keys(urlparam) + config.allSqls.forEach(item => { + if (item.type === 'datasource') { + item.urlkeys = keys + item.urlparam = urlparam + if (config.flow_code) { + item.works_flow_code = config.flow_code + } + } + window.GLOB.CacheData.set('sql_' + item.uuid, item) + }) + } let userName = sessionStorage.getItem('User_Name') || '' let fullName = sessionStorage.getItem('Full_Name') || '' diff --git a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx index f093777..c2871bb 100644 --- a/src/templates/sharecomponent/searchcomponent/searchform/index.jsx +++ b/src/templates/sharecomponent/searchcomponent/searchform/index.jsx @@ -283,7 +283,7 @@ } else if (type === 'dateweek' || type === 'daterange' || type === 'range') { reOptions.match = matchReg.class5 } else if (type === 'checkcard') { - if (this.record.multiple === 'false') { + if (this.record.multiple === 'false' || this.record.multiple === 'dropdown') { reOptions.match = matchReg.class1 } else if (this.record.multiple === 'true') { reOptions.match = matchReg.class3 diff --git a/src/utils/utils-custom.js b/src/utils/utils-custom.js index 6556d9f..2d86e2d 100644 --- a/src/utils/utils-custom.js +++ b/src/utils/utils-custom.js @@ -1985,10 +1985,18 @@ let _quot = sql.match(/'{1}/g) let _lparen = sql.match(/\({1}/g) let _rparen = sql.match(/\){1}/g) + let _ch_b = sql.match(/\$check@/ig) + let _ch_d = sql.match(/@check\$/ig) + let _m_b = sql.match(/\$@/ig) + let _m_d = sql.match(/@\$/ig) _quot = _quot ? _quot.length : 0 _lparen = _lparen ? _lparen.length : 0 _rparen = _rparen ? _rparen.length : 0 + _ch_b = _ch_b ? _ch_b.length : 0 + _ch_d = _ch_d ? _ch_d.length : 0 + _m_b = _m_b ? _m_b.length : 0 + _m_d = _m_d ? _m_d.length : 0 if (_quot % 2 !== 0) { notification.warning({ @@ -2001,6 +2009,20 @@ notification.warning({ top: 92, message: 'sql涓�()蹇呴』鎴愬鍑虹幇', + duration: 5 + }) + return false + } else if (_ch_b !== _ch_d) { + notification.warning({ + top: 92, + message: 'sql涓� $check@ 涓� @check$ 蹇呴』鎴愬鍑虹幇', + duration: 5 + }) + return false + } else if (_m_b !== _m_d) { + notification.warning({ + top: 92, + message: 'sql涓� $@ 涓� @$ 蹇呴』鎴愬鍑虹幇', duration: 5 }) return false @@ -2869,6 +2891,8 @@ let filterComponent = (components, mainSearch) => { components.forEach(item => { + item.$menuname = (config.MenuName || '') + '-' + (item.name || '') + if (item.type === 'tabs') { item.subtabs.forEach(tab => { let _mainSearch = mainSearch || [] @@ -3135,7 +3159,6 @@ let getSearches = (searches) => { let sFields = [] - let query = false searches.forEach(item => { if (!item.field) return @@ -3177,13 +3200,9 @@ } else { sFields.push(item.field) } - - if (query) return - - query = item.query !== 'false' }) - return { sFields, query } + return sFields } let getSysDefaultSql = (btn, component) => { @@ -4347,7 +4366,7 @@ searches = [...searches, ...mainSearch] } item.$searches = fromJS(searches).toJS() - let { sFields, query } = getSearches(searches) + let sFields = getSearches(searches) let _columns = [] if (item.subtype === 'dualdatacard') { @@ -4374,8 +4393,18 @@ } }) + if (_customScript || _tailScript) { + _tailScript += `${_tailScript} + aaa: + if @ErrorCode!='' + insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ + ` + } + + let _search = '' if (item.setting.execute !== 'false') { _dataresource = item.setting.dataresource || '' + _search = '@mk_search@' } if (/\s/.test(_dataresource)) { @@ -4384,11 +4413,6 @@ item.setting.dataresource = _dataresource item.setting.customScript = _customScript - - let _search = '@search@' - if (item.setting.queryType === 'statistics' || !query) { - _search = '' - } let testSql = _dataresource + _customScript + _tailScript @@ -4396,9 +4420,6 @@ let secSql = [`@ErrorCode='',@retmsg =''`] let reps = [] - if (_customScript || _tailScript) { - reps.push('UserID', 'time_id') - } let syses = ['UserName', 'FullName', 'RoleID', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address'] syses.forEach(s => { @@ -4446,134 +4467,83 @@ let LText = '' let DateCount = '' if (_dataresource) { + /*system_query*/ if (/@pageSize@|@orderBy@|@mk_total/i.test(testSql)) { - LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} ` + LText = `select ${arr_field} from ${_dataresource} ${_search} ` } else if (item.setting.laypage === 'true' && item.setting.order) { - LText = `/*system_query*/select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${_search}) tmptable where rows > @pageSize@ * (@pageIndex@ - 1) order by tmptable.rows ` + LText = `select top @pageSize@ ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${_dataresource} ${_search}) tmptable where rows > @pageSize@ * (@pageIndex@ - 1) order by tmptable.rows ` reps.push('pageSize', 'orderBy', 'pageIndex') if (item.subtype === 'dualdatacard') { - DateCount = `/*system_query*/select count(1) as total from (select distinct ${item.setting.primaryKey || 'ID'} from ${_dataresource} ${_search})a` + DateCount = `select count(1) as total from (select distinct ${item.setting.primaryKey || 'ID'} from ${_dataresource} ${_search})a` } else { - DateCount = `/*system_query*/select count(1) as total from ${_dataresource} ${_search}` + DateCount = `select count(1) as total from ${_dataresource} ${_search}` } } else if (item.setting.$top) { if (item.setting.order) { - LText = `/*system_query*/select top 1 ${arr_field} from ${_dataresource} ${_search} order by @orderBy@ ` + LText = `select top 1 ${arr_field} from ${_dataresource} ${_search} order by @orderBy@ ` reps.push('orderBy') } else { - LText = `/*system_query*/select top 1 ${arr_field} from ${_dataresource} ${_search} ` + LText = `select top 1 ${arr_field} from ${_dataresource} ${_search} ` } } else if (item.setting.order) { - LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} order by @orderBy@ ` + LText = `select ${arr_field} from ${_dataresource} ${_search} order by @orderBy@ ` reps.push('orderBy') } else { - LText = `/*system_query*/select ${arr_field} from ${_dataresource} ${_search} ` + LText = `select ${arr_field} from ${_dataresource} ${_search} ` } - } - - if (_customScript) { - _customScript = `${decSql} - ${_customScript} - ` - if (DateCount) { - DateCount = `${DateCount} - ${_tailScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode,@retmsg,@UserID@ - ` - } else if (LText) { - LText = `${LText} - ${_tailScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode,@retmsg,@UserID@ - ` - } else { - _customScript = `${_customScript} - ${_tailScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ - ` - } - } else if (_tailScript && DateCount) { - LText = `${decSql} - ${LText} - ` - DateCount = `${DateCount} - ${_tailScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ - ` - } else if (_tailScript) { - LText = `${decSql} - ${LText} - ${_tailScript} - aaa: - if @ErrorCode!='' - insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@ - ` - } else { - LText = `${decSql} - ${LText} - ` } reps = Array.from(new Set(reps)) - // LText = LText.replace(/\n\s{6,8}/g, '\n') - // DateCount = DateCount.replace(/\n\s{6,8}/g, '\n') - // _customScript = _customScript.replace(/\n\s{6,8}/g, '\n') - // LText = LText.replace(/\n\s+\/\*/g, `\n/*`) - // DateCount = DateCount.replace(/\n\s+\/\*/g, `\n/*`) - // _customScript = _customScript.replace(/\n\s+\/\*/g, `\n/*`) + let sub_name = '' + let tabid = '' + let parid = '' + let sub_field = '' + + if (item.subtype === 'dualdatacard') { + arr_field = item.columns.map(col => col.field).join(',') + sub_name = item.setting.subdata + tabid = item.setting.primaryKey || '' + parid = item.setting.subBID || '' + sub_field = item.subColumns.map(col => col.field).join(',') + } + + let sql = `SELECT obj_name='@mk_obj_name@',prm_field='',str_field='', + arr_field='${arr_field}',tabid='${tabid}',parid='${parid}',sub_name='${sub_name}',sub_field='${sub_field}' + ` + + if (DateCount) { + sql += `UNION ALL + SELECT obj_name='DateCount',prm_field='total',str_field='', + arr_field='',tabid='',parid='',sub_name='',sub_field='' + ` + } + + sql += ` + ${decSql} + ${_customScript} + ${LText} + ${DateCount} + ${_tailScript} + ` reps.forEach(n => { if (['orderBy', 'pageSize', 'pageIndex'].includes(n)) return - LText = LText.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) - DateCount = DateCount.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) - _customScript = _customScript.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) + sql = sql.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) }) - if (/\$@/ig.test(testSql)) { - LText = LText.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') - DateCount = DateCount.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') - _customScript = _customScript.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') + if (/\$@/ig.test(sql)) { + sql = sql.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') reps.push('datam_begin', 'datam_end') } - if (/@db@/ig.test(testSql)) { + if (/@db@/ig.test(sql)) { reps.push('db') } + reps.push('mk_obj_name') - // let sql = '' - // let sub_name = '' - // let tabid = '' - // let parid = '' - // let sub_field = '' + sql = sql.replace(/\n\x20{6,8}/g, '\n').replace(/\n{3,}/g, '\n\n').replace(/^\s+|\s+$/g, '') - // if (item.subtype === 'dualdatacard') { - // arr_field = item.columns.map(col => col.field).join(',') - // sub_name = item.setting.subdata - // tabid = item.setting.primaryKey || '' - // parid = item.setting.subBID || '' - // sub_field = item.subColumns.map(col => col.field).join(',') - // } - - // sql += ` - // SELECT obj_name='data',prm_field='',str_field='', - // arr_field='${arr_field}',tabid='${tabid}',parid='${parid}',sub_name='${sub_name}',sub_field='${sub_field}' - // ` - - // if (DateCount) { - // sql += `UNION ALL - // SELECT obj_name='DateCount',prm_field='total',str_field='', - // arr_field='',tabid='',parid='',sub_name='',sub_field='' - // ` - // } - - return {LText, DateCount, customScript: _customScript, reps} + return {LText: sql, reps} } let getExcelInSql = (item) => { @@ -5321,14 +5291,14 @@ item.dataSource = '(' + item.dataSource + ') tb' } - let sql = '' + let LText = '' let DateCount = '' let _search = '' let reps = [] let sFields = [] if (item.searchKey) { - _search = '@search@' + _search = '@mk_search@' sFields = item.searchKey.split(',') } @@ -5341,22 +5311,12 @@ } }) - if (item.laypage === 'true') { - sql = `/*system_query*/select top @pageSize@ ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${item.dataSource} ${_search}) tmptable where rows > @pageSize@ * (@pageIndex@ - 1) order by tmptable.rows ` - DateCount = `/*system_query*/select count(1) as total from ${item.dataSource} ${_search}` - - reps.push('pageSize', 'orderBy', 'pageIndex') - } else { - sql = `/*system_query*/select ${arrfield} from ${item.dataSource} ${_search} order by @orderBy@ ` - reps.push('orderBy') - } - let decSql = [] let secSql = [] let syses = ['mk_departmentcode', 'mk_organization', 'mk_user_type'] syses.forEach(s => { - if (new RegExp('@' + s + '[^0-9a-z_]', 'ig').test(sql)) { + if (new RegExp('@' + s + '[^0-9a-z_]', 'ig').test(item.dataSource)) { if (['mk_departmentcode', 'mk_organization'].includes(s)) { decSql.push(`@${s} nvarchar(512)`) } else { @@ -5371,27 +5331,53 @@ secSql = secSql.join(',') if (decSql) { - sql = `Declare ${decSql} select ${secSql} - ${sql} + decSql = `Declare ${decSql} select ${secSql}` + } + + if (item.laypage === 'true') { + /*system_query*/ + LText = `select top @pageSize@ ${arrfield} from (select ${arrfield} ,ROW_NUMBER() over(order by @orderBy@) as rows from ${item.dataSource} ${_search}) tmptable where rows > @pageSize@ * (@pageIndex@ - 1) order by tmptable.rows ` + DateCount = `select count(1) as total from ${item.dataSource} ${_search}` + + reps.push('pageSize', 'orderBy', 'pageIndex') + } else { + LText = `select ${arrfield} from ${item.dataSource} ${_search} order by @orderBy@ ` + reps.push('orderBy') + } + + let sql = `SELECT obj_name='data',prm_field='',str_field='', + arr_field='${arrfield}',tabid='',parid='',sub_name='',sub_field='' + ` + + if (DateCount) { + sql += `UNION ALL + SELECT obj_name='DateCount',prm_field='total',str_field='', + arr_field='',tabid='',parid='',sub_name='',sub_field='' ` } + + sql += ` + ${decSql} + ${LText} + ${DateCount} + ` reps.forEach(n => { if (['orderBy', 'pageSize', 'pageIndex'].includes(n)) return sql = sql.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) - DateCount = DateCount.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) }) if (/\$@/ig.test(sql)) { sql = sql.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') - DateCount = DateCount.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') reps.push('datam_begin', 'datam_end') } if (/@db@/ig.test(sql)) { reps.push('db') } - - return {LText: sql, DateCount, reps} + + sql = sql.replace(/\n\x20{6,8}/g, '\n').replace(/\n{3,}/g, '\n\n').replace(/^\s+|\s+$/g, '') + + return {LText: sql, reps} } let _mainSearch = [] diff --git a/src/utils/utils-datamanage.js b/src/utils/utils-datamanage.js index 4e96051..aff2f1e 100644 --- a/src/utils/utils-datamanage.js +++ b/src/utils/utils-datamanage.js @@ -13,7 +13,12 @@ let param = null if (setting.interType === 'system') { - param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + if (window.backend && window.GLOB.CacheData.has('sql_' + setting.uuid) && !window.GLOB.mkHS) { + param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + this.getBackendQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + } else { + param = this.getDefaultQueryParam(setting, search, orderBy, pageIndex, pageSize, id, BID, year) + } } else { param = this.getCustomQueryParam(setting, search, orderBy, pageIndex, pageSize, id, year) } @@ -289,72 +294,6 @@ param.menuname = setting.$name } - // if (window.backend && window.GLOB.CacheData.has('sql_' + setting.uuid)) { - // let item = window.GLOB.CacheData.get('sql_' + setting.uuid) - - // let values = { - // userid: sessionStorage.getItem('UserID') || '', - // time_id: Utils.getguid(), - // username: userName, - // fullname: fullName, - // roleid: RoleID, - // mk_departmentcode: departmentcode, - // mk_organization: organization, - // mk_user_type: mk_user_type, - // mk_nation: nation, - // mk_province: province, - // mk_city: city, - // mk_district: district, - // mk_address: address, - // orderby: orderBy, - // pagesize: setting.laypage ? pageSize : '9999', - // pageindex: pageIndex, - // id: id || '', - // bid: BID || '', - // loginuid: sessionStorage.getItem('LoginUID') || '', - // sessionuid: localStorage.getItem('SessionUid') || '', - // appkey: window.GLOB.appkey || '', - // lang: sessionStorage.getItem('lang'), - // typename: 'admin', - // datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', - // datam_begin: sessionStorage.getItem('dataM') === 'true' ? '/*' : '', - // datam_end: sessionStorage.getItem('dataM') === 'true' ? '*/' : '', - // } - - // if (setting.hasExtend) { - // values.mk_time = setting.extendTime - // } - // if (setting.$re_year) { - // values.mk_year = year - // } - // if (window.GLOB.externalDatabase !== null) { - // values.db = window.GLOB.externalDatabase - // } - // if (item.works_flow_code) { - // values.works_flow_code = item.works_flow_code - // } - // item.urlkeys.forEach(key => { - // values[key] = item.urlparam[key] - // }) - - // let Ltext = item.LText - // let DateCount = item.DateCount - // let customScript = item.customScript - - // item.reps.forEach(n => { - // let key = n.toLowerCase() - // if (values.hasOwnProperty(key)) { - // Ltext = Ltext.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // DateCount = DateCount.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // customScript = customScript.replace(new RegExp('@' + key + '@', 'ig'), values[key]) - // } - // }) - - // if (search.length) { - - // } - // } - param.custom_script = Utils.formatOptions(_customScript, param.exec_type) param.LText = Utils.formatOptions(LText, param.exec_type) param.DateCount = Utils.formatOptions(DateCount, param.exec_type) @@ -397,6 +336,235 @@ } /** + * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼鐨勫弬鏁� + */ + static getBackendQueryParam (setting, search, orderBy, pageIndex, pageSize, id, BID, year) { + let item = window.GLOB.CacheData.get('sql_' + setting.uuid) + + let param = {} + + let searchKeys = null + if (setting.dataresource) { + searchKeys = [] + + if (search.length) { + searchKeys = Utils.getSearchkeys(search) + } + + if (id) { + if (/^excel:/.test(id)) { + id = id.replace(/^excel:/, '') + searchKeys.push({ + key: setting.primaryKey || 'ID', + match: 'in', + type: 'text_in', + value: id + }) + } else { + searchKeys.push({ + key: setting.primaryKey || 'ID', + match: '=', + type: 'text', + value: id + }) + } + } + } + + let values = { + userid: sessionStorage.getItem('UserID') || '', + time_id: Utils.getguid(), + username: sessionStorage.getItem('User_Name') || '', + fullname: sessionStorage.getItem('Full_Name') || '', + roleid: sessionStorage.getItem('role_id') || '', + mk_departmentcode: sessionStorage.getItem('departmentcode') || '', + mk_organization: sessionStorage.getItem('organization') || '', + mk_user_type: sessionStorage.getItem('mk_user_type') || '', + mk_nation: sessionStorage.getItem('nation') || '', + mk_province: sessionStorage.getItem('province') || '', + mk_city: sessionStorage.getItem('city') || '', + mk_district: sessionStorage.getItem('district') || '', + mk_address: sessionStorage.getItem('address') || '', + orderby: orderBy, + pagesize: setting.laypage ? pageSize : '9999', + pageindex: pageIndex, + id: id || '', + bid: BID || '', + loginuid: sessionStorage.getItem('LoginUID') || '', + sessionuid: localStorage.getItem('SessionUid') || '', + appkey: window.GLOB.appkey || '', + lang: sessionStorage.getItem('lang'), + typename: 'admin', + datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', + // datam_begin: sessionStorage.getItem('dataM') === 'true' ? '/*' : '', + // datam_end: sessionStorage.getItem('dataM') === 'true' ? '*/' : '', + mk_obj_name: 'data' + } + + if (setting.hasExtend) { + values.mk_time = setting.extendTime + } + if (setting.$re_year) { + values.mk_year = year + } + if (window.GLOB.externalDatabase !== null) { + values.db = window.GLOB.externalDatabase + } + if (item.works_flow_code) { + values.works_flow_code = item.works_flow_code + } + + item.urlkeys.forEach(key => { + values[key] = item.urlparam[key] + }) + + let allSearch = Utils.getAllSearchOptions(search) + + allSearch.forEach(cell => { + values[cell.key.toLowerCase()] = cell.value + }) + + let list = [] + + if (searchKeys) { + list.push({ + key: 'mk_search', + value: searchKeys + }) + } + + let sql = item.sql + + item.reps.forEach(n => { + let key = n.toLowerCase() + if (values.hasOwnProperty(key)) { + list.push({ + key: n, + value: values[key] + }) + } + }) + + // let list = [ + // { + // key: "mk_search", + // value: [ + // { key: "nvarchar1,nvarchar3", match: "like", type: "text_or", value: "www" }, + // { key: "int2", match: ">=", type: "number", value: "0" }, + // { key: "int2", match: "<=", type: "number", value: "50" } + // ] + // }, + // { key: "mk_obj_name", value: "data" }, + // { key: "pageSize", value: 10 }, + // { key: "orderBy", value: "ID desc" }, + // { key: "pageIndex", value: 1 }, + // { + // key: 'mk_excel_data', + // value: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`], [`'6'`, `'7'`, `'8'`, `'9'`, `'10'`]] + // }, + // { + // key: 'mk_outer_params', + // value: [ + // { + // tb: '#tb1', + // keys: ['[nvarchar1]', '[nvarchar2]', '[nvarchar3]', '[mk_level]','[mk_id]','[mk_bid]'], + // values: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`, `'6'`], [`'7'`, `'8'`, `'9'`, `'10'`, `'11'`, `'12'`]] + // }, + // { + // tb: '@tb2', + // keys: ['[field1]', '[field2]', '[field3]', '[mk_level]','[mk_id]','[mk_bid]'], + // values: [[`'1'`, `'2'`, `'3'`, `'4'`, `'5'`, `'6'`], [`'7'`, `'8'`, `'9'`, `'10'`, `'11'`, `'12'`]] + // } + // ] + // }, + // ] + + list.forEach(cell => { + if (cell.key === 'mk_outer_params') { + let mk_outer_params = [] + cell.value.forEach(n => { + mk_outer_params.push(` Insert into ${n.tb} (${n.keys.join(',')}) `) + let vals = [] + n.values.forEach(m => { + vals.push(` Select ${m.join(',')} `) + }) + mk_outer_params.push(vals.join(' Union all ')) + }) + mk_outer_params = mk_outer_params.join('') + sql = sql.replace(/@mk_outer_params@/ig, mk_outer_params) + } else if (cell.key === 'mk_excel_data') { + let mk_excel_data = [] + cell.value.forEach(n => { + mk_excel_data.push(`Select ${n.join(',')}`) + }) + mk_excel_data = mk_excel_data.join(' Union all ') + sql = sql.replace(/@mk_excel_data@/ig, mk_excel_data) + } else if (cell.key === 'datam_begin' || cell.key === 'mk_check_begin') { + if (cell.value === 'Y') { + sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '/*') + } else { + sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '') + } + } else if (cell.key === 'datam_end' || cell.key === 'mk_check_end') { + if (cell.value === 'Y') { + sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '*/') + } else { + sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), '') + } + } else if (cell.key === 'mk_search') { + let mk_search = [] + + cell.value.forEach(n => { + let str = n.match === 'like' || n.match === 'not like' ? '%' : '' + if (n.type === 'text_or') { + let vals = n.key.split(',').map(key => { + return `${key} ${n.match} '${str}${n.value}${str}'` + }) + + mk_search.push(`(${vals.join(' OR ')})`) + } else if (n.type === 'text_multi') { + mk_search.push(`'${n.value}' ${n.match} '%'+${n.key}+'%'`) + } else if (n.type === 'number') { + mk_search.push(`${n.key} ${n.match} ${n.value}`) + } else if (n.type === 'text_in') { + mk_search.push(`${n.key} in (select ID from dbo.SplitComma('${n.value}'))`) + } else { + mk_search.push(`${n.key} ${n.match} '${str}${n.value}${str}'`) + } + }) + + if (mk_search.length === 0) { + mk_search = '' + } else { + mk_search = 'where ' + mk_search.join(' AND ') + } + + sql = sql.replace(/@mk_search@/ig, mk_search) + } else { + sql = sql.replace(new RegExp('@' + cell.key + '@', 'ig'), cell.value) + } + }) + + param.list = [ + { + id: item.v_id, + regExps: list, + menuname: setting.$name || '', + s_debug_type: window.GLOB.probation ? 'Y' : '', + // md5_id: window.GLOB.probation ? md5(JSON.stringify(list)) : '', + } + ] + + if (setting.database === 'sso' && window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } + + return param + } + + /** * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼鍚堣鍊肩殑鍙傛暟 */ static getStatQueryDataParams (setting, statFields, search, orderBy, BID) { diff --git a/src/utils/utils.js b/src/utils/utils.js index ac418a1..d63640a 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -712,6 +712,144 @@ return searchText.join(' AND ') } + static getSearchkeys (searches) { + let searchText = [] + + searches.forEach(item => { + if (item.forbid || !item.value) return + + let cell = { + key: item.key, + match: item.match, + type: 'text', + value: item.value + } + + if (item.type === 'text' || item.type === 'select') { // 缁煎悎鎼滅储锛屾枃鏈垨涓嬫媺锛屾墍鏈夊瓧娈垫嫾鎺� + if (/,/.test(item.key)) { + cell.type = 'text_or' + } + } else if (item.type === 'multi') { + cell.type = 'text_multi' + } else if (item.type === 'date') { + let _val = item.value + let timetail = '' + + if (item.match === '<' || item.match === '<=') { // 鏃堕棿涓�<=鏃讹紝鍖归厤鍚庝竴澶╃殑0鐐癸紝鍖归厤鏂瑰紡涓�< + cell.match = '<' + if (item.precision === 'day') { + _val = moment(_val, 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + } + } + if (item.match === '=') { + timetail = '' + } else if (item.precision === 'day') { + timetail = ' 00:00:00.000' + } else if (item.precision === 'hour') { + timetail = ':00:00.000' + } else if (item.precision === 'minute') { + timetail = ':00.000' + } else if (item.precision === 'second') { + timetail = '.000' + } + + cell.value = _val + timetail + } + + if (item.type === 'datemonth') { // 鏈�-杩囨护鏉′欢锛屼粠鏈堝紑濮嬭嚦缁撴潫锛岀粨鏉熸椂闂翠负鏈堟湯鍔犱竴澶╃殑0鐐癸紝鏂瑰紡涓�< + if (item.match === '=') { + searchText.push(cell) + } else { + let _startval = moment(item.value, 'YYYY-MM').startOf('month').format('YYYY-MM-DD') + ' 00:00:00.000' + let _endval = moment(item.value, 'YYYY-MM').endOf('month').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + + searchText.push({ + key: item.key, + match: '>=', + type: 'text', + value: _startval + }, { + key: item.key, + match: '<', + type: 'text', + value: _endval + }) + } + } else if (item.type === 'dateweek') { // 鍛�-杩囨护鏉′欢 + let _startval = moment(item.value, 'YYYY-MM-DD' ).startOf('week').format('YYYY-MM-DD') + ' 00:00:00.000' + let _endval = moment(item.value, 'YYYY-MM-DD').endOf('week').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + + searchText.push({ + key: item.key, + match: '>=', + type: 'text', + value: _startval + }, { + key: item.key, + match: '<', + type: 'text', + value: _endval + }) + } else if (item.type === 'daterange') { + let val = item.value.split(',') + let _startval = '' + let _endval = '' + + if (item.precision === 'day') { + _startval = val[0] + ' 00:00:00.000' + _endval = moment(val[1], 'YYYY-MM-DD').add(1, 'days').format('YYYY-MM-DD') + ' 00:00:00.000' + } else if (item.precision === 'hour') { + _startval = val[0] + ':00:00.000' + _endval = val[1] + ':00:00.000' + } else if (item.precision === 'minute') { + _startval = val[0] + ':00.000' + _endval = val[1] + ':00.000' + } else if (item.precision === 'second') { + _startval = val[0] + '.000' + _endval = val[1] + '.000' + } + + let _skey = item.key + let _ekey = item.key + + if (/,/.test(item.key)) { + _skey = item.key.split(',')[0] + _ekey = item.key.split(',')[1] + } + + searchText.push({ + key: _skey, + match: '>=', + type: 'text', + value: _startval + }, { + key: _ekey, + match: '<', + type: 'text', + value: _endval + }) + } else if (item.type === 'range') { + let val = item.value.split(',') + + searchText.push({ + key: item.key, + match: '>=', + type: 'number', + value: val[0] || -999999999 + }, { + key: item.key, + match: '<=', + type: 'number', + value: val[1] || 999999999 + }) + } else { + searchText.push(cell) + } + }) + + return searchText + } + /** * @description 鑾峰彇鎼滅储鐢ㄤ簬姝e垯鏇挎崲 * @param {Array} searches 鎼滅储鏉′欢 diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx index 494b40e..36cb91f 100644 --- a/src/views/menudesign/index.jsx +++ b/src/views/menudesign/index.jsx @@ -13,7 +13,7 @@ import Utils from '@/utils/utils.js' import { langs } from '@/store/options' import MKEmitter from '@/utils/events.js' -import { getTables, getFuncsAndInters, getLangTrans } from '@/utils/utils-custom.js' +import { getTables, getFuncsAndInters, getLangTrans, getAllSqls } from '@/utils/utils-custom.js' import asyncComponent from '@/utils/asyncComponent' import '@/assets/css/design.scss' @@ -780,7 +780,7 @@ } else if (this.checklog()) { if (sessionStorage.getItem('langList') && !config.trans) { - // } else if (window.backend && config.enabled && !config.allSqls) { + } else if (window.backend && config.enabled && !config.allSqls) { } else { notification.success({ @@ -808,13 +808,36 @@ delete config.force } - // let sqls = [] - // delete config.allSqls - // if (window.backend && config.enabled) { - // sqls = getAllSqls(config) + let long_data = '' + delete config.allSqls + if (window.backend && config.enabled) { + let sqls = getAllSqls(config) + let _t = moment().format('YYYYMMDDHHmmss') + let getguid = () => { + let uuid = '' + for (let i = 0; i < 18; i++) { + uuid += String.fromCharCode(Math.floor(Math.random() * 26) + 65) + } + return uuid + } - // config.allSqls = sqls - // } + long_data = [] + + config.allSqls = sqls.map(item => { + let v_id = _t + getguid() + long_data.push(`${md5(window.GLOB.appkey + v_id)},${item.uuid},${v_id},${window.btoa(window.encodeURIComponent(item.LText))}`) + + return { + uuid: item.uuid, + v_id: v_id, + type: item.type, + reps: item.reps, + sql: item.LText + } + }) + + long_data = long_data.join(';') + } if (config.cacheUseful !== 'true') { config.components = this.resetSyncQuery(config.components) @@ -877,8 +900,7 @@ MenuName: config.MenuName || '', PageParam: JSON.stringify({Template: 'CustomPage', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false', menuColor: config.menuColor || '', interfaces, urlFields}), open_edition: config.open_edition, - // LText: '', - // LTexttb: '', + long_data: long_data, debug_md5: key, debug_url: url, debug_list: window.btoa(tbs), diff --git a/src/views/tabledesign/index.jsx b/src/views/tabledesign/index.jsx index 8b998c2..26510b9 100644 --- a/src/views/tabledesign/index.jsx +++ b/src/views/tabledesign/index.jsx @@ -12,7 +12,7 @@ import Utils from '@/utils/utils.js' import { langs } from '@/store/options' import MKEmitter from '@/utils/events.js' -import { getTables, getFuncsAndInters, getLangTrans } from '@/utils/utils-custom.js' +import { getTables, getFuncsAndInters, getLangTrans, getAllSqls } from '@/utils/utils-custom.js' import SourceElement from '@/templates/zshare/dragsource' import asyncComponent from '@/utils/asyncComponent' import Source from './source' @@ -540,7 +540,7 @@ } else if (this.checklog()) { if (sessionStorage.getItem('langList') && !config.trans) { - // } else if (window.backend && config.enabled && !config.allSqls) { + } else if (window.backend && config.enabled && !config.allSqls) { } else { notification.success({ @@ -568,13 +568,36 @@ delete config.force } - // let sqls = [] - // delete config.allSqls - // if (window.backend && config.enabled) { - // sqls = getAllSqls(config) + let long_data = '' + delete config.allSqls + if (window.backend && config.enabled) { + let sqls = getAllSqls(config) + let _t = moment().format('YYYYMMDDHHmmss') + let getguid = () => { + let uuid = '' + for (let i = 0; i < 18; i++) { + uuid += String.fromCharCode(Math.floor(Math.random() * 26) + 65) + } + return uuid + } - // config.allSqls = sqls - // } + long_data = [] + + config.allSqls = sqls.map(item => { + let v_id = _t + getguid() + long_data.push(`${md5(window.GLOB.appkey + v_id)},${item.uuid},${v_id},${window.btoa(window.encodeURIComponent(item.LText))}`) + + return { + uuid: item.uuid, + v_id: v_id, + type: item.type, + reps: item.reps, + sql: item.LText + } + }) + + long_data = long_data.join(';') + } let tbs = [] let btns = this.getMenuMessage(tbs) @@ -625,8 +648,7 @@ MenuName: config.MenuName || '', PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false', menuColor: config.menuColor || '', interfaces, urlFields}), open_edition: config.open_edition, - // LText: '', - // LTexttb: '', + long_data: long_data, debug_md5: key, debug_url: url, debug_list: window.btoa(tbs), -- Gitblit v1.8.0