import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Popover, message } from 'antd'
|
import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, PlusCircleOutlined } from '@ant-design/icons'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import asyncIconComponent from '@/utils/asyncIconComponent'
|
import { resetStyle, getTables, checkComponent } from '@/utils/utils-custom.js'
|
import MKEmitter from '@/utils/events.js'
|
import getWrapForm from './options'
|
import Utils from '@/utils/utils.js'
|
import './index.scss'
|
|
const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
|
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
|
const SearchComponent = asyncComponent(() => import('@/templates/sharecomponent/searchcomponent'))
|
const ActionComponent = asyncComponent(() => import('@/menu/components/share/actioncomponent'))
|
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
|
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
|
const CalendarBoard = asyncComponent(() => import('./board'))
|
|
class NormalCalendarComponent extends Component {
|
static propTpyes = {
|
card: PropTypes.object,
|
deletecomponent: PropTypes.func,
|
updateConfig: PropTypes.func,
|
}
|
|
state = {
|
card: null
|
}
|
|
UNSAFE_componentWillMount () {
|
const { card } = this.props
|
|
if (card.isNew) {
|
let btnId = Utils.getuuid()
|
let _card = {
|
uuid: card.uuid,
|
type: card.type,
|
format: 'array', // 组件属性 - 数据格式
|
pageable: false, // 组件属性 - 是否可分页
|
switchable: false, // 组件属性 - 数据是否可切换
|
width: card.width || 24,
|
name: card.name,
|
subtype: card.subtype,
|
setting: { interType: 'system' },
|
wrap: { title: '', name: card.name, width: card.width || 24, levels: ['day', 'month', 'year'] },
|
style: { marginLeft: '0px', marginRight: '0px', marginTop: '0px', marginBottom: '0px' },
|
headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
|
search: [],
|
columns: [],
|
scripts: [],
|
action: [{
|
$fixed: true,
|
uuid: btnId,
|
label: '添加',
|
OpenType: 'popview',
|
popClose: 'grid',
|
display: 'modal',
|
icon: '',
|
class: 'green',
|
ratio: 85,
|
style: {
|
color: 'rgb(255, 255, 255)',
|
background: 'rgb(38, 194, 129)',
|
marginRight: '15px'
|
},
|
config: {
|
uuid: btnId,
|
MenuID: btnId,
|
ParentId: card.uuid,
|
enabled: false,
|
MenuName: '添加',
|
tables: [],
|
Template: 'CustomPage',
|
components: [],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
}]
|
}
|
|
if (card.config) {
|
let config = fromJS(card.config).toJS()
|
|
_card.wrap = config.wrap
|
_card.wrap.name = card.name
|
_card.style = config.style
|
|
_card.setting = config.setting
|
_card.columns = config.columns
|
_card.scripts = config.scripts
|
}
|
|
this.updateComponent(_card)
|
} else {
|
this.setState({
|
card: fromJS(card).toJS()
|
})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
/**
|
* @description 卡片行外层信息更新(数据源,样式等)
|
*/
|
updateComponent = (card) => {
|
card.width = card.wrap.width
|
card.name = card.wrap.name
|
if (!window.GLOB.styling || !card.errors) { // 样式修改时不做筛查
|
card.$c_ds = true
|
|
card.errors = checkComponent(card)
|
|
if (card.errors.length === 0) {
|
card.$tables = getTables(card)
|
}
|
}
|
|
this.setState({
|
card: card
|
})
|
|
this.props.updateConfig(card)
|
}
|
|
changeStyle = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('changeStyle', ['height', 'background', 'border', 'padding', 'margin', 'shadow', 'clear', 'minHeight'], card.style, this.getStyle)
|
}
|
|
getStyle = (style) => {
|
let _card = {...this.state.card, style}
|
|
this.updateComponent(_card)
|
}
|
|
addSearch = () => {
|
const { card } = this.state
|
|
MKEmitter.emit('plusSearch', card.uuid, {uuid: Utils.getuuid(), focus: true, label: 'label', type: 'text', match: '='}, 'simple')
|
}
|
|
getWrapForms = () => {
|
const { card } = this.state
|
|
return getWrapForm(card.wrap, card.columns)
|
}
|
|
updateWrap = (res) => {
|
const { card } = this.state
|
|
res.show = card.wrap.show || 'true'
|
res.advanceType = card.wrap.advanceType || 'modal'
|
res.advanceWidth = card.wrap.advanceWidth || 1000
|
res.drawerPlacement = card.wrap.drawerPlacement || 'right'
|
res.searchRatio = card.wrap.searchRatio || 6
|
res.searchLwidth = card.wrap.searchLwidth !== undefined ? card.wrap.searchLwidth : 33.3
|
res.borderRadius = card.wrap.borderRadius || 0
|
res.resetContrl = card.wrap.resetContrl || 'init'
|
|
if (res.colorField && res.signs) {
|
res.signs = res.signs.map((item, i) => {
|
try {
|
let colors = item.background.match(/\d+/g)
|
if ((colors[0] * 0.299 + colors[1] * 0.578 + colors[2] * 0.114) * colors[3] < 192) {
|
item.fontColor = '#ffffff'
|
} else {
|
item.fontColor = ''
|
}
|
} catch (e) {
|
item.fontColor = ''
|
}
|
|
item.style = {background: item.background}
|
if (item.fontColor) {
|
item.style.color = item.fontColor
|
}
|
|
item.$index = i + 1
|
|
return item
|
})
|
}
|
|
this.updateComponent({...card, wrap: res})
|
}
|
|
setSubConfig = (item) => {
|
const { card } = this.state
|
let btn = fromJS(item).toJS()
|
|
if (btn.OpenType === 'popview') {
|
MKEmitter.emit('changePopview', card, btn)
|
}
|
}
|
|
render() {
|
const { card } = this.state
|
|
let _style = resetStyle(card.style)
|
|
return (
|
<div className="menu-calendar-edit-box" style={_style} id={card.uuid}>
|
<NormalHeader hideSearch="true" config={card} updateComponent={this.updateComponent}/>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<PlusCircleOutlined className="plus" title="添加搜索" onClick={this.addSearch}/>
|
<NormalForm title="日历设置" width={850} update={this.updateWrap} getForms={this.getWrapForms}>
|
<EditOutlined style={{color: '#1890ff'}} title="编辑"/>
|
</NormalForm>
|
<CopyComponent type="calendar" card={card}/>
|
<FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
|
<DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} />
|
<SettingComponent config={card} updateConfig={this.updateComponent} />
|
</div>
|
} trigger="hover">
|
<ToolOutlined />
|
</Popover>
|
<SearchComponent config={card} updatesearch={this.updateComponent}/>
|
<ActionComponent config={card} setSubConfig={this.setSubConfig} updateaction={this.updateComponent}/>
|
<CalendarBoard config={card} />
|
<div className="component-name">
|
<div className="center">
|
<div className="title" onDoubleClick={() => {
|
let oInput = document.createElement('input')
|
oInput.value = 'anchor' + card.uuid
|
document.body.appendChild(oInput)
|
oInput.select()
|
document.execCommand('Copy')
|
document.body.removeChild(oInput)
|
message.success('复制成功。')
|
}}>{card.name}</div>
|
<div className="content">
|
{card.errors && card.errors.map((err, index) => {
|
if (err.level === 0) {
|
return <span key={index} className="error">{err.detail}</span>
|
} else {
|
return <span key={index} className="waring">{err.detail};</span>
|
}
|
})}
|
</div>
|
</div>
|
</div>
|
</div>
|
)
|
}
|
}
|
|
export default NormalCalendarComponent
|