From 76b08de3c1589181e1359e89eb04b3d8cecf8ea4 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Tue, 29 Aug 2023 16:01:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/request.ts | 22 ++++++++++++------- src/components/image/image.tsx | 13 +++++------ src/pages/home/components/adware.tsx | 21 +++++++++--------- .../home/components/feature_recommended.tsx | 15 +++++++------ src/pages/home/home.module.scss | 4 +++- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/api/request.ts b/src/api/request.ts index 3195e31..59d2501 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -44,6 +44,8 @@ export const ERROR_STATUS: Record = { 'OVERSTEP': '请求越界~' } +let notLoging = false + export function request( url: string, method: keyof Method, @@ -82,15 +84,19 @@ export function request( const data = res?.data as any if (data?.code === 0 && res?.statusCode === 200) { resolve(data?.data) + notLoging = false } else if (res.statusCode === 401) { - // Taro.showModal({ - // title: "登录过期,需重新登陆", - // showCancel: false, - // success() { - Taro.clearStorageSync() - Taro.redirectTo({url: '/pages/login/login'}) - // } - // }) + if (notLoging) return + notLoging = true + Taro.showModal({ + title: "请登录", + content: token ? '登录过期' : "完成登录开启功能", + showCancel: false, + success() { + Taro.clearStorageSync() + Taro.redirectTo({url: '/pages/login/login'}) + } + }) } else { reject(null) Taro.showToast({ diff --git a/src/components/image/image.tsx b/src/components/image/image.tsx index 1ca8d81..4297130 100644 --- a/src/components/image/image.tsx +++ b/src/components/image/image.tsx @@ -9,7 +9,7 @@ interface Props extends ImageProps { fallback?: string } -const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = shard}) => { +const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = shard, ...props}) => { const [isError, setIsError] = useState(false) const [loading, setLoading] = useState(true) @@ -35,23 +35,22 @@ const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = sha } return ( - + {!isError && } - { - loading && - - } + {loading && } { isError && !loading && - + } ) diff --git a/src/pages/home/components/adware.tsx b/src/pages/home/components/adware.tsx index e98856a..f30f547 100644 --- a/src/pages/home/components/adware.tsx +++ b/src/pages/home/components/adware.tsx @@ -1,8 +1,9 @@ -import {Image, Swiper, SwiperItem, View} from "@tarojs/components"; +import {Swiper, SwiperItem, View} from "@tarojs/components"; import {FC, useEffect, useState} from "react"; import {AdwareType} from "@/api"; import Taro from "@tarojs/taro"; import styles from '../home.module.scss' +import Img from "@/components/image/image"; interface Props { data: any[] @@ -30,16 +31,16 @@ const Adware: FC = ({data, only_flag, width}) => { } return ( - + { - adverts.length === 1 && jumpAdware(adverts[0].image_path)} - className={styles.adware}/> + width={width} + height={(space.height / space.width) * width}/> } { adverts.length > 1 && = ({data, only_flag, width}) => { autoplay circular style={{width: width + "rpx", height: (space.height / space.width) * width + "rpx", overflow: 'hidden'}} - indicatorActiveColor='rgba(255,255,255,0.5)' - className={styles.adware}> + indicatorActiveColor='rgba(255,255,255,0.5)'> {adverts.map(d => - jumpAdware(d.image_path)} - style={{width: width + "rpx", height: '100%'}}/> + width={width} + height={(space.height / space.width) * width} + onClick={() => jumpAdware(d.image_path)}/> )} } diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index 5c46994..8aef137 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -76,7 +76,8 @@ const FeatureRecommended: FC = (props) => { description: d.graphic_introduction, path: `?id=${d.id}`, })) - } catch (e) {} + } catch (e) { + } return [] } @@ -149,8 +150,8 @@ const FeatureRecommended: FC = (props) => { } return ( - - + + {data.every(d => d.data.length) && { data.map(d => = (props) => { className='flex mb-3' key={c.id} onClick={() => jump(d.detailsUrl + c.path, c.id, d.type)}> - - - + + + @@ -176,7 +177,7 @@ const FeatureRecommended: FC = (props) => { } ) } - + } ) } diff --git a/src/pages/home/home.module.scss b/src/pages/home/home.module.scss index 1e406a9..d18c670 100644 --- a/src/pages/home/home.module.scss +++ b/src/pages/home/home.module.scss @@ -72,6 +72,7 @@ .courseTag { width: 162px; + height: 46rpx; margin: 0 auto 30rpx; display: block; } @@ -85,6 +86,7 @@ } .featureTitle { + max-width: 212px; height: 42rpx; padding-bottom: 30rpx; } @@ -117,7 +119,7 @@ } .ranking { - top:0; + top: 0; position: absolute; left: 24rpx; width: 30px;