| | |
| | | export default class SettingUtils { |
| | | /** |
| | | * @description 生成页面查询语句 |
| | | * @return {String} scripts 自定义脚本 |
| | | * @return {Object} setting 页面设置 |
| | | */ |
| | | static getDebugSql (setting) { |
| | | static getDebugSql (setting, scripts) { |
| | | let arr_field = `${setting.valueField},${setting.labelField},${setting.parentField}` |
| | | let sql = '' |
| | | let _dataresource = setting.dataresource |
| | | let _customScript = setting.customScript |
| | | let _dataresource = setting.dataresource || '' |
| | | let _customScript = '' |
| | | |
| | | if (setting.interType === 'inner' && !setting.innerFunc && setting.default === 'false') { |
| | | scripts && scripts.forEach(script => { |
| | | _customScript += ` |
| | | ${script.sql} |
| | | ` |
| | | }) |
| | | |
| | | if (_customScript) { |
| | | _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg ='' |
| | | ${_customScript} |
| | | ` |
| | | } |
| | | |
| | | if (setting.default === 'false') { |
| | | _dataresource = '' |
| | | } |
| | | |
| | | if (_dataresource) { |
| | | _dataresource = _dataresource.replace(/@\$|\$@/ig, '') |
| | | } |
| | | if (_customScript) { |
| | | _customScript = _customScript.replace(/@\$|\$@/ig, '') |
| | | } |
| | | _dataresource = _dataresource.replace(/@\$|\$@/ig, '') |
| | | _customScript = _customScript.replace(/@\$|\$@/ig, '') |
| | | |
| | | // 正则替换 |
| | | let _regoptions = [ |
| | | { |
| | | reg: new RegExp('@orderBy@', 'ig'), |
| | | value: setting.order |
| | | } |
| | | ] |
| | | |
| | | if (_customScript) { |
| | | _customScript = _customScript.replace(/@orderBy@/ig, setting.order) |
| | | } |
| | | _regoptions.forEach(item => { |
| | | _customScript = _customScript.replace(item.reg, item.value) |
| | | }) |
| | | |
| | | // 数据源处理 |
| | | if (_dataresource) { |
| | |
| | | _dataresource = '(' + _dataresource + ') tb' |
| | | } |
| | | |
| | | let arr_field = `${setting.valueField}, ${setting.labelField}, ${setting.parentField}` |
| | | |
| | | _dataresource = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows` |
| | | _dataresource = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows ` |
| | | } |
| | | |
| | | if (_customScript) { |