import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Tabs, notification, Spin, Icon } from 'antd'
|
|
// import Utils from '@/utils/utils.js'
|
import Api from '@/api'
|
|
import TabCard from './tabcard'
|
import './index.scss'
|
|
const { TabPane } = Tabs
|
|
class VerifyCard extends Component {
|
static propTpyes = {
|
MenuID: PropTypes.string,
|
MenuName: PropTypes.string,
|
permAction: PropTypes.object,
|
permRoles: PropTypes.array,
|
userConfig: PropTypes.object,
|
columns: PropTypes.array,
|
config: PropTypes.object, // 页面配置
|
handleParam: PropTypes.func // 配置信息变化
|
}
|
|
state = {
|
loading: true,
|
menuParam: null,
|
menuconfig: null
|
}
|
|
UNSAFE_componentWillMount () {
|
const { MenuID, MenuName, permAction, permRoles, config, userConfig, columns } = this.props
|
let menuParam = []
|
|
this.setState({
|
loadingview: true
|
})
|
|
|
menuParam.push({
|
uuid: MenuID,
|
type: 'main',
|
label: MenuName + '(主表)',
|
setting: {
|
actionfixed: config.setting.actionfixed,
|
columnfixed: config.setting.columnfixed,
|
tableType: config.setting.tableType
|
},
|
action: config.action.map(item => {
|
let _item = {
|
uuid: item.uuid,
|
label: item.label,
|
shortcut: item.shortcut || ''
|
}
|
|
if (item.OpenType === 'funcbutton' && item.funcType === 'print') {
|
_item.type = 'print'
|
_item.verify = item.verify
|
_item.printer = item.printer || ''
|
}
|
|
return _item
|
}),
|
columns: columns.map(item => {
|
return {
|
uuid: item.uuid,
|
label: item.label,
|
Width: item.Width,
|
hidden: item.hidden || false,
|
fixed: item.fixed || false,
|
sort: item.sort || 0
|
}
|
})
|
})
|
|
let deffers = []
|
config.tabgroups.forEach(groupId => {
|
config[groupId].forEach(tab => {
|
deffers.push(new Promise(resolve => {
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: tab.linkTab
|
}
|
Api.getSystemCacheConfig(param).then(res => {
|
res.tab = tab
|
resolve(res)
|
})
|
}))
|
})
|
})
|
|
if (deffers.length > 0) {
|
Promise.all(deffers).then(result => {
|
let errors = result.filter(res => !res.status)
|
if (errors.length > 0) {
|
notification.warning({
|
top: 92,
|
message: errors[0].message,
|
duration: 10
|
})
|
this.setState({
|
loading: false
|
})
|
return
|
}
|
|
result.forEach(res => {
|
if (!res.LongParam) return
|
|
let subconfig = ''
|
let subUserConfig = userConfig ? userConfig[res.tab.uuid] : ''
|
|
try {
|
subconfig = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
errors.push('子标签《' + res.tab.label + '》参数解析错误!')
|
}
|
|
if (!subconfig || !subconfig.enabled) return
|
|
let _columns = [] // 显示列
|
let _hideCol = [] // 隐藏及合并列中字段的uuid集
|
let colMap = new Map()
|
|
// 权限过滤
|
subconfig.action = subconfig.action.filter(item => permAction[item.uuid])
|
|
subconfig.columns = subconfig.columns.filter(col => {
|
if (!col.field || !col.blacklist || col.blacklist.length === 0 || subconfig.setting.primaryKey === col.field) return true
|
|
let _black = col.blacklist.filter(v => {
|
return permRoles.indexOf(v) !== -1
|
})
|
|
if (_black.length > 0) {
|
return false
|
} else {
|
return true
|
}
|
})
|
|
if (subUserConfig) {
|
subconfig.setting.tableType = subUserConfig.setting.tableType
|
|
subconfig.action = subconfig.action.map(item => {
|
if (subUserConfig.action[item.uuid]) {
|
item = {...item, ...subUserConfig.action[item.uuid]}
|
}
|
if (item.execMode) {
|
item.OpenType = 'funcbutton'
|
}
|
|
if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify && item.printer) {
|
item.verify.defaultPrinter = item.printer.defaultPrinter || ''
|
if (item.verify.printerTypeList && item.printer.printerList) {
|
item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
|
cell.printer = item.printer.printerList[cell.Value] || ''
|
|
return cell
|
})
|
}
|
}
|
|
return item
|
})
|
} else {
|
subconfig.action = subconfig.action.map(item => {
|
if (item.execMode) {
|
item.OpenType = 'funcbutton'
|
}
|
|
return item
|
})
|
}
|
|
// 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
|
subconfig.columns.forEach(col => {
|
if (col.type === 'colspan' && col.sublist) { // 筛选隐藏列
|
_hideCol = _hideCol.concat(col.sublist)
|
} else if (col.Hide === 'true') {
|
_hideCol.push(col.uuid)
|
}
|
colMap.set(col.uuid, col)
|
})
|
|
// 生成显示列,处理合并列中的字段
|
subconfig.columns.forEach(col => {
|
if (_hideCol.includes(col.uuid)) return
|
|
if (col.type === 'colspan' && col.sublist) {
|
let _col = JSON.parse(JSON.stringify(col))
|
let subColumn = []
|
_col.sublist.forEach(sub => {
|
if (colMap.has(sub)) {
|
subColumn.push(colMap.get(sub))
|
}
|
})
|
_col.subColumn = subColumn
|
_columns.push(_col)
|
} else {
|
_columns.push(col)
|
}
|
})
|
|
let _operations = subconfig.action.filter(item => item.position === 'grid')
|
|
if (subconfig.gridBtn && subconfig.gridBtn.display && _operations.length > 0) {
|
_columns.push({
|
...subconfig.gridBtn,
|
operations: _operations
|
})
|
}
|
|
// 添加用户显示列设置
|
if (subUserConfig) {
|
_columns = _columns.map(item => {
|
if (subUserConfig.columns[item.uuid]) {
|
item = {...item, ...subUserConfig.columns[item.uuid]}
|
}
|
|
return item
|
})
|
|
_columns.sort((pre, next) => {
|
return pre.sort - next.sort
|
})
|
}
|
|
menuParam.push({
|
uuid: res.tab.uuid,
|
linkTab: res.tab.linkTab,
|
label: res.tab.label,
|
setting: {tableType: subconfig.setting.tableType},
|
action: subconfig.action.map(item => {
|
let _item = {
|
uuid: item.uuid,
|
label: item.label,
|
shortcut: item.shortcut || ''
|
}
|
|
if (item.OpenType === 'funcbutton' && item.funcType === 'print') {
|
_item.type = 'print'
|
_item.verify = item.verify
|
_item.printer = item.printer || ''
|
}
|
|
return _item
|
}),
|
columns: _columns.map(item => {
|
return {
|
uuid: item.uuid,
|
label: item.label,
|
Width: item.Width,
|
hidden: item.hidden || false,
|
fixed: item.fixed || false,
|
sort: item.sort || 0
|
}
|
})
|
})
|
})
|
|
if (errors.length > 0) {
|
notification.warning({
|
top: 92,
|
message: errors[0],
|
duration: 10
|
})
|
return
|
}
|
|
this.setState({
|
loading: false,
|
menuParam: menuParam
|
}, () => {
|
this.getInitParam()
|
})
|
})
|
} else {
|
this.setState({
|
loading: false,
|
menuParam: menuParam
|
}, () => {
|
this.getInitParam()
|
})
|
}
|
}
|
|
getInitParam = () => {
|
let config = JSON.parse(JSON.stringify(this.state.menuParam))
|
|
let _config = {}
|
|
config.forEach(tab => {
|
let _tab = {
|
label: tab.label,
|
setting: tab.setting,
|
action: {},
|
columns: {}
|
}
|
|
tab.action.forEach(item => {
|
_tab.action[item.uuid] = {
|
printer: item.printer || '',
|
shortcut: item.shortcut
|
}
|
})
|
|
tab.columns.forEach((item, index) => {
|
_tab.columns[item.uuid] = {
|
Width: item.Width,
|
hidden: item.hidden,
|
sort: index
|
}
|
})
|
|
_config[tab.uuid] = _tab
|
})
|
|
this.setState({
|
menuconfig: _config
|
})
|
this.props.handleParam(_config)
|
}
|
|
changeconfig = (uuid, param) => {
|
let _menuconfig = JSON.parse(JSON.stringify(this.state.menuconfig))
|
|
_menuconfig[uuid] = param
|
|
this.setState({
|
menuconfig: _menuconfig
|
})
|
|
this.props.handleParam(_menuconfig)
|
}
|
|
render() {
|
const { menuParam, loading } = this.state
|
|
return (
|
<div id="verify-card-box-tab" className="verify-card-horizontal-box">
|
{loading ? <Spin size="large" /> : null}
|
{menuParam ? <Tabs defaultActiveKey={menuParam[0].uuid}>
|
{menuParam.map(tab => {
|
return (
|
<TabPane tab={tab.label} key={tab.uuid}>
|
<TabCard config={tab} handleconfig={this.changeconfig}/>
|
</TabPane>
|
)
|
})}
|
</Tabs> : null}
|
{!loading && !menuParam ? <div className="message-fail"><Icon type="exclamation-circle" />信息获取失败</div> : null}
|
</div>
|
)
|
}
|
}
|
|
export default Form.create()(VerifyCard)
|