import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { fromJS } from 'immutable'
|
import { Form, Row, Col, Input, Radio, Tooltip, Icon, InputNumber, Select, Cascader } from 'antd'
|
|
import MenuUtils from '@/utils/utils-custom.js'
|
import StyleInput from '@/menu/components/share/styleInput'
|
import './index.scss'
|
|
class SettingForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object,
|
config: PropTypes.object,
|
wrap: PropTypes.object,
|
inputSubmit: PropTypes.func
|
}
|
|
state = {
|
roleList: [],
|
modules: [],
|
supmodules: [],
|
appType: sessionStorage.getItem('appType'),
|
linkType: this.props.wrap.linkType,
|
position: this.props.wrap.position,
|
}
|
|
UNSAFE_componentWillMount () {
|
let roleList = sessionStorage.getItem('sysRoles')
|
if (roleList) {
|
try {
|
roleList = JSON.parse(roleList)
|
} catch {
|
roleList = []
|
}
|
} else {
|
roleList = []
|
}
|
|
let menu = fromJS(window.GLOB.customMenu).toJS()
|
|
let modules = MenuUtils.getLinkModules(menu.components)
|
if (!modules) {
|
modules = []
|
}
|
|
let _menu = fromJS(window.GLOB.customMenu).toJS()
|
|
let supmodules = MenuUtils.getSupModules(_menu.components, '')
|
if (!supmodules) {
|
supmodules = []
|
}
|
|
this.setState({roleList, modules, supmodules})
|
}
|
|
handleConfirm = () => {
|
// 表单提交时检查输入值是否正确
|
return new Promise((resolve, reject) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
if (!err) {
|
resolve(values)
|
} else {
|
reject(err)
|
}
|
})
|
})
|
}
|
|
handleSubmit = (e) => {
|
e.preventDefault()
|
|
if (this.props.inputSubmit) {
|
this.props.inputSubmit()
|
}
|
}
|
|
render() {
|
const { wrap } = this.props
|
const { getFieldDecorator } = this.props.form
|
const { roleList, modules, supmodules, linkType, position } = this.state
|
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
|
return (
|
<div className="model-menu-setting-form">
|
<Form {...formItemLayout}>
|
<Row gutter={24}>
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="用于组件间的区分。">
|
<Icon type="question-circle" />
|
组件名称
|
</Tooltip>
|
}>
|
{getFieldDecorator('name', {
|
initialValue: wrap.name,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '组件名称!'
|
}
|
]
|
})(<Input placeholder={''} autoComplete="off" onPressEnter={this.handleSubmit} />)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="栅格布局,每行等分为24列。">
|
<Icon type="question-circle" />
|
宽度
|
</Tooltip>
|
}>
|
{getFieldDecorator('width', {
|
initialValue: wrap.width || 24,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.input'] + '宽度!'
|
}
|
]
|
})(<InputNumber min={1} max={24} precision={0} onPressEnter={this.handleSubmit} />)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="选择静态值,无需配置数据源。">
|
<Icon type="question-circle" />
|
数据来源
|
</Tooltip>
|
}>
|
{getFieldDecorator('datatype', {
|
initialValue: wrap.datatype || 'dynamic'
|
})(
|
<Radio.Group>
|
<Radio value="dynamic">动态</Radio>
|
<Radio value="static">静态</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="组件与其他组件之间的控制类型,独立表示与其他没有关联。">
|
<Icon type="question-circle" />
|
受控类型
|
</Tooltip>
|
}>
|
{getFieldDecorator('linkType', {
|
initialValue: wrap.linkType || 'static'
|
})(
|
<Radio.Group onChange={(e) => this.setState({linkType: e.target.value})}>
|
<Radio value="static">独立</Radio>
|
<Radio value="sync">同步</Radio>
|
<Radio value="sup">上级</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{linkType === 'sup' ? <Col span={12}>
|
<Form.Item label="上级组件">
|
{getFieldDecorator('supModule', {
|
initialValue: wrap.supModule,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + '上级组件!'
|
}
|
]
|
})(
|
<Cascader options={supmodules} expandTrigger="hover" placeholder="" />
|
)}
|
</Form.Item>
|
</Col> : null}
|
{linkType === 'sync' ? <Col span={12}>
|
<Form.Item label="同步组件">
|
{getFieldDecorator('syncModule', {
|
initialValue: wrap.syncModule,
|
rules: [
|
{
|
required: true,
|
message: this.props.dict['form.required.select'] + '同步组件!'
|
}
|
]
|
})(
|
<Cascader options={modules} expandTrigger="hover" placeholder="" />
|
)}
|
</Form.Item>
|
</Col> : null}
|
{linkType === 'sync' ? <Col span={12}>
|
<Form.Item label="全选">
|
{getFieldDecorator('checkAll', {
|
initialValue: wrap.checkAll || 'hidden'
|
})(
|
<Radio.Group>
|
<Radio key="hidden" value="hidden"> 隐藏 </Radio>
|
<Radio key="show" value="show"> 显示 </Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={12}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="使用固定定位时,请在测试环境中查看定位效果。">
|
<Icon type="question-circle" />
|
位置
|
</Tooltip>
|
}>
|
{getFieldDecorator('position', {
|
initialValue: wrap.position || 'relative'
|
})(
|
<Radio.Group onChange={(e) => this.setState({position: e.target.value})}>
|
<Radio value="relative">相对定位</Radio>
|
<Radio value="fixed">固定定位</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="距上">
|
{getFieldDecorator('top', {
|
initialValue: wrap.top || ''
|
})(<StyleInput options={['px', 'vh', 'vw', '%']} />)}
|
</Form.Item>
|
</Col> : null}
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="距右">
|
{getFieldDecorator('right', {
|
initialValue: wrap.right || ''
|
})(<StyleInput options={['px', 'vh', 'vw', '%']} />)}
|
</Form.Item>
|
</Col> : null}
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="距下">
|
{getFieldDecorator('bottom', {
|
initialValue: wrap.bottom || ''
|
})(<StyleInput options={['px', 'vh', 'vw', '%']} />)}
|
</Form.Item>
|
</Col> : null}
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="距左">
|
{getFieldDecorator('left', {
|
initialValue: wrap.left || ''
|
})(<StyleInput options={['px', 'vh', 'vw', '%']} />)}
|
</Form.Item>
|
</Col> : null}
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="实际宽度">
|
{getFieldDecorator('realwidth', {
|
initialValue: wrap.realwidth || ''
|
})(<StyleInput options={['px', 'vh', 'vw', '%']} />)}
|
</Form.Item>
|
</Col> : null}
|
{position === 'fixed' ? <Col span={12}>
|
<Form.Item label="变换">
|
{getFieldDecorator('transform', {
|
initialValue: wrap.transform || ''
|
})(
|
<Select>
|
<Select.Option key='1' value={''}>无</Select.Option>
|
<Select.Option key='2' value={'translateY(-50%)'}>上移50%</Select.Option>
|
<Select.Option key='3' value={'translateY(50%)'}>下移50%</Select.Option>
|
<Select.Option key='5' value={'translateX(-50%)'}>左移50%</Select.Option>
|
<Select.Option key='4' value={'translateX(50%)'}>右移50%</Select.Option>
|
</Select>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={12}>
|
<Form.Item label="黑名单">
|
{getFieldDecorator('blacklist', {
|
initialValue: wrap.blacklist || []
|
})(
|
<Select
|
showSearch
|
mode="multiple"
|
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
>
|
{roleList.map(option =>
|
<Select.Option key={option.uuid} value={option.value}>{option.text}</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
</Row>
|
</Form>
|
</div>
|
)
|
}
|
}
|
|
export default Form.create()(SettingForm)
|