import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { connect } from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
import { notification, Spin, Row, Col } from 'antd'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
import zhCN from '@/locales/zh-CN/main.js'
|
import enUS from '@/locales/en-US/main.js'
|
import Utils from '@/utils/utils.js'
|
import UtilsDM, { getStructuredParams, getStructDefaultParam } from '@/utils/utils-datamanage.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import MKEmitter from '@/utils/events.js'
|
import NotFount from '@/components/404'
|
import './index.scss'
|
|
// 通用组件
|
const AntvBarAndLine = asyncComponent(() => import('./components/chart/antv-bar-line'))
|
const AntvPie = asyncComponent(() => import('./components/chart/antv-pie'))
|
const AntvTabs = asyncComponent(() => import('./components/tabs/antv-tabs'))
|
const AntvDashboard = asyncComponent(() => import('./components/chart/antv-dashboard'))
|
const AntvScatter = asyncComponent(() => import('./components/chart/antv-scatter'))
|
const DataCard = asyncComponent(() => import('./components/card/data-card'))
|
const PropCard = asyncComponent(() => import('./components/card/prop-card'))
|
const NormalForm = asyncComponent(() => import('./components/form/normal-form'))
|
const CarouselDataCard = asyncComponent(() => import('./components/carousel/data-card'))
|
const CarouselPropCard = asyncComponent(() => import('./components/carousel/prop-card'))
|
const TableCard = asyncComponent(() => import('./components/card/table-card'))
|
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
|
const NormalTable = asyncComponent(() => import('./components/table/normal-table'))
|
const NormalGroup = asyncComponent(() => import('./components/group/normal-group'))
|
const BraftEditor = asyncComponent(() => import('./components/editor/braft-editor'))
|
const SandBox = asyncComponent(() => import('./components/code/sand-box'))
|
const NormalTree = asyncComponent(() => import('./components/tree/antd-tree'))
|
const Balcony = asyncComponent(() => import('./components/card/balcony'))
|
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
|
const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
|
|
class CustomPage extends Component {
|
static propTpyes = {
|
param: PropTypes.any, // 其他页面传递的参数
|
Tab: PropTypes.string, // 弹窗标签
|
MenuID: PropTypes.string, // 菜单Id
|
MenuNo: PropTypes.string, // 菜单参数
|
MenuName: PropTypes.string // 菜单名称
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
ContainerId: Utils.getuuid(), // 菜单外层html Id
|
BID: '', // 页面跳转时携带ID
|
loadingview: true, // 页面加载中
|
viewlost: false, // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
|
lostmsg: '', // 页面丢失时的提示信息
|
config: null, // 页面配置信息,包括组件等
|
mainSearch: null, // 主搜索
|
userConfig: null, // 用户自定义设置
|
data: null, // 列表数据集
|
loading: false, // 列表数据加载中
|
visible: false, // 标签页控制
|
treevisible: false, // 菜单结构树弹框显示隐藏控制
|
shortcuts: null // 快捷键
|
}
|
|
/**
|
* @description 获取页面配置信息
|
*/
|
async loadconfig () {
|
const { permAction, permMenus, param } = this.props
|
|
let _param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: this.props.MenuID
|
}
|
let result = await Api.getCacheConfig(_param)
|
|
if (result.status) {
|
let config = ''
|
let shortcuts = []
|
|
try { // 配置信息解析
|
config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
config = ''
|
}
|
|
// HS不使用自定义设置
|
if (result.LongParamUser && this.props.menuType !== 'HS') {
|
try { // 配置信息解析
|
let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
|
if (userConfig) {
|
shortcuts = userConfig.action
|
userConfig.printers.forEach(item => {
|
window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
|
})
|
}
|
} catch (e) {
|
console.warn('Parse Failure')
|
}
|
}
|
|
// 页面配置解析错误时提示
|
if (!config) {
|
this.setState({
|
viewlost: true,
|
loadingview: false
|
})
|
return
|
}
|
|
// 页面未启用时,显示未启用页面
|
if (!config.enabled) {
|
this.setState({
|
viewlost: true,
|
loadingview: false,
|
lostmsg: this.state.dict['main.view.unenabled']
|
})
|
return
|
}
|
|
// 数据缓存设置
|
if (config.cacheUseful === 'true') {
|
if (!['day', 'hour'].includes(config.timeUnit)) {
|
config.timeUnit = 'day'
|
}
|
config.cacheTime = config.cacheTime || 1
|
}
|
|
// 权限过滤
|
let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
|
config.components = this.filterComponent(config.components, roleId, permAction, permMenus)
|
|
// 获取主搜索条件
|
let mainSearch = []
|
config.components.forEach(component => {
|
if (component.type !== 'search') return
|
|
component.search = component.search.map(item => {
|
item.oriInitval = item.initval
|
if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
|
item.initval = param.$searchval
|
}
|
|
return item
|
})
|
|
mainSearch = Utils.initMainSearch(component.search)
|
})
|
|
let params = []
|
let BID = param && param.$BID ? param.$BID : ''
|
let inherit = {}
|
|
if (config.cacheUseful === 'true') { // 缓存继承
|
inherit.cacheUseful = config.cacheUseful
|
inherit.timeUnit = config.timeUnit
|
inherit.cacheTime = config.cacheTime
|
}
|
|
let userName = sessionStorage.getItem('User_Name') || ''
|
let fullName = sessionStorage.getItem('Full_Name') || ''
|
let city = sessionStorage.getItem('city') || ''
|
|
if (sessionStorage.getItem('isEditState') === 'true') {
|
userName = sessionStorage.getItem('CloudUserName') || ''
|
fullName = sessionStorage.getItem('CloudFullName') || ''
|
}
|
|
let regs = [
|
{ reg: /@userName@/ig, value: `'${userName}'` },
|
{ reg: /@fullName@/ig, value: `'${fullName}'` },
|
{ reg: /@login_city@/ig, value: `'${city}'` }
|
]
|
|
if (window.GLOB.externalDatabase !== null) {
|
regs.push({
|
reg: /@db@/ig,
|
value: window.GLOB.externalDatabase
|
})
|
}
|
if (config.urlFields) {
|
config.urlFields.forEach(field => {
|
let val = `'${param ? (param[field] || '') : ''}'`
|
regs.push({
|
reg: new RegExp('@' + field + '@', 'ig'),
|
value: val
|
})
|
})
|
}
|
|
config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs)
|
|
this.setState({
|
BID: BID,
|
shortcuts,
|
config,
|
mainSearch
|
}, () => {
|
if (!params || params.length === 0) {
|
setTimeout(() => { // 延时加载状态
|
this.setState({
|
loadingview: false
|
})
|
}, 1000)
|
} else {
|
this.loadmaindata(params)
|
}
|
|
if (!this.props.Tab) {
|
this.setShortcut()
|
}
|
|
this.loadData()
|
})
|
} else {
|
this.setState({
|
loadingview: false,
|
viewlost: true
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
}
|
|
setShortcut = () => {
|
const { shortcuts } = this.state
|
|
if (!shortcuts || shortcuts.length === 0) {
|
document.onkeydown = () => {}
|
return
|
}
|
|
document.onkeydown = (event) => {
|
let e = event || window.event
|
let keyCode = e.keyCode || e.which || e.charCode
|
let preKey = ''
|
|
if (e.ctrlKey) {
|
preKey = 'ctrl'
|
} else if (e.shiftKey) {
|
preKey = 'shift'
|
} else if (e.altKey) {
|
preKey = 'alt'
|
}
|
|
if (!preKey || !keyCode) return
|
|
let _shortcut = `${preKey}+${keyCode}`
|
|
shortcuts.some(item => {
|
if (item.$shortcut === _shortcut) {
|
MKEmitter.emit('triggerBtnId', item.uuid)
|
return true
|
}
|
return false
|
})
|
}
|
}
|
|
loadData = () => {
|
const { config } = this.state
|
|
if (!config.interfaces || config.interfaces.length === 0) return
|
|
let inters = []
|
|
config.interfaces.forEach(item => {
|
if (item.status !== 'true') return
|
|
if (window.GLOB.systemType === 'production' && !item.proInterface) {
|
notification.warning({
|
top: 92,
|
message: `《${item.name}》未设置正式系统地址!`,
|
duration: 3
|
})
|
return
|
}
|
|
inters.push(item)
|
})
|
|
if (inters.length > 0) {
|
this.loadOutResource(inters)
|
}
|
}
|
|
loadOutResource = (inters) => {
|
let setting = inters.shift()
|
let param = UtilsDM.getPrevQueryParams(setting, [], this.state.BID, this.props.menuType)
|
|
Api.genericInterface(param).then(res => {
|
if (res.status) {
|
if (res.mk_ex_invoke === 'false' || res.mk_ex_invoke === false) {
|
if (inters.length > 0) {
|
this.loadOutResource(inters)
|
}
|
} else {
|
this.customOuterRequest(res, setting, inters)
|
}
|
} else {
|
notification.error({
|
top: 92,
|
message: res.message,
|
duration: 10
|
})
|
}
|
})
|
}
|
|
customOuterRequest = (result, setting, inters) => {
|
let url = ''
|
|
if (window.GLOB.systemType === 'production') {
|
url = setting.proInterface
|
} else {
|
url = setting.interface
|
}
|
|
let mkey = result.mk_api_key || ''
|
|
delete result.mk_ex_invoke
|
delete result.status
|
delete result.message
|
delete result.ErrCode
|
delete result.ErrMesg
|
delete result.mk_api_key
|
|
let param = {}
|
|
Object.keys(result).forEach(key => {
|
key = key.replace(/^mk_/ig, '')
|
param[key] = result[key]
|
})
|
|
Api.directRequest(url, setting.method, param, setting.cross).then(res => {
|
if (typeof(res) !== 'object') {
|
let error = '未知的返回结果!'
|
|
if (typeof(res) === 'string') {
|
error = res.replace(/'/ig, '"')
|
}
|
|
let _result = {
|
mk_api_key: mkey,
|
$ErrCode: 'E',
|
$ErrMesg: error
|
}
|
|
this.customCallbackRequest(_result, setting, inters)
|
} else {
|
if (Array.isArray(res)) {
|
res = { data: res }
|
}
|
res.mk_api_key = mkey
|
this.customCallbackRequest(res, setting, inters)
|
}
|
}, (e) => {
|
let _result = {
|
mk_api_key: mkey,
|
$ErrCode: 'E',
|
$ErrMesg: e && e.statusText ? e.statusText : ''
|
}
|
|
this.customCallbackRequest(_result, setting, inters)
|
})
|
}
|
|
customCallbackRequest = (result, setting, inters) => {
|
let errSql = ''
|
if (result.$ErrCode === 'E') {
|
errSql = `
|
set @ErrorCode='E'
|
set @retmsg='${result.$ErrMesg}'
|
`
|
delete result.$ErrCode
|
delete result.$ErrMesg
|
}
|
|
let lines = UtilsDM.getCallBackSql(setting, result)
|
let param = {}
|
|
if (setting.callbackType === 'script') { // 使用自定义脚本
|
let sql = lines.map(item => (`
|
${item.insert}
|
${item.selects.join(` union all
|
`)}
|
`))
|
sql = sql.join('')
|
|
param = UtilsDM.getCallBackQueryParams(setting, sql, errSql)
|
|
if (this.state.BID) {
|
param.BID = this.state.BID
|
}
|
|
if (this.props.menuType === 'HS') { // 函数 sPC_TableData_InUpDe 云端验证
|
param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
|
}
|
} else {
|
param.func = 's_ex_result_back'
|
param.s_ex_result = lines.map((item, index) => ({
|
MenuID: this.props.MenuID || '',
|
MenuName: this.props.MenuName || '',
|
TableName: item.table,
|
LongText: window.btoa(window.encodeURIComponent(`${item.insert} ${item.selects.join(` union all `)}`)),
|
Sort: index + 1
|
}))
|
|
if ((window.GLOB.systemType !== 'production' && options.sysType !== 'cloud') || window.debugger === true) {
|
let sql = lines.map(item => (`
|
${item.insert}
|
${item.selects.join(` union all
|
`)}
|
`))
|
sql = sql.join('')
|
console.info(sql.replace(/\n\s{10}/ig, '\n'))
|
}
|
}
|
|
Api.genericInterface(param).then(res => {
|
if (res.status) {
|
if (inters.length > 0) {
|
this.loadOutResource(inters)
|
}
|
} else {
|
notification.error({
|
top: 92,
|
message: res.message,
|
duration: 10
|
})
|
}
|
})
|
}
|
|
filterComponent = (components, roleId, permAction, permMenus) => {
|
return components.filter(item => {
|
if (item.type === 'tabs') {
|
if (
|
item.setting.blacklist && item.setting.blacklist.length > 0 &&
|
item.setting.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
|
) {
|
return false
|
}
|
|
item.subtabs = item.subtabs.filter(tab => {
|
if (
|
tab.blacklist && tab.blacklist.length > 0 &&
|
tab.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
|
) {
|
return false
|
}
|
return true
|
})
|
|
item.subtabs = item.subtabs.map(tab => {
|
tab.components = this.filterComponent(tab.components, roleId, permAction, permMenus)
|
return tab
|
})
|
|
let supIds = []
|
item.subtabs.forEach(tab => {
|
tab.components.forEach(comp => {
|
if (comp.type === 'tabs' && comp.parentIds) {
|
supIds.push(...comp.parentIds)
|
} else if (comp.setting && comp.setting.supModule) {
|
supIds.push(comp.setting.supModule)
|
}
|
})
|
})
|
item.parentIds = supIds
|
} else if (item.type === 'group') {
|
if (
|
item.setting.blacklist && item.setting.blacklist.length > 0 &&
|
item.setting.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
|
) {
|
return false
|
}
|
|
item.components = this.filterComponent(item.components, roleId, permAction, permMenus)
|
} else if (['pie', 'bar', 'line', 'dashboard', 'scatter'].includes(item.type)) {
|
if (
|
item.plot.blacklist && item.plot.blacklist.length > 0 &&
|
item.plot.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
|
) {
|
return false
|
}
|
} else if (item.wrap) {
|
if (
|
item.wrap.blacklist && item.wrap.blacklist.length > 0 &&
|
item.wrap.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0
|
) {
|
return false
|
}
|
}
|
|
// 搜索条件初始化
|
if (item.search && item.search.length > 0) {
|
item.search = Utils.initSearchVal(item.search)
|
}
|
|
if (item.type === 'table' && item.subtype === 'normaltable') {
|
let statFields = []
|
let getCols = (cols) => {
|
return cols.filter(col => {
|
if (col.blacklist && col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
|
return false
|
} else if (col.Hide === 'true') {
|
return false
|
}
|
if (col.type === 'number' && col.sum === 'true' && !statFields.includes(col.field)) {
|
statFields.push(col)
|
} else if (col.type === 'colspan') {
|
col.subcols = getCols(col.subcols || [])
|
if (col.subcols.length === 0) {
|
return false
|
}
|
} else if (col.type === 'custom') {
|
col.elements = col.elements.map(cell => {
|
if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height) {
|
cell.innerHeight = 'auto'
|
}
|
return cell
|
})
|
}
|
|
if (col.linkmenu && col.linkmenu.length > 0) {
|
let menu_id = col.linkmenu.pop()
|
col.linkThdMenu = permMenus.filter(m => m.MenuID === menu_id)[0] || ''
|
} else {
|
col.linkThdMenu = ''
|
}
|
|
return true
|
})
|
}
|
|
item.cols = getCols(item.cols)
|
item.statFields = statFields
|
}
|
|
// 权限过滤
|
let isHS = this.props.menuType === 'HS'
|
let tabId = this.props.Tab ? this.props.Tab.uuid : '' // 弹窗标签按钮Id
|
if (item.action && item.action.length > 0) {
|
item.action = item.action.filter(cell => {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
|
if (cell.btnstyle) { // 兼容
|
cell.style = cell.style || {}
|
cell.style = {...cell.style, ...cell.btnstyle}
|
}
|
|
return isHS || permAction[cell.uuid]
|
})
|
}
|
|
if (item.type === 'card') {
|
item.subcards && item.subcards.forEach(card => {
|
let _hasheight = card.style.height && card.style.height !== 'auto'
|
|
if (card.style.shadow) { // 卡片阴影
|
card.style.boxShadow = '0 0 4px ' + card.style.shadow
|
delete card.style.shadow
|
}
|
|
card.elements = card.elements.filter(cell => {
|
if (cell.eleType === 'button') {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.Ot = 'requiredSgl'
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
if (card.btnstyle) { // 兼容
|
card.style = card.style || {}
|
card.style = {...card.style, ...card.btnstyle}
|
}
|
} else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
|
cell.innerHeight = 'auto'
|
}
|
|
return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
|
})
|
card.backElements = card.backElements.filter(cell => {
|
if (cell.eleType === 'button') {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.Ot = 'requiredSgl'
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
if (card.btnstyle) { // 兼容
|
card.style = card.style || {}
|
card.style = {...card.style, ...card.btnstyle}
|
}
|
} else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
|
cell.innerHeight = 'auto'
|
}
|
return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
|
})
|
})
|
} else if (item.type === 'balcony') {
|
item.elements = item.elements.filter(cell => {
|
if (cell.eleType === 'button') {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
} else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height) {
|
cell.innerHeight = 'auto'
|
}
|
|
return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
|
})
|
} else if ((item.type === 'table' && item.subtype === 'tablecard') || item.type === 'carousel') {
|
item.subcards && item.subcards.forEach(card => {
|
let _hasheight = card.style.height && card.style.height !== 'auto'
|
card.elements = card.elements.filter(cell => {
|
if (cell.eleType === 'button') {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.Ot = 'requiredSgl'
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
|
if (card.btnstyle) { // 兼容
|
card.style = card.style || {}
|
card.style = {...card.style, ...card.btnstyle}
|
}
|
} else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
|
cell.innerHeight = 'auto'
|
}
|
return cell.eleType !== 'button' || isHS || permAction[cell.uuid]
|
})
|
})
|
} else if (item.type === 'table' && item.subtype === 'normaltable') {
|
item.cols = item.cols.filter(col => {
|
if (col.type !== 'action') return true
|
col.elements = col.elements.filter(cell => {
|
cell.logLabel = item.name + '-' + cell.label
|
cell.Ot = 'requiredSgl'
|
cell.ContainerId = this.state.ContainerId
|
cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
|
cell.$menuId = item.uuid
|
cell.$tabId = tabId
|
cell.$view = 'CustomPage'
|
|
if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
|
cell = this.getPrinter(cell, item.uuid)
|
}
|
|
if (cell.btnstyle) { // 兼容
|
cell.style = cell.style || {}
|
cell.style = {...cell.style, ...cell.btnstyle}
|
}
|
|
return isHS || permAction[cell.uuid]
|
})
|
return col.elements.length !== 0
|
})
|
}
|
|
if (item.setting && item.setting.supModule) {
|
let pid = item.setting.supModule.pop()
|
if (pid && pid !== 'empty') {
|
item.setting.supModule = pid
|
} else {
|
item.setting.supModule = ''
|
}
|
}
|
if (item.wrap && item.wrap.doubleClick) {
|
let index = item.action.findIndex((btn) => btn.uuid === item.wrap.doubleClick)
|
if (index === -1) {
|
item.wrap.doubleClick = ''
|
}
|
}
|
|
return true
|
})
|
}
|
|
getPrinter = (item, parentId) => {
|
let _item = window.GLOB.UserCacheMap.get(parentId + item.uuid)
|
|
if (_item) {
|
item.printer = _item.printer || ''
|
item.verify.defaultPrinter = _item.printer || ''
|
if (item.verify.printerTypeList && _item.printerList) {
|
item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
|
cell.printer = _item.printerList[cell.Value] || ''
|
|
return cell
|
})
|
}
|
}
|
|
return item
|
}
|
|
// 格式化默认设置
|
formatSetting = (components, params, mainSearch, inherit, regs) => {
|
return components.map(component => {
|
if (component.type === 'tabs') {
|
component.subtabs = component.subtabs.map(tab => {
|
tab.components = this.formatSetting(tab.components, [], [], inherit, regs)
|
tab = {...tab, ...inherit}
|
return tab
|
})
|
return component
|
} else if (component.type === 'group') {
|
component.components = this.formatSetting(component.components, [], [], inherit, regs)
|
component = {...component, ...inherit}
|
return component
|
}
|
|
if (component.setting) {
|
component.setting.useMSearch = component.setting.useMSearch === 'true'
|
component.setting.syncRefresh = (component.setting.useMSearch && component.setting.syncRefresh === 'true')
|
}
|
|
if (component.wrap && component.wrap.datatype === 'static') {
|
component.format = ''
|
component.setting = component.setting || {}
|
component.setting.useMSearch = false
|
component.setting.syncRefresh = false
|
}
|
|
if (!component.setting || !component.format) return component // 1、不使用系统函数时;2、 没有动态数据 数据格式 array 或 object
|
if (component.setting.interType !== 'system') { // 不使用系统函数时
|
component.setting.sync = 'false'
|
component.setting.laypage = component.setting.laypage === 'true'
|
return component
|
}
|
|
let _customScript = ''
|
component.scripts && component.scripts.forEach(script => {
|
if (script.status !== 'false') {
|
_customScript += `
|
${script.sql}
|
`
|
}
|
})
|
delete component.scripts
|
component.setting.$name = component.name || ''
|
component.setting.execute = component.setting.execute !== 'false' // 默认sql是否执行,转为boolean 统一格式
|
component.setting.laypage = component.setting.laypage === 'true' // 是否分页,转为boolean 统一格式
|
|
if (!component.setting.execute) {
|
component.setting.dataresource = ''
|
}
|
if (/\s/.test(component.setting.dataresource)) {
|
component.setting.dataresource = '(' + component.setting.dataresource + ') tb'
|
}
|
|
if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
|
component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*')
|
component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/')
|
_customScript = _customScript.replace(/\$@/ig, '/*')
|
_customScript = _customScript.replace(/@\$/ig, '*/')
|
} else {
|
component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '')
|
_customScript = _customScript.replace(/@\$|\$@/ig, '')
|
}
|
|
regs.forEach(cell => {
|
component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value)
|
_customScript = _customScript.replace(cell.reg, cell.value)
|
})
|
|
component.setting.customScript = _customScript // 整理后自定义脚本
|
|
// floor 组件的层级
|
// dataName 系统生成的数据源名称
|
// pageable 是否分页,组件属性,不分页的组件才可以统一查询
|
if (component.floor === 1 && component.dataName && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') {
|
let searchlist = []
|
if (component.search && component.search.length > 0) {
|
searchlist = Utils.initMainSearch(component.search)
|
}
|
if (component.setting.useMSearch) {
|
let keys = searchlist.map(item => item.key)
|
mainSearch.forEach(item => {
|
if (!keys.includes(item.key)) {
|
searchlist.push(item)
|
}
|
})
|
}
|
|
if (searchlist.filter(item => item.required && item.value === '').length > 0) {
|
component.setting.sync = 'false'
|
component.setting.onload = 'false'
|
} else {
|
params.push(getStructDefaultParam(component, searchlist))
|
}
|
} else if (component.floor === 1) {
|
component.setting.sync = 'false'
|
}
|
|
return component
|
})
|
}
|
|
/**
|
* @description 主表数据加载
|
*/
|
loadmaindata = (params) => {
|
let param = getStructuredParams(params, this.state.config, this.state.BID)
|
|
this.setState({loading: true, loadingview: false})
|
|
Api.getLocalConfig(param).then(result => {
|
if (result.status) {
|
delete result.status
|
delete result.message
|
delete result.ErrMesg
|
delete result.ErrCode
|
|
this.setState({
|
data: result,
|
loading: false
|
})
|
} else {
|
this.setState({
|
data: '',
|
loading: false
|
})
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
})
|
}
|
|
reloadMenuView = (menuId) => {
|
const { MenuID } = this.props
|
|
if (MenuID !== menuId) return
|
|
this.reloadview()
|
}
|
|
resetActiveMenu = (menuId) => {
|
const { MenuID, Tab } = this.props
|
|
if (MenuID !== menuId || Tab) return
|
|
this.setShortcut()
|
}
|
|
UNSAFE_componentWillMount () {
|
// 组件加载时,获取菜单数据
|
this.loadconfig()
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
|
MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
|
MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
|
}
|
|
reloadview = () => {
|
this.setState({
|
BID: '', // 页面跳转时携带ID
|
loadingview: true, // 页面加载中
|
viewlost: false, // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
|
config: null, // 页面配置信息,包括组件等
|
loading: false, // 列表数据加载中
|
shortcuts: null
|
}, () => {
|
this.loadconfig()
|
})
|
}
|
|
resetSearch = (search) => {
|
this.setState({mainSearch: null}, () => {
|
this.setState({mainSearch: search})
|
})
|
}
|
|
getComponents = () => {
|
const { menuType } = this.props
|
const { config, BID, data, mainSearch } = this.state
|
|
if (!config || !config.components) return
|
|
return config.components.map(item => {
|
let _bid = BID
|
if (item.setting && item.setting.supModule) {
|
_bid = ''
|
}
|
|
if (item.type === 'bar' || item.type === 'line') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<AntvBarAndLine config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'pie') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<AntvPie config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'scatter') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<AntvScatter config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'dashboard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<AntvDashboard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'form') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<NormalForm config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'search') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<MainSearch config={item} BID={BID} menuType={menuType} refreshdata={this.resetSearch} />
|
</Col>
|
)
|
} else if (item.type === 'tabs') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<AntvTabs config={item} mainSearch={mainSearch} />
|
</Col>
|
)
|
} else if (item.type === 'card' && item.subtype === 'datacard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<DataCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'card' && item.subtype === 'propcard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<PropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'balcony') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<Balcony menu={config} config={item} data={data} BID={_bid} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'carousel' && item.subtype === 'datacard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<CarouselDataCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'carousel' && item.subtype === 'propcard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<CarouselPropCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'table' && item.subtype === 'tablecard') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<TableCard config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'table' && item.subtype === 'normaltable') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<NormalTable config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'group' && item.subtype === 'normalgroup') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<NormalGroup config={item} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'editor') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<BraftEditor config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'tree') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<NormalTree config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else if (item.type === 'code') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<SandBox config={item} data={data} BID={_bid} mainSearch={mainSearch} menuType={menuType} />
|
</Col>
|
)
|
} else {
|
return null
|
}
|
})
|
}
|
|
render() {
|
const { menuType } = this.props
|
const { loadingview, viewlost, config, loading, shortcuts } = this.state
|
|
return (
|
<div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}>
|
{(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
|
<Row>{this.getComponents()}</Row>
|
{menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
|
{menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
|
{viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
menuType: state.editLevel,
|
refreshTab: state.refreshTab,
|
permAction: state.permAction,
|
permMenus: state.permMenus
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(CustomPage)
|