| | |
| | | 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')) |
| | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id,用于查询下拉选择项 |
| | | searchlist: PropTypes.array, // 搜索条件列表 |
| | | config: PropTypes.object, // 组件配置信息(自定义页面) |
| | | setting: PropTypes.object, // 组件配置信息(自定义页面) |
| | | refreshdata: PropTypes.func // 刷新数据 |
| | | config: PropTypes.object, // 组件配置信息 |
| | | } |
| | | |
| | | state = { |
| | |
| | | sign = '' |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { config, searchlist, setting } = this.props |
| | | const { config } = this.props |
| | | |
| | | let _searchlist = [] |
| | | let fieldMap = new Map() |
| | |
| | | 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} |
| | | |
| | | 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.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 |
| | | } |
| | | _setting.borderRadius = config.wrap.borderRadius |
| | | _setting.resetContrl = config.wrap.resetContrl || 'init' |
| | | } |
| | | |
| | | 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 |
| | | } else { |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | if (['text', 'date', 'datemonth', 'dateweek', 'daterange'].includes(item.type)) { |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | } |
| | | } |
| | | |
| | | 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.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) { |
| | | if (window.GLOB.debugger === true) { |
| | | console.info(_option.sql) |
| | | } |
| | | |
| | | // 测试系统单个请求 |
| | | if (!window.GLOB.mkHS && options.sysType === 'local' && !window.GLOB.systemType) { |
| | | if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) { |
| | | deForms.push({ |
| | | ...item, |
| | | arr_field: _option.field, |
| | |
| | | }) |
| | | } 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`) |
| | | mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`) |
| | | } else { |
| | | localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql))}' as LText`) |
| | | localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_option.sql.replace(/%/ig, ' mpercent ')))}' as LText`) |
| | | } |
| | | } |
| | | } |
| | | item.oriOptions = fromJS(item.options).toJS() |
| | | |
| | | if (item.type === 'checkcard' && item.multiple === 'dropdown' && item.resourceType === '0') { |
| | | this.resetCheckcard(item) |
| | | } |
| | | } |
| | | |
| | | 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') { |
| | | if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | this.improveSimpleSearch(deForms) |
| | | } else if (mainItems.length > 0 || localItems.length > 0) { |
| | | this.improveSearch(mainItems, localItems) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | 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 |
| | | } |
| | | |
| | | // 查询下拉菜单 |
| | |
| | | |
| | | if (window.GLOB.mkHS) { // 云端数据验证 |
| | | mainparam.open_key = Utils.encryptOpenKey(mainparam.secretkey, mainparam.timestamp) |
| | | if (options.cloudServiceApi) { |
| | | mainparam.rduri = options.cloudServiceApi |
| | | if (window.GLOB.cloudServiceApi) { |
| | | mainparam.rduri = window.GLOB.cloudServiceApi |
| | | mainparam.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | mainparam.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } |
| | |
| | | |
| | | 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) { |
| | | 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 |
| | | result[item.field].forEach(cell => { |
| | | let _item = { |
| | | key: Utils.getuuid(), |
| | |
| | | _item.Value = cell[item.valueField] |
| | | _item.Text = cell[item.valueText] + '' |
| | | |
| | | if (!_item.Text || map.has(_item.ParentID + _item.Value)) return |
| | | if (map.has(_item.ParentID + _item.Value)) return |
| | | if (!_item.Text) { |
| | | if (!all) { |
| | | _item.Text = '全部' |
| | | all = true |
| | | } else { |
| | | return |
| | | } |
| | | } |
| | | |
| | | map.set(_item.ParentID + _item.Value, 0) |
| | | } else { |
| | |
| | | }) |
| | | |
| | | item.oriOptions = [...item.oriOptions, ...options] |
| | | |
| | | if (item.type === 'checkcard' && item.multiple === 'dropdown') { |
| | | this.resetCheckcard(item) |
| | | } |
| | | } |
| | | |
| | | if (item.linkField) { |
| | |
| | | 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)} /> |
| | | } |
| | | |
| | | if (content) { |
| | |
| | | }) |
| | | |
| | | if (setting.show || setting.showAdv) { |
| | | let style = {} |
| | | if (setting.borderRadius) { |
| | | style.borderRadius = setting.borderRadius |
| | | } |
| | | |
| | | fields.push( |
| | | <Col span={setting.ratio} style={{ whiteSpace: 'nowrap' }} className="mk-search-col search-button" key="actions"> |
| | | <Form.Item |
| | |
| | | labelCol={setting.labelCol} |
| | | wrapperCol={setting.wrapperCol} |
| | | > |
| | | {setting.show ? <Button type="primary" onClick={this.handleSubmit}> |
| | | {setting.show ? <Button style={style} type="primary" onClick={this.handleSubmit}> |
| | | 搜索 |
| | | </Button> : null} |
| | | {setting.show ? <Button style={{ marginLeft: 8 }} onClick={this.handleReset}> |
| | | {setting.show ? <Button style={{ marginLeft: 8, ...style }} onClick={this.handleReset}> |
| | | 重置 |
| | | </Button> : null} |
| | | {setting.showAdv ? <Button className={visible ? 'visible' : ''} type="link" onClick={this.handleAdvance}> |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | if (['text', 'date', 'datemonth', 'dateweek', 'daterange'].includes(item.type)) { |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | } |
| | | } |
| | | }) |
| | | this.setState({advanceValues}) |
| | |
| | | this.sign = '' |
| | | }, 2000) |
| | | |
| | | this.props.refreshdata(searches) |
| | | if (this.props.refreshdata) { |
| | | this.props.refreshdata(searches) |
| | | } else { |
| | | window.GLOB.SearchBox.set(this.props.config.$searchId, searches) |
| | | MKEmitter.emit('searchRefresh', this.props.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'].includes(item.type)) { |
| | | item.initval = '' |
| | | } |
| | | |
| | | if (item.type === 'group') { |
| | | record[item.datefield] = item.initval |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | if (['text', 'date', 'datemonth', 'dateweek', 'daterange'].includes(item.type)) { |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | } |
| | | } |
| | | |
| | | return item |
| | |
| | | val = val + ':00' |
| | | } |
| | | } |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | if (['text', 'date', 'datemonth', 'dateweek', 'daterange'].includes(item.type)) { |
| | | advanceValues.push({field: item.field, type: item.type, label: item.label, value: val}) |
| | | } |
| | | } |
| | | }) |
| | | |
| | |
| | | |
| | | return ( |
| | | <> |
| | | <Form {...formItemLayout} className={`top-search mk-float-${setting.float}`} style={setting.style}> |
| | | <Form {...formItemLayout} className={`mk-search-wrap mk-float-${setting.float}`} 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"> |