feat(cms): 添加视频内容支持并优化文章加载逻辑

- 在文章详情页添加视频播放功能,支持视频宽度自适应
- 优化文章加载逻辑,确保内容存在时才进行解析
- 添加视频元素的条件渲染判断
This commit is contained in:
2025-11-21 14:52:25 +08:00
parent 078b422db0
commit 4c6391053d

View File

@@ -17,7 +17,7 @@ function Detail() {
const reload = async () => { const reload = async () => {
const item = await getCmsArticle(Number(params.id)) const item = await getCmsArticle(Number(params.id))
if (item) { if (item && item.content) {
item.content = wxParse(item.content) item.content = wxParse(item.content)
setItem(item) setItem(item)
Taro.setNavigationBarTitle({ Taro.setNavigationBarTitle({
@@ -43,6 +43,10 @@ function Detail() {
<div className={'p-4 font-bold text-lg'}>{item?.title}</div> <div className={'p-4 font-bold text-lg'}>{item?.title}</div>
<div className={'text-gray-400 text-sm px-4 '}>{item?.createTime}</div> <div className={'text-gray-400 text-sm px-4 '}>{item?.createTime}</div>
<View className={'content p-4'}> <View className={'content p-4'}>
{/*如果有视频就显示视频 视频沾满宽度*/}
{item?.video && <View className={'w-full'}>
<video src={item?.video} controls={true} width={'100%'}></video>
</View>}
<RichText nodes={item?.content}/> <RichText nodes={item?.content}/>
</View> </View>
<Line height={44}/> <Line height={44}/>