修改登录过期

v2
king 1 year ago
parent a51502d559
commit f1bef606a9
  1. 20
      src/api/request.ts
  2. 19
      src/pages/business/videoInfo/videoInfo.tsx
  3. 9
      src/pages/home/home.tsx
  4. 8
      src/pages/login/login.tsx
  5. 6
      src/store/profile.ts

@ -86,17 +86,17 @@ export function request<T = unknown>(
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({

@ -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 ? <LoginView height={globalData.windowHeight - 100}/>
: <VideoInfo/>
}
</>
)
}
export default VerifyToken

@ -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 | HomeData>(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 (
<View className={styles.content}>
<Spin enable={enable} overlay/>
<View className={styles.header} style={{padding: `${globalData.statusBarHeight}px 0 10px 0`}}>
<Image src={logo} className={styles.logo} mode='aspectFit'/>
</View>

@ -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<string | null>(null)
const {setUser, setToken, setCompany} = Profile.useContainer()
const {setUser, setToken, setCompany, empty} = Profile.useContainer()
const [h5params, setH5Params] = useState<LoginParams | null>(null)
const [show,setShow] = useState(true)
useEffect(() => {
empty(false)
if (process.env.TARO_ENV === 'h5') {
setLoading(true);
loginApi.getParams().then((res) => {

@ -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<Company | null>(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(() => {

Loading…
Cancel
Save