king
2022-12-08 a29edbd4c670e1907e38e98f20257e5519745a4d
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
import React, {Component} from 'react'
import {HashRouter, Switch, Route, Redirect} from 'react-router-dom'
import md5 from 'md5'
import moment from 'moment'
import asyncComponent from '@/utils/asyncComponent'
import asyncLoadComponent from '@/utils/asyncLoadComponent'
 
const Login = asyncLoadComponent(() => import('@/views/login'))
const Main = asyncLoadComponent(() => import('@/views/main'))
const Sso = asyncLoadComponent(() => import('@/views/sso'))
const Pay = asyncLoadComponent(() => import('@/views/pay'))
const MainParams = asyncLoadComponent(() => import('@/views/mainparams'))
const Design = asyncLoadComponent(() => import('@/views/design'))
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 BaseDesign = asyncLoadComponent(() => import('@/views/basedesign'))
const TableDesign = asyncLoadComponent(() => import('@/views/tabledesign'))
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 SystemFunc = asyncLoadComponent(() => import('@/views/systemfunc'))
const SystemProc = asyncLoadComponent(() => import('@/views/systemproc'))
 
const routers = [
  {path: '/login', name: 'login', component: Login, auth: false},
  {path: '/main', name: 'main', component: Main, auth: true},
  {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: '/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: '/basedesign/:param', name: 'basedesign', component: BaseDesign, auth: true},
  {path: '/tabledesign/:param', name: 'tabledesign', component: TableDesign, 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: '/tab/:menuId', name: 'tab', component: MainParams, auth: false},
  {path: '/role/:param', name: 'role', component: RoleManage, auth: true},
  {path: '/hs', name: 'hs', component: SystemFunc, auth: true},
  {path: '/proc', name: 'proc', component: SystemProc, 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}/>)
    }
    
    let userId = sessionStorage.getItem('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'}}/>)
    }
  }
 
  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>
    )
  }
}