From 8e465b9d03e675216a66a49f06ebde2325fd7cef Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Tue, 29 Aug 2023 16:20:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=94=B6=E7=9B=8A=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/pages/home/components/adware.tsx | 55 ++++++++++--------- .../home/components/feature_recommended.tsx | 6 +- src/pages/home/home.tsx | 8 +-- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/pages/home/components/adware.tsx b/src/pages/home/components/adware.tsx index f30f547..16724f8 100644 --- a/src/pages/home/components/adware.tsx +++ b/src/pages/home/components/adware.tsx @@ -15,7 +15,6 @@ const Adware: FC = ({data, only_flag, width}) => { const [adverts, setAdverts] = useState([]) const [space, setSpace] = useState(null) - useEffect(() => { const res = data.find(d => d.only_flag === only_flag) setSpace(res) @@ -31,36 +30,40 @@ const Adware: FC = ({data, only_flag, width}) => { } return ( - - { - adverts.length === 1 && jumpAdware(adverts[0].image_path)} - width={width} - height={(space.height / space.width) * width}/> - } + <> { - adverts.length > 1 && - {adverts.map(d => - 0 && + { + adverts.length === 1 && jumpAdware(adverts[0].image_path)} width={width} - height={(space.height / space.width) * width} - onClick={() => jumpAdware(d.image_path)}/> - )} - + height={(space.height / space.width) * width}/> + } + { + adverts.length > 1 && + {adverts.map(d => + jumpAdware(d.image_path)}/> + )} + + } + } - + ) } diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index 8aef137..289b9bb 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -151,7 +151,7 @@ const FeatureRecommended: FC = (props) => { return ( - {data.every(d => d.data.length) && + { data.map(d => = (props) => { className={styles.featureTitle} onClick={() => jump(d.url)} src={d.titleUrl}/> { - d.data.map((c, index) => 0 && d.data.map((c, index) => jump(d.detailsUrl + c.path, c.id, d.type)}> @@ -177,7 +177,7 @@ const FeatureRecommended: FC = (props) => { } ) } - } + ) } diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index 2cd8a6c..b91c4b0 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -1,4 +1,4 @@ -import {FC, useEffect, useState} from "react"; +import {FC, useState} from "react"; import {View} from "@tarojs/components"; import styles from "./home.module.scss"; import Adware from "@/pages/home/components/adware"; @@ -20,11 +20,11 @@ const Home: FC = () => { Taro.navigateTo({url: '/pages/login/login'}) } - useEffect(() => { + Taro.useLoad(() => { HomeApi.home().then(res => { setData(res) }) - }, []) + }) return ( @@ -37,7 +37,7 @@ const Home: FC = () => { skill={data?.skill || []} /> - + {data && } { !token && 登录后享受更多学习服务~