king
2022-07-20 ed7d889f7d9dfca77fd7f055ad8d6ec6ad85ae91
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
import React, {Component} from 'react'
import {HashRouter, Switch, Route, Redirect} from 'react-router-dom'
import md5 from 'md5'
import moment from 'moment'
import { styles } from '@/store/options.js'
import asyncComponent from '@/utils/asyncComponent'
import asyncLoadComponent from '@/utils/asyncLoadComponent'
 
const Pay = asyncLoadComponent(() => import('@/views/pay'))
const Sso = asyncLoadComponent(() => import('@/views/sso'))
const Main = asyncLoadComponent(() => import('@/views/main'))
const Design = asyncLoadComponent(() => import('@/views/design'))
const Login = asyncLoadComponent(() => import('@/views/login'))
const NotFound = asyncComponent(() => import('@/views/404'))
const AppManage = asyncLoadComponent(() => import('@/views/appmanage'))
const AppCheck = asyncLoadComponent(() => import('@/views/appcheck'))
const PCDesign = asyncLoadComponent(() => import('@/views/pcdesign'))
const MobDesign = asyncLoadComponent(() => import('@/views/mobdesign'))
const ImDesign = asyncLoadComponent(() => import('@/views/imdesign'))
const MenuDesign = asyncLoadComponent(() => import('@/views/menudesign'))
const BillPrint = asyncLoadComponent(() => import('@/views/billprint'))
const PrintT = asyncLoadComponent(() => import('@/views/printTemplate'))
const Interface = asyncLoadComponent(() => import('@/views/interface'))
const RoleManage = asyncLoadComponent(() => import('@/views/rolemanage'))
 
const routers = [
  {path: '/login', name: 'login', component: Login, auth: false},
  {path: '/pay/:param', name: 'pay', component: Pay, auth: false},
  {path: '/print/:param', name: 'print', component: PrintT, auth: false},
  {path: '/ssologin/:param', name: 'ssologin', component: Sso, auth: false},
  {path: '/main', name: 'main', component: Main, auth: true},
  {path: '/design', name: 'design', component: Design, auth: true},
  {path: '/appmanage', name: 'appmanage', component: AppManage, auth: true},
  {path: '/appcheck', name: 'appcheck', component: AppCheck, auth: true},
  {path: '/pcdesign/:param', name: 'pcdesign', component: PCDesign, auth: true},
  {path: '/mobdesign/:param', name: 'mobdesign', component: MobDesign, auth: true},
  {path: '/imdesign/:param', name: 'imdesign', component: ImDesign, auth: true},
  {path: '/menudesign/:param', name: 'menudesign', component: MenuDesign, auth: true},
  {path: '/billprint/:param', name: 'billprint', component: BillPrint, auth: true},
  {path: '/docprint/:menuId', name: 'docprint', component: BillPrint, auth: false},
  {path: '/docprint/:menuId/:id', name: 'docprint', component: BillPrint, auth: false},
  {path: '/paramsmain/:param', name: 'pmain', component: Main, auth: true},
  {path: '/role/:param', name: 'role', component: RoleManage, auth: true},
  {path: '/interface', name: 'interface', component: Interface, auth: true}
]
 
export default class RouteConfig extends Component {
  controlRoute (item, props) {
    if (!item.auth) {            // 不需要授权,直接跳转
      return (<item.component {...props}/>)
    }
 
    if (item.name === 'pmain') { // 新窗口打开,取url参数放入sessionStorage
      try {
        let _param = JSON.parse(window.decodeURIComponent(window.atob(props.match.params.param)))
 
        if (typeof(_param) === 'object') {
          _param.UserID && sessionStorage.setItem('UserID', _param.UserID)
          _param.LoginUID && sessionStorage.setItem('LoginUID', _param.LoginUID)
          _param.User_Name && sessionStorage.setItem('User_Name', _param.User_Name)
          _param.Full_Name && sessionStorage.setItem('Full_Name', _param.Full_Name)
          _param.debug && sessionStorage.setItem('debug', _param.debug)
          _param.dataM && sessionStorage.setItem('dataM', _param.dataM)
          _param.dataM && sessionStorage.setItem('localDataM', _param.dataM)
          _param.avatar && sessionStorage.setItem('avatar', _param.avatar)
          _param.role_id && sessionStorage.setItem('role_id', _param.role_id)
          _param.dataM && sessionStorage.setItem('localRole_id', _param.dataM)
          _param.Member_Level && sessionStorage.setItem('Member_Level', _param.Member_Level)
          _param.ThirdMenu && sessionStorage.setItem('ThirdMenu', _param.ThirdMenu)
 
          window.GLOB.mainlogo = _param.mainlogo || ''
          window.GLOB.navBar = _param.navBar || ''
 
          if (_param.mstyle && styles[_param.mstyle]) {
            document.body.className = styles[_param.mstyle]
          }
        }
      } catch (e) {
        console.warn('菜单参数解析错误!')
      }
 
      return (<item.component {...props}/>)
    }
    
    let userId = sessionStorage.getItem('UserID') // 判断是否存在userid
 
    let authCode = localStorage.getItem(window.location.href.split('#')[0] + 'AuthCode') // 判断系统是否在授权期限内
    let _s = md5('mksoft' + moment().format('YYYYMMDD'))
    let isauth = authCode && authCode.includes(_s)
    let key = md5(window.GLOB.appId + 'minke_software' + window.GLOB.appkey).toUpperCase().substr(-6)
    let key1 = window.GLOB.licenseKey ? window.GLOB.licenseKey.substring(0, 6) : ''
 
    if (key1 === key) {
      isauth = true
    }
 
    if (userId && isauth) {
      return (<item.component {...props}/>)
    } else {
      // return (<Redirect to={{ pathname: '/login', state: {from: props.location}}}/>)
      return (<Redirect to={{ pathname: '/login'}}/>)
    }
  }
 
  render () {
    return (
      <HashRouter>
        <Switch>
          {routers.map((item, index) => <Route key={index} path={item.path} name={item.name} exact render={ props => this.controlRoute(item, props)}/>)}
          <Redirect exact from="/" to="login"/>
          <Route component= {NotFound}/>
        </Switch>
      </HashRouter>
    )
  }
}