king
2023-07-07 ac4e2892a68bb4ef5b35e8e2e12e76d3ec3ede35
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
import React, {Component} from 'react'
import { Spin, notification } from 'antd'
 
import Api from '@/api'
import asyncComponent from '@/utils/asyncLoadComponent'
import MKEmitter from '@/utils/events.js'
import './index.scss'
 
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
const BaseTable = asyncComponent(() => import('@/tabviews/basetable'))
 
class MkIframe extends Component {
  state = {
    loading: true,
    BID: '',
    MenuId: '',
    type: 'CustomPage'
  }
 
  UNSAFE_componentWillMount() {
    const { params, path } = this.props.match
    const { menuId, loginUid, bid } = params
 
    if (/^\/view\//.test(path)) {
      localStorage.setItem('getSysPermission', window.GLOB.appkey)
    
      window.addEventListener('storage', function(event) {
        if (event.key === 'sysPermissions' && event.newValue) {
          let values = event.newValue
          values = JSON.parse(values)
 
          window.GLOB.mkThdMenus = values.mkThdMenus
          window.GLOB.mkActions = values.mkActions
        }
      })
 
      setTimeout(() => {
        localStorage.removeItem('getSysPermission')
        localStorage.removeItem('sysPermissions')
 
        if (window.GLOB.mkActions) {
          this.setState({loading: false})
        } else {
          this.getPermRole()
        }
      }, 20)
    } else if (sessionStorage.getItem('UserID')) {
      this.getPermRole()
    } else {
      sessionStorage.setItem('LoginUID', loginUid)
  
      Api.getTouristMsg('login_check').then(res => {
        if (res.status) {
          sessionStorage.setItem('UserID', res.UserID)
          sessionStorage.setItem('LoginUID', res.LoginUID)
          sessionStorage.setItem('User_Name', res.UserName)
          sessionStorage.setItem('Full_Name', res.FullName)
          sessionStorage.setItem('avatar', res.icon || '')
          sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
          sessionStorage.setItem('debug', res.debug || '')
          sessionStorage.setItem('role_id', res.role_id || '')
          sessionStorage.setItem('departmentcode', res.departmentcode || '')
          sessionStorage.setItem('organization', res.organization || '')
          sessionStorage.setItem('mk_user_type', res.mk_user_type || '')
          this.getPermRole()
        } else {
          sessionStorage.clear()
          sessionStorage.setItem('iframe', `/iframe/${menuId}/@loginuid@/${bid || ''}`)
          this.props.history.replace('/login')
        }
      })
    }
 
    this.setState({BID: bid || '', MenuId: menuId})
  }
 
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    MKEmitter.addListener('closeTabView', this.closeTabView)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
    MKEmitter.removeListener('closeTabView', this.closeTabView)
  }
 
  modifyTabs = (tab) => {
    const { MenuId, BID } = this.state
 
    let _menuId = tab.MenuID
    let _BID = tab.param && tab.param.$BID ? tab.param.$BID : ''
 
    let historys = sessionStorage.getItem('page_historys')
    historys = historys ? JSON.parse(historys) : []
 
    historys.push({MenuId: MenuId, BID: BID})
 
    sessionStorage.setItem('page_historys', JSON.stringify(historys))
 
    this.setState({
      MenuId: _menuId,
      BID: _BID,
      loading: true
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
 
  closeTabView = () => {
    let historys = sessionStorage.getItem('page_historys')
    historys = historys ? JSON.parse(historys) : []
 
    if (historys.length === 0) return
 
    let tab = historys.shift()
 
    sessionStorage.setItem('page_historys', JSON.stringify(historys))
    
    this.setState({
      MenuId: tab.MenuId,
      BID: tab.BID,
      loading: true
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
 
  getPermRole = () => {
    Api.getSystemConfig({
      func: 's_Get_TrdMenu_Role',
      edition_type: 'A',
      pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
    }).then(result => {
      if (!result.status) {
        notification.error({
          top: 92,
          message: result.message,
          duration: 10
        })
        return
      }
 
      let _permAction = {loaded: true} // 按钮权限
  
      if (result.UserRoles_Menu) {
        result.UserRoles_Menu.forEach(menu => {
          if (!menu.MenuID) return
          _permAction[menu.MenuID] = true
        })
      }
  
      window.GLOB.mkActions = _permAction
 
      this.setState({loading: false})
    })
  }
 
  changeTemp = (MenuID, Template) => {
    this.setState({
      type: Template
    })
  }
 
  render () {
    const { loading, BID, MenuId, type } = this.state
 
    return (
      <div className="main-iframe">
        {loading ? <Spin size="large" /> : null}
        {!loading && type === 'CustomPage' ? <CustomPage MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
        {!loading && type === 'BaseTable' ? <BaseTable MenuID={MenuId} param={{$BID: BID}} changeTemp={this.changeTemp}/> : null}
      </div>
    )
  }
}
 
export default MkIframe