| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Icon, Popover } from 'antd' |
| | | import { ExpandOutlined, ReloadOutlined } from '@ant-design/icons' |
| | | import { Popover } from 'antd' |
| | | import { ExpandOutlined, ReloadOutlined, EllipsisOutlined, LogoutOutlined, ToolOutlined, ScanOutlined, LeftOutlined, EditOutlined, FontColorsOutlined, DeleteOutlined, SearchOutlined, MenuOutlined } from '@ant-design/icons' |
| | | |
| | | import asyncIconComponent from '@/utils/asyncIconComponent' |
| | | import getWrapForm from './options' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import avatar from '@/assets/img/avatar.jpg' |
| | | import './index.scss' |
| | | |
| | | const NormalForm = asyncIconComponent(() => import('@/components/normalform')) |
| | |
| | | } |
| | | |
| | | state = { |
| | | avatar: sessionStorage.getItem('CloudAvatar') || avatar, |
| | | card: null, |
| | | back: false |
| | | } |
| | |
| | | let _card = { |
| | | uuid: card.uuid, |
| | | type: card.type, |
| | | floor: card.floor, |
| | | width: 24, |
| | | subtype: card.subtype, |
| | | wrap: { type: 'navbar', height: 50, title: 'NavBar', back: 'true', search: 'false', logout: 'false' }, |
| | | wrap: { type: 'navbar', height: 50, title: 'NavBar', back: 'true', logout: 'false' }, |
| | | style: {boxShadow: '0 0 3px #D9D9D9', shadowColor: '#D9D9D9', shadowBlur: '3px', paddingLeft: '10px', paddingRight: '10px', lineHeight: '2.8', fontSize: '18px' }, |
| | | searchStyle: {} |
| | | searchStyle: {}, |
| | | titleStyle: {} |
| | | } |
| | | |
| | | if (card.config) { |
| | |
| | | }) |
| | | this.props.updateConfig(_card) |
| | | } else { |
| | | let _card = fromJS(card).toJS() |
| | | if (_card.wrap.type === 'navbar' && _card.wrap.search === 'true') { |
| | | _card.wrap.type = 'searchIcon' |
| | | } |
| | | this.setState({ |
| | | card: fromJS(card).toJS() |
| | | card: _card |
| | | }) |
| | | } |
| | | } |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('submitStyle', this.getStyle) |
| | | MKEmitter.addListener('submitSearch', this.getSearch) |
| | | } |
| | | |
| | |
| | | this.setState = () => { |
| | | return |
| | | } |
| | | MKEmitter.removeListener('submitStyle', this.getStyle) |
| | | MKEmitter.removeListener('submitSearch', this.getSearch) |
| | | } |
| | | |
| | |
| | | this.props.updateConfig(component) |
| | | } |
| | | |
| | | getStyle = (comIds, style) => { |
| | | const { card } = this.state |
| | | getStyle = (style) => { |
| | | let _card = {...this.state.card, style} |
| | | |
| | | if (comIds[0] !== card.uuid) return |
| | | this.setState({ |
| | | card: _card |
| | | }) |
| | | |
| | | this.props.updateConfig(_card) |
| | | } |
| | | |
| | | let _card = fromJS(card).toJS() |
| | | getSearchStyle = (style) => { |
| | | let _card = {...this.state.card, searchStyle: style} |
| | | |
| | | if (comIds[1] === 'search') { |
| | | _card.searchStyle = style |
| | | } else { |
| | | _card.style = style |
| | | } |
| | | this.setState({ |
| | | card: _card |
| | | }) |
| | | |
| | | this.props.updateConfig(_card) |
| | | } |
| | | |
| | | getTitleStyle = (style) => { |
| | | let _card = {...this.state.card, titleStyle: style} |
| | | |
| | | this.setState({ |
| | | card: _card |
| | |
| | | changeStyle = () => { |
| | | const { card } = this.state |
| | | |
| | | MKEmitter.emit('changeStyle', [card.uuid], ['font', 'background', 'border', 'padding', 'shadow'], card.style) |
| | | MKEmitter.emit('changeStyle', ['font', 'background', 'border', 'padding', 'shadow'], card.style, this.getStyle) |
| | | } |
| | | |
| | | changeTitleStyle = () => { |
| | | const { card } = this.state |
| | | |
| | | MKEmitter.emit('changeStyle', ['font'], card.titleStyle || {}, this.getTitleStyle) |
| | | } |
| | | |
| | | changeSearchStyle = () => { |
| | | const { card } = this.state |
| | | |
| | | MKEmitter.emit('changeStyle', [card.uuid, 'search'], ['font', 'background', 'border'], card.searchStyle || {}) |
| | | } |
| | | |
| | | clickComponent = (e) => { |
| | | if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') { |
| | | e.stopPropagation() |
| | | MKEmitter.emit('clickComponent', this.state.card) |
| | | } |
| | | } |
| | | |
| | | changeMenu = (menu) => { |
| | | if (menu.property === 'link') { |
| | | window.open(menu.link) |
| | | } else { |
| | | MKEmitter.emit('changeEditMenu', { |
| | | MenuID: menu.property === 'linkmenu' ? menu.linkMenuId : menu.MenuID, |
| | | copyMenuId: menu.property === 'menu' ? menu.copyMenuId : '', |
| | | MenuNo: menu.MenuNo, |
| | | MenuName: menu.name, |
| | | }) |
| | | } |
| | | MKEmitter.emit('changeStyle', ['font', 'background', 'border'], card.searchStyle || {}, this.getSearchStyle) |
| | | } |
| | | |
| | | getSearch = (config) => { |
| | |
| | | if (!card.search) { |
| | | card.search = { |
| | | floor: 1, |
| | | setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden' }, |
| | | setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden', backgroundColor: sessionStorage.getItem('sysBgColor') }, |
| | | groups: [], |
| | | fields: [] |
| | | } |
| | |
| | | } |
| | | |
| | | updateWrap = (res) => { |
| | | let funs = res.funs || [] |
| | | |
| | | delete res.funs |
| | | |
| | | funs.forEach(n => { |
| | | res[n] = 'true' |
| | | }) |
| | | |
| | | this.updateComponent({...this.state.card, wrap: res}) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { card } = this.state |
| | | const { card, avatar } = this.state |
| | | |
| | | let right = null |
| | | if (card.wrap.logout === 'true') { |
| | | right = <Icon type="logout" /> |
| | | right = <LogoutOutlined /> |
| | | } |
| | | if (card.wrap.scan === 'true') { |
| | | right = !right ? <ExpandOutlined onDoubleClick={this.skip}/> : <Icon type="ellipsis" /> |
| | | right = !right ? <ExpandOutlined onDoubleClick={this.skip}/> : <EllipsisOutlined /> |
| | | } |
| | | if (card.wrap.refresh === 'true') { |
| | | right = !right ? <ReloadOutlined /> : <Icon type="ellipsis" onDoubleClick={this.skip}/> |
| | | right = !right ? <ReloadOutlined /> : <EllipsisOutlined onDoubleClick={this.skip}/> |
| | | } |
| | | if (card.wrap.menus && card.wrap.menus.length > 0) { |
| | | right = !right ? <MenuOutlined /> : <EllipsisOutlined onDoubleClick={this.skip}/> |
| | | } |
| | | |
| | | return ( |
| | | <div className="normal-topbar-edit-box" style={card.style} onClick={this.clickComponent} id={card.uuid}> |
| | | <div className="normal-topbar-edit-box" style={card.style} id={card.uuid}> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <NormalForm title="导航栏设置" width={750} update={this.updateWrap} getForms={this.getWrapForms}> |
| | | <Icon type="edit" style={{color: '#1890ff'}} title="编辑"/> |
| | | <NormalForm title="导航栏设置" width={900} update={this.updateWrap} getForms={this.getWrapForms}> |
| | | <EditOutlined style={{color: '#1890ff'}} title="编辑"/> |
| | | </NormalForm> |
| | | <CopyComponent type="topbar" card={card}/> |
| | | <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" /> |
| | | <Icon className="close" title="删除组件" type="delete" onClick={() => this.props.deletecomponent(card.uuid)} /> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/> |
| | | <DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} /> |
| | | </div> |
| | | } trigger="hover"> |
| | | <Icon type="tool" /> |
| | | <ToolOutlined /> |
| | | </Popover> |
| | | <div className="am-navbar"> |
| | | <div className="am-navbar-left"> |
| | | {card.wrap.back !== 'false' ? <Icon type="left" /> : null} |
| | | {card.wrap.back === 'true' && card.wrap.menuPosition !== 'left' ? <LeftOutlined /> : null} |
| | | {card.wrap.menuPosition === 'left' ? <div className="img" style={{backgroundImage: `url(${avatar})`}}></div> : null} |
| | | </div> |
| | | {card.wrap.type !== 'search' ? |
| | | <div className="am-navbar-title">{card.wrap.title || ''}</div> : |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeTitleStyle}/> |
| | | </div> |
| | | } trigger="hover"> |
| | | <div className="am-navbar-title" style={card.titleStyle}>{card.wrap.title || ''}</div> |
| | | </Popover> : |
| | | <div className="am-navbar-search" onDoubleClick={this.setSearch}> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <Icon className="style" title="调整样式" onClick={this.changeSearchStyle} type="font-colors" /> |
| | | <FontColorsOutlined className="style" title="调整样式" onClick={this.changeSearchStyle}/> |
| | | </div> |
| | | } trigger="hover"> |
| | | <div style={card.searchStyle} className="search-bar"> |
| | | {card.search && card.search.setting.scan === 'true' ? <Icon type="scan" /> : <Icon type="search" />} |
| | | {card.search && card.search.setting.scan === 'true' ? <ScanOutlined /> : <SearchOutlined />} |
| | | </div> |
| | | </Popover> |
| | | </div> |
| | | } |
| | | <div className="am-navbar-right"> |
| | | {card.wrap.search === 'true' ? <Icon type="search" onDoubleClick={this.setSearch}/> : null} |
| | | {card.wrap.type === 'searchIcon' ? <SearchOutlined onDoubleClick={this.setSearch}/> : null} |
| | | {right} |
| | | </div> |
| | | </div> |