| | |
| | | } |
| | | |
| | | /** |
| | | * @description 格式化搜索条件 |
| | | */ |
| | | export function formatSearch (searches) { |
| | | if (!searches) return [] |
| | | |
| | | let newsearches = [] |
| | | searches.forEach(item => { |
| | | if (!item.field) return |
| | | |
| | | if (item.type === 'group') { |
| | | newsearches.push({ |
| | | key: item.field, |
| | | match: '', |
| | | type: item.type, |
| | | value: 'customized', |
| | | forbid: true |
| | | }, { |
| | | key: item.datefield, |
| | | match: 'between', |
| | | type: 'daterange', |
| | | value: '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000', |
| | | forbid: item.query === 'false' |
| | | }) |
| | | } else { |
| | | let value = item.initval |
| | | let type = item.type |
| | | |
| | | if (item.type === 'date') { |
| | | value = '1949-10-01 00:00:00.000' |
| | | } else if (item.type === 'datemonth') { |
| | | value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' |
| | | } else if (item.type === 'dateweek') { |
| | | value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' |
| | | } else if (item.type === 'daterange') { |
| | | value = '1949-10-01 00:00:00.000,1949-10-02 00:00:00.000' |
| | | } else if (item.type === 'range') { |
| | | value = `${item.minValue},${item.maxValue}` |
| | | } else if (item.type === 'multiselect' || (item.type === 'checkcard' && item.multiple === 'true')) { |
| | | type = 'multi' |
| | | value = '0' |
| | | } else { |
| | | value = '0' |
| | | } |
| | | newsearches.push({ |
| | | key: item.field, |
| | | match: item.match, |
| | | type: type, |
| | | value: value, |
| | | precision: item.precision || 'day', |
| | | forbid: item.query === 'false' |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | return newsearches |
| | | } |
| | | |
| | | /** |
| | | * @description 拼接where条件 |
| | | */ |
| | | export function joinMainSearchkey (searches) { |
| | | if (!searches || searches.length === 0) return '' |
| | | |
| | | let searchText = [] |
| | | searches.forEach(item => { |
| | | if (item.forbid) return |
| | | |
| | | if (item.type === 'text' || item.type === 'select') { // 综合搜索,文本或下拉,所有字段拼接 |
| | | let str = item.match === 'like' || item.match === 'not like' ? '%' : '' |
| | | let fields = item.key.split(',').map(field => { |
| | | return field + ' ' + item.match + ' \'' + str + item.value + str + '\'' |
| | | }) |
| | | |
| | | searchText.push('(' + fields.join(' OR ') + ')') |
| | | } else if (item.type === 'checkcard') { |
| | | let str = item.match === 'like' || item.match === 'not like' ? '%' : '' |
| | | |
| | | searchText.push('(' + item.key + ' ' + item.match + ' \'' + str + item.value + str + '\')') |
| | | } else if (item.type === 'multi') { |
| | | searchText.push(`('${item.value}' ${item.match} '%'+${item.key}+'%')`) |
| | | } else if (item.type === 'date') { |
| | | searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')') |
| | | } else if (item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'range') { |
| | | let val = item.value.split(',') |
| | | searchText.push('(' + item.key + ' >= \'' + val[0] + '\' AND ' + item.key + ' < \'' + val[1] + '\')') |
| | | } else if (item.type === 'daterange') { |
| | | let val = item.value.split(',') |
| | | |
| | | let _skey = item.key |
| | | let _ekey = item.key |
| | | |
| | | if (/,/.test(item.key)) { |
| | | _skey = item.key.split(',')[0] |
| | | _ekey = item.key.split(',')[1] |
| | | } |
| | | |
| | | searchText.push('(' + _skey + ' >= \'' + val[0] + '\' AND ' + _ekey + ' < \'' + val[1] + '\')') |
| | | } else { |
| | | searchText.push('(' + item.key + ' ' + item.match + ' \'' + item.value + '\')') |
| | | } |
| | | }) |
| | | |
| | | return searchText.join(' AND ') |
| | | } |
| | | |
| | | /** |
| | | * @description 获取搜索正则替换 |
| | | */ |
| | | export function getSearchRegs (searches) { |
| | | if (!searches) return [] |
| | | |
| | | let options = [] |
| | | let fieldmap = new Map() |
| | | searches.forEach(item => { |
| | | if (item.type === 'date') { |
| | | if (fieldmap.has(item.key)) { |
| | | options.push({ |
| | | reg: new RegExp('@' + item.key + '1@', 'ig'), |
| | | value: `'${item.value}'` |
| | | }) |
| | | } else { |
| | | fieldmap.set(item.key, true) |
| | | options.push({ |
| | | reg: new RegExp('@' + item.key + '@', 'ig'), |
| | | value: `'${item.value}'` |
| | | }) |
| | | } |
| | | } else if (['dateweek', 'datemonth', 'range'].includes(item.type)) { |
| | | let val = item.value.split(',') |
| | | options.push({ |
| | | reg: new RegExp('@' + item.key + '@', 'ig'), |
| | | value: `'${val[0]}'` |
| | | }, { |
| | | reg: new RegExp('@' + item.key + '1@', 'ig'), |
| | | value: `'${val[1]}'` |
| | | }) |
| | | } else if (item.type === 'daterange') { |
| | | let val = item.value.split(',') |
| | | let _skey = item.key |
| | | let _ekey = item.key + '1' |
| | | |
| | | if (/,/.test(item.key)) { |
| | | _skey = item.key.split(',')[0] |
| | | _ekey = item.key.split(',')[1] |
| | | } |
| | | |
| | | options.push({ |
| | | reg: new RegExp('@' + _skey + '@', 'ig'), |
| | | value: `'${val[0]}'` |
| | | }, { |
| | | reg: new RegExp('@' + _ekey + '@', 'ig'), |
| | | value: `'${val[1]}'` |
| | | }) |
| | | } else if (item.type === 'text' || item.type === 'select') { |
| | | item.key.split(',').forEach(field => { |
| | | options.push({ |
| | | reg: new RegExp('@' + field + '@', 'ig'), |
| | | value: `'${item.value}'` |
| | | }) |
| | | }) |
| | | } else { |
| | | options.push({ |
| | | reg: new RegExp('@' + item.key + '@', 'ig'), |
| | | value: `'${item.value}'` |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | return options |
| | | } |
| | | |
| | | /** |
| | | * @description 重置移动端style |
| | | * @return {Object} style |
| | | */ |
| | |
| | | * @description 获取接口及函数 |
| | | */ |
| | | export function getFuncsAndInters (config) { |
| | | let inters = [] |
| | | // let funcs = [] |
| | | let inters = 'false' |
| | | |
| | | let filterBtn = (cell) => { |
| | | if (cell.intertype === 'inner') { |
| | | // funcs.push(cell.innerFunc) |
| | | } else if (cell.intertype === 'outer' || cell.intertype === 'custom') { |
| | | // if (cell.innerFunc) { |
| | | // funcs.push(cell.innerFunc) |
| | | // } |
| | | // if (cell.outerFunc) { |
| | | // funcs.push(cell.outerFunc) |
| | | // } |
| | | if (cell.interface && cell.sysInterface !== 'true') { |
| | | inters.push(cell.interface) |
| | | } |
| | | if (cell.proInterface) { |
| | | inters.push(cell.proInterface) |
| | | } |
| | | // if (cell.callbackFunc) { |
| | | // funcs.push(cell.callbackFunc) |
| | | // } |
| | | } |
| | | } |
| | | |
| | | let filterSetting = (item) => { |
| | | if (!item.setting) return |
| | | if (item.setting.interType === 'inner') { |
| | | // funcs.push(item.setting.innerFunc) |
| | | } else if (item.setting.interType === 'outer') { |
| | | // if (item.setting.outerFunc) { |
| | | // funcs.push(item.setting.outerFunc) |
| | | // } |
| | | if (item.setting.interface && item.setting.sysInterface !== 'true') { |
| | | inters.push(item.setting.interface) |
| | | } |
| | | if (item.setting.proInterface) { |
| | | inters.push(item.setting.proInterface) |
| | | } |
| | | if ((cell.intertype === 'outer' && cell.sysInterface !== 'true') || cell.intertype === 'custom') { |
| | | inters = 'true' |
| | | } |
| | | } |
| | | |
| | | let traversal = (components) => { |
| | | if (!components) return |
| | | if (!components || inters === 'true') return |
| | | |
| | | components.forEach(item => { |
| | | if (item.type === 'tabs') { |
| | |
| | | } else if (item.type === 'group') { |
| | | traversal(item.components) |
| | | } else { |
| | | filterSetting(item) |
| | | if (item.setting && item.setting.interType === 'outer' && item.setting.sysInterface !== 'true') { |
| | | inters = 'true' |
| | | } |
| | | |
| | | if (item.action) { |
| | | item.action.forEach(cell => { |
| | |
| | | |
| | | if (config.interfaces) { |
| | | config.interfaces.forEach(item => { |
| | | filterSetting(item) |
| | | if (item.setting && item.setting.interType === 'outer' && item.setting.sysInterface !== 'true') { |
| | | inters = 'true' |
| | | } |
| | | }) |
| | | } |
| | | |
| | | traversal(config.components) |
| | | |
| | | // inters = Array.from(new Set(inters)) |
| | | |
| | | return inters.length > 0 ? 'true' : 'false' |
| | | return inters |
| | | } |
| | | |
| | | /** |