feat:login-设置
This commit is contained in:
parent
51cb4a47cc
commit
7fa8bb49d6
|
@ -13,6 +13,7 @@
|
||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"antd": "^5.16.1",
|
"antd": "^5.16.1",
|
||||||
"axios": "^1.6.8",
|
"axios": "^1.6.8",
|
||||||
|
"js-cookie": "^3.0.5",
|
||||||
"next": "14.1.3",
|
"next": "14.1.3",
|
||||||
"postcss": "8.4.31",
|
"postcss": "8.4.31",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
@ -22,6 +23,7 @@
|
||||||
"tailwindcss": "3.3.3"
|
"tailwindcss": "3.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^18",
|
"@types/react": "^18",
|
||||||
"@types/react-big-calendar": "^1.8.9",
|
"@types/react-big-calendar": "^1.8.9",
|
||||||
|
@ -1537,6 +1539,12 @@
|
||||||
"integrity": "sha512-p9eZ2X9B80iKiTW4ukVj8B4K6q9/+xFtQ5MGYA5HWToY9nL4EkhV9+6ftT2VHpVMEZb5Tv00Iel516bVdO+yRw==",
|
"integrity": "sha512-p9eZ2X9B80iKiTW4ukVj8B4K6q9/+xFtQ5MGYA5HWToY9nL4EkhV9+6ftT2VHpVMEZb5Tv00Iel516bVdO+yRw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/js-cookie": {
|
||||||
|
"version": "3.0.6",
|
||||||
|
"resolved": "https://registry.npmmirror.com/@types/js-cookie/-/js-cookie-3.0.6.tgz",
|
||||||
|
"integrity": "sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/@types/json-schema": {
|
"node_modules/@types/json-schema": {
|
||||||
"version": "7.0.15",
|
"version": "7.0.15",
|
||||||
"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
|
"resolved": "https://registry.npmmirror.com/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||||
|
@ -4529,6 +4537,14 @@
|
||||||
"integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==",
|
"integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/js-cookie": {
|
||||||
|
"version": "3.0.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/js-cookie/-/js-cookie-3.0.5.tgz",
|
||||||
|
"integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/js-tokens": {
|
"node_modules/js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",
|
"resolved": "https://registry.npmmirror.com/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"antd": "^5.16.1",
|
"antd": "^5.16.1",
|
||||||
"axios": "^1.6.8",
|
"axios": "^1.6.8",
|
||||||
|
"js-cookie": "^3.0.5",
|
||||||
"next": "14.1.3",
|
"next": "14.1.3",
|
||||||
"postcss": "8.4.31",
|
"postcss": "8.4.31",
|
||||||
"react": "^18",
|
"react": "^18",
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
"tailwindcss": "3.3.3"
|
"tailwindcss": "3.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^18",
|
"@types/react": "^18",
|
||||||
"@types/react-big-calendar": "^1.8.9",
|
"@types/react-big-calendar": "^1.8.9",
|
||||||
|
|
|
@ -19,7 +19,8 @@ import type {CSSProperties} from 'react';
|
||||||
import {useState} from 'react';
|
import {useState} from 'react';
|
||||||
import {LoginObject} from "@/lib/login/definitions";
|
import {LoginObject} from "@/lib/login/definitions";
|
||||||
import {httpReq} from "@/utils/axiosReq";
|
import {httpReq} from "@/utils/axiosReq";
|
||||||
|
import Cookies from 'js-cookie';
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
type LoginType = 'phone' | 'account';
|
type LoginType = 'phone' | 'account';
|
||||||
|
|
||||||
const iconStyles: CSSProperties = {
|
const iconStyles: CSSProperties = {
|
||||||
|
@ -32,6 +33,7 @@ const iconStyles: CSSProperties = {
|
||||||
const Page = () => {
|
const Page = () => {
|
||||||
const [loginType, setLoginType] = useState<LoginType>('phone');
|
const [loginType, setLoginType] = useState<LoginType>('phone');
|
||||||
const {token} = theme.useToken();
|
const {token} = theme.useToken();
|
||||||
|
const router = useRouter()
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
@ -57,22 +59,6 @@ const Page = () => {
|
||||||
backgroundColor: 'rgba(255,255,255,0.25)',
|
backgroundColor: 'rgba(255,255,255,0.25)',
|
||||||
backdropFilter: 'blur(4px)',
|
backdropFilter: 'blur(4px)',
|
||||||
},
|
},
|
||||||
// title: '活动标题,可配置图片',
|
|
||||||
// subTitle: '活动介绍说明文字',
|
|
||||||
// action: (
|
|
||||||
// action: (
|
|
||||||
// <Button
|
|
||||||
// size="large"
|
|
||||||
// style={{
|
|
||||||
// borderRadius: 20,
|
|
||||||
// background: token.colorBgElevated,
|
|
||||||
// color: token.colorPrimary,
|
|
||||||
// width: 120,
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// 去看看
|
|
||||||
// </Button>
|
|
||||||
// ),
|
|
||||||
}}
|
}}
|
||||||
onFinish={(formData:LoginObject)=>{
|
onFinish={(formData:LoginObject)=>{
|
||||||
console.log("登录信息:"+formData.username+";"+formData.password)
|
console.log("登录信息:"+formData.username+";"+formData.password)
|
||||||
|
@ -80,9 +66,17 @@ const Page = () => {
|
||||||
username: formData.username,
|
username: formData.username,
|
||||||
password: formData.password
|
password: formData.password
|
||||||
}).then(response=>{
|
}).then(response=>{
|
||||||
console.log(response)
|
console.log(response);
|
||||||
response.status;
|
if(response.data.status.code===200){
|
||||||
response.data;
|
// localStorage.removeItem("platform-security")
|
||||||
|
localStorage.setItem('platform-security',response.data.data)
|
||||||
|
// 删除名为 'platform-security' 的Cookie
|
||||||
|
// Cookies.remove('platform-security');
|
||||||
|
// 设置一个有效期为7天的Cookie
|
||||||
|
Cookies.set('platform-security', response.data.data, { expires: 7 });
|
||||||
|
// 登录成功,跳转到首页或者回调
|
||||||
|
router.push('/task/project')
|
||||||
|
};
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
actions={
|
actions={
|
||||||
|
|
|
@ -15,4 +15,32 @@ export const httpReq = axios.create({
|
||||||
const cancelTokenSource: CancelTokenSource = axios.CancelToken.source();
|
const cancelTokenSource: CancelTokenSource = axios.CancelToken.source();
|
||||||
|
|
||||||
httpReq.defaults.headers.common['Accept'] = 'application/json';
|
httpReq.defaults.headers.common['Accept'] = 'application/json';
|
||||||
httpReq.interceptors.request.use()
|
httpReq.interceptors.request.use((config) => {
|
||||||
|
const token = localStorage.getItem('platform-security'); // 从本地存储中获取 token
|
||||||
|
if (token) {
|
||||||
|
// config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
config.headers.Authorization = `${token}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
return Promise.reject(error);
|
||||||
|
})
|
||||||
|
httpReq.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
// http请求最外层
|
||||||
|
if (response.status >= 500) {
|
||||||
|
console.log("系统异常")
|
||||||
|
} else if (response.status >= 400 && response.status <= 500) {
|
||||||
|
console.log("无权限")
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
if (error.response && error.response.status === 401) {
|
||||||
|
localStorage.removeItem('authToken');
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
Loading…
Reference in New Issue