| | |
| | | import md5 from 'md5' |
| | | |
| | | import Api from '@/api' |
| | | import options from '@/store/options.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncSpinComponent from '@/utils/asyncSpinComponent' |
| | | import Utils from '@/utils/utils.js' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import MKInput from './mkInput' |
| | | import './index.scss' |
| | | |
| | | const MutilForm = asyncSpinComponent(() => import('./advanceform')) |
| | | const MKCheckCard = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkCheckCard')) |
| | | const MKCheckCard = asyncComponent(() => import('./mkCheckCard')) |
| | | const MKCheck = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkCheck')) |
| | | const MKSwitch = asyncComponent(() => import('@/tabviews/zshare/mutilform/mkSwitch')) |
| | | const MKRadio = asyncComponent(() => import('./mkRadio')) |
| | | const MKSelect = asyncComponent(() => import('./mkSelect')) |
| | | const DateGroup = asyncComponent(() => import('./dategroup')) |
| | | const MKDatePicker = asyncComponent(() => import('./mkDatePicker')) |
| | | const MKNumber = asyncComponent(() => import('./mkNumber')) |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id,用于查询下拉选择项 |
| | | searchlist: PropTypes.array, // 搜索条件列表 |
| | | config: PropTypes.object, // 组件配置信息(自定义页面) |
| | | setting: PropTypes.object, // 组件配置信息(自定义页面) |
| | | refreshdata: PropTypes.func // 刷新数据 |
| | | BID: PropTypes.any, |
| | | config: PropTypes.object |
| | | } |
| | | |
| | | state = { |
| | |
| | | sign = '' |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config, searchlist, setting } = this.props |
| | | const { config } = this.props |
| | | |
| | | let _searchlist = [] |
| | | let fieldMap = new Map() |
| | | let mainItems = [] // 云端或单点数据 |
| | | let localItems = [] // 本地数据 |
| | | let backMItems = [] // 云端或单点数据 |
| | | let backLItems = [] // 本地数据 |
| | | let deForms = [] // 测试系统,单个请求 |
| | | let advanceValues = [] |
| | | let linkFields = {} |
| | | let record = {} |
| | | let hasReqFields = false |
| | | |
| | | let forbid = false // header中不设置高级搜索 |
| | | let _setting = {showAdv: false, show: false} |
| | | let _setting = {showAdv: false, show: false, style: null} |
| | | let BID = this.props.BID |
| | | let sysvals = {} |
| | | |
| | | if (window.backend) { |
| | | sysvals = { |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | bid: BID || '', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | } |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | sysvals.db = window.GLOB.externalDatabase |
| | | } |
| | | } |
| | | |
| | | if (setting) { |
| | | _setting.show = setting.show !== 'false' |
| | | _setting.float = setting.float || 'left' |
| | | _setting.advanceType = setting.advanceType || 'modal' |
| | | _setting.advWidth = setting.advanceWidth || 1000 |
| | | _setting.placement = setting.drawerPlacement || 'right' |
| | | _setting.ratio = setting.searchRatio || 6 |
| | | _setting.labelwidth = setting.searchLwidth !== undefined ? setting.searchLwidth : 33.3 |
| | | if (config.wrap) { |
| | | _setting.show = config.wrap.show !== 'false' |
| | | _setting.advanceType = config.wrap.advanceType || 'modal' |
| | | _setting.advWidth = config.wrap.advanceWidth || 1000 |
| | | _setting.placement = config.wrap.drawerPlacement || 'right' |
| | | _setting.ratio = config.wrap.searchRatio || 6 |
| | | _setting.labelwidth = config.wrap.searchLwidth !== undefined ? config.wrap.searchLwidth : 33.3 |
| | | _setting.labelCol = {style: {width: _setting.labelwidth + '%'}} |
| | | _setting.wrapperCol = {style: {width: (100 - _setting.labelwidth) + '%'}} |
| | | _setting.style = null |
| | | } else if (config) { |
| | | if (config.wrap) { |
| | | _setting.show = config.wrap.show !== 'false' |
| | | _setting.advanceType = config.wrap.advanceType || 'modal' |
| | | _setting.advWidth = config.wrap.advanceWidth || 1000 |
| | | _setting.placement = config.wrap.drawerPlacement || 'right' |
| | | _setting.ratio = config.wrap.searchRatio || 6 |
| | | _setting.labelwidth = config.wrap.searchLwidth !== undefined ? config.wrap.searchLwidth : 33.3 |
| | | _setting.labelCol = {style: {width: _setting.labelwidth + '%'}} |
| | | _setting.wrapperCol = {style: {width: (100 - _setting.labelwidth) + '%'}} |
| | | _setting.borderRadius = config.wrap.borderRadius |
| | | _setting.borderRadius = config.wrap.borderRadius |
| | | _setting.resetContrl = config.wrap.resetContrl || 'init' |
| | | _setting.size = config.wrap.searchSize || '' |
| | | |
| | | if (config.wrap.searchBtn === 'show') { |
| | | _setting.showBtn = true |
| | | } |
| | | _setting.style = null |
| | | |
| | | if (config.type === 'search') { |
| | | _setting.float = config.wrap.float || 'left' |
| | | _setting.style = config.style |
| | | } else if (config.type === 'table') { |
| | | _setting.float = 'left' |
| | | } else { |
| | | _setting.float = 'right' |
| | | _setting.show = false |
| | | forbid = true |
| | | |
| | | if (config.wrap.supModule) { |
| | | let BData = window.GLOB.CacheData.get(config.wrap.supModule) |
| | | BID = BData ? (BData.$BID || '') : '' |
| | | } |
| | | } |
| | | |
| | | if (config.type === 'search') { |
| | | _setting.float = config.wrap.float || 'left' |
| | | _setting.style = config.style |
| | | } else if (config.type === 'table') { |
| | | _setting.float = 'left' |
| | | } else { |
| | | _setting.float = 'right' |
| | | _setting.show = false |
| | | forbid = true |
| | | } |
| | | |
| | | if (_setting.advanceType === 'drawer' && _setting.advWidth) { |
| | |
| | | } |
| | | } |
| | | |
| | | if (searchlist) { |
| | | _searchlist = fromJS(searchlist).toJS() |
| | | } else if (config) { |
| | | _searchlist = fromJS(config.search).toJS() |
| | | } |
| | | _searchlist = fromJS(config.search).toJS() |
| | | |
| | | _searchlist.forEach(item => { |
| | | if (item.linkField) { |
| | |
| | | item.field = item.field + '@tail@' |
| | | } |
| | | |
| | | if (item.required) { |
| | | hasReqFields = true |
| | | } |
| | | |
| | | if (item.advanced && !forbid) { |
| | | _setting.showAdv = true |
| | | if (!['group', 'check', 'switch'].includes(item.type)) { |
| | | item.signValue = true |
| | | } |
| | | } else { |
| | | item.advanced = false |
| | | } |
| | | |
| | | if (item.advanced && item.initval) { |
| | | let val = item.initval |
| | | if (item.precision === 'hour') { |
| | | if (/,/ig.test(val)) { |
| | | val = val.split(',').map(m => m + ':00').join(',') |
| | | } else { |
| | | val = val + ':00' |
| | | if (item.checkShift && !item.initval) { |
| | | let d = '' |
| | | if (window.GLOB.CacheData.has(item.$supId)) { |
| | | d = window.GLOB.CacheData.get(item.$supId) |
| | | d = d[item.dateShift] || '' |
| | | if (d) { |
| | | d = moment(d).format('YYYY-MM-DD') |
| | | d = d === 'Invalid date' ? '' : d |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | |
| | | if (d) { |
| | | if (item.type === 'daterange') { |
| | | if (item.$initval === 'week') { |
| | | item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',') |
| | | } else if (item.$initval === 'month') { |
| | | item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',') |
| | | } else if (item.$initval === 'lastMonth') { |
| | | item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',') |
| | | } else { |
| | | try { |
| | | let _initval = JSON.parse(item.$initval) |
| | | let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)] |
| | | item.initval = _vals.join(',') |
| | | } catch (e) { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | } else { |
| | | item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM') |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (item.type === 'group') { |
| | |
| | | record[item.field] = item.initval |
| | | } |
| | | |
| | | if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type)) { |
| | | if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(item.type)) { |
| | | item.options = item.options || [] |
| | | item.options = item.options.filter(op => !op.Hide) |
| | | if (item.setAll === 'true' && ['select', 'link'].includes(item.type)) { |
| | |
| | | |
| | | // 数据源查询语句 |
| | | if (item.resourceType === '1' && item.dataSource) { |
| | | let _option = Utils.getSelectQueryOptions(item) |
| | | if (window.backend && window.GLOB.CacheData.has('sql_' + item.uuid)) { |
| | | let ex = window.GLOB.CacheData.get('sql_' + item.uuid) |
| | | let exps = [] |
| | | |
| | | if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) { |
| | | console.info(_option.sql) |
| | | } |
| | | |
| | | // 测试系统单个请求 |
| | | if (!window.GLOB.mkHS && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: _option.field, |
| | | data_sql: Utils.formatOptions(_option.sql) |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (sysvals.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: sysvals[key] |
| | | }) |
| | | } |
| | | }) |
| | | } 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`) |
| | | |
| | | let cell = { |
| | | id: ex.id, |
| | | exps: exps, |
| | | menuname: item.label + '(搜索)', |
| | | md5_id: '' |
| | | } |
| | | if (item.checkBid) { |
| | | item.sqlId = ex.id |
| | | item.exps = exps |
| | | } |
| | | |
| | | if (item.checkBid && !BID) { |
| | | |
| | | } else if (item.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | backMItems.push(cell) |
| | | } else { |
| | | localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`) |
| | | backLItems.push(cell) |
| | | } |
| | | } else { |
| | | let _option = Utils.getSelectQueryOptions(item) |
| | | let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20) select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n` |
| | | |
| | | let exec = true |
| | | if (item.checkBid) { |
| | | item.sql = _declare + _option.sql |
| | | item.arr_field = _option.field |
| | | |
| | | exec = !!BID |
| | | } |
| | | |
| | | if (exec) { |
| | | let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | | window.mkInfo(_declare + _sql) |
| | | } |
| | | |
| | | // 测试系统单个请求 |
| | | if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) { |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: _option.field, |
| | | data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType) |
| | | }) |
| | | } else { // 合并请求,区分本地及系统 |
| | | _sql = _sql.replace(/%/ig, ' mpercent ') |
| | | if (item.database === 'sso') { |
| | | if (mainItems.length === 0) { |
| | | _sql = _declare + _sql |
| | | } |
| | | mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`) |
| | | } else { |
| | | if (localItems.length === 0) { |
| | | _sql = _declare + _sql |
| | | } |
| | | localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | item.oriOptions = fromJS(item.options).toJS() |
| | | |
| | | if (item.type === 'checkcard' && item.multiple === 'dropdown' && item.resourceType === '0') { |
| | | this.resetCheckcard(item) |
| | | } |
| | | } |
| | | |
| | | if (item.signValue && item.initval) { |
| | | let val = item.initval |
| | | if (item.precision === 'hour') { |
| | | if (/,/ig.test(val)) { |
| | | val = val.split(',').map(m => m + ':00').join(',') |
| | | } else { |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | |
| | | let text = val |
| | | |
| | | if (item.type === 'select' || item.type === 'link' || item.type === 'radio') { |
| | | item.oriOptions.forEach(cell => { |
| | | if (cell.Value === val) { |
| | | text = cell.Text |
| | | } |
| | | }) |
| | | } |
| | | |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val, text}) |
| | | } |
| | | |
| | | fieldMap.set(item.field, item) |
| | |
| | | |
| | | this.setState({ |
| | | setting: _setting, |
| | | hasReqFields, |
| | | hasReqFields: config.$s_req, |
| | | advanceValues, |
| | | searchlist: _list |
| | | }, () => { |
| | | if (!window.GLOB.mkHS && options.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | this.improveSimpleSearch(deForms) |
| | | if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) { |
| | | this.improveBackSearch(backMItems, backLItems, false) |
| | | } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | this.improveSimpleSearch(deForms, false, null, BID) |
| | | } else if (mainItems.length > 0 || localItems.length > 0) { |
| | | this.improveSearch(mainItems, localItems) |
| | | this.improveSearch(mainItems, localItems, BID) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | componentDidMount () { |
| | | const { config } = this.props |
| | | |
| | | if (config.type === 'search' && config.wrap.supModule) { |
| | | MKEmitter.addListener('resetSelectLine', this.resetParentParam) |
| | | } |
| | | } |
| | | |
| | | componentWillUnmount () { |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('resetSelectLine', this.resetParentParam) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps(nextProps) { |
| | | const { config, BID } = this.props |
| | | |
| | | if (config.checkBid && config.type !== 'search' && nextProps.BID !== BID) { |
| | | this.resetOptions(nextProps.BID) |
| | | } |
| | | } |
| | | |
| | | resetParentParam = (MenuID, id) => { |
| | | const { config } = this.props |
| | | |
| | | if (config.wrap.supModule !== MenuID) return |
| | | |
| | | this.resetOptions(id) |
| | | } |
| | | |
| | | resetOptions = (BID) => { |
| | | let deForms = [] |
| | | let backMItems = [] // 云端或单点数据 |
| | | let backLItems = [] // 本地数据 |
| | | let searchlist = fromJS(this.state.searchlist).toJS().map(item => { |
| | | if (item.checkBid) { |
| | | if (window.backend && item.sqlId) { |
| | | let cell = { |
| | | id: item.sqlId, |
| | | menuname: item.label + '(搜索)', |
| | | md5_id: '', |
| | | exps: item.exps.map(n => { |
| | | if (n.key === 'BID') { |
| | | n.value = BID |
| | | } |
| | | return n |
| | | }) |
| | | } |
| | | |
| | | if (item.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | backMItems.push(cell) |
| | | } else { |
| | | backLItems.push(cell) |
| | | } |
| | | } else { |
| | | let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | | window.mkInfo(sql) |
| | | } |
| | | |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: item.arr_field, |
| | | data_sql: Utils.formatOptions(sql, window.GLOB.execType) |
| | | }) |
| | | } |
| | | } else if (item.checkShift) { |
| | | let d = '' |
| | | if (window.GLOB.CacheData.has(item.$supId)) { |
| | | d = window.GLOB.CacheData.get(item.$supId) |
| | | d = d[item.dateShift] || '' |
| | | if (d) { |
| | | d = moment(d).format('YYYY-MM-DD') |
| | | d = d === 'Invalid date' ? '' : d |
| | | } |
| | | } |
| | | |
| | | if (d) { |
| | | if (item.type === 'daterange') { |
| | | if (item.$initval === 'week') { |
| | | item.initval = [moment(d).startOf('week').format(item.format), moment(d).endOf('week').format(item.format)].join(',') |
| | | } else if (item.$initval === 'month') { |
| | | item.initval = [moment(d).startOf('month').format(item.format), moment(d).endOf('month').format(item.format)].join(',') |
| | | } else if (item.$initval === 'lastMonth') { |
| | | item.initval = [moment(d).subtract(1, 'months').startOf('month').format(item.format), moment(d).subtract(1, 'months').endOf('month').format(item.format)].join(',') |
| | | } else { |
| | | try { |
| | | let _initval = JSON.parse(item.$initval) |
| | | let _vals = [moment(d).subtract(_initval[0], 'days').format(item.format), moment(d).subtract(_initval[1], 'days').format(item.format)] |
| | | item.initval = _vals.join(',') |
| | | } catch (e) { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | } else { |
| | | item.initval = moment(d).subtract(item.$initval, 'month').format('YYYY-MM') |
| | | } |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) { |
| | | this.improveBackSearch(backMItems, backLItems, true, searchlist) |
| | | } else if (deForms.length > 0) { |
| | | this.improveSimpleSearch(deForms, true, searchlist, BID) |
| | | } else { |
| | | this.setState({ |
| | | searchlist: searchlist |
| | | }) |
| | | |
| | | setTimeout(() => { |
| | | this.handleSubmit() |
| | | }, 20) |
| | | } |
| | | } |
| | | |
| | | resetCheckcard = (item) => { |
| | | let pid = item.resourceType === '0' ? 'pid' : item.parentField |
| | | let _options = [] |
| | | let _others = [] |
| | | item.oriOptions.forEach(op => { |
| | | if (op[pid] === item.mark) { |
| | | _options.push(op) |
| | | } else { |
| | | _others.push(op) |
| | | } |
| | | }) |
| | | |
| | | _options = _options.map(op => { |
| | | op.children = [] |
| | | |
| | | _others = _others.filter(cell => { |
| | | if (cell[pid] === op.$value) { |
| | | op.children.push(cell) |
| | | return false |
| | | } |
| | | return true |
| | | }) |
| | | |
| | | op.subIds = op.children.map(cell => cell.$value) |
| | | |
| | | return op |
| | | }) |
| | | |
| | | item.oriOptions = _options |
| | | item.options = _options |
| | | } |
| | | |
| | | // 查询下拉菜单 |
| | | improveSearch = (mainItems, localItems) => { |
| | | const { BID } = this.props |
| | | improveSearch = (mainItems, localItems, BID) => { |
| | | let deffers = [] |
| | | |
| | | // 本地请求 |
| | |
| | | } |
| | | |
| | | if (param.LText) { |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | if (window.GLOB.execType === 'x') { |
| | | param.exec_type = 'x' |
| | | } |
| | | |
| | | param.LText = Utils.formatOptions(param.LText, param.exec_type) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : param.LText, param.timestamp) |
| | | |
| | | if (window.GLOB.mkHS) { // 云端数据验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | |
| | | } |
| | | |
| | | if (mainparam.LText) { |
| | | mainparam.LText = Utils.formatOptions(mainparam.LText) |
| | | mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp) |
| | | if (window.GLOB.execType === 'x') { |
| | | mainparam.exec_type = 'x' |
| | | } |
| | | |
| | | mainparam.LText = Utils.formatOptions(mainparam.LText, mainparam.exec_type) |
| | | mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | mainparam.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : mainparam.LText, mainparam.timestamp) |
| | | |
| | | if (window.GLOB.mainSystemApi) { |
| | | mainparam.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | if (window.GLOB.mkHS) { // 云端数据验证 |
| | | mainparam.open_key = Utils.encryptOpenKey(mainparam.secretkey, mainparam.timestamp) |
| | | 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( |
| | |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetSearch(result) |
| | | this.resetSearch(result, false) |
| | | }) |
| | | } |
| | | |
| | | // 查询下拉菜单 |
| | | improveBackSearch = (mainItems, localItems, trigger, searchlist) => { |
| | | let deffers = [] |
| | | |
| | | if (localItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | $type: 's_Get_SelectedList', |
| | | data: localItems |
| | | }) |
| | | } |
| | | |
| | | if (mainItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | $type: 's_Get_SelectedList', |
| | | data: mainItems, |
| | | rduri: window.GLOB.mainSystemApi |
| | | }) |
| | | } |
| | | |
| | | deffers = deffers.map(item => { |
| | | return new Promise(resolve => { |
| | | Api.getSystemCacheConfig(item).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | |
| | | Promise.all(deffers).then(response => { |
| | | let result = {...response[0], ...(response[1] || {})} |
| | | |
| | | delete result.ErrCode |
| | | delete result.ErrMesg |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetSearch(result, trigger, searchlist) |
| | | }) |
| | | } |
| | | |
| | | // 测试系统单个请求下拉选项 |
| | | improveSimpleSearch = (deForms) => { |
| | | improveSimpleSearch = (deForms, trigger, searchlist, BID) => { |
| | | if (deForms.length === 0) return |
| | | |
| | | let deffers = deForms.map((item, index) => { |
| | |
| | | arr_field: item.arr_field |
| | | } |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | if (BID) { |
| | | param.BID = BID |
| | | } |
| | | |
| | | if (window.GLOB.execType === 'x') { |
| | | param.exec_type = 'x' |
| | | } |
| | | |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : param.LText, param.timestamp) |
| | | |
| | | if (item.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetSearch(result) |
| | | this.resetSearch(result, trigger, searchlist) |
| | | }) |
| | | } |
| | | |
| | | resetSearch = (result) => { |
| | | let _searchlist = fromJS(this.state.searchlist).toJS().map(item => { |
| | | if (['select', 'link', 'multiselect', 'checkcard'].includes(item.type) && result[item.field] && result[item.field].length > 0) { |
| | | resetSearch = (result, submit, searchlist) => { |
| | | let trigger = submit |
| | | let _searchlist = fromJS(searchlist || this.state.searchlist).toJS().map(item => { |
| | | if (['select', 'link', 'multiselect', 'checkcard', 'radio'].includes(item.type) && result[item.field] && result[item.field].length > 0) { |
| | | let options = [] |
| | | let map = new Map() |
| | | let all = false |
| | |
| | | } |
| | | |
| | | if (item.linkField) { |
| | | _item.ParentID = cell[item.linkField] |
| | | _item.ParentID = cell[item.linkField] + '' |
| | | } |
| | | |
| | | if (item.type !== 'checkcard') { |
| | | _item.Value = cell[item.valueField] |
| | | _item.Value = cell[item.valueField] + '' |
| | | _item.Text = cell[item.valueText] + '' |
| | | |
| | | if (map.has(_item.ParentID + _item.Value)) return |
| | |
| | | |
| | | map.set(_item.ParentID + _item.Value, 0) |
| | | } else { |
| | | _item.$value = cell[item.cardValField] |
| | | _item.$value = cell[item.cardValField] + '' |
| | | _item = {..._item, ...cell} |
| | | |
| | | if (item.urlField) { |
| | |
| | | }) |
| | | |
| | | item.oriOptions = [...item.oriOptions, ...options] |
| | | |
| | | if (item.type === 'checkcard' && item.multiple === 'dropdown') { |
| | | this.resetCheckcard(item) |
| | | } |
| | | } |
| | | |
| | | if (item.linkField) { |
| | |
| | | item.options = item.oriOptions |
| | | } |
| | | |
| | | if (item.$first) { |
| | | if (item.options.length > 0) { |
| | | item.initval = item.options[0].Value |
| | | trigger = true |
| | | } else { |
| | | item.initval = '' |
| | | } |
| | | } |
| | | |
| | | return item |
| | | }) |
| | | |
| | | this.setState({ |
| | | searchlist: _searchlist |
| | | }) |
| | | |
| | | if (trigger) { |
| | | setTimeout(() => { |
| | | this.handleSubmit() |
| | | }, 20) |
| | | } |
| | | } |
| | | |
| | | recordChange = (val, defer, item) => { |
| | |
| | | const _rules = [ |
| | | { |
| | | required: item.required, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (window.GLOB.dict['not_empty'] || '不可为空!') |
| | | } |
| | | ] |
| | | |
| | |
| | | } else if (item.type === 'select' || item.type === 'link' || item.type === 'multiselect') { |
| | | content = (<MKSelect config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />) |
| | | } else if (item.type === 'date' || item.type === 'datemonth' || item.type === 'dateweek' || item.type === 'daterange') { |
| | | content = (<MKDatePicker config={item} onChange={(val) => this.recordChange(val, false, item)} />) |
| | | content = (<MKDatePicker config={item} onChange={(val, defer) => this.recordChange(val, defer, item)} />) |
| | | } else if (item.type === 'group') { |
| | | field = item.datefield |
| | | content = <DateGroup position={index} config={item} onChange={(val, type) => this.dateGroupChange(val, type, item)} /> |
| | | } else if (item.type === 'checkcard') { |
| | | content = <MKCheckCard config={item} onChange={(val) => this.cardChange(val, item)} /> |
| | | } else if (item.type === 'radio') { |
| | | content = <MKRadio config={item} onChange={(val) => this.recordChange(val, false, item)} /> |
| | | } else if (item.type === 'check') { |
| | | content = <MKCheck config={item} onChange={(val) => this.recordChange(val, false, item)} /> |
| | | } else if (item.type === 'switch') { |
| | | content = <MKSwitch config={item} onChange={(val) => this.recordChange(val, false, item)} /> |
| | | } else if (item.type === 'range') { |
| | | content = <MKNumber config={item} onInputSubmit={this.handleSubmit} /> |
| | | } |
| | | |
| | | if (content) { |
| | |
| | | wrapperCol={setting.wrapperCol} |
| | | > |
| | | {setting.show ? <Button style={style} type="primary" onClick={this.handleSubmit}> |
| | | 搜索 |
| | | {window.GLOB.dict['search'] || '搜索'} |
| | | </Button> : null} |
| | | {setting.show ? <Button style={{ marginLeft: 8, ...style }} onClick={this.handleReset}> |
| | | 重置 |
| | | {window.GLOB.dict['reset'] || '重置'} |
| | | </Button> : null} |
| | | {setting.showAdv ? <Button className={visible ? 'visible' : ''} type="link" onClick={this.handleAdvance}> |
| | | 高级{setting.advanceType === 'pulldown' ? <DownOutlined /> : null} |
| | | {window.GLOB.dict['senior'] || '高级'}{setting.advanceType === 'pulldown' ? <DownOutlined /> : null} |
| | | </Button> : null} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (setting.showBtn) { |
| | | fields.push( |
| | | <Col className="mk-search-col search-button" key="actions"> |
| | | <Form.Item> |
| | | <Button type="primary" onClick={this.handleSubmit}> |
| | | {window.GLOB.dict['search'] || '搜索'} |
| | | </Button> |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | |
| | | if (visible) { |
| | | let advanceValues = [] |
| | | this.state.searchlist.forEach(item => { |
| | | if (!item.advanced) return |
| | | if (!item.signValue) return |
| | | |
| | | let val = this.record[item.field] |
| | | if (val || val === 0) { |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | |
| | | let text = val |
| | | |
| | | if (item.type === 'select' || item.type === 'link' || item.type === 'radio') { |
| | | item.oriOptions.forEach(cell => { |
| | | if (cell.Value === val) { |
| | | text = cell.Text |
| | | } |
| | | }) |
| | | } |
| | | |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val, text}) |
| | | } |
| | | }) |
| | | this.setState({advanceValues}) |
| | |
| | | } |
| | | |
| | | handleSubmit = () => { |
| | | const { config } = this.props |
| | | |
| | | this.setState({}, () => { |
| | | this.props.form.validateFields((err, values) => { |
| | | if (err) return |
| | |
| | | |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请输入' + labels.join('、') + ' !', |
| | | message: (window.GLOB.dict['input_tip'] || '请输入') + labels.join('、') + ' !', |
| | | duration: 3 |
| | | }) |
| | | return |
| | |
| | | this.sign = '' |
| | | }, 2000) |
| | | |
| | | this.props.refreshdata(searches) |
| | | if (config.wrap && config.wrap.cacheSearch === 'true') { |
| | | let _values = {} |
| | | searches.forEach(item => { |
| | | _values[item.key] = item.value |
| | | }) |
| | | |
| | | window.GLOB.SearchBox.set(config.$searchId + 'cache', _values) |
| | | } |
| | | |
| | | if (this.props.refreshdata) { |
| | | this.props.refreshdata(searches) |
| | | } else { |
| | | window.GLOB.SearchBox.set(config.$searchId, searches) |
| | | MKEmitter.emit('searchRefresh', config.$searchId) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | |
| | | * @description 搜索条件重置 |
| | | */ |
| | | handleReset = () => { |
| | | const { setting } = this.state |
| | | |
| | | let record = {} |
| | | let advanceValues = [] |
| | | let searchlist = this.state.searchlist.map(item => { |
| | | item.initval = item.oriInitval |
| | | |
| | | if (setting.resetContrl === 'clear' && ['text', 'date', 'datemonth', 'dateweek', 'daterange', 'range'].includes(item.type)) { |
| | | item.initval = '' |
| | | } |
| | | |
| | | if (item.type === 'group') { |
| | | record[item.datefield] = item.initval |
| | |
| | | } else { |
| | | record[item.field] = item.initval |
| | | } |
| | | if (item.advanced && item.initval) { |
| | | if (item.signValue && item.initval) { |
| | | let val = item.initval |
| | | if (item.precision === 'hour') { |
| | | if (/,/ig.test(val)) { |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | |
| | | let text = val |
| | | |
| | | if (item.type === 'select' || item.type === 'link' || item.type === 'radio') { |
| | | item.oriOptions.forEach(cell => { |
| | | if (cell.Value === val) { |
| | | text = cell.Text |
| | | } |
| | | }) |
| | | } |
| | | |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val, text}) |
| | | } |
| | | |
| | | return item |
| | |
| | | } |
| | | |
| | | if (typeof(val) === 'string') { |
| | | val = val.replace(/(^\s*|\s*$)/ig, '') |
| | | val = val.replace(/(^\s+|\s+$)/ig, '').replace(/\t+|\v+/g, '') |
| | | } |
| | | |
| | | search.push({ |
| | |
| | | |
| | | let advanceValues = [] |
| | | this.state.searchlist.forEach(item => { |
| | | if (!item.advanced) return |
| | | if (!item.signValue) return |
| | | |
| | | let val = this.record[item.field] |
| | | if (val || val === 0) { |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | |
| | | let text = val |
| | | |
| | | if (item.type === 'select' || item.type === 'link' || item.type === 'radio') { |
| | | item.oriOptions.forEach(cell => { |
| | | if (cell.Value === val) { |
| | | text = cell.Text |
| | | } |
| | | }) |
| | | } |
| | | |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val, text}) |
| | | } |
| | | }) |
| | | |
| | |
| | | |
| | | return ( |
| | | <> |
| | | <Form {...formItemLayout} className={`mk-search-wrap mk-float-${setting.float}`} style={setting.style}> |
| | | <Form {...formItemLayout} className={`mk-search-wrap mk-float-${setting.float} mk-size-${setting.size}`} style={setting.style}> |
| | | <Row gutter={24}>{this.getFields()}</Row> |
| | | {advanceValues.length && (setting.advanceType !== 'pulldown' || (setting.advanceType === 'pulldown' && !visible)) ? <Row gutter={24}> |
| | | <div className="advanced-list"> |
| | |
| | | return ( |
| | | <div key={index}> |
| | | <span>{item.label}: </span> |
| | | <span className="advance-value">{item.value}</span> |
| | | <span className="advance-value">{item.text}</span> |
| | | <CloseOutlined onClick={() => this.closeAdvanceForm(item)} /> |
| | | </div>) |
| | | })} |
| | |
| | | </Row> : null} |
| | | </Form> |
| | | {setting.advanceType === 'modal' ? <Modal |
| | | title="高级搜索" |
| | | title={window.GLOB.dict['adv_search'] || '高级搜索'} |
| | | maskClosable={false} |
| | | visible={visible} |
| | | width={setting.advWidth} |
| | |
| | | /> |
| | | </Modal> : null} |
| | | {setting.advanceType === 'drawer' ? <Drawer |
| | | title="高级搜索" |
| | | title={window.GLOB.dict['adv_search'] || '高级搜索'} |
| | | className="mk-search-drawer" |
| | | width={setting.advWidth} |
| | | height={setting.advHeight} |