import React, { Component } from 'react'
|
import { DndProvider } from 'react-dnd'
|
import { is, fromJS } from 'immutable'
|
import HTML5Backend from 'react-dnd-html5-backend'
|
import { ConfigProvider, notification, Collapse, Card, Switch, Button } from 'antd'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import zhCN from '@/locales/zh-CN/mob.js'
|
import enUS from '@/locales/en-US/mob.js'
|
import antdEnUS from 'antd/es/locale/en_US'
|
import antdZhCN from 'antd/es/locale/zh_CN'
|
import asyncComponent from '@/utils/asyncComponent'
|
|
import './index.scss'
|
|
const { Panel } = Collapse
|
const _locale = localStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS
|
|
const Header = asyncComponent(() => import('@/menu/header'))
|
const MenuForm = asyncComponent(() => import('@/menu/menuform'))
|
const SourceWrap = asyncComponent(() => import('@/menu/modelsource'))
|
const MenuShell = asyncComponent(() => import('@/menu/menushell'))
|
const BgController = asyncComponent(() => import('@/menu/bgcontroller'))
|
const PaddingController = asyncComponent(() => import('@/menu/padcontroller'))
|
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
|
const ModalController = asyncComponent(() => import('@/menu/modalconfig/controller'))
|
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
|
|
class BillPrint extends Component {
|
state = {
|
dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
BID: '',
|
tempId: '',
|
config: null,
|
}
|
|
UNSAFE_componentWillMount() {
|
try {
|
let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
|
|
this.setState({
|
BID: param.id,
|
tempId: param.tempId,
|
}, () => {
|
this.getMenuParam()
|
})
|
} catch {
|
notification.warning({
|
top: 92,
|
message: '菜单信息解析错误!',
|
duration: 5
|
})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
|
getMenuParam = () => {
|
const { tempId } = this.state
|
|
let param = {
|
func: 's_PrintTemplateMGetData',
|
Type: 'Y',
|
PrintTempNO: tempId
|
}
|
|
if (window.GLOB.mainSystemApi) { // 从单点登录服务器取打印配置信息
|
param.rduri = window.GLOB.mainSystemApi
|
}
|
|
Api.getLocalConfig(param).then(result => {
|
if (result.status) {
|
// let config = null
|
|
// try {
|
// config = JSON.parse(window.decodeURIComponent(window.atob(result.ConfigParam)))
|
// } catch (e) {
|
// console.warn('Parse Failure')
|
// config = null
|
// }
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
|
// Api.getSystemConfig(param).then(result => {
|
// if (result.status) {
|
// let config = null
|
|
// try {
|
// config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
|
// } catch (e) {
|
// console.warn('Parse Failure')
|
// config = null
|
// }
|
|
// if (!config) {
|
// config = {
|
// version: 1.0,
|
// uuid: MenuId,
|
// MenuID: MenuId,
|
// parentId: ParentId,
|
// Template: 'CustomPage',
|
// MenuType: MenuType,
|
// easyCode: '',
|
// enabled: false,
|
// MenuName: MenuName,
|
// MenuNo: MenuNo,
|
// tables: [],
|
// components: [],
|
// style: {
|
// backgroundColor: '#ffffff', backgroundImage: '',
|
// paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
|
// }
|
// }
|
// } else {
|
// config.uuid = MenuId
|
// config.MenuID = MenuId
|
// config.MenuType = config.MenuType || MenuType
|
// }
|
|
// if (MenuType === 'billPrint') {
|
// config.FstID = 'BillPrintTemp'
|
// config.SndID = 'BillPrintTemp'
|
// config.ParentID = 'BillPrintTemp'
|
// }
|
|
// this.setState({
|
// oriConfig: config,
|
// config: fromJS(config).toJS(),
|
// openEdition: result.open_edition || '',
|
// })
|
|
// this.getRoleFields()
|
// } else {
|
// notification.warning({
|
// top: 92,
|
// message: result.message,
|
// duration: 5
|
// })
|
// }
|
// })
|
}
|
|
getRoleFields = () => {
|
Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
|
if (res.status) {
|
let _permFuncField = []
|
let _sysRoles = []
|
|
if (res.Roles && res.Roles.length > 0) {
|
_sysRoles = res.Roles.map(role => {
|
return {
|
uuid: Utils.getuuid(),
|
value: role.RoleID,
|
text: role.RoleName
|
}
|
})
|
}
|
|
if (res.sModular && res.sModular.length > 0) {
|
res.sModular.forEach(field => {
|
if (field.ModularNo) {
|
_permFuncField.push(field.ModularNo)
|
}
|
})
|
_permFuncField = _permFuncField.sort()
|
}
|
|
let config = {...this.state.config, sysRoles: _sysRoles, permFuncField: _permFuncField}
|
|
this.setState({config})
|
}
|
})
|
}
|
|
initMenuList = (msg) => {
|
let config = {...this.state.config, ...msg}
|
|
this.setState({config})
|
}
|
|
onEnabledChange = () => {
|
const { config } = this.state
|
|
if (!config.enabled && this.verifyConfig(true)) {
|
return
|
}
|
|
this.setState({
|
config: {...config, enabled: !config.enabled}
|
})
|
}
|
|
verifyConfig = (show) => {
|
const { config } = this.state
|
let error = ''
|
|
if (!config.MenuID) {
|
notification.warning({
|
top: 92,
|
message: '请完善菜单基本信息!',
|
duration: 5
|
})
|
return
|
} else if (config.MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId)) {
|
notification.warning({
|
top: 92,
|
message: '请完善菜单基本信息!',
|
duration: 5
|
})
|
return
|
}
|
|
config.components.forEach(item => {
|
if (error) return
|
if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return
|
|
if (item.setting) {
|
if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) {
|
error = `组件《${item.name}》未设置数据源!`
|
} else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.length === 0) {
|
error = `组件《${item.name}》未设置数据源!`
|
} else if (item.setting.interType && !item.setting.primaryKey) {
|
error = `组件《${item.name}》未设置主键!`
|
}
|
}
|
if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') {
|
if (!item.plot.Xaxis) {
|
error = `组件《${item.name}》图表字段尚未设置!`
|
}
|
}
|
})
|
|
if (show && error) {
|
notification.warning({
|
top: 92,
|
message: error,
|
duration: 5
|
})
|
}
|
|
return error
|
}
|
|
// 更新配置信息
|
updateConfig = (config) => {
|
this.setState({
|
config: config
|
})
|
}
|
|
/**
|
* @description 更新常用表信息,快捷添加后更新配置信息
|
*/
|
updatetable = (config, fields) => {
|
const { tableFields } = this.state
|
|
config.tableFields = fields ? fields : tableFields
|
|
this.setState({
|
tableFields: fields ? fields : tableFields,
|
config
|
})
|
}
|
|
render () {
|
const { activeKey, MenuType, dict, MenuId, config, ParentId, MenuName, MenuNo, menuloading } = this.state
|
|
return (
|
<ConfigProvider locale={_locale}>
|
<div className="pc-menu-view" id="view">
|
<Header view="design" closeView={this.closeView} />
|
<DndProvider backend={HTML5Backend}>
|
<div className="menu-body">
|
<div className="menu-setting">
|
<Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
|
{/* 基本信息 */}
|
<Panel header={dict['mob.basemsg']} key="basedata">
|
{/* 菜单信息 */}
|
{config && MenuType === 'custom' ? <MenuForm
|
dict={dict}
|
config={config}
|
MenuId={MenuId}
|
parentId={ParentId}
|
MenuName={MenuName}
|
MenuNo={MenuNo}
|
initMenuList={this.initMenuList}
|
updateConfig={this.updateConfig}
|
/> : null}
|
{/* 表名添加 */}
|
{config ? <TableComponent config={config} updatetable={this.updatetable}/> : null}
|
</Panel>
|
{/* 组件添加 */}
|
<Panel header={dict['mob.component']} key="component">
|
<SourceWrap MenuType={MenuType} />
|
</Panel>
|
<Panel header={'背景'} key="background">
|
{config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
|
</Panel>
|
<Panel header={'内边距'} key="padding">
|
{config ? <PaddingController config={config} updateConfig={this.updateConfig} /> : null}
|
</Panel>
|
</Collapse>
|
</div>
|
<div className={'menu-view ' + (menuloading ? 'saving' : '')}>
|
<Card title={
|
<div> {config && config.MenuName} </div>
|
} bordered={false} extra={
|
<div>
|
{config ? <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config.enabled} onChange={this.onEnabledChange} /> : null}
|
<Button type="primary" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button>
|
</div>
|
} style={{ width: '100%' }}>
|
{config && config.components ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
|
</Card>
|
</div>
|
</div>
|
</DndProvider>
|
<StyleController />
|
<ModalController />
|
</div>
|
</ConfigProvider>
|
)
|
}
|
}
|
|
export default BillPrint
|