Explorar el Código

fix: 使用class组件替换登录FC组件

lanjianrong hace 4 años
padre
commit
0c78c2efac

+ 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).

+ 3 - 29
package-lock.json

@@ -2452,6 +2452,7 @@
             "version": "2.1.0",
             "resolved": "https://registry.npmjs.org/@types/redux-thunk/-/redux-thunk-2.1.0.tgz",
             "integrity": "sha1-vCtulylhgxr7gqm/TwZybjUflBY=",
+            "dev": true,
             "requires": {
                 "redux-thunk": "*"
             }
@@ -3695,28 +3696,6 @@
                 }
             }
         },
-        "babel-eslint": {
-            "version": "10.1.0",
-            "resolved": "https://registry.npmjs.org/babel-eslint/-/babel-eslint-10.1.0.tgz",
-            "integrity": "sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==",
-            "dev": true,
-            "requires": {
-                "@babel/code-frame": "^7.0.0",
-                "@babel/parser": "^7.7.0",
-                "@babel/traverse": "^7.7.0",
-                "@babel/types": "^7.7.0",
-                "eslint-visitor-keys": "^1.0.0",
-                "resolve": "^1.12.0"
-            },
-            "dependencies": {
-                "eslint-visitor-keys": {
-                    "version": "1.3.0",
-                    "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
-                    "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
-                    "dev": true
-                }
-            }
-        },
         "babel-extract-comments": {
             "version": "1.0.0",
             "resolved": "https://registry.npmjs.org/babel-extract-comments/-/babel-extract-comments-1.0.0.tgz",
@@ -15460,12 +15439,6 @@
                 "tiny-warning": "^1.0.0"
             }
         },
-        "react-router-redux": {
-            "version": "4.0.8",
-            "resolved": "https://registry.npmjs.org/react-router-redux/-/react-router-redux-4.0.8.tgz",
-            "integrity": "sha1-InQDWWtRUeGCN32rg1tdRfD4BU4=",
-            "dev": true
-        },
         "read-pkg": {
             "version": "3.0.0",
             "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz",
@@ -15567,7 +15540,8 @@
         "redux-thunk": {
             "version": "2.3.0",
             "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-2.3.0.tgz",
-            "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw=="
+            "integrity": "sha512-km6dclyFnmcvxhAcrQV2AkZmPQjzPDjgVlQtR0EQjxZPyJ0BnMf3in1ryuR8A2qU0HldVRfxYXbFSKlI3N7Slw==",
+            "dev": true
         },
         "regenerate": {
             "version": "1.4.1",

+ 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",

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

@@ -21,7 +21,7 @@ export default function AyncModuleLoader(importComponent: any) {
             })
         }
         render() {
-            const {asyncComponent:Component} = this.state
+            const { asyncComponent:Component } = this.state
             return Component ? <Component {...this.props} /> : null
         }
     }

+ 15 - 33
src/components/Menu/index.tsx

@@ -1,10 +1,10 @@
 import logo from '@/assets/img/logo.png'
-import { RootState } from '@/store/reducers'
+import store from '@/store'
+import { deleteUserInfo } from '@/store/modules/user'
 import { iMenuItem } from '@/types/router'
 import consts from '@/utils/consts'
-import { Button, Dropdown, Menu, message } from "antd"
-import React from 'react'
-import { connect } from 'react-redux'
+import { Button, Dropdown, Menu } from "antd"
+import React, { useEffect } from 'react'
 import { Link, RouteComponentProps, withRouter } from "react-router-dom"
 import { apiLogout } from './api'
 import styles from './index.module.scss'
@@ -14,18 +14,20 @@ interface iMenuProps extends RouteComponentProps{
   list: iMenuItem[],
   history: any
 }
-const NavSider:React.FC<iMenuProps> = (props)=> {
-  console.log(props)
 
+const NavSider:React.FC<iMenuProps> = (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)
+      const { code = -1 } = await apiLogout()
+      if (code === consts.RET_CODE.SUCCESS) {
+        history.push('/')
       }
-      // dispatch(delUserInfo)
-      history.push('/login')
   }
+  useEffect(() => {
+    return () => {
+      store.dispatch(deleteUserInfo())
+    }
+  }, [])
   return (
     <div className="main-nav">
       <div className="logo"><img src={logo}></img></div>
@@ -63,7 +65,7 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
                   </Menu>
                 )
             }} trigger={[ 'click' ]} placement="topRight">
-              <Button size="small" className={styles.bottomBtn} onClick={handleLogout}>张三</Button>
+              <Button size="small" className={styles.bottomBtn} >张三</Button>
             </Dropdown>
           </div>
         </div>
@@ -71,24 +73,4 @@ const NavSider:React.FC<iMenuProps> = (props)=> {
     </div>
   )
 }
-const mapStateToProps = (state: RootState) => {
-  const { userInfo } = state
-  return {
-    userInfo
-  }
-}
-
-// 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))
+export default withRouter(NavSider)

+ 2 - 0
src/layout/NavSide/index.tsx

@@ -10,6 +10,8 @@ export default function NavSide(props: any) {
     return { path: combinationPath(match.path, item.path), ...item.menuConfig }
   })
 
+  console.log('333')
+
   return (
     <div className="pi-flex-row">
       <Menu list={menuList}></Menu>

+ 178 - 70
src/pages/Login/index.tsx

@@ -1,8 +1,12 @@
 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'
@@ -14,87 +18,191 @@ interface iProjectInfo {
   code?: number
   name?: string
 }
-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) => {
+
+const initLoginState = {
+  projectInfo: '',
+  projectCode: '',
+  visible: false,
+  user: initUserState
+}
+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<Partial<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) => {
+    console.log(this.props)
+
     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>
-
-      <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>
-  )
+        <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={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 }) => {

+ 8 - 11
src/router/Guard.tsx

@@ -1,4 +1,4 @@
-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'
@@ -6,17 +6,15 @@ 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 { location, routeConfig, match, check, permission, isLogin } = props
 
+  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()
@@ -25,7 +23,6 @@ const NavigationGuards:React.FC<NavigationGuardsProps> = props => {
   // 利用重定向使 / 访问/dashboard路由
   if (targetRoute && targetRoute.redirect) {
     const redirectPath = combinationRedirect(parentPath, targetRoute.redirect)
-
     return <Redirect to={redirectPath}/>
   }
 
@@ -112,11 +109,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 +138,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

+ 33 - 17
src/store/modules/user/index.ts

@@ -1,26 +1,30 @@
-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 { 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 }
+      delUserInfo()
+      return { ...state }
     default:
       return state
   }
@@ -34,8 +38,20 @@ export function updateUserInfo(userInfo: iUserInfo): UserInfoActionTypes{
   }
 }
 
-export function deleteUserInfo() {
+export function deleteUserInfo(): UserInfoActionTypes {
   return {
     type: DEL_USER_INFO
   }
 }
+
+export function checkPermission(): UserInfoActionTypes {
+  const userInfo: iUserInfo = getUserInfo()
+  return {
+    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

+ 2 - 1
src/types/login.ts

@@ -1,5 +1,6 @@
 interface iLoginProps {
   history: any
+  saveUser: () => void
 }
 
 interface iRetrieveFormProps {
@@ -16,5 +17,5 @@ export {
   iLoginProps,
   iRetrieveFormProps,
   iFromValues
-};
+}
 

+ 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()
-
 }
+

+ 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": {