From 70e61e187e62e534c89e86fac5a34ecc20b84d30 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Tue, 5 Sep 2023 10:21:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=8A=A0=E8=BD=BD=E7=B1=BB=E5=9E=8B=20=E5=92=8C=20?= =?UTF-8?q?=E6=88=91=E7=9A=84=E9=A1=B5=E9=9D=A2header=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +-- src/api/brand.ts | 16 +++++----- src/components/image/image.tsx | 29 +++++++++++++++---- .../learningRecord/learningRecord.tsx | 1 - src/pages/my/components/header/header.tsx | 5 ++-- src/pages/my/my.module.scss | 10 +++++-- src/pages/my/my.tsx | 8 ++--- src/pages/preview/brand/list/list.tsx | 11 +++---- 8 files changed, 55 insertions(+), 29 deletions(-) diff --git a/.env b/.env index 86e2b46..3852d45 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -#TARO_APP_API=https://yjx.dev.yaojiankang.top -TARO_APP_API=https://mooc.yaojiankang.top +TARO_APP_API=https://yjx.dev.yaojiankang.top +#TARO_APP_API=https://mooc.yaojiankang.top #TARO_APP_API=https://shopfix.yaojiankang.top #TARO_APP_API=https://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/brand.ts b/src/api/brand.ts index 12a129e..fe673cc 100644 --- a/src/api/brand.ts +++ b/src/api/brand.ts @@ -8,7 +8,9 @@ export type BrandRecord = { brand_album: string graphic_introduction: string disabled: number - introductory_video_resource:any + introductory_video_resource: any + article_count: number + created_at: string } export type ArticleRecord = { title: string @@ -19,24 +21,24 @@ export type ArticleRecord = { export const brandApi = { /** 品牌列表 */ - list(page: number , page_size: number) { + list(page: number, page_size: number) { return request<{ list: BrandRecord[], total: number - }>(`/home/v1/brand/list?page=${page}&page_size=${page_size}` , "GET") + }>(`/home/v1/brand/list?page=${page}&page_size=${page_size}`, "GET") }, /** 品牌详情 */ info(id: number) { return request(`/home/v1/brand/${id}`, "GET") }, /** 文章列表 */ - articleList(owner_id: number,page:number) { + articleList(owner_id: number, page: number) { return request<{ list: ArticleRecord[], total: number - }>(`/home/v1/article/list?owner_id=${owner_id}&page=${page}&page_size=10` , "GET") + }>(`/home/v1/article/list?owner_id=${owner_id}&page=${page}&page_size=10`, "GET") }, - articleInfo(id: number ) { - return request(`/home/v1/article/${id}` , "GET") + articleInfo(id: number) { + return request(`/home/v1/article/${id}`, "GET") }, } diff --git a/src/components/image/image.tsx b/src/components/image/image.tsx index b726f93..de4c186 100644 --- a/src/components/image/image.tsx +++ b/src/components/image/image.tsx @@ -3,16 +3,19 @@ import {Image, ImageProps, View} from "@tarojs/components"; import shard from '@/static/img/shard.png' import styles from './image.module.scss' import Taro from "@tarojs/taro"; +import avatar from '@/static/img/avatar.png' interface Props extends ImageProps { width?: number | string height?: number | string fallback?: string + errorType?: "acquiesce" | 'avatar' } const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = shard, ...props}) => { const [isError, setIsError] = useState(false) const [loading, setLoading] = useState(true) + const [errorUrl, setErrorUrl] = useState(fallback) const imgAnimation = Taro.createAnimation({duration: 0}).opacity(0).step() const [animationData, setAnimationData] = useState(imgAnimation.export()) @@ -22,6 +25,18 @@ const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = sha setLoading(!!src) }, [src]) + useEffect(() => { + switch (props.errorType) { + case undefined: + case "acquiesce": + setErrorUrl(fallback) + break + case "avatar": + setErrorUrl(avatar) + break + } + }, [props.errorType]) + // 图片加载失败 function onErrorHandler() { setLoading(false) @@ -40,8 +55,8 @@ const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = sha style={{ width: `${width}rpx`, height: `${height}rpx`, - backgroundColor: '#F8F8F8' - }} + backgroundColor: (isError || !loading) ? 'transparent' : '#F8F8F8' + }} className={`${props?.className} ${styles.imgBox}`}> {!isError && @@ -51,8 +66,12 @@ const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = sha mode={mode} lazyLoad fadeIn - defaultSource={fallback} - style={{width: width ? `${width}rpx` : "100%", height: height ? `${height}rpx` : "100%"}} + defaultSource={errorUrl} + style={{ + width: width ? `${width}rpx` : "100%", + height: height ? `${height}rpx` : "100%", + verticalAlign: 'middle' + }} onError={onErrorHandler} onLoad={onLoadHandler}/> @@ -62,7 +81,7 @@ const Img: FC = ({src, mode = 'aspectFill', width, height, fallback = sha = ({userId}) => { }, [userId]) return ( - 学习记录 总共学习 diff --git a/src/pages/my/components/header/header.tsx b/src/pages/my/components/header/header.tsx index f000052..3432e85 100644 --- a/src/pages/my/components/header/header.tsx +++ b/src/pages/my/components/header/header.tsx @@ -4,6 +4,7 @@ import styles from "@/pages/my/my.module.scss"; import avatar from "@/static/img/avatar.png" import blacktriang from "@/static/img/blacktriangle.png" import {FC} from "react"; +import Img from "@/components/image/image"; interface Props { companyList: Company[] @@ -16,13 +17,13 @@ const Header: FC = ({companyList, showCompany}) => { return ( - + { token ? {user?.name} {company?.name} - {companyList.length > 2 && } + {companyList.length > 2 && } : diff --git a/src/pages/my/my.module.scss b/src/pages/my/my.module.scss index e37d523..cb6a7ad 100644 --- a/src/pages/my/my.module.scss +++ b/src/pages/my/my.module.scss @@ -4,6 +4,12 @@ page { overflow-x: hidden; } +.navigation { + transition: all 300ms; + display: flex; + align-items: center; +} + .page { background: linear-gradient(180deg, #45D4A8 0%, rgba(69, 212, 168, 0) 100%) no-repeat; background-size: 100% 458rpx; @@ -47,8 +53,6 @@ page { font-size: 10rpx; .avatar { - width: 100px; - height: 100px; margin-right: 30px; } } @@ -59,7 +63,7 @@ page { box-sizing: border-box; height: 136rpx; - &:nth-child(n) { + &:nth-child(odd) { padding-right: 11rpx; } diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index 116bd53..cf62fcb 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -69,9 +69,10 @@ const My: FC = () => { backgroundColor={`rgba(255,255,255,${navbarOpacity})`} cancelBack> { - Number(navbarOpacity) > .5 && - - {user?.name} + .5 ? "0%" : '-300%'})`}}> + + {user?.name} } @@ -139,7 +140,6 @@ const My: FC = () => { - ) } diff --git a/src/pages/preview/brand/list/list.tsx b/src/pages/preview/brand/list/list.tsx index 570c444..00dd5c4 100644 --- a/src/pages/preview/brand/list/list.tsx +++ b/src/pages/preview/brand/list/list.tsx @@ -5,6 +5,7 @@ import Taro, {useReachBottom} from "@tarojs/taro"; import Empty from "@/components/empty/empty"; import Spinner from "@/components/spinner"; import Img from "@/components/image/image"; +import {formatDate} from "@/utils/time"; const BrandItem: FC<{ data: BrandRecord; onClick: VoidFunction }> = ({data, onClick}) => { let media: ReactNode @@ -41,14 +42,14 @@ const BrandItem: FC<{ data: BrandRecord; onClick: VoidFunction }> = ({data, onCl {data.name} - + {data.graphic_introduction} - 2023/03.29 12:22:01 + {formatDate(new Date(data.created_at), "YY-MM-dd hh:mm:ss")} - 文章:123 - 点赞:234 + 文章:{data.article_count} + 点赞:{(Math.random() * 100).toFixed(0)} @@ -108,7 +109,7 @@ const BrandList: FC = () => { ) } else { - content = + content = } return (