From 2949eaafda55bd230652fe6233189583a92b8dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Mon, 3 Jul 2023 14:22:47 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E8=B7=B3=E8=BD=ACh5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/init/index.tsx | 5 +++++ src/routes/index.tsx | 14 +++++++++++++- src/utils/index.ts | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pages/init/index.tsx b/src/pages/init/index.tsx index 45d4c50..ec1e21e 100644 --- a/src/pages/init/index.tsx +++ b/src/pages/init/index.tsx @@ -9,6 +9,7 @@ import { import { loginAction } from "../../store/user/loginUserSlice"; import { Header, NoHeader, Footer } from "../../compenents"; import { useParams, useLocation } from "react-router-dom"; +import { isMobile } from "../../utils/index"; interface Props { loginData?: any; @@ -72,6 +73,10 @@ export const InitPage = (props: Props) => { props.configData["player-bullet-secret-opacity"], }; dispatch(saveConfigAction(config)); + if (isMobile() && props.configData["system-h5-url"] !== "") { + let url = props.configData["system-h5-url"]; + window.location.href = url; + } } setInit(true); }, [props]); diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 9c70365..77a7cc7 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -30,7 +30,19 @@ if (getToken()) { }); }); } else { - RootPage = ; + RootPage = lazy(async () => { + return new Promise(async (resolve) => { + try { + let configRes: any = await system.config(); + + resolve({ + default: , + }); + } catch (e) { + console.error("系统初始化失败", e); + } + }); + }); } // 懒加载 diff --git a/src/utils/index.ts b/src/utils/index.ts index 7a18b20..397f374 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -104,3 +104,10 @@ export function changeAppUrl(str: string) { return str + "/"; } } + +export function isMobile() { + let flag = navigator.userAgent.match( + /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i + ); + return flag; +} From 7e81dc1a9dc91a2b163ecead53b5f56606c8977a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Mon, 3 Jul 2023 14:53:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=99=BB=E9=99=86=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/login.ts | 9 +----- src/pages/login/index.tsx | 63 ++++----------------------------------- 2 files changed, 6 insertions(+), 66 deletions(-) diff --git a/src/api/login.ts b/src/api/login.ts index 0ff7cce..8b41e40 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -1,16 +1,9 @@ import client from "./internal/httpClient"; -export function login( - email: string, - password: string, - captchaKey: string, - captchaVal: string -) { +export function login(email: string, password: string) { return client.post("/api/v1/auth/login/password", { email: email, password: password, - captcha_key: captchaKey, - captcha_val: captchaVal, }); } diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 5a7d043..93f1695 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -1,11 +1,11 @@ -import { Spin, Input, Button, message } from "antd"; +import { Input, Button, message } from "antd"; import React, { useState, useEffect } from "react"; import styles from "./index.module.scss"; import banner from "../../assets/images/login/banner.png"; -import { useDispatch, useSelector } from "react-redux"; +import { useDispatch } from "react-redux"; import { useNavigate } from "react-router-dom"; -import { loginAction, logoutAction } from "../../store/user/loginUserSlice"; -import { login, system, user } from "../../api/index"; +import { loginAction } from "../../store/user/loginUserSlice"; +import { login, user } from "../../api/index"; import { setToken } from "../../utils/index"; import { NoFooter } from "../../compenents"; @@ -13,25 +13,8 @@ const LoginPage: React.FC = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const [loading, setLoading] = useState(false); - const [image, setImage] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const [captchaVal, setCaptchaVal] = useState(""); - const [captchaKey, setCaptchaKey] = useState(""); - const [captchaLoading, setCaptchaLoading] = useState(true); - - useEffect(() => { - fetchImageCaptcha(); - }, []); - - const fetchImageCaptcha = () => { - setCaptchaLoading(true); - system.imageCaptcha().then((res: any) => { - setImage(res.data.image); - setCaptchaKey(res.data.key); - setCaptchaLoading(false); - }); - }; const loginSubmit = (e: any) => { if (!email) { @@ -42,14 +25,6 @@ const LoginPage: React.FC = () => { message.error("请输入密码"); return; } - if (!captchaVal) { - message.error("请输入图形验证码"); - return; - } - if (captchaVal.length < 4) { - message.error("图形验证码错误"); - return; - } if (loading) { return; } @@ -68,7 +43,7 @@ const LoginPage: React.FC = () => { } setLoading(true); login - .login(email, password, captchaKey, captchaVal) + .login(email, password) .then((res: any) => { const token = res.data.token; setToken(token); @@ -76,8 +51,6 @@ const LoginPage: React.FC = () => { }) .catch((e) => { setLoading(false); - setCaptchaVal(""); - fetchImageCaptcha(); }); }; @@ -120,32 +93,6 @@ const LoginPage: React.FC = () => { placeholder="请输入密码" /> - - { - setCaptchaVal(e.target.value); - }} - onKeyUp={(e) => keyUp(e)} - /> - - {captchaLoading && ( - - - - )} - - {!captchaLoading && ( - - )} - - Date: Mon, 3 Jul 2023 15:41:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=99=BB=E9=99=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login/index.module.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/login/index.module.scss b/src/pages/login/index.module.scss index 48cd192..0dd4a06 100644 --- a/src/pages/login/index.module.scss +++ b/src/pages/login/index.module.scss @@ -47,7 +47,7 @@ height: 100%; box-sizing: border-box; border-left: 1px solid #d8d8d8; - padding: 0px 60px; + padding: 50px 60px; display: flex; flex-direction: column; .captcha-box { From 4af407e6b9b9328a72a4c6ab48b7c01a4e319f17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Mon, 3 Jul 2023 16:20:32 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E9=A1=B5=E9=9D=A2tab?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E5=88=B0url=E9=87=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.tsx | 45 +++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 2c02372..002c5a0 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { Row, Col, Spin, Tree, Popover, Space, Image } from "antd"; -import type { MenuProps } from "antd"; +import { useNavigate, useLocation } from "react-router-dom"; import { user } from "../../api/index"; import styles from "./index.module.scss"; import { useSelector } from "react-redux"; @@ -12,14 +12,20 @@ import iconRoute from "../../assets/images/commen/icon-route.png"; import { studyTimeFormat } from "../../utils/index"; const IndexPage = () => { + const navigate = useNavigate(); + const result = new URLSearchParams(useLocation().search); const systemConfig = useSelector((state: any) => state.systemConfig.value); const [open, setOpen] = useState(false); const [loading, setLoading] = useState(false); - const [tabKey, setTabKey] = useState(0); + const [tabKey, setTabKey] = useState(Number(result.get("tab") || 0)); const [coursesList, setCoursesList] = useState([]); const [categories, setCategories] = useState([]); - const [categoryId, setCategoryId] = useState(0); - const [categoryText, setCategoryText] = useState("所有分类"); + const [categoryId, setCategoryId] = useState( + Number(result.get("cid") || 0) + ); + const [categoryText, setCategoryText] = useState( + String(result.get("catName") || "所有分类") + ); const [selectKey, setSelectKey] = useState([0]); const [learnCourseRecords, setLearnCourseRecords] = useState({}); const [learnCourseHourCount, setLearnCourseHourCount] = useState({}); @@ -36,6 +42,12 @@ const IndexPage = () => { getParams(); }, []); + useEffect(() => { + let arr = []; + arr.push(Number(result.get("cid") || 0)); + setSelectKey(arr); + }, [result.get("cid")]); + useEffect(() => { if (currentDepId === 0) { return; @@ -163,17 +175,38 @@ const IndexPage = () => { const onChange = (key: number) => { setTabKey(key); + navigate( + "/?cid=" + categoryId + "&catName=" + categoryText + "&tab=" + key + ); }; const onSelect = (selectedKeys: any, info: any) => { setCategoryId(selectedKeys[0]); if (info.node.key === 0) { setCategoryText(info.node.title); + setSelectKey(selectedKeys); + hide(); + navigate( + "/?cid=" + + selectedKeys[0] + + "&catName=" + + info.node.title + + "&tab=" + + tabKey + ); } else { setCategoryText(info.node.title.props.children); + setSelectKey(selectedKeys); + hide(); + navigate( + "/?cid=" + + selectedKeys[0] + + "&catName=" + + info.node.title.props.children + + "&tab=" + + tabKey + ); } - setSelectKey(selectedKeys); - hide(); }; const handleOpenChange = (newOpen: boolean) => {