Skip to content

Commit

Permalink
chore: 删除接口调用
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-void0 committed Apr 3, 2023
1 parent 25368bb commit 29f1e4d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cta-template-admin",
"version": "1.3.3",
"version": "1.3.4",
"description": "基于react18的模板项目,支持路由keepalive,历史访问页签等",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 8 additions & 4 deletions template/src/components/HeaderRight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { Avatar, Button, Popover, Space, Typography } from 'antd'

import { FC, useRef } from 'react'
import styles from './index.module.css'
import { reqLoginOut } from '@/api'
// import { reqLoginOut } from '@/api'
import { useGlobal } from '@/core'
import { useNavigate } from 'react-router'
import UserModal, { UserModalRef } from '../UserModal'

const HeaderRight: FC<any> = () => {
const userModalRef = useRef<UserModalRef>(null)
const { globalState } = useGlobal()
const { globalState, dispatch } = useGlobal()
const navigator = useNavigate()

function handleLoginOut() {
reqLoginOut().then(() => navigator('/login'))
// reqLoginOut().then(() => navigator('/login'))
dispatch({
...globalState,
userInfo: {}
})
setTimeout(() => navigator('/login'), 1000)
}

function handleOpenModal() {
Expand Down
10 changes: 5 additions & 5 deletions template/src/config/core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import HeaderRight from '@/components/HeaderRight'
import IconLogo from '@/assets/img/logo.svg'
import { InitialStateType } from '@/core/context/global'
import { LayoutProProps } from '@/core/Layout'
import { reqGetUserInfo } from '@/api'
// import { reqGetUserInfo } from '@/api'

// layout配置
export const layoutSettings: LayoutProProps = {
Expand All @@ -19,10 +19,10 @@ export const getInitialState = async (): Promise<InitialStateType> => {
}

// 获取用户登录信息
const userRes = await reqGetUserInfo()
if (userRes.data) {
values.userInfo = userRes.data
}
// const userRes = await reqGetUserInfo()
// if (userRes.data) {
// values.userInfo = userRes.data
// }

return values
}
2 changes: 1 addition & 1 deletion template/src/config/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const proxyTarget = {
user: 'http://127.0.0.1:3003/'
user: 'http://thomas-void0.tech:3003'
}
export default proxyTarget
1 change: 1 addition & 0 deletions template/src/core/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const BASE_CONFIG: CreateAxiosDefaults<any> = {
}
}

// 添加auth token,如果有必要的话
const TOKEN_KEY = '@@cta-template-admin-authorization'

const request = new AxiosPro(BASE_CONFIG)
Expand Down
29 changes: 20 additions & 9 deletions template/src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Form, Input, message } from 'antd'
import { reqLogin } from '@/api'
// import { reqLogin } from '@/api'
import { useNavigate } from 'react-router'
import { useGlobal } from '@/core'

Expand All @@ -8,16 +8,27 @@ const Login = () => {
const { globalState, dispatch } = useGlobal()

const onFinish = (values: any) => {
reqLogin(values).then(res => {
const { success, msg, data } = res
if (success && data) {
message.success('登录成功')
dispatch({ ...globalState, userInfo: data })
setTimeout(() => navigate('/'), 0)
} else {
message.error(msg)
// reqLogin(values).then(res => {
// const { success, msg, data } = res
// if (success && data) {
// message.success('登录成功')
// dispatch({ ...globalState, userInfo: data })
// setTimeout(() => navigate('/'), 0)
// } else {
// message.error(msg)
// }
// })

message.success('登录成功')
dispatch({
...globalState,
userInfo: {
userId: '1',
nickName: 'Thomas',
headImgUrl: 'https://avatars.githubusercontent.com/u/48620706?v=4'
}
})
setTimeout(() => navigate('/'), 500)
}

return (
Expand Down

1 comment on commit 29f1e4d

@vercel
Copy link

@vercel vercel bot commented on 29f1e4d Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.