From ae170a9d58b4f91a225eada1dc83ed4a116b8d50 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期日, 25 八月 2024 00:57:37 +0800 Subject: [PATCH] 2024-08-25 --- src/utils/utils-custom.js | 354 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 327 insertions(+), 27 deletions(-) diff --git a/src/utils/utils-custom.js b/src/utils/utils-custom.js index 01210e4..6556d9f 100644 --- a/src/utils/utils-custom.js +++ b/src/utils/utils-custom.js @@ -2855,11 +2855,17 @@ /** * @description 鑾峰彇鎵ц鑴氭湰 */ -export function getAllSqls (config) { +export function getAllSqls (conf) { + let config = fromJS(conf).toJS() + let sqls = [] let urlFields = config.urlFields let appType = sessionStorage.getItem('appType') let process = config.process === 'true' + + if (urlFields) { + urlFields = urlFields.map(n => n.toLowerCase()) + } let filterComponent = (components, mainSearch) => { components.forEach(item => { @@ -2888,6 +2894,15 @@ if (appType === 'mob' && item.type !== 'search' && item.type !== 'topbar' && item.search && item.search.length > 0) { item.search = [] } + if (appType !== 'mob' && item.search && item.search.length > 0) { + item.search.forEach(cell => { + if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(cell.type) && cell.resourceType === '1' && cell.dataSource) { + let msg = getFormSql(cell) + + sqls.push({uuid: cell.uuid, type: 'sForm', ...msg}) + } + }) + } if (item.subtype === 'tablecard') { // 鍏煎 item.type = 'card' @@ -2901,7 +2916,7 @@ let msg = getDataSource(item, mainSearch) - sqls.push({uuid: item.uuid, ...msg}) + sqls.push({uuid: item.uuid, type: 'datasource', ...msg}) } else if (item.setting && item.setting.useMSearch === 'true') { let searches = item.search || [] if (mainSearch.length > 0) { @@ -2930,6 +2945,24 @@ resetButton(item, cell) }) + } else if (item.subtype === 'editable' && col.editable === 'true') { + if (col.editType === 'select' && col.resourceType === '1') { + let msg = getFormSql(col) + + sqls.push({uuid: col.uuid, type: 'tbForm', ...msg}) + } else if (col.editType === 'popSelect') { + if (col.pops) { + col.pops.forEach(n => { + let msg = getPopSelectSql(n) + + sqls.push({uuid: n.uuid, type: 'popSource', ...msg}) + }) + } else { + let msg = getPopSelectSql(col) + + sqls.push({uuid: col.uuid, type: 'popSource', ...msg}) + } + } } }) } @@ -2939,7 +2972,7 @@ if (item.subtype === 'editable' && item.submit.intertype === 'system') { let msg = getEditTableSql(item.submit, item.cols, item.columns) - sqls.push({uuid: 'submit_' + item.uuid, ...msg}) + sqls.push({uuid: 'submit_' + item.uuid, type: 'editable', ...msg}) } } else if (item.type === 'card' || item.type === 'carousel' || item.type === 'timeline') { item.subcards && item.subcards.forEach(card => { @@ -2991,11 +3024,11 @@ let msg = getSysDefaultSql(cell, _item) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'button', ...msg}) } else { let msg = getSysDefaultSql(cell, item) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'button', ...msg}) } } if (cell.callbackType === 'script' && cell.verify && cell.verify.cbScripts) { @@ -3005,42 +3038,70 @@ let msg = getSysBackSql(cell, _item) - sqls.push({uuid: 'back_' + cell.uuid, ...msg}) + sqls.push({uuid: 'back_' + cell.uuid, type: 'btnCallBack', ...msg}) } else { let msg = getSysBackSql(cell, item) - sqls.push({uuid: 'back_' + cell.uuid, ...msg}) + sqls.push({uuid: 'back_' + cell.uuid, type: 'btnCallBack', ...msg}) } + } + if (['pop', 'formSubmit'].includes(cell.OpenType) && cell.modal && cell.modal.fields) { + cell.modal.fields.forEach(form => { + // 鏁版嵁婧恠ql璇彞锛岄澶勭悊锛屾潈闄愰粦鍚嶅崟瀛楁璁剧疆涓洪殣钘忚〃鍗� + if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(form.type) && form.resourceType === '1') { + let msg = getFormSql(form) + + sqls.push({uuid: form.uuid, type: 'form', ...msg}) + } else if (form.type === 'popSelect') { + let msg = getPopSelectSql(form) + + sqls.push({uuid: form.uuid, type: 'popSource', ...msg}) + } + }) } } else if (cell.OpenType === 'excelIn') { if (cell.intertype === 'system') { let msg = getExcelInSql(cell) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'excelIn', ...msg}) } } else if (cell.OpenType === 'excelOut') { if (cell.intertype === 'system' && cell.verify && cell.verify.dataType === 'custom') { let msg = getExcelOutSql(cell, item) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'excelOut', ...msg}) } } else if (cell.OpenType === 'funcbutton') { if (cell.funcType === 'print') { if (cell.intertype === 'system' && cell.verify && cell.verify.dataType === 'custom') { let msg = getPrintSql(cell) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'print', ...msg}) + } + if (cell.execMode === 'pop' && cell.modal && cell.modal.fields) { + cell.modal.fields.forEach(form => { + // 鏁版嵁婧恠ql璇彞锛岄澶勭悊锛屾潈闄愰粦鍚嶅崟瀛楁璁剧疆涓洪殣钘忚〃鍗� + if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(form.type) && form.resourceType === '1') { + let msg = getFormSql(form) + + sqls.push({uuid: form.uuid, type: 'form', ...msg}) + } else if (form.type === 'popSelect') { + let msg = getPopSelectSql(form) + + sqls.push({uuid: form.uuid, type: 'popSource', ...msg}) + } + }) } } else if ((cell.funcType === 'refund' || cell.funcType === 'pay') && cell.payMode === 'system') { let msg = getPaySql(cell, item) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'pay', ...msg}) } } else if (cell.OpenType === 'innerpage' || cell.OpenType === 'outerpage') { if (cell.pageTemplate === 'pay' && cell.payMode === 'system') { let msg = getPaySql(cell, item) - sqls.push({uuid: cell.uuid, ...msg}) + sqls.push({uuid: cell.uuid, type: 'pay', ...msg}) } } else if (cell.OpenType === 'popview') { if (cell.config && cell.config.components) { @@ -3148,6 +3209,11 @@ verify.invalid = 'false' } else if (btn.Ot === 'notRequired') { verify.invalid = 'false' + } + } + if (verify.uniques && verify.uniques.length > 0 && btn.Ot === 'requiredOnce') { + if (component.wrap && (component.wrap.datatype === 'static' || component.wrap.datatype === 'public')) { + verify.uniques = [] } } @@ -4011,6 +4077,9 @@ _sql = _sql.replace(/\$check@/ig, '@mk_check_begin@').replace(/@check\$/ig, '@mk_check_end@') reps.push('mk_check_begin', 'mk_check_end') } + if (/@db@/ig.test(_sql)) { + reps.push('db') + } reps = Array.from(new Set([...reps, ...colreps])) @@ -4261,6 +4330,9 @@ _sql = _sql.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') reps.push('datam_begin', 'datam_end') } + if (/@db@/ig.test(_sql)) { + reps.push('db') + } reps = Array.from(new Set([...reps, ...colreps])) @@ -4270,7 +4342,6 @@ let getDataSource = (item, mainSearch = []) => { if (!item.setting || item.setting.interType !== 'system') return - item.setting.primaryKey = item.setting.primaryKey || 'ID' let searches = item.search || [] if (item.setting.useMSearch === 'true' && mainSearch.length > 0) { searches = [...searches, ...mainSearch] @@ -4348,7 +4419,7 @@ select ${secSql.join(',')}` // 涓嶉渶瑕佸崟寮曞彿锛歰rderBy銆乸ageSize銆乸ageIndex銆乨b - let regs = [...sFields, 'orderBy', 'pageSize', 'pageIndex', 'typename', 'datam', 'ID', 'BID', 'time_id', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'lang', 'typename'] + let regs = [...sFields, 'orderBy', 'pageSize', 'pageIndex', 'ID', 'BID', 'time_id', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'lang', 'datam', 'typename'] if (item.hasExtend) { regs.push('mk_time') @@ -4378,10 +4449,10 @@ if (/@pageSize@|@orderBy@|@mk_total/i.test(testSql)) { LText = `/*system_query*/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 > @mk_rows_begin@ order by tmptable.rows ` - reps.push('pageSize', 'orderBy', 'mk_rows_begin') + 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 ` + reps.push('pageSize', 'orderBy', 'pageIndex') if (item.subtype === 'dualdatacard') { - DateCount = `/*system_query*/select count(1) as total from (select distinct ${item.setting.primaryKey} from ${_dataresource} ${_search})a` + DateCount = `/*system_query*/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}` } @@ -4452,15 +4523,15 @@ 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/*`) + // 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/*`) reps.forEach(n => { - if (['orderBy', 'pageSize', 'pageIndex', 'mk_rows_begin'].includes(n)) return + if (['orderBy', 'pageSize', 'pageIndex'].includes(n)) return LText = LText.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) DateCount = DateCount.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) @@ -4472,6 +4543,35 @@ _customScript = _customScript.replace(/\$@/ig, '@datam_begin@').replace(/@\$/ig, '@datam_end@') reps.push('datam_begin', 'datam_end') } + if (/@db@/ig.test(testSql)) { + reps.push('db') + } + + // let sql = '' + // 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(',') + // } + + // 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} } @@ -4727,6 +4827,9 @@ sql = sql.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, reps} } @@ -4958,6 +5061,9 @@ sql = sql.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, reps} } @@ -4979,7 +5085,6 @@ item.setting.interType = 'system' item.setting.execute = btn.verify.defaultSql || 'true' item.setting.dataresource = btn.verify.dataresource || '' - item.setting.primaryKey = btn.verify.primaryKey || '' item.setting.queryType = btn.verify.queryType item.setting.laypage = btn.pagination item.setting.order = btn.verify.order || '' @@ -5001,7 +5106,6 @@ item.setting.interType = 'system' item.setting.execute = btn.verify.setting.defaultSql || 'true' item.setting.dataresource = btn.verify.setting.dataresource || '' - item.setting.primaryKey = '' item.setting.queryType = btn.verify.setting.queryType item.setting.laypage = 'false' item.setting.order = btn.verify.setting.order || '' @@ -5100,8 +5204,194 @@ _sql = _sql.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, reps} + } + + let getFormSql = (item) => { + let arrfield = [item.valueField, item.valueText] + + if (item.type === 'checkcard') { + arrfield = item.fields ? item.fields.map(f => f.field) : [] + arrfield.push(item.cardValField) + if (item.urlField) { + arrfield.push(item.urlField) + } else if (item.colorField) { + arrfield.push(item.colorField) + } else if (item.parentField) { + arrfield.push(item.parentField) + } + } + + if (item.linkField) { + arrfield.push(item.linkField) + } + if (['select', 'radio', 'link', 'checkcard'].includes(item.type) && item.linkSubField && item.linkSubField.length > 0) { + arrfield.push(...item.linkSubField) + } else if (item.type === 'text' && item.editType === 'select' && item.linkSubField && item.linkSubField.length > 0) { // 鍙紪杈戣〃 + arrfield.push(...item.linkSubField) + } + if (item.disableField) { + arrfield.push(item.disableField) + } + + arrfield = Array.from(new Set(arrfield)) + + let _datasource = item.dataSource + let sql = '' + + if (/\s/.test(_datasource)) { // 鎷兼帴鍒悕 + _datasource = '(' + _datasource + ') tb' + } + + arrfield = arrfield.join(',') + + if (item.orderBy) { + sql = `select distinct ${arrfield},${item.orderBy} as orderfield from ${_datasource} order by orderfield ${item.orderType}` + } else { + sql = `select distinct ${arrfield} from ${_datasource}` + } + + let reps = [] + + 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 (['mk_departmentcode', 'mk_organization'].includes(s)) { + decSql.push(`@${s} nvarchar(512)`) + } else { + decSql.push(`@${s} nvarchar(20)`) + } + secSql.push(`@${s}=@${s}@`) + reps.push(s) + } + }) + + decSql = decSql.join(',') + secSql = secSql.join(',') + + if (decSql) { + sql = `Declare ${decSql} select ${secSql} + ${sql} + ` + } + + let regs = ['ID', 'BID', 'datam', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'lang'] + + regs.forEach(s => { + if (new RegExp('@' + s + '@', 'ig').test(sql)) { + reps.push(s) + } + }) + + reps.forEach(n => { + sql = sql.replace(new RegExp('@' + n + '@', 'ig'), `'@${n}@'`) + }) + + if (/\$@/ig.test(sql)) { + sql = sql.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, reps} + } + + let getPopSelectSql = (item) => { + let arrfield = item.columns.map(f => f.field) + + if (item.linkSubField && item.linkSubField.length > 0) { + item.linkSubField.forEach(n => { + if (!arrfield.includes(n)) { + arrfield.push(n) + } + }) + } + + arrfield = arrfield.join(',') + if (/\s/.test(item.dataSource)) { // 鎷兼帴鍒悕 + item.dataSource = '(' + item.dataSource + ') tb' + } + + let sql = '' + let DateCount = '' + let _search = '' + let reps = [] + let sFields = [] + + if (item.searchKey) { + _search = '@search@' + sFields = item.searchKey.split(',') + } + + // 涓嶉渶瑕佸崟寮曞彿锛歰rderBy銆乸ageSize銆乸ageIndex銆乨b + let regs = [...sFields, 'orderBy', 'pageSize', 'pageIndex', 'ID', 'BID', 'time_id', 'LoginUID', 'SessionUid', 'UserID', 'Appkey', 'lang', 'datam'] + + regs.forEach(s => { + if (new RegExp('@' + s + '@', 'ig').test(item.dataSource)) { + reps.push(s) + } + }) + + 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 (['mk_departmentcode', 'mk_organization'].includes(s)) { + decSql.push(`@${s} nvarchar(512)`) + } else { + decSql.push(`@${s} nvarchar(20)`) + } + secSql.push(`@${s}=@${s}@`) + reps.push(s) + } + }) + + decSql = decSql.join(',') + secSql = secSql.join(',') + + if (decSql) { + sql = `Declare ${decSql} select ${secSql} + ${sql} + ` + } + + 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} } let _mainSearch = [] @@ -5138,6 +5428,16 @@ } search.push(...group.fields) }) + + if (search.length > 0) { + search.forEach(cell => { + if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(cell.type) && cell.resourceType === '1' && cell.dataSource) { + let msg = getFormSql(cell) + + sqls.push({uuid: cell.uuid, type: 'sForm', ...msg}) + } + }) + } } if (search.length > 0) { @@ -5160,7 +5460,7 @@ let msg = getDataSource(m, _mainSearch) - sqls.push({uuid: m.uuid, ...msg}) + sqls.push({uuid: m.uuid, type: 'interface', ...msg}) }) } -- Gitblit v1.8.0