修改登录过期

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) resolve(data?.data)
notLoging = false notLoging = false
} else if (res.statusCode === 401) { } else if (res.statusCode === 401) {
if (notLoging) return if (notLoging || !token) return
notLoging = true notLoging = true
// Taro.showModal({ Taro.showModal({
// title: "请登录", title: "登录过期",
// content: token ? '登录过期' : "完成登录开启功能", confirmText: "登录",
// showCancel: false, showCancel: false,
// success() { success() {
// Taro.clearStorageSync() Taro.clearStorage()
// Taro.redirectTo({url: '/pages/login/login'}) Taro.navigateTo({url: '/pages/login/login'})
// } }
// }) })
} else { } else {
reject(null) reject(null)
Taro.showToast({ Taro.showToast({

@ -10,6 +10,8 @@ import {formatMinute} from "@/utils/time";
import videoEvents from "@/hooks/videoEvents"; import videoEvents from "@/hooks/videoEvents";
import unique_ident from "@/hooks/unique_ident"; import unique_ident from "@/hooks/unique_ident";
import Img from "@/components/image/image"; import Img from "@/components/image/image";
import {Profile} from "@/store";
import LoginView from "@/components/loginView";
const VideoInfo: FC = () => { const VideoInfo: FC = () => {
const {id, depId} = Taro.getCurrentInstance()?.router?.params as any const {id, depId} = Taro.getCurrentInstance()?.router?.params as any
@ -18,6 +20,7 @@ const VideoInfo: FC = () => {
const [preview, setPreview] = useState(false) // 预览 const [preview, setPreview] = useState(false) // 预览
const [playing, setPlaying] = useState(false) // 学习中 const [playing, setPlaying] = useState(false) // 学习中
const getData = useCallback(async (playing: boolean) => { const getData = useCallback(async (playing: boolean) => {
try { try {
const res = await curriculum.courseDep(id, depId) 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 Taro from "@tarojs/taro";
import {HomeApi, HomeData} from "@/api"; import {HomeApi, HomeData} from "@/api";
import logo from '@/static/img/logo.png' import logo from '@/static/img/logo.png'
import Spin from "@/components/spinner";
const Home: FC = () => { const Home: FC = () => {
const globalData = Taro.getApp().globalData const globalData = Taro.getApp().globalData
const {token} = Profile.useContainer() const {token} = Profile.useContainer()
const [data, setData] = useState<null | HomeData>(null) const [data, setData] = useState<null | HomeData>(null)
console.log(globalData) const [enable, setEnable] = useState(true)
function unLogin() { function unLogin() {
Taro.removeStorageSync('profile') Taro.clearStorage()
Taro.navigateTo({url: '/pages/login/login'}) Taro.navigateTo({url: '/pages/login/login'})
} }
@ -27,10 +28,14 @@ const Home: FC = () => {
HomeApi.home().then(res => { HomeApi.home().then(res => {
setData(res) setData(res)
}) })
setTimeout(() => {
setEnable(false)
}, 300)
}) })
return ( return (
<View className={styles.content}> <View className={styles.content}>
<Spin enable={enable} overlay/>
<View className={styles.header} style={{padding: `${globalData.statusBarHeight}px 0 10px 0`}}> <View className={styles.header} style={{padding: `${globalData.statusBarHeight}px 0 10px 0`}}>
<Image src={logo} className={styles.logo} mode='aspectFit'/> <Image src={logo} className={styles.logo} mode='aspectFit'/>
</View> </View>

@ -1,6 +1,6 @@
import {FC, useEffect, useState} from "react"; import {FC, useEffect, useState} from "react";
import {Profile} from "@/store"; 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 Taro from "@tarojs/taro";
import styles from './login.module.scss' import styles from './login.module.scss'
import Icon from "@/components/icon"; import Icon from "@/components/icon";
@ -12,13 +12,11 @@ import MyButton from "@/components/button/MyButton";
const Login: FC = () => { const Login: FC = () => {
const [isLoading, setLoading] = useState(false) const [isLoading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null) 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 [h5params, setH5Params] = useState<LoginParams | null>(null)
const [show,setShow] = useState(true)
useEffect(() => { useEffect(() => {
empty(false)
if (process.env.TARO_ENV === 'h5') { if (process.env.TARO_ENV === 'h5') {
setLoading(true); setLoading(true);
loginApi.getParams().then((res) => { loginApi.getParams().then((res) => {

@ -1,6 +1,7 @@
import {useEffect, useState} from "react"; import {useEffect, useState} from "react";
import {createContainer} from "unstated-next"; import {createContainer} from "unstated-next";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
// import {whiteList} from "@/config"; // import {whiteList} from "@/config";
@ -52,12 +53,13 @@ function useProfile() {
const [company, setCompany] = useState<Company | null>(data?.company || null) const [company, setCompany] = useState<Company | null>(data?.company || null)
function empty() { function empty(jump = true) {
setUser(null) setUser(null)
setUser(null) setUser(null)
setToken(null) setToken(null)
Taro.removeStorageSync('profile') Taro.removeStorageSync('profile')
Taro.navigateTo({url: '/pages/login/login'}) Taro.clearStorage()
jump && Taro.navigateTo({url: '/pages/login/login'})
} }
useEffect(() => { useEffect(() => {

Loading…
Cancel
Save