feat: 登录用户信息缓存
This commit is contained in:
@@ -12,7 +12,7 @@ VITE_API_BASE_URL='http://1.95.0.111:3000'
|
||||
VITE_TITLE_NAME='五味子云存储'
|
||||
|
||||
# token key
|
||||
VITE_APP_TOKEN_KEY='token'
|
||||
VITE_APP_TOKEN_KEY='schisandra'
|
||||
|
||||
# the upload url
|
||||
VITE_UPLOAD_URL='http://1.95.0.111:3000'
|
||||
|
@@ -60,4 +60,3 @@ export const login = (data: API.LoginRequest) => {
|
||||
data: data,
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -33,8 +33,8 @@ class Request {
|
||||
// 后端返回字符串表示需要解密操作
|
||||
// if (typeof response.data == "string") {
|
||||
// response.data = DecryptData(response.data);
|
||||
// if (!response.data.code && response.data.code !== 200) {
|
||||
// message.error(response.data.message).then();
|
||||
// if (response.status !== 200) {
|
||||
// message.error(response.statusText).then();
|
||||
// return Promise.reject(response.data);
|
||||
// }
|
||||
// }
|
||||
|
@@ -33,11 +33,14 @@ import logo from "@/assets/icons/schisandra.svg";
|
||||
import qrCode from "@/assets/images/login_qrcode-landaiqing.jpg";
|
||||
import styles from "./index.module.less";
|
||||
import { observer } from "mobx-react";
|
||||
import useStore from "@/utils/store/useStore.tsx";
|
||||
import FooterComponent from "@/components/Footer";
|
||||
import RotateCaptcha, { CaptchaInstance, type TicketInfoType } from "react-rotate-captcha";
|
||||
import { get, load } from "@/api/captcha/index.ts";
|
||||
import { getSms, login, oauthLogin } from "@/api/user";
|
||||
import { TinyColor } from "@ctrl/tinycolor";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { setStorage } from "@/utils/localStorage/config.ts";
|
||||
|
||||
type LoginType = "account" | "phone";
|
||||
|
||||
@@ -53,6 +56,8 @@ export default observer(() => {
|
||||
const smsCaptcha = useRef<CaptchaInstance>(null);
|
||||
const loginCaptcha = useRef<CaptchaInstance>(null);
|
||||
const captchaRef = useRef<CaptFieldRef | null | undefined>();
|
||||
const navigate = useNavigate();
|
||||
const store = useStore("user");
|
||||
const colors = ["#40e495", "#30dd8a", "#2bb673"];
|
||||
const getHoverColors = (colors: string[]) =>
|
||||
colors.map((color) => new TinyColor(color).lighten(5).toString());
|
||||
@@ -94,6 +99,14 @@ export default observer(() => {
|
||||
};
|
||||
const res: any = await login(data);
|
||||
if (res && res.success && res.code === 0) {
|
||||
store.setToken(res.data.token);
|
||||
store.setUserId(res.data.user.id);
|
||||
setStorage("token", res.data.token, 24 * 60 * 30);
|
||||
if (store.getToken() !== null || store.getUserId() !== null) {
|
||||
setTimeout(() => {
|
||||
navigate("/main");
|
||||
}, 3000);
|
||||
}
|
||||
message.open({
|
||||
content: "登录成功!",
|
||||
type: "success",
|
||||
|
@@ -309,7 +309,7 @@ export default observer(() => {
|
||||
onClick={async () => {
|
||||
const validateFields = [
|
||||
"phone",
|
||||
"userName",
|
||||
"username",
|
||||
"password",
|
||||
"activeCode",
|
||||
"confirmPassword",
|
||||
|
Reference in New Issue
Block a user