From 145c4b6ec2ea4f1dd7986b3179ca505a79bc0598 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 18 八月 2020 17:47:44 +0800 Subject: [PATCH] 2020-08-18 --- src/tabviews/zshare/topSearch/index.jsx | 353 ++++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 244 insertions(+), 109 deletions(-) diff --git a/src/tabviews/zshare/topSearch/index.jsx b/src/tabviews/zshare/topSearch/index.jsx index ab365b4..a809ad3 100644 --- a/src/tabviews/zshare/topSearch/index.jsx +++ b/src/tabviews/zshare/topSearch/index.jsx @@ -5,6 +5,7 @@ import moment from 'moment' import Api from '@/api' +import options from '@/store/options.js' import DateGroup from '@/tabviews/zshare/dategroup' import Utils from '@/utils/utils.js' import './index.scss' @@ -38,6 +39,9 @@ let required = {} let _list = [] let fieldMap = new Map() + let mainItems = [] // 浜戠鎴栧崟鐐规暟鎹� + let localItems = [] // 鏈湴鏁版嵁 + let deForms = [] // 娴嬭瘯绯荤粺锛屽崟涓姹� searchlist.forEach(item => { if (fieldMap.has(item.field)) { @@ -50,13 +54,40 @@ style[item.field] = item.type required[item.field] = item.required === 'true' - if (item.type === 'select' || item.type === 'link') { - if (item.setAll === 'true') { + if (['select', 'link', 'multiselect'].includes(item.type)) { + if (item.setAll === 'true' && item.type !== 'multiselect') { item.options.unshift({ key: Utils.getuuid(), Value: '', Text: this.props.dict['main.all'] }) + } + + // 鏁版嵁婧愭煡璇㈣鍙� + if (item.resourceType === '1' && item.dataSource) { + let _option = Utils.getSelectQueryOptions(item) + + if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + _option.sql = _option.sql.replace(/\$@/ig, '/*') + _option.sql = _option.sql.replace(/@\$/ig, '*/') + } else { + _option.sql = _option.sql.replace(/@\$|\$@/ig, '') + } + + // 娴嬭瘯绯荤粺鍗曚釜璇锋眰 + if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { + deForms.push({ + ...item, + arr_field: _option.field, + data_sql: Utils.formatOptions(_option.sql) + }) + } else { // 鍚堝苟璇锋眰锛屽尯鍒嗘湰鍦板強绯荤粺 + if (item.database === 'sso') { + mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`) + } else { + localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`) + } + } } item.oriOptions = fromJS(item.options).toJS() } @@ -75,7 +106,9 @@ message: '鏈煡璇㈠埌鎼滅储鏉′欢銆�' + item.label + '銆嬪叧鑱斿瓧娈碉紒', duration: 5 }) + item.supInitVal = '' } else { + item.supInitVal = supItem.initval item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval) } } else if (item.type === 'group' && item.Hide !== 'true') { @@ -93,135 +126,237 @@ searchlist: _list, groups: _groups }, () => { - this.improveSearch() + if (this.props.menuType !== 'HS' && options.sysType === 'local' && !window.GLOB.systemType) { + this.improveSimpleSearch(deForms) + } else { + this.improveSearch(mainItems, localItems) + } }) } - improveSearch = () => { - let searchlist = fromJS(this.props.searchlist).toJS() + // 鏌ヨ涓嬫媺鑿滃崟 + improveSearch = (mainItems, localItems) => { + const { menuType, BID } = this.props let deffers = [] - searchlist.forEach(item => { - if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return - if (item.setAll === 'true') { - item.options.unshift({ - key: Utils.getuuid(), - Value: '', - Text: this.props.dict['main.all'] - }) + if (menuType !== 'HS' && window.GLOB.systemType !== 'production') { + localItems = [...localItems, ...mainItems] + mainItems = [] + } + + // 鏈湴璇锋眰 + let param = { + func: 'sPC_Get_SelectedList', + LText: localItems.join(' union all '), + obj_name: '', + arr_field: '', + table_type: 'Y' + } + + if (BID) { + param.BID = BID + } + + if (param.LText) { + param.LText = Utils.formatOptions(param.LText) + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 + param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) } - if (item.resourceType === '1' && item.dataSource) { - let _option = Utils.getSelectQueryOptions(item) - let _sql = Utils.formatOptions(_option.sql) - let isSSO = item.database === 'sso' - - let param = { - func: 'sPC_Get_SelectedList', - LText: _sql, - obj_name: 'data', - arr_field: _option.field - } - - if (this.props.BID) { - param.BID = this.props.BID - } - - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 - 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') + '.000' - param.secretkey = Utils.encrypt(param.LText, param.timestamp) - - if (this.props.menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 - param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) - } else if (window.GLOB.systemType !== 'production') { - isSSO = false - } - - let defer = new Promise(resolve => { - Api.getSystemCacheConfig(param, isSSO).then(res => { - res.search = item + deffers.push( + new Promise(resolve => { + Api.getSystemCacheConfig(param).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + } resolve(res) }) }) - deffers.push(defer) - } else if (item.resourceType === '1' && !item.dataSource) { - notification.warning({ - top: 92, - message: item.label + ': ' + this.props.dict['main.datasource.settingerror'], - duration: 5 - }) - } - }) - - if (deffers.length === 0) { - return + ) } - Promise.all(deffers).then(result => { - result.forEach(res => { - if (res.status) { - searchlist = searchlist.map(item => { - if (item.uuid === res.search.uuid) { - res.data.forEach(cell => { - let _item = { - key: Utils.getuuid(), - Value: cell[res.search.valueField], - Text: cell[res.search.valueText] - } + // 绯荤粺璇锋眰 + let mainparam = { + func: 'sPC_Get_SelectedList', + LText: mainItems.join(' union all '), + obj_name: '', + arr_field: '', + table_type: 'Y' + } - if (res.search.type === 'link') { - _item.ParentID = cell[res.search.linkField] - } + if (BID) { + mainparam.BID = BID + } - item.options.push(_item) + if (mainparam.LText) { + mainparam.LText = Utils.formatOptions(mainparam.LText) + mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp) + + if (menuType === 'HS') { // 浜戠鏁版嵁楠岃瘉 + mainparam.open_key = Utils.encrypt(mainparam.secretkey, mainparam.timestamp, true) + if (options.cloudServiceApi) { + mainparam.rduri = options.cloudServiceApi + mainparam.userid = sessionStorage.getItem('CloudUserID') || '' + mainparam.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' + } + } else if (window.GLOB.mainSystemApi) { + mainparam.rduri = window.GLOB.mainSystemApi + } + + deffers.push( + new Promise(resolve => { + Api.getSystemCacheConfig(mainparam).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 }) } - return item + resolve(res) }) - } else { - notification.warning({ - top: 92, - message: res.search.label + ':' + res.message, - duration: 5 + }) + ) + } + + Promise.all(deffers).then(response => { + let result = {...response[0], ...(response[1] || {})} + + delete result.ErrCode + delete result.ErrMesg + delete result.message + delete result.status + + let _searchlist = this.state.searchlist.map(item => { + if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) { + let options = result[item.field].map(cell => { + let _item = { + key: Utils.getuuid(), + Value: cell[item.valueField], + Text: cell[item.valueText] + } + + if (item.type === 'link') { + _item.ParentID = cell[item.linkField] + } + + return _item }) + + item.oriOptions = [...item.oriOptions, ...options] } - }) - - let _list = [] - let fieldMap = new Map() - - searchlist.forEach(item => { - if (fieldMap.has(item.field)) { - item.field = item.field + '@tail@' - } - fieldMap.set(item.field, true) - - if (item.type === 'select' || item.type === 'link') { - item.oriOptions = fromJS(item.options).toJS() - } - - _list.push(item) - }) - - _list = _list.map(item => { - if (item.type === 'link') { - let supItem = _list.filter(form => form.field === item.linkField)[0] - - if (supItem) { - item.options = item.oriOptions.filter(option => option.ParentID === supItem.initval) - } - } - return item }) - this.setState({searchlist: _list}) + this.setState({ + searchlist: _searchlist.map(item => { + if (item.type === 'link') { + if (item.supInitVal) { + item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal) + } else { + item.options = item.oriOptions + } + } else if (item.type === 'select' || item.type === 'multiselect') { + item.options = item.oriOptions + } + + return item + }) + }) + }) + } + + // 娴嬭瘯绯荤粺鍗曚釜璇锋眰涓嬫媺閫夐」 + improveSimpleSearch = (deForms) => { + if (deForms.length === 0) return + + let deffers = deForms.map(item => { + let param = { + func: 'sPC_Get_SelectedList', + LText: item.data_sql, + obj_name: item.field, + arr_field: item.arr_field + } + + if (this.props.BID) { + param.BID = this.props.BID + } + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000' + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + return ( + new Promise(resolve => { + Api.getSystemCacheConfig(param).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + } + resolve(res) + }) + }) + ) + }) + + Promise.all(deffers).then(response => { + let result = {} + + response.forEach(res => { + result = {...result, ...res} + }) + + delete result.ErrCode + delete result.ErrMesg + delete result.message + delete result.status + + let _searchlist = this.state.searchlist.map(item => { + if (['select', 'link', 'multiselect'].includes(item.type) && result[item.field] && result[item.field].length > 0) { + let options = result[item.field].map(cell => { + let _item = { + key: Utils.getuuid(), + Value: cell[item.valueField], + Text: cell[item.valueText] + } + + if (item.type === 'link') { + _item.ParentID = cell[item.linkField] + } + + return _item + }) + + item.oriOptions = [...item.oriOptions, ...options] + } + return item + }) + + this.setState({ + searchlist: _searchlist.map(item => { + if (item.type === 'link') { + if (item.supInitVal) { + item.options = item.oriOptions.filter(option => option.ParentID === item.supInitVal) + } else { + item.options = item.oriOptions + } + } else if (item.type === 'select' || item.type === 'multiselect') { + item.options = item.oriOptions + } + + return item + }) + }) }) } -- Gitblit v1.8.0