king
2022-10-08 9c6795fd3c44e46cf3955fbfd8f8eeca23acb7a9
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
import React, {Component} from 'react'
import { BackTop, Breadcrumb, notification} from 'antd'
import { HomeOutlined, RightOutlined, RedoOutlined } from '@ant-design/icons'
import moment from 'moment'
import 'moment/locale/zh-cn'
 
import asyncComponent from '@/utils/asyncLoadComponent'
import NotFount from '@/components/404'
import options from '@/store/options.js'
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 CalendarPage = asyncComponent(() => import('@/tabviews/calendar'))
const TreePage = asyncComponent(() => import('@/tabviews/treepage'))
const Iframe = asyncComponent(() => import('@/tabviews/iframe'))
const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage'))
const FormTab = asyncComponent(() => import('@/tabviews/formtab'))
 
class BreadView extends Component {
  state = {
    tabview: null, // 标签
    hasNavBar: window.GLOB.navBar === 'linkage_navigation'
  }
 
  refreshTabview = () => {
    const { tabview } = this.state
    window.GLOB.CacheMap = new Map()
 
    if (options.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)
    }
  }
 
  selectcomponent = (view) => {
    // 根据tab页中菜单信息,选择所需的组件
    if (view.type === 'Home') {
      return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
    } else if (view.type === 'CommonTable') {
      return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    // } else if (view.type === 'BaseTable') {
    //   return (<BaseTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'CustomPage') {
      return (<CustomPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'TreePage') {
      return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'CalendarPage') {
      return (<CalendarPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'RolePermission') {
      return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>)
    } else if (view.type === 'FormTab') {
      return (<FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>)
    } else if (view.type === 'iframe') {
      return (<Iframe key={view.MenuID} MenuID={view.MenuID} MenuNo={view.MenuNo} title={view.MenuName} MenuName={view.MenuName} url={window.GLOB.baseurl + 'zh-CN/' + view.LinkUrl}/>)
    } else {
      return (<NotFount key={view.MenuID} />)
    }
  }
 
  UNSAFE_componentWillMount () {
    if (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') {
      moment.locale('zh-cn')
    } else {
      moment.locale('en')
    }
 
    let home = {
      MenuID: 'home_page_id',
      MenuName: '首页',
      type: 'Home'
    }
    this.setState({tabview: home})
  }
 
  gotoHome = () => {
    let home = {
      MenuID: 'home_page_id',
      MenuName: '首页',
      type: 'Home'
    }
    this.setState({tabview: home})
  }
 
  modifyTabs = (tab, type) => {
    if (!tab || type !== 'replace') return
 
    this.setState({
      tabview: tab,
    })
 
    let node = document.getElementById('root').parentNode.parentNode
    if (node) {
      node.scrollTop = 0
    }
  }
 
  componentDidMount () {
    MKEmitter.addListener('modifyTabs', this.modifyTabs)
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('modifyTabs', this.modifyTabs)
  }
 
  render () {
    const { tabview, hasNavBar } = this.state
 
    return (
      <section id="mk-breadview-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>
      </section>
    )
  }
}
 
export default BreadView