import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { notification, Spin, Modal, Button } from 'antd'
|
import moment from 'moment'
|
|
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 asyncComponent from '@/utils/asyncComponent'
|
import asyncSpinComponent from '@/utils/asyncSpinComponent'
|
import MKEmitter from '@/utils/events.js'
|
import NotFount from '@/components/404'
|
import './index.scss'
|
|
// 通用组件
|
const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
|
const CalendarComponent = asyncSpinComponent(() => import('@/tabviews/zshare/calendar'))
|
const SubTabTable = asyncSpinComponent(() => import('@/tabviews/subtabtable'))
|
const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
|
|
class MkCalendar 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
|
BID: null, // 页面跳转时携带ID
|
loadingview: true, // 页面加载中
|
viewlost: false, // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
|
lostmsg: '', // 页面丢失时的提示信息
|
config: {}, // 页面配置信息,包括按钮、搜索、显示列、标签等
|
userConfig: null, // 用户自定义设置
|
searchlist: null, // 搜索条件
|
arr_field: '', // 查询字段集
|
setting: null, // 页面全局设置:数据源、按钮及显示列固定、主键等
|
data: null, // 列表数据集
|
loading: false, // 列表数据加载中
|
search: '', // 搜索条件数组,使用时需分场景处理
|
visible: false, // 标签页控制
|
triggerTime: '', // 点击时间
|
calendarYear: moment().format('YYYY'), // 日历年份
|
hasReqFields: false
|
}
|
|
/**
|
* @description 获取页面配置信息
|
*/
|
async loadconfig () {
|
const { 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 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 && !window.GLOB.mkHS) {
|
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 (!window.GLOB.mkHS) {
|
if (config.tab && !window.GLOB.mkActions[config.tab.linkTab]) {
|
config.tab = null
|
}
|
}
|
if (config.tab) {
|
config.tab.uuid = Utils.getuuid()
|
}
|
|
if (_curUserConfig) {
|
config.setting = {...config.setting, ..._curUserConfig.setting}
|
config.easyCode = _curUserConfig.easyCode || config.easyCode || ''
|
}
|
|
config.search = Utils.initSearchVal(config.search)
|
|
// 字段透视
|
let hasReqFields = false
|
config.search = config.search.map(item => {
|
if (param && ['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) {
|
item.initval = param.$searchval
|
}
|
|
if (item.required) {
|
hasReqFields = true
|
}
|
|
return item
|
})
|
|
// 数据源
|
if (config.setting.interType === 'inner' && !config.setting.innerFunc) {
|
config.setting.interType = 'system'
|
}
|
|
if (config.setting.interType === 'system') {
|
// 整理数据源自定义脚本
|
let _customScript = ''
|
config.scripts && config.scripts.forEach(script => {
|
if (script.status !== 'false') {
|
_customScript += `
|
${script.sql}
|
`
|
}
|
})
|
|
if (/\s/.test(config.setting.dataresource)) {
|
config.setting.dataresource = '(' + config.setting.dataresource + ') tb'
|
}
|
|
if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
|
config.setting.dataresource = config.setting.dataresource.replace(/\$@/ig, '/*')
|
config.setting.dataresource = config.setting.dataresource.replace(/@\$/ig, '*/')
|
_customScript = _customScript.replace(/\$@/ig, '/*')
|
_customScript = _customScript.replace(/@\$/ig, '*/')
|
} else {
|
config.setting.dataresource = config.setting.dataresource.replace(/@\$|\$@/ig, '')
|
_customScript = _customScript.replace(/@\$|\$@/ig, '')
|
}
|
|
let userName = sessionStorage.getItem('User_Name') || ''
|
let fullName = sessionStorage.getItem('Full_Name') || ''
|
|
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}'` }
|
]
|
|
regs.forEach(cell => {
|
config.setting.dataresource = config.setting.dataresource.replace(cell.reg, cell.value)
|
_customScript = _customScript.replace(cell.reg, cell.value)
|
})
|
|
if (config.urlFields) {
|
let _param = param || {}
|
config.urlFields.forEach(field => {
|
let reg = new RegExp('@' + field + '@', 'ig')
|
let val = `'${_param[field] || ''}'`
|
config.setting.dataresource = config.setting.dataresource.replace(reg, val)
|
_customScript = _customScript.replace(reg, val)
|
})
|
}
|
|
config.setting.customScript = _customScript
|
}
|
|
this.setState({
|
hasReqFields,
|
BID: param && param.$BID ? param.$BID : '',
|
loadingview: false,
|
config: config,
|
userConfig: userConfig,
|
setting: config.setting,
|
searchlist: config.search,
|
arr_field: config.columns.map(item => item.field).join(','),
|
search: Utils.initMainSearch(config.search)
|
}, () => {
|
if (config.setting.onload !== 'false') {
|
this.loadmaindata()
|
}
|
})
|
} else {
|
this.setState({
|
loadingview: false,
|
viewlost: true
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
}
|
|
/**
|
* @description 主表数据加载
|
*/
|
async loadmaindata () {
|
const { setting, search, BID, hasReqFields } = this.state
|
let param = ''
|
|
if (hasReqFields) {
|
let requireFields = search.filter(item => item.required && item.value === '')
|
|
if (requireFields.length > 0) {
|
return
|
}
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
if (setting.interType === 'system') {
|
param = this.getDefaultParam()
|
} else {
|
param = this.getCustomParam()
|
}
|
|
if (BID) {
|
param.BID = BID
|
}
|
// 数据管理权限
|
if (sessionStorage.getItem('dataM') === 'true') {
|
param.dataM = 'Y'
|
}
|
|
let result = await Api.genericInterface(param)
|
if (result.status) {
|
this.setState({
|
data: result.data.map((item, index) => {
|
item.key = index
|
return item
|
}),
|
loading: false
|
})
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.error({
|
top: 92,
|
message: result.message,
|
duration: 10
|
})
|
}
|
}
|
|
/**
|
* @description 获取用户自定义存储过程传参
|
*/
|
getCustomParam = () => {
|
const { search, setting, calendarYear, config } = this.state
|
|
let _search = Utils.formatCustomMainSearch(search)
|
|
let param = {
|
..._search
|
}
|
|
if (config.calendar.refresh === 'true') {
|
param.calendarDate = calendarYear
|
}
|
|
if (setting.interType === 'inner') {
|
param.func = setting.innerFunc
|
} else {
|
if (window.GLOB.mkHS) {
|
if (setting.sysInterface === 'true' && options.cloudServiceApi) {
|
param.rduri = options.cloudServiceApi
|
param.userid = sessionStorage.getItem('CloudUserID') || ''
|
param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
|
} else if (setting.sysInterface !== 'true') {
|
param.rduri = setting.interface
|
}
|
} 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 获取系统存储过程的参数
|
*/
|
getDefaultParam = () => {
|
const { arr_field, search, setting, config, calendarYear } = this.state
|
|
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.execute || 'true',
|
menuname: this.props.MenuName || ''
|
}
|
|
let _dataresource = setting.dataresource
|
let regoptions = []
|
let userName = sessionStorage.getItem('User_Name') || ''
|
let fullName = sessionStorage.getItem('Full_Name') || ''
|
let RoleID = sessionStorage.getItem('role_id') || ''
|
let departmentcode = sessionStorage.getItem('departmentcode') || ''
|
let organization = sessionStorage.getItem('organization') || ''
|
let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
|
let nation = sessionStorage.getItem('nation') || ''
|
let province = sessionStorage.getItem('province') || ''
|
let city = sessionStorage.getItem('city') || ''
|
let district = sessionStorage.getItem('district') || ''
|
let address = sessionStorage.getItem('address') || ''
|
|
if (sessionStorage.getItem('isEditState') === 'true') {
|
userName = sessionStorage.getItem('CloudUserName') || ''
|
fullName = sessionStorage.getItem('CloudFullName') || ''
|
}
|
|
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}'`
|
}
|
})
|
regoptions.push({
|
reg: new RegExp('@userName@', 'ig'),
|
value: userName
|
}, {
|
reg: new RegExp('@fullName@', 'ig'),
|
value: fullName
|
})
|
}
|
|
if (config.calendar.refresh === 'true') {
|
regoptions.push({
|
reg: new RegExp('@calendarDate@', 'ig'),
|
value: `'${calendarYear}-01-01 00:00:00.000'`
|
})
|
regoptions.push({
|
reg: new RegExp('@calendarDate1@', 'ig'),
|
value: `'${calendarYear}-12-31 23:59:59.999'`
|
})
|
}
|
|
if ((setting.queryType === 'statistics' || config.calendar.refresh === 'true') && setting.execute !== 'false') { // 统计数据源,内容替换
|
regoptions.forEach(item => {
|
_dataresource = _dataresource.replace(item.reg, item.value)
|
})
|
_search = ''
|
}
|
|
let LText = ''
|
|
if (setting.execute !== 'false') {
|
LText = `select ${arr_field} from ${_dataresource} ${_search}`
|
}
|
|
if (param.custom_script) {
|
regoptions.forEach(item => {
|
param.custom_script = param.custom_script.replace(item.reg, item.value)
|
})
|
|
param.custom_script = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000),@UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100)
|
Select @ErrorCode='',@retmsg ='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}'
|
${param.custom_script}
|
`
|
|
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@
|
`
|
}
|
}
|
|
// 测试系统打印查询语句
|
if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
|
param.custom_script && console.info(`${LText ? '' : '/*不执行默认sql*/\n'}${param.custom_script}`)
|
LText && console.info(LText)
|
}
|
|
param.custom_script = Utils.formatOptions(param.custom_script)
|
param.LText = Utils.formatOptions(LText)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
param.DateCount = ''
|
|
if (window.GLOB.mkHS) { // 云端数据验证
|
param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
|
}
|
|
return param
|
}
|
|
/**
|
* @description 搜索条件改变时,重置表格数据
|
* 含有初始不加载的页面,修改设置
|
*/
|
refreshbysearch = (searches) => {
|
const { setting } = this.state
|
|
if (setting.onload === 'false') {
|
this.setState({
|
search: searches,
|
setting: {...setting, onload: 'true'}
|
}, () => {
|
this.loadmaindata()
|
})
|
} else {
|
this.setState({
|
search: searches
|
}, () => {
|
this.loadmaindata()
|
})
|
}
|
}
|
|
|
/**
|
* @description 页面刷新,重新获取配置
|
*/
|
reloadview = () => {
|
this.setState({ loadingview: true, viewlost: false, lostmsg: '', data: null, loading: false, search: ''
|
}, () => {
|
this.loadconfig()
|
})
|
}
|
|
reloadMenuView = (menuId) => {
|
const { MenuID } = this.props
|
|
if (MenuID !== menuId) return
|
|
this.reloadview()
|
}
|
|
UNSAFE_componentWillMount () {
|
// 组件加载时,获取菜单数据
|
this.loadconfig()
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('openNewTab', this.closeTab)
|
MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
|
MKEmitter.addListener('refreshPopButton', this.refreshPopButton)
|
}
|
|
/**
|
* @description 组件销毁,清除state更新,清除快捷键设置
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('openNewTab', this.closeTab)
|
MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
|
MKEmitter.removeListener('refreshPopButton', this.refreshPopButton)
|
}
|
|
refreshPopButton = (tabId) => {
|
const { config } = this.props
|
|
if (!config.tab || config.tab.uuid !== tabId) return
|
|
this.loadmaindata()
|
}
|
|
triggerDate = (item) => {
|
const { config } = this.state
|
|
if (!config.tab) return
|
|
this.setState({
|
visible: true,
|
triggerTime: item.time.substr(0, 4) + '-' + item.time.substr(4, 2) + '-' + item.time.substr(6, 2)
|
})
|
}
|
|
closeTab = () => {
|
this.setState({
|
visible: false,
|
triggerTime: ''
|
})
|
}
|
|
render() {
|
const { BID, setting, searchlist, loadingview, viewlost, config, loading, data, triggerTime } = this.state
|
|
return (
|
<div className="calendar-page" id={this.state.ContainerId}>
|
{loadingview && <Spin size="large" />}
|
{searchlist && searchlist.length > 0 ?
|
<MainSearch BID={BID} searchlist={searchlist} setting={setting} refreshdata={this.refreshbysearch}/> : null
|
}
|
{config && config.calendar ? <CalendarComponent calendar={config.calendar} loading={loading} data={data} triggerDate={this.triggerDate} changeDate={this.changeDate}/> : null}
|
{!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
|
<Modal
|
title={config.tab ? config.tab.label : ''}
|
width={'80vw'}
|
maskClosable={false}
|
visible={this.state.visible}
|
onCancel={this.closeTab}
|
footer={[
|
<Button key="close" onClick={this.closeTab}>{this.state.dict['main.close']}</Button>
|
]}
|
destroyOnClose
|
>
|
{config.tab ? <SubTabTable
|
BID={triggerTime}
|
Tab={config.tab}
|
MenuID={config.tab.linkTab}
|
SupMenuID={this.props.MenuID}
|
/> : null}
|
</Modal>
|
{viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
|
</div>
|
)
|
}
|
}
|
|
export default MkCalendar
|