diff --git a/src/api/request.ts b/src/api/request.ts index 5c1712f..49722d0 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -86,17 +86,17 @@ export function request( resolve(data?.data) notLoging = false } else if (res.statusCode === 401) { - if (notLoging) return + if (notLoging || !token) return notLoging = true - // Taro.showModal({ - // title: "请登录", - // content: token ? '登录过期' : "完成登录开启功能", - // showCancel: false, - // success() { - // Taro.clearStorageSync() - // Taro.redirectTo({url: '/pages/login/login'}) - // } - // }) + Taro.showModal({ + title: "登录过期", + confirmText: "登录", + showCancel: false, + success() { + Taro.clearStorage() + Taro.navigateTo({url: '/pages/login/login'}) + } + }) } else { reject(null) Taro.showToast({ diff --git a/src/pages/business/videoInfo/videoInfo.tsx b/src/pages/business/videoInfo/videoInfo.tsx index 5dee99c..6a4a236 100644 --- a/src/pages/business/videoInfo/videoInfo.tsx +++ b/src/pages/business/videoInfo/videoInfo.tsx @@ -10,6 +10,8 @@ import {formatMinute} from "@/utils/time"; import videoEvents from "@/hooks/videoEvents"; import unique_ident from "@/hooks/unique_ident"; import Img from "@/components/image/image"; +import {Profile} from "@/store"; +import LoginView from "@/components/loginView"; const VideoInfo: FC = () => { const {id, depId} = Taro.getCurrentInstance()?.router?.params as any @@ -18,6 +20,7 @@ const VideoInfo: FC = () => { const [preview, setPreview] = useState(false) // 预览 const [playing, setPlaying] = useState(false) // 学习中 + const getData = useCallback(async (playing: boolean) => { try { const res = await curriculum.courseDep(id, depId) @@ -128,4 +131,18 @@ const VideoInfo: FC = () => { ) } -export default VideoInfo +const VerifyToken: FC = () => { + const {token} = Profile.useContainer() + const globalData = Taro.getApp().globalData + + return ( + <> + { + !token ? + : + } + + ) +} + +export default VerifyToken diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index 3eaef5a..bf38e35 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -10,16 +10,17 @@ import {Profile} from "@/store"; import Taro from "@tarojs/taro"; import {HomeApi, HomeData} from "@/api"; import logo from '@/static/img/logo.png' +import Spin from "@/components/spinner"; const Home: FC = () => { const globalData = Taro.getApp().globalData const {token} = Profile.useContainer() const [data, setData] = useState(null) - console.log(globalData) + const [enable, setEnable] = useState(true) function unLogin() { - Taro.removeStorageSync('profile') + Taro.clearStorage() Taro.navigateTo({url: '/pages/login/login'}) } @@ -27,10 +28,14 @@ const Home: FC = () => { HomeApi.home().then(res => { setData(res) }) + setTimeout(() => { + setEnable(false) + }, 300) }) return ( + diff --git a/src/pages/login/login.tsx b/src/pages/login/login.tsx index 86b9750..bf19ea2 100644 --- a/src/pages/login/login.tsx +++ b/src/pages/login/login.tsx @@ -1,6 +1,6 @@ import {FC, useEffect, useState} from "react"; import {Profile} from "@/store"; -import {Image, PageContainer, Text, View} from "@tarojs/components"; +import {Image, Text, View} from "@tarojs/components"; import Taro from "@tarojs/taro"; import styles from './login.module.scss' import Icon from "@/components/icon"; @@ -12,13 +12,11 @@ import MyButton from "@/components/button/MyButton"; const Login: FC = () => { const [isLoading, setLoading] = useState(false) const [error, setError] = useState(null) - const {setUser, setToken, setCompany} = Profile.useContainer() + const {setUser, setToken, setCompany, empty} = Profile.useContainer() const [h5params, setH5Params] = useState(null) - const [show,setShow] = useState(true) - useEffect(() => { - + empty(false) if (process.env.TARO_ENV === 'h5') { setLoading(true); loginApi.getParams().then((res) => { diff --git a/src/store/profile.ts b/src/store/profile.ts index 3f47d55..abd2846 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -1,6 +1,7 @@ import {useEffect, useState} from "react"; import {createContainer} from "unstated-next"; import Taro from "@tarojs/taro"; + // import {whiteList} from "@/config"; @@ -52,12 +53,13 @@ function useProfile() { const [company, setCompany] = useState(data?.company || null) - function empty() { + function empty(jump = true) { setUser(null) setUser(null) setToken(null) Taro.removeStorageSync('profile') - Taro.navigateTo({url: '/pages/login/login'}) + Taro.clearStorage() + jump && Taro.navigateTo({url: '/pages/login/login'}) } useEffect(() => {