From 9973c5b6fd429d5f9d94c8c5b27012a678d3fe4f Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Fri, 25 Aug 2023 19:13:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=85=AC=E5=85=B1=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/home.ts | 16 +++++- src/components/tabs/tabs.scss | 15 ++++-- src/pages/home/components/adware.tsx | 42 +++++++++------ src/pages/home/components/curRecommended.tsx | 4 +- src/pages/home/components/feature.tsx | 7 +-- .../home/components/feature_recommended.tsx | 53 ++++++++++++------- src/pages/home/home.module.scss | 51 ++++++++++++++---- src/pages/home/home.tsx | 31 +++++++++-- src/pages/preview/brand/info/info.module.scss | 1 - .../preview/illness/sort/sort.module.scss | 25 ++++++--- src/pages/preview/illness/sort/sort.tsx | 17 +++--- src/pages/preview/profession/profession.tsx | 1 + types/home.d.ts | 4 +- 13 files changed, 190 insertions(+), 77 deletions(-) diff --git a/src/api/home.ts b/src/api/home.ts index 5e73f53..aa884b5 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -16,7 +16,7 @@ export interface AdwareLinkType { } export interface AdwareType { - image_path:string + image_path: string advert_link: AdwareLinkType scope_id: number | string id: number @@ -29,6 +29,14 @@ export interface AdwareType { end_time?: number } +export interface HomeData { + adverts: AdwareType[] + skill: Kill[] + health: Health[] + brand: Brand[] + illness: Illness[] +} + export const HomeApi = { advert(only_flag: string) { return request("/home/v1/advert/unique?only_flag=" + only_flag, "GET") @@ -61,11 +69,17 @@ export const HomeApi = { skillList(categoryId: number, page: number, page_size: number) { return request<{ data: Kill[], total: number }>('/home/v1/skill/index', "GET", {categoryId, page, page_size}) }, + skillSetPlay(id: number) { + return request(`/home/v1/skill/set_play/${id}`, "PUT") + }, /** 疾病知识 */ illness(page: number, page_size: number) { return request<{ list: Illness[], total: number }>('/home/v1/article/illness_list', "GET", {page, page_size}) }, category(type: number) { return request('/home/v1/category/index/info?type=' + type, "GET") + }, + home() { + return request('/home/v1/home/home_page', "GET", {count: 3}) } } diff --git a/src/components/tabs/tabs.scss b/src/components/tabs/tabs.scss index 77db956..3d1c9c0 100644 --- a/src/components/tabs/tabs.scss +++ b/src/components/tabs/tabs.scss @@ -17,9 +17,20 @@ View::-webkit-scrollbar { text-align: center; } + .tabs-item { + padding: 20rpx; + font-size: 36rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #606563; + } + .current { position: relative; + font-size: 36rpx; + font-family: PingFang SC-Bold, PingFang SC; font-weight: bold; + color: #323635; &:after { position: absolute; @@ -37,10 +48,6 @@ View::-webkit-scrollbar { transition: all 200ms; } } - - .tabs-item { - padding: 20rpx; - } } @keyframes spread { diff --git a/src/pages/home/components/adware.tsx b/src/pages/home/components/adware.tsx index 37c68bd..e98856a 100644 --- a/src/pages/home/components/adware.tsx +++ b/src/pages/home/components/adware.tsx @@ -1,16 +1,25 @@ import {Image, Swiper, SwiperItem, View} from "@tarojs/components"; -import {FC, useState} from "react"; -import {AdwareType, HomeApi} from "@/api"; +import {FC, useEffect, useState} from "react"; +import {AdwareType} from "@/api"; import Taro from "@tarojs/taro"; import styles from '../home.module.scss' -const Adware: FC = () => { - const [data, setData] = useState([]) +interface Props { + data: any[] + only_flag: string + width: number +} + +const Adware: FC = ({data, only_flag, width}) => { + const [adverts, setAdverts] = useState([]) + const [space, setSpace] = useState(null) - async function getAdware() { - const res = await HomeApi.advert('home_space') - setData(res) - } + + useEffect(() => { + const res = data.find(d => d.only_flag === only_flag) + setSpace(res) + setAdverts(res?.adverts || []) + }, [data]) function jumpAdware(url: string) { if (url.substring(0, 3) === 'wx:') { @@ -20,34 +29,33 @@ const Adware: FC = () => { } } - Taro.useLoad(getAdware) - return ( { - data.length === 1 && jumpAdware(data[0].image_path)} + style={{width: width + "rpx", height: (space.height / space.width) * width + "rpx"}} + onClick={() => jumpAdware(adverts[0].image_path)} className={styles.adware}/> } { - data.length > 1 && 1 && - {data.map(d => + {adverts.map(d => jumpAdware(d.image_path)} - style={{width: "100%"}}/> + style={{width: width + "rpx", height: '100%'}}/> )} } diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx index f15a8c5..1685a93 100644 --- a/src/pages/home/components/curRecommended.tsx +++ b/src/pages/home/components/curRecommended.tsx @@ -37,7 +37,7 @@ const CurRecommended: FC = () => { return ( <> { - data.length > 0 && + data.length > 0 && { @@ -52,7 +52,7 @@ const CurRecommended: FC = () => { } - - 暂无更多 - + - 暂无更多 - ) } diff --git a/src/pages/home/components/feature.tsx b/src/pages/home/components/feature.tsx index 7614661..d6ae52b 100644 --- a/src/pages/home/components/feature.tsx +++ b/src/pages/home/components/feature.tsx @@ -4,6 +4,7 @@ import illness from '@/static/img/illness.png' import profession from '@/static/img/profession.png' import health from '@/static/img/health.png' import article from '@/static/img/article.png' +import styles from '../home.module.scss' import Taro from "@tarojs/taro"; const Feature: FC = () => { @@ -19,11 +20,11 @@ const Feature: FC = () => { } return ( - + { list.map(d => jump(d.url)}> - - {d.text} + + {d.text} ) } diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index afdf4c8..0145a83 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -25,9 +25,17 @@ interface Data { url: string detailsUrl: string data: DataContent[] + type?: 'health' | 'kill' } -const FeatureRecommended: FC = () => { +interface Props { + skill: Kill[] // 技能 + health: Health[] // 健康 + brand: Brand[] // 品牌 + illness: Illness[] // 疾病 +} + +const FeatureRecommended: FC = (props) => { const [data, setData] = useState([ { titleUrl: brandTop, @@ -39,13 +47,15 @@ const FeatureRecommended: FC = () => { titleUrl: healthTop, url: '/pages/preview/health/health', detailsUrl: '/pages/preview/videoFull/videoFull', - data: [] + data: [], + type: "health" }, { titleUrl: professionTop, url: '/pages/preview/profession/profession', detailsUrl: '/pages/preview/videoFull/videoFull', - data: [] + data: [], + type: 'kill' }, { titleUrl: illnessTop, @@ -58,8 +68,7 @@ const FeatureRecommended: FC = () => { /** 品牌 */ async function getBrand(): Promise { try { - const res = await HomeApi.brand(1, 3) - return res.list.map(d => ({ + return props.brand.map(d => ({ id: d.id, title: d.name, imageUrl: d.brand_album, @@ -67,6 +76,7 @@ const FeatureRecommended: FC = () => { path: `?id=${d.id}`, })) } catch (e) { + console.log(e) } return [] } @@ -74,8 +84,7 @@ const FeatureRecommended: FC = () => { /** 健康知识 */ async function getHealth(): Promise { try { - const res = await HomeApi.healthTop(3) - return res.map(d => ({ + return props.health?.map(d => ({ id: d.id, title: d.title, imageUrl: d.url_path, @@ -90,8 +99,7 @@ const FeatureRecommended: FC = () => { /** 技能 */ async function getKill(): Promise { try { - const res = await HomeApi.skillTop(3) - return res.map(d => ({ + return props.skill.map(d => ({ id: d.id, imageUrl: d.url_path, description: d.introduction, @@ -106,12 +114,11 @@ const FeatureRecommended: FC = () => { /** 疾病 */ async function getIllness(): Promise { try { - const res = await HomeApi.illness(1, 3) - return res.list.map(d => ({ + return props.illness.map(d => ({ id: d.id, imageUrl: '', - description: d.content, - title: d.title, + description: d.description, + title: d.name, path: `?id=${d.id}` })) } catch (e) { @@ -128,15 +135,23 @@ const FeatureRecommended: FC = () => { oldData[3].data = illness setData(oldData) }) - }, []) + }, [props]) - function jump(url: string) { + // TODO 后续增加播放量使用公共接口 + function jump(url: string, playId?: number, type?: 'health' | 'kill') { + if (playId && type) { + if (type === 'health') { + HomeApi.healthSetPlay(playId) + } else if (type === 'kill') { + HomeApi.skillSetPlay(playId) + } + } Taro.navigateTo({url}) } return ( - + { data.map(d => { d.data.map((c, index) => jump(d.detailsUrl + c.path)}> + onClick={() => jump(d.detailsUrl + c.path, c.id, d.type)}> - {c.title} - {c.description} + {c.title} + {c.description} ) } diff --git a/src/pages/home/home.module.scss b/src/pages/home/home.module.scss index 6fd3f7d..4fb817b 100644 --- a/src/pages/home/home.module.scss +++ b/src/pages/home/home.module.scss @@ -1,5 +1,5 @@ .tipsLogin { - padding: 24rpx; + padding: 20px; color: #fff; align-items: center; position: fixed; @@ -9,7 +9,10 @@ justify-content: space-between; width: 100%; box-sizing: border-box; - background: rgba(#000, .7); + background: rgba(#000, .6); + font-size: 28rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; } @@ -48,18 +51,25 @@ } .adware { - //margin-top: 40rpx; - width: 100%; - height: 260rpx; border-radius: 16rpx; overflow: hidden; background: #eee; + margin-bottom: 40rpx; } .videoListBox { border-radius: 20px; } +.featureList { + font-size: 28rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #323635; + margin-top: 10px; +} + + .courseTag { width: 200px; margin: auto; @@ -70,7 +80,7 @@ color: #323635; background: #fff; padding: 30rpx 0 30rpx 30rpx; - margin-top: 40rpx; + margin-bottom: 40rpx; border-radius: 30rpx; } @@ -83,16 +93,39 @@ width: calc(100% - 140px - 50px); } +.featureTextTitle { + font-size: 30rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #323635; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; + line-height: 2; +} + +.featureTextDescription { + font-size: 24rpx; + font-family: PingFang SC-Medium, PingFang SC; + font-weight: 500; + color: #909795; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; +} + .ranking { position: absolute; left: 24rpx; - width: 24px; - height: 24px; + width: 40px; + height: 40px; } .featureImage { width: 140px; - height: 90px; + height: 100px; background: #eee; border-radius: 12rpx; overflow: hidden; diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index 506d598..bbd407a 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -1,4 +1,4 @@ -import {FC} from "react"; +import {FC, useEffect, useState} from "react"; import {View} from "@tarojs/components"; import styles from "./home.module.scss"; // import {Search} from "@/pages/home/components/search"; @@ -8,19 +8,40 @@ import FeatureRecommended from "@/pages/home/components/feature_recommended"; import CurRecommended from "@/pages/home/components/curRecommended"; import MyButton from "@/components/button/MyButton"; import {Profile} from "@/store"; +import Taro from "@tarojs/taro"; +import {HomeApi, HomeData} from "@/api"; + const Home: FC = () => { - const {token, empty} = Profile.useContainer() + const {token} = Profile.useContainer() + const [data, setData] = useState(null) + + function unLogin() { + Taro.removeStorageSync('profile') + Taro.navigateTo({url: '/pages/login/login'}) + } + + useEffect(() => { + HomeApi.home().then(res => { + setData(res) + }) + }, []) return ( {/**/} - + - + + { - !token && + !token && 登录后享受更多学习服务~ 立即登录 diff --git a/src/pages/preview/brand/info/info.module.scss b/src/pages/preview/brand/info/info.module.scss index aebea31..60ed52f 100644 --- a/src/pages/preview/brand/info/info.module.scss +++ b/src/pages/preview/brand/info/info.module.scss @@ -26,7 +26,6 @@ page{ position: -webkit-sticky; top: 0; padding:40rpx 30rpx 30rpx 30rpx; - border-radius: 32rpx; background-color: #fff; .title{ font-size: 32rpx; diff --git a/src/pages/preview/illness/sort/sort.module.scss b/src/pages/preview/illness/sort/sort.module.scss index f5319b6..efab5db 100644 --- a/src/pages/preview/illness/sort/sort.module.scss +++ b/src/pages/preview/illness/sort/sort.module.scss @@ -1,4 +1,4 @@ -.scrollView{ +.scrollView { position: fixed; top: 0; bottom: 0; @@ -9,19 +9,18 @@ } .firstOrder { - width: 300rpx; + width: 400rpx; height: 100%; View { width: 100%; - text-align: center; min-height: 100rpx; - color: #323635; + color: #606563; display: flex; align-items: center; - padding: 10rpx; + padding: 20rpx 20rpx 20rpx 30rpx; box-sizing: border-box; - justify-content: center; + font-size: 28rpx; } } @@ -36,8 +35,8 @@ &:after { content: ''; display: block; - width: 8rpx; - height: 60rpx; + width: 6rpx; + height: 40rpx; background: #45D4A8; position: absolute; left: 0; @@ -65,6 +64,10 @@ background: #fff; box-sizing: border-box; height: 100%; + font-size: 28rpx; + font-family: PingFang SC-Bold, PingFang SC; + font-weight: bold; + color: #323635; } .list { @@ -77,3 +80,9 @@ display: flex; align-items: center; } + +.back { + padding: 25rpx 10rpx 20rpx 30rpx; + width: 30rpx; + height: 30rpx; +} diff --git a/src/pages/preview/illness/sort/sort.tsx b/src/pages/preview/illness/sort/sort.tsx index 3812077..3c0bbe7 100644 --- a/src/pages/preview/illness/sort/sort.tsx +++ b/src/pages/preview/illness/sort/sort.tsx @@ -14,11 +14,9 @@ const Sort: FC = () => { const [firstId, setFirstId] = useState(undefined) const [secondId, setSecondId] = useState(undefined) const [list, setList] = useState([]) - const globalData = Taro.getApp().globalData const menu = Taro.getMenuButtonBoundingClientRect() - async function getData() { const res = await HomeApi.category(3) setData(res) @@ -44,7 +42,6 @@ const Sort: FC = () => { display: 'flex', alignItems: "center", width: menu.left - 10 + 'px', - paddingLeft: '10px' } function firstIdChange(id: number) { @@ -75,15 +72,21 @@ const Sort: FC = () => { Taro.navigateBack()}/> - firstIdChange(data.tab?.value as number)}/> + + + firstIdChange(data.tab?.value as number)}/> + + {/**/} - + { data.find(d => d.id === firstId)?.resource_category?.map(d => { diff --git a/src/pages/preview/profession/profession.tsx b/src/pages/preview/profession/profession.tsx index 71f195a..7382144 100644 --- a/src/pages/preview/profession/profession.tsx +++ b/src/pages/preview/profession/profession.tsx @@ -68,6 +68,7 @@ const Profession = () => { } function jump(kill: Kill) { + HomeApi.skillSetPlay(kill.id) Taro.navigateTo({url: `/pages/preview/videoFull/videoFull?url=${kill.resource.url}&poster=${kill.url_path}&title=${kill.resource.name}`}) } diff --git a/types/home.d.ts b/types/home.d.ts index badd229..1c9ce4e 100644 --- a/types/home.d.ts +++ b/types/home.d.ts @@ -32,7 +32,7 @@ interface Kill { interface Illness { id: number - content: string - title: string + description: string + name: string thumb:string }