import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import {connect} from 'react-redux'
|
import { is, fromJS } from 'immutable'
|
import { notification, Spin, Tabs, Icon, Switch, Modal, Button, message, Tree, Typography, Col } from 'antd'
|
import moment from 'moment'
|
|
import Api from '@/api'
|
import zhCN from '@/locales/zh-CN/main.js'
|
import enUS from '@/locales/en-US/main.js'
|
import Utils from '@/utils/utils.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import asyncSpinComponent from '@/utils/asyncSpinComponent'
|
import { refreshTabView } from '@/store/action'
|
|
import MainSearch from '@/tabviews/zshare/topSearch'
|
import NotFount from '@/components/404'
|
import './index.scss'
|
|
// 通用组件
|
const MainAction = asyncSpinComponent(() => import('@/tabviews/zshare/actionList'))
|
const MainTable = asyncSpinComponent(() => import('@/tabviews/zshare/normalTable'))
|
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
|
const SubTable = asyncSpinComponent(() => import('@/tabviews/subtable'))
|
const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
|
const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
|
|
// 自定义标签
|
const SecretKeyTable = asyncSpinComponent(() => import('./secretKeyTable'))
|
|
const { TabPane } = Tabs
|
const { TreeNode } = Tree
|
const { Paragraph } = Typography
|
|
class NormalTable extends Component {
|
static propTpyes = {
|
param: PropTypes.any, // 其他页面传递的搜索条件等参数
|
MenuID: PropTypes.string, // 菜单Id
|
MenuNo: PropTypes.string, // 菜单参数
|
MenuName: PropTypes.string // 菜单名称
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
ContainerId: Utils.getuuid(), // 菜单外层html Id
|
loadingview: true, // 页面加载中
|
viewlost: false, // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
|
lostmsg: '', // 页面丢失时的提示信息
|
config: {}, // 页面配置信息,包括按钮、搜索、显示列、标签等
|
userConfig: null, // 用户自定义设置
|
searchlist: null, // 搜索条件
|
actions: null, // 按钮集
|
columns: null, // 显示列
|
logcolumns: null, // 日志中显示的列信息 (增加至全部列,除去合并列)
|
arr_field: '', // 使用 sPC_Get_TableData 时的查询字段集
|
setting: null, // 页面全局设置:数据源、按钮及显示列固定、主键等
|
data: null, // 列表数据集
|
selectedData: [], // 已选表格数据
|
resetTable: false, // 表格重置,值在true与false之间切换,切换时表格重置
|
total: 0, // 总数
|
loading: false, // 列表数据加载中
|
pageIndex: 1, // 页码
|
pageSize: 10, // 每页数据条数
|
orderBy: '', // 排序
|
search: '', // 搜索条件数组,使用时需分场景处理
|
BIDs: {}, // 上级表id
|
pickup: false, // 主表数据隐藏显示切换
|
treevisible: false, // 菜单结构树弹框显示隐藏控制
|
refreshtabs: null, // 需要刷新的标签集
|
triggerBtn: null, // 点击表格中或快捷键触发的按钮
|
tabActive: null, // 标签页展开控制
|
chartId: '' // 展开图表ID
|
}
|
|
/**
|
* @description 获取页面配置信息
|
*/
|
async loadconfig () {
|
const { permAction, permMenus, param } = this.props
|
|
let _param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: this.props.MenuID
|
}
|
let result = await Api.getSystemCacheConfig(_param)
|
|
if (result.status) {
|
let config = ''
|
let userConfig = null
|
let _curUserConfig = ''
|
|
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 { // 配置信息解析
|
userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
|
_curUserConfig = userConfig[this.props.MenuID]
|
} catch (e) {
|
console.warn('Parse Failure')
|
userConfig = null
|
}
|
}
|
|
// 页面配置解析错误时提示
|
if (!config) {
|
this.setState({
|
loadingview: false,
|
viewlost: true
|
})
|
return
|
}
|
|
// 页面未启用时,显示未启用页面
|
if (!config.enabled) {
|
this.setState({
|
loadingview: false,
|
viewlost: true,
|
lostmsg: this.state.dict['main.view.unenabled']
|
})
|
return
|
}
|
|
if (!config.version || config.version < '1.0') {
|
// 兼容标签
|
if (!config.tabgroups) {
|
config.tabgroups = [{ uuid: 'tabs', sublist: [] }]
|
} else if (typeof(config.tabgroups[0]) === 'string') {
|
let _tabgroups = []
|
config.tabgroups.forEach(groupId => {
|
let _group = {
|
uuid: groupId,
|
sublist: fromJS(config[groupId]).toJS()
|
}
|
|
delete config[groupId]
|
|
_tabgroups.push(_group)
|
})
|
|
config.tabgroups = _tabgroups
|
}
|
|
// 兼容图表
|
if (!config.charts) {
|
config.expand = true
|
config.charts = [{ uuid: Utils.getuuid(), label: '', title: '', chartType: 'table', icon: 'table', Hide: 'false', blacklist: [] }]
|
} else {
|
config.charts.forEach(card => {
|
if (card.chartType === 'card') {
|
card.details = card.details.map(_cell => {
|
_cell.fontSize = _cell.fontSize || 14
|
if (!_cell.width) {
|
_cell.width = 100
|
} else if (_cell.width === 'helf') {
|
_cell.width = 50
|
} else if (_cell.width === 'third') {
|
_cell.width = 33
|
}
|
if (!_cell.fontWeight && _cell.bold === 'true') {
|
_cell.fontWeight = 'normal'
|
}
|
_cell.height = _cell.height || 1
|
|
return _cell
|
})
|
}
|
})
|
}
|
}
|
|
// 权限过滤
|
if (this.props.menuType !== 'HS') {
|
config.action = config.action.filter(item => permAction[item.uuid])
|
config.tabgroups.forEach(group => {
|
group.sublist = group.sublist.filter(tab => permAction[tab.linkTab])
|
})
|
}
|
// 去除空行标签
|
config.tabgroups = config.tabgroups.filter(group => group.sublist.length > 0)
|
|
// HS下自定义处理的标签
|
if (this.props.menuType === 'HS') {
|
config.tabgroups.forEach(group => {
|
group.sublist = group.sublist.map(tab => {
|
if (tab.linkTab === '1586577325055l2ng7t75g7i4ek2ng8o') {
|
tab.type = 'SecretKeyTable'
|
}
|
return tab
|
})
|
})
|
}
|
|
// 视图权限
|
config.charts = config.charts.filter(item => {
|
if (item.Hide === 'true') return false
|
if (!item.blacklist || item.blacklist.length === 0) return true
|
|
let _black = item.blacklist.filter(v => {
|
return this.props.permRoles.indexOf(v) !== -1
|
})
|
|
if (_black.length > 0 || item.Hide === 'true') {
|
return false
|
} else {
|
return true
|
}
|
})
|
|
if (config.charts.length <= 1) {
|
config.expand = true
|
}
|
let chartId = config.charts[0] ? config.charts[0].uuid : ''
|
|
// 字段权限黑名单
|
config.search = config.search.filter(item => {
|
if (!item.blacklist || item.blacklist.length === 0) return true
|
|
let _black = item.blacklist.filter(v => {
|
return this.props.permRoles.indexOf(v) !== -1
|
})
|
|
if (_black.length > 0) {
|
return false
|
} else {
|
return true
|
}
|
})
|
|
config.columns = config.columns.filter(col => {
|
if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return true
|
|
let _black = col.blacklist.filter(v => {
|
return this.props.permRoles.indexOf(v) !== -1
|
})
|
|
if (_black.length > 0) {
|
return false
|
} else {
|
return true
|
}
|
})
|
|
// 标记主页面,用于按钮固定及表单挂载设置
|
config.setting.tabType = 'main'
|
|
if (_curUserConfig) {
|
config.setting = {...config.setting, ..._curUserConfig.setting}
|
config.easyCode = _curUserConfig.easyCode || config.easyCode || ''
|
|
config.action = config.action.map(item => {
|
if (item.execMode) {
|
item.OpenType = 'funcbutton'
|
}
|
|
if (_curUserConfig.action[item.uuid]) {
|
delete _curUserConfig.action[item.uuid].label
|
item = {...item, ..._curUserConfig.action[item.uuid]}
|
}
|
|
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
|
})
|
}
|
|
let _tabActive = {} // 筛选展开的tab页
|
|
config.tabgroups.forEach(group => {
|
_tabActive[group.uuid] = group.sublist[0].uuid
|
})
|
|
let _arrField = [] // 字段集
|
let _columns = [] // 显示列
|
let _logcolumns = [] // 日志显示列
|
let _hideCol = [] // 隐藏及合并列中字段的uuid集
|
let colMap = new Map() // 用于字段过滤
|
|
let _actions = [] // 工具栏按钮
|
let _operations = [] // 操作列按钮(存在时)
|
|
config.action.forEach(item => {
|
if (item.execMode) {
|
item.OpenType = 'funcbutton'
|
}
|
|
if (item.position === 'toolbar') {
|
_actions.push(item)
|
} else if (item.position === 'grid') {
|
_operations.push(item)
|
}
|
})
|
|
// 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
|
config.columns.forEach(col => {
|
if (col.field) {
|
_arrField.push(col.field)
|
_logcolumns.push(col)
|
|
col.nameField && _arrField.push(col.nameField) // 链接名字段
|
}
|
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)
|
})
|
|
// 生成显示列,处理合并列中的字段
|
config.columns.forEach((col, index) => {
|
if (_hideCol.includes(col.uuid)) return
|
|
if (col.linkThdMenu && !permMenus[col.linkThdMenu.MenuID]) {
|
col.linkThdMenu = ''
|
}
|
|
col.sort = index
|
|
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)
|
}
|
})
|
|
if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
|
config.gridBtn.operations = _operations
|
_columns.push(config.gridBtn)
|
}
|
|
let valid = true // 搜索条件必填验证, 初始搜索条件, 如通过上级透视,写入搜索条件
|
let initSearch = config.search.map(item => {
|
let _item = JSON.parse(JSON.stringify(item))
|
if (_item.type === 'text' && param && param.searchkey === _item.field) {
|
_item.initval = param.searchval
|
}
|
|
if (_item.required === 'true' && !_item.initval) {
|
valid = false
|
}
|
return _item
|
})
|
|
if (_curUserConfig) {
|
_columns = _columns.map(item => {
|
if (_curUserConfig.columns[item.uuid]) {
|
delete _curUserConfig.columns[item.uuid].label
|
item = {...item, ..._curUserConfig.columns[item.uuid]}
|
}
|
|
return item
|
})
|
|
_columns.sort((pre, next) => {
|
return pre.sort - next.sort
|
})
|
}
|
|
this.setState({
|
loadingview: false,
|
chartId: chartId,
|
config: config,
|
tabActive: _tabActive,
|
userConfig: userConfig,
|
setting: config.setting,
|
searchlist: config.search,
|
actions: _actions,
|
columns: _columns,
|
logcolumns: _logcolumns,
|
arr_field: _arrField.join(','),
|
search: Utils.initMainSearch(initSearch) // 搜索条件初始化(含有时间格式,需要转化)
|
}, () => {
|
this.improveSearch()
|
if (config.setting.onload !== 'false' && valid) { // 初始化可加载
|
this.loadmaindata()
|
}
|
this.setShortcut()
|
})
|
} else {
|
this.setState({
|
loadingview: false,
|
viewlost: true
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
}
|
|
setShortcut = () => {
|
const { actions, userConfig, config } = this.state
|
if (!userConfig) 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) return
|
|
let istrigger = false
|
|
actions.forEach(item => {
|
if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return
|
|
if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
|
e.preventDefault()
|
istrigger = true
|
|
this.setState({
|
triggerBtn: {
|
uuid: new Date().getTime(),
|
parentId: this.props.MenuID,
|
button: item,
|
data: null
|
}
|
})
|
}
|
})
|
|
if (istrigger) return
|
|
Object.keys(userConfig).forEach(key => {
|
if (key === this.props.MenuID || !userConfig[key].action || istrigger) return
|
|
let _actions = userConfig[key].action
|
|
Object.keys(_actions).forEach(btnkey => {
|
let item = _actions[btnkey]
|
|
if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return
|
|
if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
|
e.preventDefault()
|
istrigger = true
|
|
let _groupId = ''
|
let _ActiveTabId = ''
|
config.tabgroups.forEach(group => {
|
if (group.sublist.length === 0) return
|
|
let _tab = group.sublist.filter(tab => tab.uuid === key)[0]
|
if (_tab) {
|
_groupId = group.uuid
|
_ActiveTabId = _tab.uuid
|
}
|
})
|
|
if (this.state.tabActive[_groupId] === _ActiveTabId) {
|
this.setState({
|
triggerBtn: {
|
uuid: new Date().getTime(),
|
parentId: key,
|
button: {...item, uuid: btnkey},
|
data: null
|
}
|
})
|
} else {
|
this.setState({
|
tabActive: {...this.state.tabActive, [_groupId]: _ActiveTabId}
|
}, () => {
|
this.setState({
|
triggerBtn: {
|
uuid: new Date().getTime(),
|
parentId: key,
|
button: {...item, uuid: btnkey},
|
data: null
|
}
|
})
|
})
|
}
|
}
|
})
|
})
|
}
|
}
|
|
/**
|
* @description 搜索条件下拉选项预加载
|
*/
|
improveSearch = () => {
|
let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
|
let deffers = []
|
searchlist.forEach(item => {
|
if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return
|
if (item.setAll === 'true') {
|
item.options.unshift({
|
key: Utils.getuuid(),
|
Value: '',
|
Text: this.state.dict['main.all']
|
})
|
}
|
|
if (item.resourceType === '1' && item.dataSource) {
|
let _option = Utils.getSelectQueryOptions(item)
|
let _sql = Utils.formatOptions(_option.sql)
|
let isSSO = item.database === 'sso'
|
|
let param = {
|
func: 'sPC_Get_SelectedList',
|
LText: _sql,
|
obj_name: 'data',
|
arr_field: _option.field
|
}
|
|
if (this.props.dataManager) { // 数据权限
|
param.LText = param.LText.replace(/\$@/ig, '/*')
|
param.LText = param.LText.replace(/@\$/ig, '*/')
|
} else {
|
param.LText = param.LText.replace(/@\$|\$@/ig, '')
|
}
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
if (this.props.menuType === 'HS') { // 云端数据验证
|
param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true)
|
}
|
|
let defer = new Promise(resolve => {
|
Api.getSystemCacheConfig(param, isSSO).then(res => {
|
res.search = item
|
resolve(res)
|
})
|
})
|
deffers.push(defer)
|
} else if (item.resourceType === '1' && !item.dataSource) {
|
notification.warning({
|
top: 92,
|
message: item.label + ': ' + this.state.dict['main.datasource.settingerror'],
|
duration: 5
|
})
|
}
|
})
|
|
if (deffers.length === 0) {
|
this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
|
return
|
}
|
|
Promise.all(deffers).then(result => {
|
result.forEach(res => {
|
if (res.status) {
|
searchlist = searchlist.map(item => {
|
if (item.uuid === res.search.uuid) {
|
res.data.forEach(cell => {
|
let _item = {
|
key: Utils.getuuid(),
|
Value: cell[res.search.valueField],
|
Text: cell[res.search.valueText]
|
}
|
|
if (res.search.type === 'link') {
|
_item.parentId = cell[res.search.linkField]
|
}
|
|
item.options.push(_item)
|
})
|
}
|
return item
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.search.label + ':' + res.message,
|
duration: 5
|
})
|
}
|
})
|
|
this.setState({searchlist})
|
})
|
}
|
|
/**
|
* @description 主表数据加载
|
*/
|
async loadmaindata () {
|
const { setting, BIDs, search } = this.state
|
let param = ''
|
let requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
|
|
if (requireFields.length > 0) {
|
let labels = requireFields.map(item => item.label)
|
labels = Array.from(new Set(labels))
|
|
notification.warning({
|
top: 92,
|
message: this.state.dict['form.required.input'] + labels.join('、') + ' !',
|
duration: 3
|
})
|
return
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
if (setting.interType !== 'inner' || (setting.interType === 'inner' && setting.innerFunc)) {
|
param = this.getCustomParam()
|
} else {
|
param = this.getDefaultParam()
|
}
|
|
let result = await Api.genericInterface(param)
|
if (result.status) {
|
this.setState({
|
data: result.data.map((item, index) => {
|
item.key = index
|
return item
|
}),
|
total: result.total,
|
loading: false,
|
pickup: false,
|
BIDs: {
|
...BIDs,
|
mainTable: '',
|
mainTabledata: ''
|
}
|
})
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
}
|
|
/**
|
* @description 获取用户自定义存储过程传参
|
*/
|
getCustomParam = () => {
|
const { pageIndex, pageSize, orderBy, search, setting } = this.state
|
|
let _search = Utils.formatCustomMainSearch(search)
|
|
let param = {
|
OrderCol: orderBy || setting.order,
|
dataM: this.props.dataManager ? 'Y' : '',
|
..._search
|
}
|
|
if (setting.laypage !== 'false') {
|
param.PageIndex = pageIndex
|
param.PageSize = pageSize
|
}
|
|
if (setting.interType === 'inner') {
|
param.func = setting.innerFunc
|
} else {
|
if (setting.sysInterface === 'true' && window.GLOB.mainSystemApi) {
|
param.rduri = window.GLOB.mainSystemApi
|
} else if (setting.sysInterface !== 'true') {
|
param.rduri = setting.interface
|
}
|
|
if (setting.outerFunc) {
|
param.func = setting.outerFunc
|
}
|
}
|
|
return param
|
}
|
|
/**
|
* @description 获取系统存储过程 sPC_Get_TableData 的参数
|
*/
|
getDefaultParam = () => {
|
const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state
|
|
if (!arr_field) {
|
notification.warning({
|
top: 92,
|
message: '未设置显示列!',
|
duration: 5
|
})
|
return null
|
}
|
|
let _search = Utils.joinMainSearchkey(search)
|
|
_search = _search ? 'where ' + _search : ''
|
|
let param = {
|
func: 'sPC_Get_TableData',
|
obj_name: 'data',
|
arr_field: arr_field,
|
custom_script: setting.customScript || '',
|
default_sql: setting.default || 'true',
|
dataM: this.props.dataManager ? 'Y' : ''
|
}
|
|
let _orderBy = orderBy || setting.order
|
let _dataresource = setting.dataresource
|
|
if (/\s/.test(_dataresource)) {
|
_dataresource = '(' + _dataresource + ') tb'
|
}
|
|
if (this.props.dataManager) { // 数据权限
|
_dataresource = _dataresource.replace(/\$@/ig, '/*')
|
_dataresource = _dataresource.replace(/@\$/ig, '*/')
|
param.custom_script = param.custom_script.replace(/\$@/ig, '/*')
|
param.custom_script = param.custom_script.replace(/@\$/ig, '*/')
|
} else {
|
_dataresource = _dataresource.replace(/@\$|\$@/ig, '')
|
param.custom_script = param.custom_script.replace(/@\$|\$@/ig, '')
|
}
|
|
let regoptions = null
|
if (setting.queryType === 'statistics' || param.custom_script) {
|
let allSearch = Utils.getAllSearchOptions(search)
|
|
regoptions = allSearch.map(item => {
|
return {
|
reg: new RegExp('@' + item.key + '@', 'ig'),
|
value: `'${item.value}'`
|
}
|
})
|
}
|
|
if (setting.queryType === 'statistics' && setting.default !== 'false') { // 统计数据源,内容替换
|
regoptions.forEach(item => {
|
_dataresource = _dataresource.replace(item.reg, item.value)
|
})
|
_search = ''
|
}
|
|
let LText = ''
|
let DateCount = ''
|
|
if (setting.default !== 'false' && setting.laypage !== 'false') {
|
LText = ` select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
|
DateCount = `select count(1) as total from ${_dataresource} ${_search}`
|
} else if (setting.default !== 'false') {
|
LText = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
|
DateCount = ''
|
}
|
|
if (param.custom_script) {
|
regoptions.push({
|
reg: new RegExp('@orderBy@', 'ig'),
|
value: _orderBy
|
})
|
if (setting.laypage !== 'false') {
|
regoptions.push({
|
reg: new RegExp('@pageSize@', 'ig'),
|
value: pageSize
|
}, {
|
reg: new RegExp('@pageIndex@', 'ig'),
|
value: pageIndex
|
})
|
}
|
|
regoptions.forEach(item => {
|
param.custom_script = param.custom_script.replace(item.reg, item.value)
|
})
|
|
if (LText) {
|
LText += `
|
aaa:
|
if @ErrorCode!=''
|
insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
|
`
|
} else {
|
param.custom_script += `
|
aaa:
|
if @ErrorCode!=''
|
insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
|
`
|
}
|
|
param.custom_script = Utils.formatOptions(param.custom_script)
|
}
|
|
param.LText = Utils.formatOptions(LText)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
param.DateCount = Utils.formatOptions(DateCount)
|
|
if (this.props.menuType === 'HS') { // 云端数据验证
|
param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true)
|
}
|
|
return param
|
}
|
|
/**
|
* @description 搜索条件改变时,重置表格数据
|
* 含有初始不加载的页面,修改设置
|
*/
|
refreshbysearch = (searches) => {
|
const { setting } = this.state
|
|
if (setting.onload === 'false') {
|
this.setState({
|
pageIndex: 1,
|
search: searches,
|
setting: {...setting, onload: 'true'}
|
}, () => {
|
this.loadmaindata()
|
})
|
} else {
|
this.setState({
|
resetTable: !this.state.resetTable,
|
selectedData: [],
|
pageIndex: 1,
|
search: searches
|
}, () => {
|
this.loadmaindata()
|
})
|
}
|
}
|
|
/**
|
* @description 表格条件改变时重置数据(分页或排序)
|
*/
|
refreshbytable = (pagination, filters, sorter) => {
|
if (sorter.order) {
|
let _chg = {
|
ascend: 'asc',
|
descend: 'desc'
|
}
|
sorter.order = _chg[sorter.order]
|
}
|
|
this.setState({
|
selectedData: [],
|
pageIndex: pagination.current,
|
pageSize: pagination.pageSize,
|
orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
|
}, () => {
|
this.loadmaindata()
|
})
|
}
|
|
/**
|
* @description 表格刷新
|
*/
|
reloadtable = () => {
|
this.setState({
|
resetTable: !this.state.resetTable,
|
selectedData: [],
|
pageIndex: 1
|
}, () => {
|
this.loadmaindata()
|
})
|
}
|
|
/**
|
* @description 页面刷新,重新获取配置
|
*/
|
reloadview = () => {
|
this.setState({ loadingview: true, viewlost: false, lostmsg: '', config: {}, userConfig: null, searchlist: null,
|
actions: null, columns: null, arr_field: '', setting: null, data: null, total: 0, loading: false, pageIndex: 1,
|
pageSize: 10, orderBy: '', search: '', BIDs: {}, pickup: false
|
}, () => {
|
this.loadconfig()
|
})
|
}
|
|
/**
|
* @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项
|
*/
|
refreshbyaction = (position) => {
|
if (position === 'grid') {
|
this.reloadtable()
|
} else if (position === 'view') {
|
this.reloadview()
|
}
|
}
|
|
/**
|
* @description 子表操作完成后刷新主表
|
*/
|
handleMainTable = (type, tab) => {
|
if (type === 'maingrid' && tab.supMenu === 'mainTable') {
|
this.reloadtable()
|
} else if (type === 'mainline' && tab.supMenu === 'mainTable') {
|
this.reloadtable()
|
} else if ((type === 'maingrid' || type === 'mainline') && tab.supMenu) {
|
this.setState({
|
refreshtabs: [type, tab.supMenu]
|
}, () => {
|
this.setState({
|
refreshtabs: null
|
})
|
})
|
} else if (type === 'equaltab' && tab.equalTab && tab.equalTab.length > 0) {
|
this.setState({
|
refreshtabs: tab.equalTab
|
}, () => {
|
this.setState({
|
refreshtabs: null
|
})
|
})
|
}
|
}
|
|
/**
|
* @description 导出Excel时,获取页面搜索排序等参数
|
*/
|
getexceloutparam = () => {
|
const { MenuName } = this.props
|
const { arr_field, orderBy, search, setting} = this.state
|
|
return {
|
arr_field: arr_field,
|
orderBy: orderBy || setting.order,
|
search: search,
|
menuName: MenuName
|
}
|
}
|
|
/**
|
* @description 表格选择项切换
|
*/
|
changeSelectedData = (selectedData) => {
|
this.setState({selectedData})
|
}
|
|
/**
|
* @description 表格中,按钮触发事件传递
|
*/
|
buttonTrigger = (btn, record) => {
|
this.setState({
|
triggerBtn: {
|
uuid: new Date().getTime(),
|
parentId: this.props.MenuID,
|
button: btn,
|
data: record
|
}
|
})
|
}
|
|
/**
|
* @description 表格Id变化
|
*/
|
handleTableId = (type, id, data) => {
|
const { BIDs } = this.state
|
|
this.setState({
|
BIDs: {
|
...BIDs,
|
[type]: id,
|
[type + 'data']: data
|
}
|
})
|
}
|
|
/**
|
* @description 数据展开合并切换
|
*/
|
pickupChange = () => {
|
const { pickup } = this.state
|
this.setState({
|
pickup: !pickup
|
})
|
}
|
|
handleviewconfig = (e) => {
|
e.stopPropagation()
|
|
const { MenuNo } = this.props
|
const { config } = this.state
|
|
if (config && config.funcs && config.funcs.length > 0) {
|
this.setState({
|
treevisible: true
|
})
|
} else {
|
let oInput = document.createElement('input')
|
oInput.value = MenuNo || ''
|
document.body.appendChild(oInput)
|
oInput.select()
|
document.execCommand('Copy')
|
document.body.removeChild(oInput)
|
message.success(this.state.dict['main.copy.success'])
|
}
|
}
|
|
getTreeNode = (data) => {
|
let _type = {
|
view: '页面',
|
btn: '按钮',
|
tab: '标签'
|
}
|
|
return data.map(item => {
|
let _title = _type[item.subtype]
|
let _others = []
|
|
_others.push(
|
(item.menuNo ? item.menuNo + '(菜单参数)' : ''),
|
(item.tableName ? item.tableName + '(表名) ' : ''),
|
(item.innerFunc ? item.innerFunc + '(内部函数) ' : ''),
|
(item.outerFunc ? item.outerFunc + '(外部函数)' : '')
|
)
|
_others = _others.filter(Boolean)
|
_others = _others.join('、')
|
|
if (item.label) {
|
_title = _title + '(' + item.label + ')'
|
}
|
if (_others) {
|
_title = _title + ': ' + _others
|
}
|
|
if (item.subfuncs && item.subfuncs.length > 0) {
|
return (
|
<TreeNode title={_title} key={item.uuid} dataRef={item} selectable={false}>
|
{this.getTreeNode(item.subfuncs)}
|
</TreeNode>
|
)
|
}
|
return <TreeNode key={item.uuid} title={_title} isLeaf selectable={false} />
|
})
|
}
|
|
/**
|
* @description 图表视图切换
|
*/
|
changeChart = (uuid) => {
|
this.setState({chartId: uuid})
|
}
|
|
UNSAFE_componentWillMount () {
|
// 组件加载时,获取菜单数据
|
this.loadconfig()
|
}
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
|
if (nextProps.refreshTab.position === 'grid') {
|
this.reloadtable()
|
} else if (nextProps.refreshTab.position === 'view') {
|
this.reloadview()
|
}
|
this.props.refreshTabView('')
|
} else if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
|
let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0]
|
if (selectTab && selectTab.MenuID === this.props.MenuID) {
|
this.setShortcut()
|
}
|
} else if (nextProps.param && !is(fromJS(this.props.param), fromJS(nextProps.param))) {
|
let search = this.state.search.map(item => {
|
if (item.type === 'text' && item.key === nextProps.param.searchkey) {
|
item.value = nextProps.param.searchval
|
}
|
return item
|
})
|
this.refreshbysearch(search)
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
document.onkeydown = () => {}
|
}
|
|
render() {
|
const { setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig, tabActive, chartId, search, selectedData } = this.state
|
|
return (
|
<div className="commontable pick-control" id={this.state.ContainerId}>
|
{loadingview && <Spin size="large" />}
|
{searchlist && searchlist.length > 0 ?
|
<MainSearch
|
dict={this.state.dict}
|
searchlist={searchlist}
|
refreshdata={this.refreshbysearch}
|
/> : null
|
}
|
{setting && setting.onload !== 'false' ? <div className="chart-view">
|
{/* 视图组 */}
|
{!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
|
{config.charts.map(item => (
|
<TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane>
|
))}
|
</Tabs> : null}
|
{config.charts.map(item => {
|
if (!config.expand && chartId !== item.uuid) return null
|
|
if (item.chartType === 'table') {
|
return (
|
<Col span={item.width || 24} key={item.uuid}>
|
{config.charts.length > 1 && item.title ? <p className="chart-table chart-title">{item.title}</p> : null}
|
<div style={{minHeight: '25px'}}>
|
<MainAction
|
setting={setting}
|
actions={actions}
|
dict={this.state.dict}
|
triggerBtn={triggerBtn}
|
MenuID={this.props.MenuID}
|
selectedData={selectedData}
|
logcolumns={this.state.logcolumns}
|
ContainerId={this.state.ContainerId}
|
operations={config.gridBtn.operations || []}
|
refreshdata={this.refreshbyaction}
|
getexceloutparam={this.getexceloutparam}
|
/>
|
</div>
|
<div className="main-table-box">
|
{this.props.menuType !== 'HS' ? <SettingComponent
|
config={config}
|
columns={columns}
|
dict={this.state.dict}
|
MenuID={this.props.MenuID}
|
MenuName={this.props.MenuName}
|
permAction={this.props.permAction}
|
permRoles={this.props.permRoles}
|
userConfig={this.state.userConfig}
|
reloadview={this.reloadview}
|
/> : null}
|
{(setting.tableType === 'radio' || setting.tableType === 'checkbox') && this.state.data && this.state.data.length > 0 ?
|
<Switch title="收起" className="main-pickup" checkedChildren="开" unCheckedChildren="关" defaultChecked={pickup} onChange={this.pickupChange} /> : null
|
}
|
<MainTable
|
tableId="mainTable"
|
pickup={pickup}
|
config={config}
|
setting={setting}
|
columns={columns}
|
pageSize={pageSize}
|
dict={this.state.dict}
|
data={this.state.data}
|
total={this.state.total}
|
MenuID={this.props.MenuID}
|
loading={this.state.loading}
|
refreshdata={this.refreshbytable}
|
buttonTrigger={this.buttonTrigger}
|
handleTableId={this.handleTableId}
|
resetTable={this.state.resetTable}
|
chgSelectData={this.changeSelectedData}
|
/>
|
</div>
|
</Col>
|
)
|
} else if (item.chartType === 'card') {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<CardComponent
|
plot={item}
|
config={config}
|
tableId="mainTable"
|
data={this.state.data}
|
MenuID={this.props.MenuID}
|
loading={this.state.loading}
|
logcolumns={this.state.logcolumns}
|
ContainerId={this.state.ContainerId}
|
refreshdata={this.refreshbyaction}
|
handleTableId={this.handleTableId}
|
/>
|
</Col>
|
)
|
} else {
|
return (
|
<Col span={item.width} key={item.uuid}>
|
<ChartComponent
|
plot={item}
|
config={config}
|
data={this.state.data}
|
loading={this.state.loading}
|
/>
|
</Col>
|
)
|
}
|
})}
|
</div> : null }
|
{setting && setting.onload !== 'false' &&
|
config.tabgroups.map(group => (
|
<Tabs activeKey={tabActive[group.uuid]} key={group.uuid} onChange={(key) => this.setState({tabActive: {...tabActive, [group.uuid]: key}})}>
|
{group.sublist.map(_tab => {
|
return (
|
<TabPane tab={
|
<span>
|
{_tab.icon ? <Icon type={_tab.icon} /> : null}
|
{_tab.label}
|
</span>
|
} key={_tab.uuid}>
|
{_tab.type === 'SubTable' ?
|
<SubTable
|
Tab={_tab}
|
MenuID={_tab.linkTab}
|
mainSearch={_tab.searchPass === 'true' ? search : null}
|
userConfig={userConfig ? userConfig[_tab.uuid] : null}
|
triggerBtn={triggerBtn}
|
SupMenuID={this.props.MenuID}
|
refreshtabs={this.state.refreshtabs}
|
ContainerId={this.state.ContainerId}
|
BID={this.state.BIDs[_tab.supMenu] || ''}
|
BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
|
handleTableId={this.handleTableId}
|
handleMainTable={(type) => this.handleMainTable(type, _tab)}
|
/> : null}
|
{_tab.type === 'SecretKeyTable' ?
|
<SecretKeyTable
|
Tab={_tab}
|
MenuID={_tab.linkTab}
|
SupMenuID={this.props.MenuID}
|
refreshtabs={this.state.refreshtabs}
|
ContainerId={this.state.ContainerId}
|
BID={this.state.BIDs[_tab.supMenu] || ''}
|
BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
|
handleMainTable={(type) => this.handleMainTable(type, _tab)}
|
/> : null}
|
</TabPane>
|
)
|
})}
|
</Tabs>)
|
)
|
}
|
<Button
|
icon="copy"
|
shape="circle"
|
className="common-table-copy"
|
onClick={this.handleviewconfig}
|
/>
|
<Modal
|
className="menu-tree-modal"
|
title={'菜单结构树'}
|
width={'650px'}
|
maskClosable={false}
|
visible={this.state.treevisible}
|
onCancel={() => this.setState({treevisible: false})}
|
footer={[
|
<Button key="close" onClick={() => this.setState({treevisible: false})}>{this.state.dict['main.close']}</Button>
|
]}
|
destroyOnClose
|
>
|
<div className="menu-header">
|
<span>菜单名称:{this.props.MenuName}</span>
|
<span>菜单参数:{<Paragraph copyable>{this.props.MenuNo}</Paragraph>}</span>
|
</div>
|
{this.state.treevisible ? <Tree defaultExpandAll showLine={true}>
|
{this.getTreeNode(config.funcs)}
|
</Tree> : null}
|
</Modal>
|
{viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
|
</div>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
menuType: state.editLevel,
|
tabviews: state.tabviews,
|
refreshTab: state.refreshTab,
|
permAction: state.permAction,
|
permMenus: state.permMenus,
|
permRoles: state.permRoles,
|
dataManager: state.dataManager
|
}
|
}
|
|
const mapDispatchToProps = (dispatch) => {
|
return {
|
refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab))
|
}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)
|