Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
baeb2a89
提交
baeb2a89
authored
11月 10, 2025
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 农技视频轮播展示改为图片 + 点击播放
上级
360688e5
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
160 行增加
和
64 行删除
+160
-64
index.vue
src/components/IframeVideo/index.vue
+19
-0
nongchang.vue
src/pages/nongchang/nongchang.vue
+69
-31
shouye.vue
src/pages/shouye/shouye.vue
+71
-33
components.d.ts
types/components.d.ts
+1
-0
没有找到文件。
src/components/IframeVideo/index.vue
0 → 100644
浏览文件 @
baeb2a89
<
template
>
<iframe
:onload=
"onloadCode"
style=
"width: 100%; height: 100%; border: 1px solid #fff; background: #000"
></iframe>
</
template
>
<
script
>
export
default
{
props
:
{
src
:
{},
},
data
()
{
return
{
onloadCode
:
''
,
}
},
created
()
{
this
.
onloadCode
=
`this.contentWindow.document.body.innerHTML = '<video style="width: 100%;height: 100%" controls="controls" src="
${
this
.
src
}
"></video>';`
},
}
</
script
>
<
style
lang=
"scss"
></
style
>
src/pages/nongchang/nongchang.vue
浏览文件 @
baeb2a89
...
...
@@ -352,34 +352,35 @@
// 轮播视频切换的时候触发
function
handleChangeVideo
(
e
:
any
)
{
const
currentIndex
=
e
.
detail
.
current
const
prevIndex
=
pageData
.
current
pageData
.
current
=
currentIndex
pageData
.
agricultureClass
.
title
=
pageData
.
agricultureClass
.
videoList
[
currentIndex
]?.
title
// 延迟处理视频切换,避免卡顿
setTimeout
(()
=>
{
// 停止所有其他视频的播放(只暂停,不重置位置)
pageData
.
agricultureClass
.
videoList
.
forEach
((
_
,
index
)
=>
{
if
(
index
!==
currentIndex
)
{
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
// 不重置到开头,保留播放位置
}
catch
(
error
)
{
console
.
log
(
'停止视频失败:'
,
error
)
}
}
else
{
// 当前视频:尝试播放
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
// 自动播放当前视频
videoContext
.
play
()
}
catch
(
error
)
{
console
.
log
(
'播放视频失败:'
,
error
)
}
}
})
},
100
)
console
.
log
(
'当前索引:'
,
currentIndex
)
// // 延迟处理视频切换,避免卡顿
// setTimeout(() => {
// // 停止所有其他视频的播放(只暂停,不重置位置)
// pageData.agricultureClass.videoList.forEach((_, index) => {
// if (index !== currentIndex) {
// try {
// const videoContext = uni.createVideoContext(`video${index}`)
// videoContext.pause()
// // 不重置到开头,保留播放位置
// } catch (error) {
// console.log('停止视频失败:', error)
// }
// } else {
// // 当前视频:尝试播放
// try {
// const videoContext = uni.createVideoContext(`video${index}`)
// // 自动播放当前视频
// videoContext.play()
// } catch (error) {
// console.log('播放视频失败:', error)
// }
// }
// })
// }, 100)
}
// 处理swiper过渡动画
...
...
@@ -411,6 +412,33 @@
function
handleVideoPause
(
currentIndex
)
{
console
.
log
(
`视频
${
currentIndex
}
暂停`
)
}
function
playVideo
(
index
)
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
requestFullScreen
()
videoContext
.
play
()
}
function
handleFullscreenChange
(
e
:
any
,
index
)
{
console
.
log
(
`视频
${
index
}
全屏状态改变`
)
if
(
!
e
.
detail
.
fullScreen
)
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
}
}
onHide
(()
=>
{
// 停止所有其他视频的播放(只暂停,不重置位置)
pageData
.
agricultureClass
.
videoList
.
forEach
((
_
,
index
)
=>
{
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
// 不重置到开头,保留播放位置
}
catch
(
error
)
{
console
.
log
(
'停止视频失败:'
,
error
)
}
})
})
</
script
>
<
template
>
...
...
@@ -714,7 +742,7 @@
<text
class=
"font text_66"
>
农技学习
</text>
<text
class=
"font_6 text_43 text_67"
@
click=
"onViewMoreClass"
>
查看更多
</text>
</view>
<view
class=
"codefun-flex-col section_20"
>
<view
class=
"codefun-flex-col section_20
!relative
"
>
<fui-swiper-dot
:items=
"pageData.agricultureClass.videoList"
:current=
"pageData.current"
...
...
@@ -740,23 +768,32 @@
@
transition=
"handleTransition"
>
<swiper-item
v-for=
"(video, index) in pageData.agricultureClass.videoList"
:key=
"index"
>
<image
:src=
"video.cover_image"
mode=
"scaleToFill"
class=
"w-654rpx h-358rpx"
@
click=
"playVideo(index)"
/>
<video
:id=
"`video${index}`"
:src=
"video.media_video"
:poster=
"video.cover_image"
:controls=
"false"
:title=
"video.title"
:controls=
"true"
style=
"width: 654rpx; height: 358rpx"
:autoplay=
"
fals
e"
:autoplay=
"
tru
e"
:muted=
"false"
:loop=
"
fals
e"
:loop=
"
tru
e"
:show-play-btn=
"true"
:show-center-play-btn=
"true"
:enable-progress-gesture=
"
fals
e"
:show-progress=
"
fals
e"
:enable-progress-gesture=
"
tru
e"
:show-progress=
"
tru
e"
object-fit=
"contain"
@
loadedmetadata=
"handleMetadataLoaded"
@
play=
"handleVideoPlay(index)"
@
pause=
"handleVideoPause(index)"
@
fullscreenchange=
"handleFullscreenChange($event, index)"
class=
"!hidden"
></video>
</swiper-item>
</swiper>
...
...
@@ -1833,6 +1870,7 @@
position
:
absolute
;
bottom
:
52
rpx
;
left
:
40
rpx
;
z-index
:
1
;
.text_34
{
color
:
#ffffff
;
...
...
src/pages/shouye/shouye.vue
浏览文件 @
baeb2a89
...
...
@@ -398,34 +398,35 @@
// 轮播视频切换的时候触发
function
handleChangeVideo
(
e
:
any
)
{
const
currentIndex
=
e
.
detail
.
current
const
_prevIndex
=
pageData
.
current
pageData
.
current
=
currentIndex
pageData
.
agricultureClass
.
title
=
pageData
.
agricultureClass
.
videoList
[
currentIndex
]?.
title
// 延迟处理视频切换,避免卡顿
setTimeout
(()
=>
{
// 停止所有其他视频的播放(只暂停,不重置位置)
pageData
.
agricultureClass
.
videoList
.
forEach
((
_
,
index
)
=>
{
if
(
index
!==
currentIndex
)
{
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
// 不重置到开头,保留播放位置
}
catch
(
error
)
{
console
.
log
(
'停止视频失败:'
,
error
)
}
}
else
{
// 当前视频:尝试播放
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
// 自动播放当前视频
videoContext
.
play
()
}
catch
(
error
)
{
console
.
log
(
'播放视频失败:'
,
error
)
}
}
})
},
100
)
console
.
log
(
'当前索引:'
,
currentIndex
)
// // 延迟处理视频切换,避免卡顿
// setTimeout(() => {
// // 停止所有其他视频的播放(只暂停,不重置位置)
// pageData.agricultureClass.videoList.forEach((_, index) => {
// if (index !== currentIndex) {
// try {
// const videoContext = uni.createVideoContext(`video${index}`)
// videoContext.pause()
// // 不重置到开头,保留播放位置
// } catch (error) {
// console.log('停止视频失败:', error)
// }
// } else {
// // 当前视频:尝试播放
// try {
// const videoContext = uni.createVideoContext(`video${index}`)
// // 自动播放当前视频
// videoContext.play()
// } catch (error) {
// console.log('播放视频失败:', error)
// }
// }
// })
// }, 100)
}
// 处理swiper过渡动画
...
...
@@ -439,6 +440,14 @@
console
.
log
(
`视频
${
currentIndex
}
暂停`
)
}
function
handleFullscreenChange
(
e
:
any
,
index
)
{
console
.
log
(
`视频
${
index
}
全屏状态改变`
)
if
(
!
e
.
detail
.
fullScreen
)
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
}
}
// 获取视频时长
function
handleMetadataLoaded
(
e
:
any
)
{
pageData
.
agricultureClass
.
time
=
e
.
target
.
duration
...
...
@@ -452,6 +461,25 @@
}
})
}
function
playVideo
(
index
)
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
requestFullScreen
()
videoContext
.
play
()
}
onHide
(()
=>
{
// 停止所有其他视频的播放(只暂停,不重置位置)
pageData
.
agricultureClass
.
videoList
.
forEach
((
_
,
index
)
=>
{
try
{
const
videoContext
=
uni
.
createVideoContext
(
`video
${
index
}
`
)
videoContext
.
pause
()
// 不重置到开头,保留播放位置
}
catch
(
error
)
{
console
.
log
(
'停止视频失败:'
,
error
)
}
})
})
</
script
>
<
template
>
...
...
@@ -723,7 +751,7 @@
<
text
class
=
"font_6 text_32"
>
农技课堂
<
/text
>
<!--
<
text
class
=
"font_7 text_33"
@
click
=
"onViewMoreClass"
>
查看全部
<
/text> --
>
<
/view
>
<
view
class
=
"codefun-flex-col section_13"
>
<
view
class
=
"codefun-flex-col section_13
!relative
"
>
<
fui
-
swiper
-
dot
:
items
=
"pageData.agricultureClass.videoList"
:
current
=
"pageData.current"
...
...
@@ -749,23 +777,32 @@
@
transition
=
"handleTransition"
>
<
swiper
-
item
v
-
for
=
"(video, index) in pageData.agricultureClass.videoList"
:
key
=
"index"
>
<
image
:
src
=
"video.cover_image"
mode
=
"scaleToFill"
class
=
"w-654rpx h-358rpx"
@
click
=
"playVideo(index)"
/>
<
video
:
id
=
"`video${index
}
`"
:
src
=
"video.media_video"
:
poster
=
"video.cover_image"
:
controls
=
"false"
:
title
=
"video.title"
:
controls
=
"true"
style
=
"width: 654rpx; height: 358rpx"
:
autoplay
=
"
fals
e"
:
autoplay
=
"
tru
e"
:
muted
=
"false"
:
loop
=
"
fals
e"
:
loop
=
"
tru
e"
:
show
-
play
-
btn
=
"true"
:
show
-
center
-
play
-
btn
=
"true"
:
enable
-
progress
-
gesture
=
"
fals
e"
:
show
-
progress
=
"
fals
e"
:
enable
-
progress
-
gesture
=
"
tru
e"
:
show
-
progress
=
"
tru
e"
object
-
fit
=
"contain"
@
loadedmetadata
=
"handleMetadataLoaded"
@
play
=
"handleVideoPlay(index)"
@
pause
=
"handleVideoPause(index)"
@
fullscreenchange
=
"handleFullscreenChange($event, index)"
class
=
"!hidden"
><
/video
>
<
/swiper-item
>
<
/swiper
>
...
...
@@ -1526,10 +1563,10 @@
position
:
relative
;
margin
-
right
:
28
rpx
;
margin
-
top
:
32.86
rpx
;
height
:
4
1
8
rpx
;
height
:
4
2
8
rpx
;
// padding: 271.06rpx 36.64rpx 22rpx 48rpx;
padding
:
20
rpx
;
padding
-
bottom
:
0
;
padding
-
bottom
:
10
rpx
;
background
-
color
:
#
ffffff
;
border
-
radius
:
16
rpx
;
mix
-
blend
-
mode
:
NOTTHROUGH
;
...
...
@@ -1562,6 +1599,7 @@
position
:
absolute
;
bottom
:
52
rpx
;
left
:
40
rpx
;
z
-
index
:
1
;
}
.
text_34
{
...
...
types/components.d.ts
浏览文件 @
baeb2a89
...
...
@@ -144,6 +144,7 @@ declare module 'vue' {
FuiWhiteSpace
:
typeof
import
(
'./../src/components/FirstUI/fui-white-space/fui-white-space.vue'
)[
'default'
]
FuiWingBlank
:
typeof
import
(
'./../src/components/FirstUI/fui-wing-blank/fui-wing-blank.vue'
)[
'default'
]
Icon
:
typeof
import
(
'./../src/components/Icon/index.vue'
)[
'default'
]
IframeVideo
:
typeof
import
(
'./../src/components/IframeVideo/index.vue'
)[
'default'
]
ThumbnailPreview
:
typeof
import
(
'./../src/components/ThumbnailPreview/index.vue'
)[
'default'
]
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论