import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Button, Modal, notification } from 'antd'
|
import moment from 'moment'
|
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
import Utils from '@/utils/utils.js'
|
import MenuUtils from '@/utils/utils-custom.js'
|
import SettingForm from './settingform'
|
import Api from '@/api'
|
import './index.scss'
|
|
class CreateView extends Component {
|
static propTpyes = {
|
resetmenu: PropTypes.func
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
visible: false,
|
loading: false
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
verifySubmit = () => {
|
this.verifyRef.handleConfirm().then(res => {
|
|
|
let parMenuId = sessionStorage.getItem('kei_no') + sessionStorage.getItem('typename') + sessionStorage.getItem('lang')
|
let menuId = Utils.getuuid()
|
|
if (res.MenuId) {
|
let appMenus = sessionStorage.getItem('appMenus')
|
if (appMenus) {
|
try {
|
appMenus = JSON.parse(appMenus)
|
} catch (e) {
|
appMenus = []
|
}
|
} else {
|
appMenus = []
|
}
|
if (appMenus.findIndex(item => item.MenuID === res.MenuId) > -1) {
|
notification.warning({
|
top: 92,
|
message: '当前菜单已存在!',
|
duration: 5
|
})
|
return
|
}
|
menuId = res.MenuId
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
let config = {
|
version: 1.0,
|
uuid: menuId,
|
MenuID: menuId,
|
Template: 'webPage',
|
enabled: false,
|
MenuName: res.MenuName || '',
|
MenuNo: res.MenuNo || '',
|
tables: [],
|
components: [],
|
viewType: 'menu',
|
statusBarbgColor: sessionStorage.getItem('sysBgColor') || '#ffffff',
|
style: {
|
backgroundColor: sessionStorage.getItem('sysBgColor') || '#ffffff'
|
}
|
}
|
|
let param = {
|
func: 'sPC_TrdMenu_AddUpt',
|
FstID: parMenuId,
|
SndID: parMenuId,
|
ParentID: parMenuId,
|
MenuID: menuId,
|
MenuNo: res.MenuNo || '',
|
EasyCode: '',
|
Template: 'webPage',
|
TypeCharOne: sessionStorage.getItem('kei_no'),
|
Typename: sessionStorage.getItem('typename'),
|
MenuName: res.MenuName || '',
|
PageParam: JSON.stringify({Template: 'webPage'}),
|
open_edition: '',
|
LText: '',
|
LTexttb: ''
|
}
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt('', param.timestamp)
|
|
if (!res.copymenuId) {
|
param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
} else {
|
notification.success({
|
top: 92,
|
message: '创建成功',
|
duration: 5
|
})
|
}
|
|
this.setState({
|
visible: false,
|
loading: false
|
})
|
|
this.props.resetmenu()
|
})
|
} else {
|
Api.getSystemConfig({
|
func: 'sPC_Get_LongParam',
|
TypeCharOne: sessionStorage.getItem('kei_no'),
|
typename: sessionStorage.getItem('typename') || 'pc',
|
MenuID: res.copymenuId
|
}).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
let _config = null
|
try {
|
_config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
_config = null
|
}
|
|
if (!_config) {
|
notification.warning({
|
top: 92,
|
message: '未获取到配置信息!',
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
if (_config.components) {
|
config.components = MenuUtils.resetConfig(_config.components)
|
config.tables = _config.tables || []
|
config.style = _config.style || {}
|
config.statusBarbgColor = _config.statusBarbgColor || ''
|
}
|
|
param.LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(config)))
|
|
Api.getSystemConfig(param).then(result => {
|
if (!result.status) {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
} else {
|
notification.success({
|
top: 92,
|
message: '创建成功',
|
duration: 5
|
})
|
}
|
|
this.setState({
|
visible: false,
|
loading: false
|
})
|
|
this.props.resetmenu()
|
})
|
})
|
}
|
})
|
}
|
|
render () {
|
const { config } = this.props
|
const { visible, dict, loading } = this.state
|
|
return (
|
<div className="create-view">
|
<Button icon="plus" className="mk-border-green" onClick={() => {this.setState({visible: true, loading: false})}}>新建页面</Button>
|
<Modal
|
title="新建页面"
|
visible={visible}
|
width={500}
|
maskClosable={false}
|
okText={dict['model.submit']}
|
onOk={this.verifySubmit}
|
onCancel={() => { this.setState({ visible: false }) }}
|
confirmLoading={loading}
|
destroyOnClose
|
>
|
<SettingForm
|
dict={dict}
|
config={config}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default CreateView
|