import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Popover, Input } from 'antd'
|
import { EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, SettingOutlined } from '@ant-design/icons'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import asyncIconComponent from '@/utils/asyncIconComponent'
|
import { resetStyle, getTables } from '@/utils/utils-custom.js'
|
import MKEmitter from '@/utils/events.js'
|
import getWrapForm from './options'
|
import './index.scss'
|
|
const { Search } = Input
|
|
const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
|
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
|
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
|
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
|
|
class NormalIframe 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 _card = {
|
uuid: card.uuid,
|
type: card.type,
|
format: 'object', // 组件属性 - 数据格式
|
pageable: false, // 组件属性 - 是否可分页
|
switchable: false, // 组件属性 - 数据是否可切换
|
width: card.width || 24,
|
name: card.name,
|
subtype: card.subtype,
|
setting: { interType: 'system' },
|
wrap: { title: '', name: card.name, datatype: 'static', width: card.width || 24, height: '300px', linkType: 'fixed' },
|
style: { marginLeft: '0px', marginRight: '0px', marginTop: '0px', marginBottom: '0px' },
|
headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
|
columns: [],
|
scripts: [],
|
}
|
|
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.errors = []
|
|
if (card.wrap.datatype === 'dynamic') {
|
let columns = card.columns.map(c => c.field)
|
|
if (card.setting.interType === 'system' && card.setting.execute !== 'false' && !card.setting.dataresource) {
|
card.errors.push({ level: 0, detail: '未设置数据源!'})
|
} else if (card.setting.interType === 'system' && card.setting.execute === 'false' && card.scripts.filter(script => script.status !== 'false').length === 0) {
|
card.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
|
} else if (!card.setting.primaryKey) {
|
card.errors.push({ level: 0, detail: '未设置主键!'})
|
} else if (!columns.includes(card.setting.primaryKey)) {
|
card.errors.push({ level: 0, detail: '主键已失效!'})
|
} else if (!card.setting.supModule) {
|
card.errors.push({ level: 0, detail: '未设置上级组件!'})
|
}
|
}
|
|
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', ['border', 'padding', 'margin', 'shadow', 'clear'], card.style, this.getStyle)
|
}
|
|
getStyle = (style) => {
|
let _card = {...this.state.card, style}
|
|
this.updateComponent(_card)
|
}
|
|
getWrapForms = () => {
|
const { card } = this.state
|
|
return getWrapForm(card.wrap, card.columns)
|
}
|
|
updateWrap = (res) => {
|
let _card = {...this.state.card, wrap: res}
|
|
this.updateComponent(_card)
|
}
|
|
render() {
|
const { card } = this.state
|
|
let _style = resetStyle(card.style)
|
|
return (
|
<div className="menu-iframe-edit-box" style={_style} id={card.uuid}>
|
<Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
|
<div className="mk-popover-control">
|
<NormalForm title="iframe设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}>
|
<EditOutlined style={{color: '#1890ff'}} title="编辑"/>
|
</NormalForm>
|
<CopyComponent type="iframe" card={card}/>
|
<FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
|
<DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} />
|
{card.wrap.datatype === 'dynamic' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>}
|
</div>
|
} trigger="hover">
|
<ToolOutlined />
|
</Popover>
|
<NormalHeader hideSearch="true" config={card} updateComponent={this.updateComponent}/>
|
{card.wrap.linkType === 'input' ? <div className="input-box">
|
<Search placeholder="请输入地址" enterButton="确定"/>
|
</div> : null}
|
<div className="iframe-wrap" style={{height: card.wrap.height}}>
|
<iframe title="mk" className="iframe" src={card.wrap.linkUrl || 'http://www.minkesoft.com/index.html'} frameBorder="0"></iframe>
|
</div>
|
<div className="component-name">
|
<div className="center">
|
<div className="title">{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 NormalIframe
|