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

v2
king 1 year ago
parent 485bc0815b
commit 9fb280b866
  1. 45
      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 Taro, {useRouter} from "@tarojs/taro";
import {ArticleRecord, brandApi} from "@/api";
@ -7,44 +7,69 @@ import down from "@/static/img/doubleDown.png";
import {Profile} from "@/store";
import {parse} from "@/utils/marked/marked";
import Empty from "@/components/empty/empty";
import Spin from "@/components/spinner";
const article: FC = () => {
const {token} = Profile.useContainer()
const [enable, setEnable] = useState(true)
const {id} = useRouter().params as unknown as { id: number }
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])
useEffect(() => {
getData()
}, [id])
const query = Taro.createSelectorQuery()
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 {
const data = await brandApi.articleInfo(id)
Taro.setNavigationBarTitle({title: data.title})
if (data.content.length < 200) {
setUltra(false)
}
setArticleInfo(data)
} catch (e) {
}
}
setEnable(false)
}, [id])
function helloWorld() {
return (
<>
<Spin overlay enable={enable}/>
<View style={{
padding: '10px',
height: !token ? Taro.getWindowInfo().windowHeight - 60 + 'px' : 'auto',
overflow: !token ? 'hidden' : 'auto'
}}>
{
children.length > 0 ? children : <Empty name='暂无数据'/>
}
<View id="childrenNode">
{
children.length > 0 ? children : <Empty name='暂无数据'/>
}
</View>
</View>
{
!token &&
!token && ultra &&
<View className={styles.fixedBox}>
<View className={styles['fixedBox-inner']}>
<View className={styles['fixedBox-inner-icon']}>
<Image src={down}></Image>
<Image src={down}/>
</View>
<View className={styles['fixedBox-inner-box']} onClick={() => {
Taro.navigateTo({url: '/pages/login/login'})

Loading…
Cancel
Save