未登录的时候文章内容不超过半屏不显示登录按钮

v2
king 1 year ago
parent 485bc0815b
commit 9fb280b866
  1. 39
      src/pages/preview/brand/article/article.tsx

@ -1,4 +1,4 @@
import {FC, useEffect, useMemo, useState} from "react"; import {FC, useCallback, useEffect, useMemo, useState} from "react";
import {Image, Text, View} from "@tarojs/components"; import {Image, Text, View} from "@tarojs/components";
import Taro, {useRouter} from "@tarojs/taro"; import Taro, {useRouter} from "@tarojs/taro";
import {ArticleRecord, brandApi} from "@/api"; import {ArticleRecord, brandApi} from "@/api";
@ -7,44 +7,69 @@ import down from "@/static/img/doubleDown.png";
import {Profile} from "@/store"; import {Profile} from "@/store";
import {parse} from "@/utils/marked/marked"; import {parse} from "@/utils/marked/marked";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import Spin from "@/components/spinner";
const article: FC = () => { const article: FC = () => {
const {token} = Profile.useContainer() const {token} = Profile.useContainer()
const [enable, setEnable] = useState(true)
const {id} = useRouter().params as unknown as { id: number } const {id} = useRouter().params as unknown as { id: number }
const [articleInfo, setArticleInfo] = useState<ArticleRecord>() const [articleInfo, setArticleInfo] = useState<ArticleRecord>()
const [ultra, setUltra] = useState(true)
const globalData = Taro.getApp().globalData
const pageHeight = globalData.windowHeight - globalData.textBarHeight - globalData.statusBarHeight
const {children} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) const {children} = useMemo(() => parse(articleInfo?.content || ''), [articleInfo])
useEffect(() => { useEffect(() => {
getData() const query = Taro.createSelectorQuery()
}, [id]) query.select('#childrenNode').boundingClientRect((res) => {
if (!Array.isArray(res)) {
if (res.height !== 240) {
console.log({childrenNode: res})
setUltra(pageHeight * .45 < res.height)
}
}
}).exec()
}, [children])
Taro.useReady(() => {
getData().then()
})
const getData = async () => { const getData = useCallback(async () => {
try { try {
const data = await brandApi.articleInfo(id) const data = await brandApi.articleInfo(id)
Taro.setNavigationBarTitle({title: data.title}) Taro.setNavigationBarTitle({title: data.title})
if (data.content.length < 200) {
setUltra(false)
}
setArticleInfo(data) setArticleInfo(data)
} catch (e) { } catch (e) {
} }
} setEnable(false)
}, [id])
function helloWorld() { function helloWorld() {
return ( return (
<> <>
<Spin overlay enable={enable}/>
<View style={{ <View style={{
padding: '10px', padding: '10px',
height: !token ? Taro.getWindowInfo().windowHeight - 60 + 'px' : 'auto', height: !token ? Taro.getWindowInfo().windowHeight - 60 + 'px' : 'auto',
overflow: !token ? 'hidden' : 'auto' overflow: !token ? 'hidden' : 'auto'
}}> }}>
<View id="childrenNode">
{ {
children.length > 0 ? children : <Empty name='暂无数据'/> children.length > 0 ? children : <Empty name='暂无数据'/>
} }
</View> </View>
</View>
{ {
!token && !token && ultra &&
<View className={styles.fixedBox}> <View className={styles.fixedBox}>
<View className={styles['fixedBox-inner']}> <View className={styles['fixedBox-inner']}>
<View className={styles['fixedBox-inner-icon']}> <View className={styles['fixedBox-inner-icon']}>
<Image src={down}></Image> <Image src={down}/>
</View> </View>
<View className={styles['fixedBox-inner-box']} onClick={() => { <View className={styles['fixedBox-inner-box']} onClick={() => {
Taro.navigateTo({url: '/pages/login/login'}) Taro.navigateTo({url: '/pages/login/login'})

Loading…
Cancel
Save