import React, {Component} from 'react'
|
import { fromJS } from 'immutable'
|
import { Spin, notification, Button } from 'antd'
|
import moment from 'moment'
|
// import { QuestionCircleOutlined } from '@ant-design/icons'
|
|
import Api from '@/api'
|
import Utils from '@/utils/utils.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
import { getAllSqls } from '@/utils/utils-custom.js'
|
import './index.scss'
|
|
const Header = asyncComponent(() => import('./header'))
|
|
class SysCheck extends Component {
|
state = {
|
loading: false,
|
menulist: [],
|
thdMenuList: [],
|
applist: [],
|
lackmenus: [],
|
outmenus: [],
|
backmenus: [],
|
unablemenus: [],
|
}
|
|
sqlmap = null
|
repmap = null
|
|
UNSAFE_componentWillMount() {
|
document.body.className = ''
|
window.GLOB.syscheck = true
|
}
|
|
componentDidMount() {
|
if (!sessionStorage.getItem('UserID')) {
|
this.props.history.replace('/login')
|
return
|
}
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
getMenus = () => {
|
this.setState({
|
loading: true
|
})
|
Api.getCloudConfig({func: 's_get_pc_menus', systemType: window.GLOB.sysType, debug: 'Y'}).then(result => {
|
if (result.status) {
|
let thdMenuList = []
|
let menulist = result.fst_menu.map(fst => {
|
let fstItem = {
|
MenuID: fst.MenuID,
|
MenuName: fst.MenuName,
|
children: []
|
}
|
|
if (fst.snd_menu) {
|
fstItem.children = fst.snd_menu.map(snd => {
|
let sndItem = {
|
MenuID: snd.MenuID,
|
MenuName: snd.MenuName,
|
children: []
|
}
|
|
if (snd.trd_menu) {
|
sndItem.children = snd.trd_menu.map(trd => {
|
let trdItem = {
|
MenuID: trd.MenuID,
|
MenuName: trd.MenuName,
|
MenuNo: trd.MenuNo,
|
pName: fst.MenuName + '-' + snd.MenuName,
|
type: 'CustomPage',
|
}
|
|
if (trd.PageParam) {
|
try {
|
trd.PageParam = JSON.parse(trd.PageParam)
|
trdItem.type = trd.PageParam.Template || 'CustomPage'
|
} catch (e) {
|
|
}
|
}
|
|
thdMenuList.push(trdItem)
|
|
return trdItem
|
})
|
}
|
return sndItem
|
})
|
}
|
return fstItem
|
})
|
|
this.setState({
|
menulist,
|
thdMenuList
|
})
|
|
if (thdMenuList.length === 0) {
|
this.setState({
|
loading: false
|
})
|
} else {
|
this.sqlmap = new Map()
|
this.repmap = new Map()
|
this.getMenuParam(fromJS(thdMenuList).toJS())
|
}
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
getAppList = () => {
|
let param = {
|
func: 's_get_kei'
|
}
|
|
this.setState({
|
loading: true
|
})
|
|
Api.getCloudConfig(param).then(result => {
|
if (result.status) {
|
let applist = []
|
result.data.forEach(item => {
|
if (!item.data_detail) return
|
item.data_detail.forEach(cell => {
|
applist.push({
|
ID: cell.d_id,
|
name: item.remark,
|
typename: cell.typename,
|
kei_no: item.kei_no,
|
lang: cell.lang,
|
menus: []
|
})
|
})
|
})
|
|
if (applist.length === 0) {
|
this.setState({
|
loading: false
|
})
|
} else {
|
let deffers = applist.map((app, i) =>
|
new Promise(resolve => {
|
let param = {
|
func: 's_get_app_menus',
|
TypeCharOne: app.kei_no,
|
typename: app.typename,
|
LText: `select '${window.GLOB.appkey}'`,
|
timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
|
lang: app.lang
|
}
|
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
setTimeout(() => {
|
Api.getCloudConfig(param).then(result => {
|
delete result.ErrCode
|
delete result.ErrMesg
|
|
if (result.status) {
|
result = {
|
...app,
|
status: true,
|
menus: []
|
}
|
|
result.menus.forEach(m => {
|
if (m.menus_rolelist) {
|
try {
|
let pageParam = JSON.parse(window.decodeURIComponent(window.atob(m.menus_rolelist)))
|
if (pageParam.type === 'navbar') {
|
m.type = pageParam.type
|
}
|
} catch(e) {
|
|
}
|
if (m.type === 'navbar') return
|
}
|
delete m.menus_rolelist
|
|
result.menus.push(m)
|
})
|
}
|
|
resolve(result)
|
})
|
}, 200 * i)
|
})
|
)
|
|
Promise.all(deffers).then(response => {
|
let error = response.filter(cell => !cell.status)
|
if (error[0]) {
|
notification.warning({
|
top: 92,
|
message: error[0].message,
|
duration: 5
|
})
|
this.setState({
|
loading: false
|
})
|
} else {
|
let list = response.filter(cell => cell.menus.length > 0)
|
this.setState({
|
loading: false,
|
applist: list
|
})
|
}
|
})
|
}
|
} else {
|
this.setState({
|
loading: false
|
})
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
getMenuParam = (menus) => {
|
const { lackmenus, outmenus, unablemenus, backmenus } = this.state
|
|
let menu = menus.shift()
|
const { MenuID } = menu
|
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: MenuID
|
}
|
|
Api.getCloudConfig(param).then(result => {
|
if (result.status) {
|
let config = null
|
|
try {
|
config = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : null
|
} catch (e) {
|
console.warn('Parse Failure')
|
config = null
|
}
|
|
if (!config) {
|
this.setState({lackmenus: [...lackmenus, menu]})
|
} else if (!['CustomPage', 'BaseTable'].includes(config.Template)) {
|
this.setState({outmenus: [...outmenus, menu]})
|
} else if (config.Template === 'CustomPage' && config.version !== 2.0) {
|
menu.version = config.version
|
this.setState({outmenus: [...outmenus, menu]})
|
} else if (!config.enabled) {
|
this.setState({unablemenus: [...unablemenus, menu]})
|
} else {
|
let sqls = getAllSqls(config)
|
let keys = sqls.map(item => item.uuid)
|
|
sqls.forEach(item => {
|
if (this.sqlmap.has(item.uuid)) {
|
if (!this.repmap.has(item.uuid)) {
|
this.repmap.set(item.uuid, menu)
|
}
|
} else {
|
this.sqlmap.set(item.uuid, menu)
|
}
|
})
|
|
if (keys.length > Array.from(new Set(keys)).length) {
|
this.setState({backmenus: [...backmenus, menu]})
|
}
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
render () {
|
const { loading } = this.state
|
|
if (!sessionStorage.getItem('UserID')) return null
|
|
return (
|
<div className="mk-app-check">
|
<Header view="manage" />
|
{loading ?
|
<div className="loading-mask">
|
<Spin size="large" />
|
</div> : null
|
}
|
<div className="view-wrap">
|
<div>
|
<Button disabled={loading} type="primary" style={{marginRight: '15px'}} onClick={this.getMenus}>检查管理系统菜单</Button>
|
<Button disabled={loading} type="primary" onClick={this.getAppList}>检查子应用菜单</Button>
|
</div>
|
</div>
|
</div>
|
)
|
}
|
}
|
|
export default SysCheck
|