king
2024-03-29 deb2536eaaa559d6c8ec94f81afb94b6c7806b4d
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
import React, {Component} from 'react'
import { BackTop, Breadcrumb, notification, Modal } from 'antd'
import { HomeOutlined, RightOutlined, RedoOutlined, LoadingOutlined } from '@ant-design/icons'
import moment from 'moment'
import 'moment/locale/zh-cn'
 
import asyncComponent from '@/utils/asyncLoadComponent'
import NotFount from '@/components/404'
import MKEmitter from '@/utils/events.js'
import Api from '@/api'
import './index.scss'
 
const Home = asyncComponent(() => import('@/tabviews/home'))
const CustomPage = asyncComponent(() => import('@/tabviews/custom'))
const CommonTable = asyncComponent(() => import('@/tabviews/commontable'))
const BaseTable = asyncComponent(() => import('@/tabviews/basetable'))
const TreePage = asyncComponent(() => import('@/tabviews/treepage'))
const Iframe = asyncComponent(() => import('@/tabviews/iframe'))
const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
 
moment.locale('zh-cn')
 
class BreadView extends Component {
  state = {
    tabview: null,
    hasNavBar: window.GLOB.navBar === 'linkage_navigation',
    visible: false
  }
 
  reloading = false
 
  UNSAFE_componentWillMount () {
    let home = {
      MenuID: 'home_page_id',
      MenuName: '首页',
      type: 'Home'
    }
    this.setState({tabview: home})
  }
 
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
    if (window.GLOB.forcedUpdate) {
      MKEmitter.addListener('reloadTabs', this.reloadTabs)
    }
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('reloadTabs', this.reloadTabs)
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
  }
 
  refreshTabview = () => {
    const { tabview } = this.state
    window.GLOB.CacheMap = new Map()
 
    if (window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
      let roledefer = new Promise(resolve => {
        Api.getSystemConfig({
          func: 's_Get_TrdMenu_Role',
          edition_type: 'A',
          pro_sys: ''
        }).then(result => {
          if (!result) return
          if (!result.status) {
            notification.error({
              top: 92,
              message: result.message,
              duration: 10
            })
          } else {
            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
          }
 
          resolve()
        })
      })
  
      // 获取主菜单参数
      let menudefer = new Promise(resolve => {
        Api.getAppVersion().then(() => {
          resolve()
        }, () => {
          resolve()
        })
      })
      
      Promise.all([roledefer, menudefer]).then(() => {
        MKEmitter.emit('reloadMenuView', tabview.MenuID)
      })
    } else {
      MKEmitter.emit('reloadMenuView', tabview.MenuID)
    }
  }
 
  changeTemp = (MenuID, Template) => {
    this.setState({
      tabview: {...this.state.tabview, type: Template}
    })
  }
 
  selectcomponent = (view) => {
    // 根据tab页中菜单信息,选择所需的组件
    if (view.type === 'BaseTable') {
      return (<BaseTable MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'CustomPage') {
      return (<CustomPage MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'Home') {
      return (<Home MenuID={view.MenuID} MenuName={view.MenuName}/>)
    } else if (view.type === 'RolePermission') {
      return (<RoleManage MenuID={view.MenuID}/>)
    } else if (view.type === 'CommonTable') {
      return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} param={view.param} changeTemp={this.changeTemp}/>)
    } else if (view.type === 'TreePage') {
      return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} param={view.param}/>)
    } else if (view.type === 'iframe') {
      return (<Iframe MenuID={view.MenuID} title={view.MenuName} url={view.src}/>)
    } else {
      return (<NotFount />)
    }
  }
 
  gotoHome = () => {
    let home = {
      MenuID: 'home_page_id',
      MenuName: '首页',
      type: 'Home'
    }
    this.setState({tabview: home})
  }
 
  modifyTabs = (tab) => {
    this.setState({
      tabview: tab
    })
 
    let node = document.getElementById('root').parentNode.parentNode
    if (node) {
      node.scrollTop = 0
    }
  }
 
  reloadTabs = () => {
    if (this.reloading) return
 
    this.reloading = true
    let time = new Date().getTime()
 
    this.setState({visible: true})
 
    Api.getAppVersion(true).then((list) => {
      let _time = new Date().getTime()
      let delay = _time - time
      delay = delay < 3000 ? 3000 - delay : 0
 
      setTimeout(() => {
        this.setState({visible: false})
        this.reloading = false
  
        Modal.success({
          title: '更新成功。',
        })
  
        if (list && list.length && list.includes(this.state.tabview.MenuID)) {
          MKEmitter.emit('reloadMenuView', this.state.tabview.MenuID)
        }
      }, delay)
    }, (message) => {
      let _time = new Date().getTime()
      let delay = _time - time
      delay = delay < 3000 ? 3000 - delay : 0
 
      setTimeout(() => {
        this.setState({visible: false})
        this.reloading = false
        Modal.error({
          title: message || '系统配置更新失败!',
        })
      }, delay)
    })
  }
 
  render () {
    const { tabview, hasNavBar, visible } = this.state
 
    return (
      <section id="mk-tabgroup-wrap" className="mk-breadview-wrap">
        {hasNavBar && tabview ? <Breadcrumb separator="">
          <Breadcrumb.Item>
            <HomeOutlined onClick={this.gotoHome} />
          </Breadcrumb.Item>
          {tabview.ParentNames && tabview.ParentNames[0] ?
            <Breadcrumb.Item>{tabview.ParentNames[0]}</Breadcrumb.Item> : null}
          {tabview.ParentNames && tabview.ParentNames[0] ?
              <Breadcrumb.Separator children={<RightOutlined />} /> : null}
          {tabview.ParentNames && tabview.ParentNames[1] ?
            <Breadcrumb.Item>{tabview.ParentNames[1]}</Breadcrumb.Item> : null}
          {tabview.ParentNames && tabview.ParentNames[1] ?
              <Breadcrumb.Separator children={<RightOutlined />} /> : null}
          <Breadcrumb.Item><RedoOutlined onClick={this.refreshTabview}/>{tabview.MenuName}</Breadcrumb.Item>
        </Breadcrumb> : null}
        {tabview ? this.selectcomponent(tabview) : null}
        <BackTop>
          <div className="ant-back-top">
            <div className="ant-back-top-content">
              <div className="ant-back-top-icon"></div>
            </div>
          </div>
        </BackTop>
        <Modal
          visible={visible}
          width={400}
          closable={false}
          centered={true}
          footer={null}
          destroyOnClose
        >
          <div className="mk-menus-update">
            <div className="tip">
              系统更新中,请稍后
            </div>
            <LoadingOutlined />
          </div>
        </Modal>
      </section>
    )
  }
}
 
export default BreadView