| | |
| | | import React, { Component } from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { connect } from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Modal, notification, Popover, Icon } from 'antd' |
| | | import { Modal, notification, Popover, Switch } from 'antd' |
| | | import { PlusOutlined, EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | |
| | | import zhCN from '@/locales/zh-CN/model.js' |
| | | import enUS from '@/locales/en-US/model.js' |
| | | import { getSearchForm } from '@/templates/zshare/formconfig' |
| | | |
| | | import { resetStyle } from '@/utils/utils-custom.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import asyncIconComponent from '@/utils/asyncIconComponent' |
| | | import SearchForm from '@/templates/sharecomponent/searchcomponent/searchform' |
| | | import DragElement from './dragsearch' |
| | | import getWrapForm from './options' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import './index.scss' |
| | | |
| | | const { confirm } = Modal |
| | | |
| | | const WrapComponent = asyncIconComponent(() => import('./wrapsetting')) |
| | | const NormalForm = asyncIconComponent(() => import('@/components/normalform')) |
| | | const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent')) |
| | | const SearchForm = asyncIconComponent(() => import('@/templates/sharecomponent/searchcomponent/searchform')) |
| | | const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent')) |
| | | const PasteComponent = asyncIconComponent(() => import('@/menu/components/share/pastecomponent')) |
| | | |
| | | class MainSearchComponent extends Component { |
| | | static propTpyes = { |
| | | card: PropTypes.object, |
| | | updateConfig: PropTypes.func, |
| | | deletecomponent: PropTypes.func, |
| | | |
| | | menu: PropTypes.object, // 当前菜单信息 |
| | | config: PropTypes.object, // 配置信息 |
| | | pasteContent: PropTypes.object, // 粘贴配置信息 |
| | | sysRoles: PropTypes.array, // 角色列表,黑名单 |
| | | updatesearch: PropTypes.func // 更新 |
| | | deletecomponent: PropTypes.func |
| | | } |
| | | |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | appType: sessionStorage.getItem('appType'), |
| | | searchlist: null, // 搜索条件集 |
| | | sqlVerifing: false, // sql验证中 |
| | | visible: false, // 模态框控制 |
| | | showField: false, |
| | | editcard: null // 编辑中元素 |
| | | } |
| | | |
| | |
| | | let _card = { |
| | | uuid: card.uuid, |
| | | type: card.type, |
| | | floor: card.floor, |
| | | tabId: card.tabId || '', |
| | | parentId: card.parentId || '', |
| | | width: 24, |
| | | name: card.name, |
| | | subtype: card.subtype, |
| | | wrap: { name: card.name, width: 24 }, |
| | | wrap: { name: card.name, width: 24, show: this.state.appType === 'mob' ? 'false' : 'true', float: 'left' }, |
| | | style: { |
| | | marginLeft: '8px', marginRight: '8px', marginTop: '8px', marginBottom: '8px' |
| | | }, |
| | |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('submitStyle', this.getStyle) |
| | | MKEmitter.addListener('plusSearch', this.plusSearch) |
| | | } |
| | | |
| | | /** |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('submitStyle', this.getStyle) |
| | | MKEmitter.removeListener('plusSearch', this.plusSearch) |
| | | } |
| | | |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | |
| | | changeStyle = () => { |
| | | const { card } = this.state |
| | | |
| | | MKEmitter.emit('changeStyle', [card.uuid], ['background', 'border', 'padding', 'margin'], card.style) |
| | | MKEmitter.emit('changeStyle', [card.uuid], ['background', 'border', 'padding', 'margin', 'shadow'], card.style) |
| | | } |
| | | |
| | | /** |
| | |
| | | this.props.updateConfig(component) |
| | | } |
| | | |
| | | checkComponent = (component) => { |
| | | this.updateComponent(component) |
| | | |
| | | let _item = null |
| | | component.search.forEach(item => { |
| | | if (!_item && item.focus) { |
| | | _item = item |
| | | } |
| | | }) |
| | | if (_item) { |
| | | this.handleSearch(_item) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 搜索条件顺序调整,或拖拽添加 |
| | | */ |
| | | handleList = (list, card) => { |
| | | const { config } = this.props |
| | | handleList = (list, newcell) => { |
| | | const { card } = this.state |
| | | let _card = {...card, search: list} |
| | | |
| | | if (card) { |
| | | this.setState({searchlist: list}) |
| | | this.handleSearch(card) |
| | | if (newcell) { |
| | | this.setState({card: _card}) |
| | | this.handleSearch(newcell) |
| | | } else { |
| | | this.setState({searchlist: list}, ()=> { |
| | | this.props.updatesearch({...config, search: list}) |
| | | this.setState({card: _card}, ()=> { |
| | | this.props.updateConfig(_card) |
| | | }) |
| | | } |
| | | } |
| | |
| | | let linkableFields = [] |
| | | |
| | | card.search.forEach(item => { |
| | | if (item.uuid !== cell.uuid && (item.type === 'select' || item.type === 'link')) { |
| | | linkableFields.push({ |
| | | value: item.field, |
| | | text: item.label |
| | | }) |
| | | } |
| | | if (item.uuid === card.uuid) return |
| | | if (!['select', 'link', 'checkcard'].includes(item.type)) return |
| | | if (item.type === 'checkcard' && item.multiple === 'true') return |
| | | |
| | | linkableFields.push({ |
| | | value: item.field, |
| | | text: item.label |
| | | }) |
| | | }) |
| | | |
| | | this.setState({ |
| | | visible: true, |
| | | editcard: cell, |
| | | formlist: getSearchForm(cell, this.props.sysRoles, linkableFields) |
| | | formlist: getSearchForm(cell, linkableFields) |
| | | }) |
| | | } |
| | | |
| | |
| | | * @description 取消保存,如果元素为新添元素,则从序列中删除 |
| | | */ |
| | | editModalCancel = () => { |
| | | const { card } = this.state |
| | | const { card, editcard } = this.state |
| | | |
| | | if (card.focus) { |
| | | let searchlist = fromJS(this.state.searchlist).toJS() |
| | | |
| | | searchlist = searchlist.filter(item => item.uuid !== card.uuid) |
| | | if (editcard.focus) { |
| | | card.search = card.search.filter(item => item.uuid !== editcard.uuid) |
| | | |
| | | this.setState({ |
| | | card: null, |
| | | searchlist: searchlist, |
| | | card: card, |
| | | editcard: null, |
| | | visible: false |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | card: null, |
| | | editcard: null, |
| | | visible: false |
| | | }) |
| | | } |
| | |
| | | |
| | | /** |
| | | * @description 搜索修改后提交保存 |
| | | * 1、去除系统默认搜索条件 |
| | | * 2、字段及提示文字重复校验 |
| | | * 3、更新下拉菜单可选集合 |
| | | * 4、下拉菜单数据源语法验证 |
| | | * 1、字段及提示文字重复校验 |
| | | * 2、下拉菜单数据源语法验证 |
| | | */ |
| | | handleSubmit = () => { |
| | | const { config } = this.props |
| | | let _searchlist = fromJS(this.state.searchlist).toJS() |
| | | let card = fromJS(this.state.card).toJS() |
| | | |
| | | this.searchFormRef.handleConfirm().then(res => { |
| | | let fieldrepet = false // 字段重复 |
| | | let labelrepet = false // 提示文字重复 |
| | | |
| | | _searchlist = _searchlist.filter(item => !item.origin || item.uuid === res.uuid) // 去除系统项 |
| | | |
| | | _searchlist = _searchlist.map(item => { // 数据更新及重复检测 |
| | | card.search = card.search.map(item => { // 数据更新及重复检测 |
| | | if (item.uuid !== res.uuid && res.field && item.field) { |
| | | let itemFields = [] |
| | | if (item.type === 'text') { |
| | |
| | | if (fieldrepet) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['model.field.exist'] + ' !', |
| | | message: '字段已存在!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (labelrepet) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: this.state.dict['model.name.exist'] + ' !', |
| | | message: '名称已存在!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } |
| | | |
| | | if ((res.type === 'select' || res.type === 'multiselect' || res.type === 'link') && res.resourceType === '1' && /\s/.test(res.dataSource)) { |
| | | if (['select', 'multiselect', 'link', 'checkcard'].includes(res.type) && res.resourceType === '1' && /\s/.test(res.dataSource)) { |
| | | this.setState({ |
| | | sqlVerifing: true |
| | | }) |
| | | |
| | | let param = { |
| | | func: 's_debug_sql', |
| | | exec_type: 'y', |
| | | LText: res.dataSource |
| | | } |
| | | |
| | |
| | | |
| | | param.LText = Utils.formatOptions(param.LText) |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | param.secretkey = Utils.encrypt('', param.timestamp) |
| | | |
| | | if (window.GLOB.mainSystemApi && res.database === 'sso') { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | |
| | | Api.getLocalConfig(param).then(result => { |
| | | if (result.status) { |
| | | this.setState({ |
| | | card: card, |
| | | sqlVerifing: false, |
| | | searchlist: _searchlist, |
| | | visible: false |
| | | }, ()=> { |
| | | this.props.updatesearch({...config, search: _searchlist}) |
| | | this.props.updateConfig(card) |
| | | }) |
| | | } else { |
| | | this.setState({sqlVerifing: false}) |
| | |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | searchlist: _searchlist, |
| | | card: card, |
| | | visible: false |
| | | }, ()=> { |
| | | this.props.updatesearch({...config, search: _searchlist}) |
| | | this.props.updateConfig(card) |
| | | }) |
| | | } |
| | | }) |
| | |
| | | /** |
| | | * @description 搜索条件删除 |
| | | */ |
| | | deleteElement = (card) => { |
| | | const { config } = this.props |
| | | deleteElement = (cell) => { |
| | | const { dict } = this.state |
| | | let _this = this |
| | | |
| | | confirm({ |
| | | content: dict['model.confirm'] + dict['model.delete'] + ` - ${card.label} ?`, |
| | | content: dict['model.confirm'] + dict['model.delete'] + ` - ${cell.label} ?`, |
| | | onOk() { |
| | | let _searchlist = fromJS(_this.state.searchlist).toJS() |
| | | |
| | | _searchlist = _searchlist.filter(item => item.uuid !== card.uuid) |
| | | let _card = fromJS(_this.state.card).toJS() |
| | | _card.search = _card.search.filter(item => item.uuid !== cell.uuid) |
| | | |
| | | _this.setState({ |
| | | searchlist: _searchlist |
| | | card: _card |
| | | }, () => { |
| | | _this.props.updatesearch({...config, search: _searchlist}) |
| | | _this.props.updateConfig(_card) |
| | | }) |
| | | }, |
| | | onCancel() {} |
| | |
| | | } |
| | | card.search.push(item) |
| | | |
| | | this.setState({card}) |
| | | this.setState({card}, () => { |
| | | this.handleSearch(item) |
| | | }) |
| | | } |
| | | |
| | | onFieldChange = () => { |
| | | const { showField } = this.state |
| | | |
| | | this.setState({ |
| | | showField: !showField |
| | | }) |
| | | } |
| | | |
| | | plusSearch = (MenuId, item, type) => { |
| | | const { card } = this.state |
| | | |
| | | if (MenuId !== card.uuid) return |
| | | |
| | | let _card = fromJS(card).toJS() |
| | | |
| | | if (type === 'simple') { |
| | | _card.search.push(item) |
| | | this.setState({ |
| | | card: _card, |
| | | }, () => { |
| | | this.props.updateConfig(_card) |
| | | }) |
| | | } else if (type === 'multil') { |
| | | _card.search.push(...item) |
| | | this.setState({ |
| | | card: _card, |
| | | }, () => { |
| | | this.props.updateConfig(_card) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | getWrapForms = () => { |
| | | const { wrap, action } = this.state.card |
| | | |
| | | return getWrapForm(wrap, action) |
| | | } |
| | | |
| | | updateWrap = (res) => { |
| | | this.updateComponent({...this.state.card, wrap: res}) |
| | | } |
| | | |
| | | clickComponent = (e) => { |
| | | if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') { |
| | | e.stopPropagation() |
| | | MKEmitter.emit('clickComponent', this.state.card) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { dict, card, visible, sqlVerifing } = this.state |
| | | const { dict, card, visible, sqlVerifing, showField } = this.state |
| | | let _style = resetStyle(card.style) |
| | | |
| | | return ( |
| | | <div className="main-search-edit-list" style={card.style}> |
| | | <div className={`main-search-edit-list ${card.wrap.float} ${card.wrap.show || ''}`} onClick={this.clickComponent} id={card.uuid} style={_style}> |
| | | <FieldsComponent config={card} type="search" /> |
| | | <Switch checkedChildren={dict['model.switch.open']} size="small" unCheckedChildren={dict['model.switch.close']} defaultChecked={showField} onChange={this.onFieldChange} /> |
| | | <DragElement |
| | | list={card.search} |
| | | showField={showField} |
| | | handleList={this.handleList} |
| | | handleMenu={this.handleSearch} |
| | | deleteMenu={this.deleteElement} |
| | | placeholder={dict['header.form.search.placeholder']} |
| | | /> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="plus" title="添加" onClick={this.addSearch} type="plus" /> |
| | | <WrapComponent config={card} updateConfig={this.updateComponent}/> |
| | | <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" /> |
| | | <Icon className="close" title="delete" type="delete" onClick={() => this.props.deletecomponent(card.uuid)} /> |
| | | <PlusOutlined className="plus" title="添加" onClick={this.addSearch}/> |
| | | <NormalForm title="搜索设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}> |
| | | <EditOutlined style={{color: '#1890ff'}} title="编辑"/> |
| | | </NormalForm> |
| | | <CopyComponent type="mainsearch" card={card}/> |
| | | <PasteComponent config={card} options={['search', 'form']} updateConfig={this.checkComponent} /> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/> |
| | | <DeleteOutlined className="close" onClick={() => this.props.deletecomponent(card.uuid)} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <Icon type="tool" /> |
| | | <ToolOutlined /> |
| | | </Popover> |
| | | <div className="component-name"><div className="center">{card.name}</div></div> |
| | | {/* 编辑搜索条件 */} |
| | | <Modal |
| | | title={dict['model.searchCriteria'] + '-' + dict['model.edit']} |
| | | title="搜索条件-编辑" |
| | | visible={visible} |
| | | width={850} |
| | | maskClosable={false} |
| | |
| | | > |
| | | <SearchForm |
| | | dict={dict} |
| | | card={this.state.card} |
| | | card={this.state.editcard} |
| | | formlist={this.state.formlist} |
| | | inputSubmit={this.handleSubmit} |
| | | wrappedComponentRef={(inst) => this.searchFormRef = inst} |
| | |
| | | ) |
| | | } |
| | | } |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | menu: state.customMenu |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = () => { |
| | | return {} |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(MainSearchComponent) |
| | | export default MainSearchComponent |