king
2024-12-31 cce4ab076f3fa26f393fe4039ef5a891e2e8b2a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
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