Browse Source

Merge branch 'master' of http://192.168.1.41:3000/lanjianrong/management

# Conflicts:
#	package-lock.json
caipin 4 years ago
parent
commit
8ab8db580d

+ 0 - 6
config/webpack.config.js

@@ -394,12 +394,6 @@ module.exports = function(webpackEnv) {
                         },
                       },
                     },
-                  ],
-                  [
-                    require.resolve('@babel/plugin-proposal-decorators'),
-                    {
-                        legacy: true
-                    }
                   ]
                 ],
                 // This is a feature of `babel-loader` for webpack (not Babel itself).

File diff suppressed because it is too large
+ 20729 - 0
package-lock.json


+ 7 - 2
package.json

@@ -2,7 +2,6 @@
   "name": "management",
   "version": "0.1.0",
   "private": true,
-  "homepage": ".",
   "proxy": "http://cm.com",
   "scripts": {
     "dev": "node scripts/start.js",
@@ -82,6 +81,12 @@
           "libraryName": "antd",
           "style": "css"
         }
+      ],
+      [
+        "@babel/plugin-proposal-decorators",
+        {
+          "legacy": true
+        }
       ]
     ]
   },
@@ -100,6 +105,7 @@
     "@types/react-redux": "^7.1.9",
     "@types/react-router-dom": "^5.1.5",
     "@types/redux": "^3.6.0",
+    "@types/redux-thunk": "^2.1.0",
     "@typescript-eslint/eslint-plugin": "^4.1.1",
     "@typescript-eslint/parser": "^4.1.1",
     "babel-jest": "^24.9.0",
@@ -166,7 +172,6 @@
   },
   "dependencies": {
     "@ant-design/icons": "^4.2.2",
-    "@types/redux-thunk": "^2.1.0",
     "antd": "^4.6.4",
     "axios": "^0.20.0",
     "nprogress": "^0.2.0",

+ 8 - 1
src/components/AsyncModuleLoader/index.tsx

@@ -1,3 +1,4 @@
+import NProgress from 'nprogress'
 import React from 'react'
 
 export interface AyncModuleLoaderState {
@@ -10,6 +11,7 @@ export default function AyncModuleLoader(importComponent: any) {
             this.state = {
                 asyncComponent: null
             }
+            NProgress.start()
         }
         async componentDidMount() {
             if (this.state.asyncComponent) {
@@ -19,9 +21,14 @@ export default function AyncModuleLoader(importComponent: any) {
             this.setState({
                 asyncComponent: component
             })
+            NProgress.done()
+        }
+
+        componentWillUnmount() {
+            NProgress.start()
         }
         render() {
-            const {asyncComponent:Component} = this.state
+            const { asyncComponent:Component } = this.state
             return Component ? <Component {...this.props} /> : null
         }
     }

+ 31 - 54
src/components/Menu/index.tsx

@@ -1,31 +1,21 @@
 import logo from '@/assets/img/logo.png'
 import { RootState } from '@/store/reducers'
 import { iMenuItem } from '@/types/router'
-import consts from '@/utils/consts'
-import { Button, Dropdown, Menu, message } from "antd"
+import { Button, Dropdown, Menu } from "antd"
 import React from 'react'
 import { connect } from 'react-redux'
-import { Link, RouteComponentProps, withRouter } from "react-router-dom"
-import { apiLogout } from './api'
+import { Link } from "react-router-dom"
+import store from 'store'
 import styles from './index.module.scss'
 import './index.scss'
 import MenuItem from './MenuItem'
-interface iMenuProps extends RouteComponentProps{
+interface iMenuProps {
   list: iMenuItem[],
-  history: any
+  username: string
 }
-const NavSider:React.FC<iMenuProps> = (props)=> {
-  console.log(props)
 
-  const { list: MeunList, history } = props
-  const handleLogout = async () => {
-    const { code = -1, msg = '登出错误' } = await apiLogout()
-      if (code !== consts.RET_CODE.SUCCESS) {
-        return message.error(msg)
-      }
-      // dispatch(delUserInfo)
-      history.push('/login')
-  }
+const NavSider:React.FC<iMenuProps> = (props)=> {
+  const { list: MeunList, username } = props
   return (
     <div className="main-nav">
       <div className="logo"><img src={logo}></img></div>
@@ -44,26 +34,8 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
             )
           }
           <div className="pi-text-center">
-            <Dropdown overlay={() => {
-                return (
-                  <Menu>
-                    <Menu.Item key="0">
-                      <Link to="/acount/safe">账号资料</Link>
-                    </Menu.Item>
-                    <Menu.Item key="1">
-                      <Link to="/acount/safe">账号安全</Link>
-                    </Menu.Item>
-                    <Menu.Divider />
-                    <Menu.Item key="2">
-                      <Link to="/acount/safe">帮助中心</Link>
-                    </Menu.Item>
-                    <Menu.Item key="3">
-                      <span onClick={handleLogout}>退出登录</span>
-                    </Menu.Item>
-                  </Menu>
-                )
-            }} trigger={[ 'click' ]} placement="topRight">
-              <Button size="small" className={styles.bottomBtn} onClick={handleLogout}>张三</Button>
+            <Dropdown overlay={DropMenu} trigger={[ 'click' ]} placement="topRight">
+              <Button size="small" className={styles.bottomBtn}>{username}</Button>
             </Dropdown>
           </div>
         </div>
@@ -71,24 +43,29 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
     </div>
   )
 }
-const mapStateToProps = (state: RootState) => {
-  const { userInfo } = state
+const mapStateToProps = (state:RootState) => {
   return {
-    userInfo
+    username: state.user.userInfo.Name
   }
 }
 
-// const mapDispatchToProps = (dispatch: Dispatch<AnyAction>) => {
-//   return {
-//     logoutBtnClick: async (history) => {
-//       const { code = -1, msg = '登出错误' } = await apiLogout()
-//       if (code !== consts.RET_CODE.SUCCESS) {
-//         return message.error(msg)
-//       }
-//       dispatch(delUserInfo)
-//       history.push('/login')
-//     }
-//   }
-// }
-const connector = connect(mapStateToProps)
-export default withRouter(connector(NavSider))
+const DropMenu = () => {
+  return (
+    <Menu>
+      <Menu.Item key="0">
+        <Link to="/acount/safe">账号资料</Link>
+      </Menu.Item>
+      <Menu.Item key="1">
+        <Link to="/acount/safe">账号安全</Link>
+      </Menu.Item>
+      <Menu.Divider />
+      <Menu.Item key="2">
+        <Link to="/acount/safe">帮助中心</Link>
+      </Menu.Item>
+      <Menu.Item key="3">
+        <span onClick={store.dispatch()}>退出登录</span>
+      </Menu.Item>
+    </Menu>
+  )
+}
+export default connect(mapStateToProps)(NavSider)

+ 172 - 73
src/pages/Login/index.tsx

@@ -1,100 +1,199 @@
 import logo from '@/assets/img/loginlogo.png'
+import { initUserState, updateUserInfo } from '@/store/modules/user'
+import { iUserInfo } from '@/store/modules/user/types'
+import { RootState } from '@/store/reducers'
 import { iFromValues, iLoginProps, iRetrieveFormProps } from '@/types/login'
 import consts from '@/utils/consts'
 import { Button, Form, Input, Modal } from 'antd'
-import React, { useEffect, useState } from 'react'
+import React, { Component } from 'react'
+import { connect } from 'react-redux'
 import { RouteComponentProps, withRouter } from 'react-router-dom'
 import { apiLogin, apiProject } from "./api"
 import styles from './index.module.scss'
 import './index.scss'
 
 // 正常登录Form表单
-interface iProjectInfo {
-  id?: number
-  code?: number
-  name?: string
+const initLoginState = {
+  projectInfo: '',
+  projectCode: '',
+  visible: false,
+  user: initUserState.userInfo
 }
-const NormalLoginForm:React.FC<iLoginProps> = ({ history }) => {
-  let timer: any = null
-  const [ projectInfo, setProjectInfo ] = useState('')
-  const [ visible, setVisible ] = useState(false)
-  const [ projectAnimation, setProjectAnimation ] = useState(false) // 控制project-title的动画显示
-  const onFinish = async (values: iFromValues) => {
+type iState = typeof initLoginState
+const mapStateToProps = (state: RootState) => {
+  return {}
+}
+const mapDispathToProps = {
+  saveUser(user: iUserInfo) {
+    return updateUserInfo(user)
+  }
+}
+// @ts-ignore
+@connect(mapStateToProps, mapDispathToProps)
+class NormalLoginForm extends Component<iLoginProps, iState> {
+
+  constructor(props: iLoginProps) {
+    super(props)
+    this.state = initLoginState
+  }
+  onFinish = async (values: iFromValues) => {
     const { code = -1, data }  = await apiLogin(values)
     if (code === consts.RET_CODE.SUCCESS) {
-      // store.dispatch({ type: SAVE_USER_INFO, payload: data })
-      // store.dispatch({ type: SAVE_PERMISSION, payload: { isLogin: true, permission: data.Role } })
-      history.push('/')
+      this.setState({ user: data })
+      this.props.history!.push('/')
     }
   }
 
-  const handleProjectCode = (e: any) => {
-    if (timer) clearTimeout(timer)
+  componentWillUnmount() {
+    this.props.saveUser!(this.state.user)
+  }
+  handleProjectCode = async (e: any) => {
     const projectCode = e.target?.value
-    !projectCode && (setProjectInfo(''))
-    timer = setTimeout(() => {
-      projectCode && apiProject(projectCode).then(({ code = -1, data }) => {
-        if (code === consts.RET_CODE.SUCCESS) {
-          if (data.length) {
-            const project: iProjectInfo = data[0]
-            project.name && setProjectInfo(project.name)
-          } else {
-            setProjectInfo('')
-          }
-        }
-      })
-    }, 300)
+    const { code = -1, data = [] } = await apiProject(projectCode)
+    if (code === consts.RET_CODE.SUCCESS) {
+      if (data.length && data[0].name) {
+        this.setState({ projectInfo: data[0].name })
+      }
+    }
+
   }
-  const handleForgetPsw = () => {
-    setVisible(!visible)
+  setVisible = (label: boolean) => {
+    this.setState({ visible: label })
   }
 
-useEffect(() => {
-  if (projectInfo) {
-    setProjectAnimation(false)
-  } else {
-    setProjectAnimation(true)
+  handleForgetPsw = () => {
+    this.setState({ visible: !this.state.visible })
   }
-}, [ projectInfo ])
-  return (
-    <Form
-      name="normal_login"
-      className={styles.loginForm}
-      initialValues={{ remember: true }}
-      onFinish={onFinish}
-    >
-      <h4>纵横工程建设项目管理系统</h4>
-      <h5 className={[ 'project-title', projectAnimation ? 'scale-out-ver-bottom' : 'scale-in-ver-bottom' ].join(' ')} >{projectInfo}</h5>
-      <Form.Item
-        name="code"
-        rules={[ { required: true, message: 'Please input your Project!' } ]}
-      >
-        <Input placeholder="项目编号" onChange={handleProjectCode}/>
-      </Form.Item>
-      <Form.Item
-        name="account"
-        rules={[ { required: true, message: 'Please input your Account!' } ]}
-      >
-        <Input placeholder="登录账号" />
-      </Form.Item>
-      <Form.Item
-        name="password"
-        rules={[ { required: true, message: 'Please input your Password!' } ]}
+
+  render() {
+    const { projectInfo } = this.state
+    return (
+      <Form
+        name="normal_login"
+        className={styles.loginForm}
+        initialValues={{ remember: true }}
+        onFinish={this.onFinish}
       >
-        <Input.Password type="password" placeholder="密码"
-        />
-      </Form.Item>
+        <h4>纵横工程建设项目管理系统</h4>
+        <h5 className={[ 'project-title' ].join(' ')} >{projectInfo}</h5>
+        <Form.Item
+          name="code"
+          rules={[ { required: true, message: 'Please input your Project!' } ]}
+        >
+          <Input placeholder="项目编号" onChange={this.handleProjectCode}/>
+        </Form.Item>
+        <Form.Item
+          name="account"
+          rules={[ { required: true, message: 'Please input your Account!' } ]}
+        >
+          <Input placeholder="登录账号" />
+        </Form.Item>
+        <Form.Item
+          name="password"
+          rules={[ { required: true, message: 'Please input your Password!' } ]}
+        >
+          <Input.Password type="password" placeholder="密码"
+          />
+        </Form.Item>
 
-      <Form.Item>
-        <Button type="primary" htmlType="submit">登录</Button>
-      </Form.Item>
-      <div className={styles.textRight}>
-        <span onClick={handleForgetPsw}>忘记密码?</span>
-      </div>
-      <RetrieveForm visible={visible} setVisible={setVisible}></RetrieveForm>
-    </Form>
-  )
+        <Form.Item>
+          <Button type="primary" htmlType="submit">登录</Button>
+        </Form.Item>
+        <div className={styles.textRight}>
+          <span onClick={this.handleForgetPsw}>忘记密码?</span>
+        </div>
+        <RetrieveForm visible={this.state.visible} setVisible={this.setVisible}></RetrieveForm>
+      </Form>
+    )
+  }
 }
+// const NormalLoginForm:React.FC<iLoginProps> = ({ history }) => {
+//   let timer: any = null
+//   const [ projectInfo, setProjectInfo ] = useState('')
+//   const [ visible, setVisible ] = useState(false)
+//   const [ user, setUser ] = useState(initUserState.userInfo)
+//   const [ projectAnimation, setProjectAnimation ] = useState(false) // 控制project-title的动画显示
+//   const onFinish = async (values: iFromValues) => {
+//     const { code = -1, data }  = await apiLogin(values)
+//     if (code === consts.RET_CODE.SUCCESS) {
+//       console.log('data', data)
+
+//       setUser(data)
+//     }
+//   }
+//   useEffect(() => {
+//     history.push('/')
+//     return () => {
+//       store.dispatch({ type: SAVE_USER_INFO, payload: user })
+//     }
+//   }, [ user ])
+//   const handleProjectCode = (e: any) => {
+//     if (timer) clearTimeout(timer)
+//     const projectCode = e.target?.value
+//     !projectCode && (setProjectInfo(''))
+//     timer = setTimeout(() => {
+//       projectCode && apiProject(projectCode).then(({ code = -1, data }) => {
+//         if (code === consts.RET_CODE.SUCCESS) {
+//           if (data.length) {
+//             const project: iProjectInfo = data[0]
+//             project.name && setProjectInfo(project.name)
+//           } else {
+//             setProjectInfo('')
+//           }
+//         }
+//       })
+//     }, 300)
+//   }
+//   const handleForgetPsw = () => {
+//     setVisible(!visible)
+//   }
+
+// useEffect(() => {
+//   if (projectInfo) {
+//     setProjectAnimation(false)
+//   } else {
+//     setProjectAnimation(true)
+//   }
+// }, [ projectInfo ])
+//   return (
+//     <Form
+//       name="normal_login"
+//       className={styles.loginForm}
+//       initialValues={{ remember: true }}
+//       onFinish={onFinish}
+//     >
+//       <h4>纵横工程建设项目管理系统</h4>
+//       <h5 className={[ 'project-title', projectAnimation ? 'scale-out-ver-bottom' : 'scale-in-ver-bottom' ].join(' ')} >{projectInfo}</h5>
+//       <Form.Item
+//         name="code"
+//         rules={[ { required: true, message: 'Please input your Project!' } ]}
+//       >
+//         <Input placeholder="项目编号" onChange={handleProjectCode}/>
+//       </Form.Item>
+//       <Form.Item
+//         name="account"
+//         rules={[ { required: true, message: 'Please input your Account!' } ]}
+//       >
+//         <Input placeholder="登录账号" />
+//       </Form.Item>
+//       <Form.Item
+//         name="password"
+//         rules={[ { required: true, message: 'Please input your Password!' } ]}
+//       >
+//         <Input.Password type="password" placeholder="密码"
+//         />
+//       </Form.Item>
+
+//       <Form.Item>
+//         <Button type="primary" htmlType="submit">登录</Button>
+//       </Form.Item>
+//       <div className={styles.textRight}>
+//         <span onClick={handleForgetPsw}>忘记密码?</span>
+//       </div>
+//       <RetrieveForm visible={visible} setVisible={setVisible}></RetrieveForm>
+//     </Form>
+//   )
+// }
 
 // 找回密码Form表单
 const RetrieveForm:React.FC<iRetrieveFormProps>= ({ visible, setVisible }) => {

+ 0 - 2
src/pages/Management/index.tsx

@@ -5,8 +5,6 @@ import { Switch } from 'react-router-dom'
 import LeftSide from './components/leftSide'
 const Management:React.FC<NavigationGuardsProps> = props => {
   const { routeConfig, match, location } = props
-  console.log(props)
-
   return (
     <>
       <LeftSide childRoutes={routeConfig}></LeftSide>

+ 10 - 18
src/router/Guard.tsx

@@ -1,31 +1,23 @@
-import { checkPermission } from '@/store/modules/permission'
+import { checkPermission } from '@/store/modules/user'
 import { RootState } from '@/store/reducers'
 import { NavigationGuardsProps, RouteModol } from '@/types/router'
-import NProgress from 'nprogress'
 import React, { Dispatch, useEffect } from 'react'
 import { connect } from 'react-redux'
 import { Redirect, Route } from "react-router-dom"
 import { AnyAction } from 'redux'
-const NavigationGuards:React.FC<NavigationGuardsProps> = props => {
-  const { location, routeConfig, match, permission, check } = props
-  // check()
-  // console.log(props)
 
+const NavigationGuards:React.FC<NavigationGuardsProps> = props => {
+  const { location, routeConfig, match, check, permission, isLogin } = props
+  useEffect(() => {
+    check()
+  }, [])
   const parentPath: string | null = match?.path || null // 父路由的路径
   const targetPath: string | null  = location?.pathname || null// 目标路由的位置
   const targetRoute: RouteModol | null = targetPath && findTargetRoute(parentPath, targetPath, routeConfig) || null
 
-  const isLogin = permission.isLogin // 是否已登录
-
-  NProgress.start()
-  useEffect(() => {
-    NProgress.done()
-  })
-
   // 利用重定向使 / 访问/dashboard路由
   if (targetRoute && targetRoute.redirect) {
     const redirectPath = combinationRedirect(parentPath, targetRoute.redirect)
-
     return <Redirect to={redirectPath}/>
   }
 
@@ -112,11 +104,10 @@ function findTargetRoute (parentPath: any, targetPath: string, routeConfig: Rout
 function LoginHandler(props: any) {
   const { targetRoute } = props
   const { path } = targetRoute
-
   if (path === '/login') {
     return <Redirect to="/"></Redirect>
   } else {
-    return <Route path={targetRoute.path} render={
+    return <Route path={path} render={
       props => (
         <targetRoute.component {...props} routeConfig={targetRoute.childRoutes}/>
       )
@@ -142,9 +133,10 @@ function NotLoginHandler(props: any) {
 }
 
 const mapStateToProps = (state: RootState) => {
-  const { permission } = state
+  const { permission, isLogin } = state.user
   return {
-    permission
+    permission,
+    isLogin
   }
 }
 

+ 12 - 2
src/store/index.ts

@@ -1,9 +1,19 @@
-import { applyMiddleware, createStore } from 'redux'
+import { applyMiddleware, compose, createStore } from 'redux'
+import createSagaMiddleware from "redux-saga"
 import thunk from 'redux-thunk'
 import rootReducer from './reducers'
+
+//添加中间件和调试工具
+const sagaMiddleware = createSagaMiddleware()
+const composeEnhancers =
+    typeof window === 'object' &&
+    (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
+        (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose
+
+
 const store = createStore(
   rootReducer,
-  applyMiddleware(thunk)
+  composeEnhancers(applyMiddleware(thunk, sagaMiddleware))
 )
 
 export default store

+ 0 - 52
src/store/modules/permission/index.ts

@@ -1,52 +0,0 @@
-import { getUserInfo } from './../../../utils/common/user'
-import { CHECK_PERMISSION, DEL_PERMISSION, iPermissionState, PermissionAction, SAVE_PERMISSION } from './types'
-
-const initState: iPermissionState = {
-  isLogin: false,
-  permission: ''
-}
-
-// reducer
-export function updatePermissionReducer(state = initState, action: PermissionAction): iPermissionState {
-  switch (action.type) {
-    case SAVE_PERMISSION:
-      return { ...state, ...action.payload }
-      break
-    case DEL_PERMISSION:
-      return initState
-      break
-    case CHECK_PERMISSION:
-      return { ...state, ...action.payload }
-      break
-    default:
-      return state
-      break
-  }
-}
-
-// action
-export function savePermission(payload: iPermissionState): PermissionAction{
-  return {
-    type: SAVE_PERMISSION,
-    payload
-  }
-}
-
-export function checkPermission(): PermissionAction {
-  const userInfo = getUserInfo()
-  console.log(userInfo)
-
-  return {
-    type: CHECK_PERMISSION,
-    payload: {
-      isLogin: userInfo?.Id ? true : false,
-      permission: []
-    }
-  }
-}
-
-export function delPermission(): PermissionAction {
-  return {
-    type: DEL_PERMISSION
-  }
-}

+ 0 - 28
src/store/modules/permission/types.ts

@@ -1,28 +0,0 @@
-// state
-export type iPermissionState = {
-  isLogin: boolean
-  permission: string | []
-}
-
-
-// action
-export const SAVE_PERMISSION = 'save_permission'
-export const DEL_PERMISSION = 'del_permission'
-export const CHECK_PERMISSION = 'check_permission'
-
-interface SavePermissionAction {
-  type: typeof SAVE_PERMISSION
-  payload: iPermissionState
-}
-
-interface DelPermissionAction {
-  type: typeof DEL_PERMISSION
-}
-
-
-interface CheckPermissionAction {
-  type: typeof CHECK_PERMISSION
-  payload: iPermissionState
-}
-
-export type PermissionAction = SavePermissionAction | DelPermissionAction | CheckPermissionAction

+ 43 - 18
src/store/modules/user/index.ts

@@ -1,26 +1,34 @@
-import { delUserInfo, saveUserInfo } from './../../../utils/common/user'
-import { DEL_USER_INFO, iUserInfo, SAVE_USER_INFO, UserInfoActionTypes } from './types'
-const initState = {
-  Id: '',
-  ProjectId: '',
-  Account: '',
-  Name: '',
-  Company: '',
-  Role: '',
-  Mobile: '',
-  Telephone: '',
-  Csrf: ''
+import { apiLogout } from '@/components/Menu/api'
+import consts from '@/utils/consts'
+import history from '@/utils/history'
+import { delUserInfo, getUserInfo, saveUserInfo } from './../../../utils/common/user'
+import { CHECK_PERMISSION, DEL_USER_INFO, iUserInfo, iUserInfoState, SAVE_USER_INFO, UserInfoActionTypes } from './types'
+export const initUserState: iUserInfoState = {
+  userInfo: {
+    Id: '',
+    ProjectId: '',
+    Account: '',
+    Name: '',
+    Company: '',
+    Role: '',
+    Mobile: '',
+    Telephone: '',
+    Csrf: ''
+  },
+  permission: '',
+  isLogin: false
 }
 // reducer
-export function userInfoReducer(state = initState, action: UserInfoActionTypes): iUserInfo {
+export function userInfoReducer(state = initUserState, action: UserInfoActionTypes): iUserInfoState {
   switch (action.type) {
     case SAVE_USER_INFO:
       saveUserInfo(action.payload)
-      return { ...state, ...action.payload }
+      return { ...state, userInfo: action.payload, isLogin: true, permission: action.payload.Role }
       break
     case DEL_USER_INFO:
-      delUserInfo
-      return { ...state, ...initState }
+      return { ...initUserState }
+    case CHECK_PERMISSION:
+      return { ...action.payload }
     default:
       return state
   }
@@ -34,8 +42,25 @@ export function updateUserInfo(userInfo: iUserInfo): UserInfoActionTypes{
   }
 }
 
-export function deleteUserInfo() {
+export async function deleteUserInfo(): UserInfoActionTypes {
+    const { code = -1 } = await apiLogout()
+    if (code === consts.RET_CODE.SUCCESS) {
+      history.push('/')
+      delUserInfo()
+    }
+    return {
+      type: DEL_USER_INFO
+    }
+}
+
+export function checkPermission(): UserInfoActionTypes {
+  const userInfo: iUserInfo = getUserInfo()
   return {
-    type: DEL_USER_INFO
+    type: CHECK_PERMISSION,
+    payload: {
+      userInfo,
+      isLogin: userInfo && userInfo?.Id ? true : false,
+      permission: userInfo?.Role || ''
+    }
   }
 }

+ 14 - 5
src/store/modules/user/types.ts

@@ -10,11 +10,15 @@ export interface iUserInfo {
   Telephone?: string
   Csrf?: string
 }
-
+export interface iUserInfoState {
+  userInfo: iUserInfo
+  permission: string | []
+  isLogin: boolean
+}
 // action
-export const SAVE_USER_INFO = 'SAVE_USER_INFO'
-export const DEL_USER_INFO = 'DEL_USER_INFO'
-
+export const SAVE_USER_INFO = 'save_user_info'
+export const DEL_USER_INFO = 'del_user_info'
+export const CHECK_PERMISSION = 'check_permission'
 
 interface SaveUserInfoAction {
   type: typeof SAVE_USER_INFO
@@ -25,4 +29,9 @@ interface DelUserInfoAction {
   type: typeof DEL_USER_INFO
 }
 
-export type UserInfoActionTypes = SaveUserInfoAction | DelUserInfoAction
+interface CheckPermissionAction {
+  type: typeof CHECK_PERMISSION
+  payload: iUserInfoState
+}
+
+export type UserInfoActionTypes = SaveUserInfoAction | DelUserInfoAction | CheckPermissionAction

+ 1 - 3
src/store/reducers.ts

@@ -1,9 +1,7 @@
 import { combineReducers } from "redux"
-import { updatePermissionReducer } from './modules/permission'
 import { userInfoReducer } from './modules/user'
 const rootReducer = combineReducers({
-  userInfo: userInfoReducer,
-  permission: updatePermissionReducer
+  user: userInfoReducer
 })
 
 export default rootReducer

+ 1 - 0
src/types/login.ts

@@ -1,5 +1,6 @@
 interface iLoginProps {
   history: any
+  saveUser?: Function
 }
 
 interface iRetrieveFormProps {

+ 2 - 2
src/types/router.ts

@@ -1,5 +1,4 @@
 import { RouteProps } from 'react-router'
-import { iPermissionState } from './../store/modules/permission/types'
 interface RouteModol {
   path: string;
   component?: Object;
@@ -30,7 +29,8 @@ interface NavigationGuardsProps extends RouteProps {
   routeConfig: RouteModol[];
   match?: any;
   location?: any
-  permission: iPermissionState
+  permission: string | []
+  isLogin: boolean
   check: () => void
 }
 export {

+ 0 - 2
src/utils/common/request.ts

@@ -42,8 +42,6 @@ service.interceptors.request.use(
     return request
   },
   err => {
-    console.log(err)
-
     return Promise.reject(err)
   }
 )

+ 2 - 3
src/utils/common/user.ts

@@ -1,7 +1,6 @@
 import { storage } from '@/utils/util'
 import { iUserInfo } from './../../store/modules/user/types'
 const USER_INFO = 'user_info' // 用户个人信息
-
 /**
  * 保存用户信息到本地存储中
  * @param {Object} userInfo - 用户信息
@@ -28,7 +27,7 @@ export const delUserInfo = (): void => {
 /**
  * 用户注销
  */
-export const logout = async () => {
+export const logout = () => {
   delUserInfo()
-
 }
+

+ 3 - 3
src/utils/consts.ts

@@ -6,10 +6,10 @@ export default {
     PROD: ''
   },
   TOKEN_API: '', // 获取token
-  TOKEN_INVALID_CODE: [2, 3], // 接口返回码如果是2/3 则表明token过期或无效 需要自动刷新token
-  TOKEN_WHITE_LIST: ['/api/login'], // 不需要设置token的白名单
+  TOKEN_INVALID_CODE: [ 2, 3 ], // 接口返回码如果是2/3 则表明token过期或无效 需要自动刷新token
+  TOKEN_WHITE_LIST: [ '/api/login' ], // 不需要设置token的白名单
   RET_CODE: { SUCCESS: 0, FAIL: 1, TOKEN_UNDEFINED: 19, TOKEN_EXPIRED: 2 }, // 接口返回状态码
-  RETRY: {COUNT: 3, DELAY: 1000} // 请求重试次数/间隙
+  RETRY: { COUNT: 3, DELAY: 1000 } // 请求重试次数/间隙
 
 }
 

+ 13 - 1
src/utils/util.ts

@@ -35,8 +35,20 @@ const storage = {
   }
 }
 
+const debounce = (fn:Function, debTime: number): any | Promise<void> => {
+  let timer:any = null
+  return (debTime: number,...args:any[]) => {
+    if(timer) clearTimeout(timer)
+    timer = setTimeout(() => {
+        fn.apply(this,...args)
+        timer = null
+      }, debTime)
+  }
+}
+
 export {
   getCookie,
-  storage
+  storage,
+  debounce
 }
 

+ 2 - 0
tsconfig.json

@@ -12,7 +12,9 @@
     "moduleResolution": "node",
     "resolveJsonModule": true,
     "isolatedModules": false,
+    "experimentalDecorators": true,
     "noEmit": true,
+    "noImplicitThis": false,
     "jsx": "react",
     "baseUrl": "./src",
     "paths": {