Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
2ed72d94
提交
2ed72d94
authored
1月 01, 2026
作者:
e
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 前端获取视频文件的宽高,虽然获取到了,但感觉还是有很大的卡顿感
上级
a1ed374c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
123 行增加
和
8 行删除
+123
-8
shouye.vue
src/pages/shouye/shouye.vue
+123
-6
components.d.ts
types/components.d.ts
+0
-2
没有找到文件。
src/pages/shouye/shouye.vue
浏览文件 @
2ed72d94
<
script
setup
lang=
"ts"
>
import
{
reactive
,
ref
}
from
'vue'
import
{
reactive
,
ref
,
getCurrentInstance
}
from
'vue'
import
{
onPullDownRefresh
}
from
'@dcloudio/uni-app'
import
dayjs
from
'dayjs'
import
{
closeSplashscreenAndChechUpgrade
}
from
'@/utils/upgrade'
...
...
@@ -288,6 +288,9 @@ const pageData = reactive({
agricultureClass: {
videoList: [],
},
videoListIsShow:false,
videwHtmlList:""
})
function getServiceItems() {
...
...
@@ -325,8 +328,13 @@ function getServiceStatsList() {
}
function getAgricultureClassList() {
getVideoList({ pageNo: 1, pageSize: 10, status: 1 }).then((res) => {
const { records } = res
pageData.agricultureClass.videoList = records
const { records } = res;
let videwHtmlList = '';
for(let i = 0; i < records.length;i++){
videwHtmlList += '<video class="htmlvideo" data-index="'+i+'" src="'+records[i].url+'"></video>'
}
pageData.videwHtmlList = videwHtmlList;
pageData.agricultureClass.videoList = records;
})
}
...
...
@@ -464,6 +472,82 @@ onHide(() => {
}
})
})
// 引入实例
const instance = getCurrentInstance();
const getDomDataSetFunc = (domName='',datasetName='index') =>{
return new Promise((resolve,reject)=>{
const queryDataget = uni.createSelectorQuery().in(instance.proxy);
// 获取内容
queryDataget.select(domName).fields({dataset:true},(data)=>{
if(data && data.dataset){
resolve(data.dataset[datasetName])
}else{
reject()
}
}).exec();
})
}
function domClick(){
getDomDataSetFunc('.domClick','index').then((res)=>{
// console.log(res)
let whArr = JSON.parse(res);
let videoList = pageData.agricultureClass.videoList;
let videoLen = videoList.length,scale = 0;
for(let i = 0; i < videoLen;i++){
/* videoList[i].videoWidth = whArr[i].w; */
scale = (340 / whArr[i].w).toFixed(1);
videoList[i].videoWidth = 340;
videoList[i].videoHeight = Math.floor(whArr[i].h * scale);
if(videoLen >= i){
pageData.videoListIsShow = true;
}
}
})
}
</
script
>
<
script
module=
"renderscript"
lang=
"renderjs"
>
export default {
data() {
return {};
},
methods: {
methodInRenderjs(newValue, oldValue, ownerVm, vm) {
if(newValue && newValue.length){
let valLen = newValue.length;
let videoWH = [],videoIndex = 0;
for(let i = 0; i < newValue.length; i++){
videoWH.push(0)
}
setTimeout(()=>{
let domClick = document.querySelector(".domClick");
const videos = document.querySelectorAll('.htmlvideo');
videos.forEach(video => {
video.addEventListener('loadedmetadata', function() {
var dataIndex = video.getAttribute('data-index');
videoWH[dataIndex] = {w:video.videoWidth,h:video.videoHeight};
videoIndex++;
if(videoIndex >= valLen){
domClick.dataset.index = JSON.stringify(videoWH);
domClick.click();
}
// console.log('Video width:',dataIndex, videoWidth, 'Video height:', videoHeight);
});
});
},600)
}
},
// renderjs 向普通 Vue 传值的方法
sendDataToVue(event, ownerInstance) {
ownerInstance.callMethod('someMethodInVue', { // 调用 Vue 组件中的方法
someData: '这是从 renderjs 传来的数据'
});
}
}
};
</
script
>
<
template
>
...
...
@@ -666,7 +750,38 @@ onHide(() => {
<text
class=
"font_6 text_32"
>
农技课堂
</text>
<text
class=
"font_7 text_33"
@
click=
"onViewMoreClass"
>
查看全部
</text>
</view>
<view
class=
"codefun-flex-col section_13 !relative rounded-lg"
style=
"margin-left: -28rpx;"
>
<view
v-if=
"pageData.videoListIsShow"
class=
"codefun-flex-col section_13 !relative rounded-lg"
style=
"margin-left: -28rpx;"
>
<fui-waterfall
topGap=
"20"
leftGap=
"20"
rightGap=
"20"
bottomGap=
"20"
>
<fui-waterfall-item
:imgWidth=
"video.videoWidth"
:imgHeight=
"video.videoHeight"
v-for=
"(video, index) in pageData.agricultureClass.videoList"
:key=
"index"
:src=
"video.thumbnailPath"
@
click=
"playVideo(index)"
>
<view
class=
"flex flex-col justify-between pl-2 pr-2 pb-2"
>
<view
class=
"fontsize_28 mt-1 mb-2 font-13"
>
{{
video
.
title
}}
</view>
<view
class=
"flex justify-between text-25 color-#686868"
>
<view
class=
"mr-1 flex-center"
>
<view
class=
"flex-center text-24 lh-24rpx"
>
{{
video
.
viewCount
||
0
}}
次播放
</view>
</view>
<text>
{{
dayjs
(
video
.
publishDate
).
format
(
'MM-DD'
)
}}
</text>
</view>
</view>
<video
:id=
"`video$
{index}`" :src="video.url" :poster="video.thumbnailPath"
:title="video.title" :controls="true" :autoplay="false" :muted="false" :loop="true"
:show-play-btn="true" :show-center-play-btn="true" :enable-progress-gesture="true"
:show-progress="true" :direction="0" object-fit="contain"
@loadedmetadata="handleMetadataLoaded" @play="handleVideoPlay(index)"
@pause="handleVideoPause(index)"
@fullscreenchange="handleFullscreenChange($event, index)" class="!hidden">
</video>
</fui-waterfall-item>
</fui-waterfall>
</view>
<view
v-show=
"false"
style=
"width:0px;height:0px;"
class=
"domClick"
@
click=
"domClick"
:vsrc=
"pageData.agricultureClass.videoList"
:change:vsrc=
"renderscript.methodInRenderjs"
>
<!--
<video
class=
"htmlvideo"
:src=
"video.url"
v-for=
"(video, index) in pageData.agricultureClass.videoList"
:key=
"index"
></video>
-->
<view
v-html=
"pageData.videwHtmlList"
></view>
</view>
<!--
<view
class=
"codefun-flex-col section_13 !relative rounded-lg"
style=
"margin-left: -28rpx;"
>
<fui-waterfall
topGap=
"20"
leftGap=
"20"
rightGap=
"20"
bottomGap=
"20"
>
<fui-waterfall-item
v-for=
"(video, index) in pageData.agricultureClass.videoList"
:key=
"index"
:src=
"video.thumbnailPath"
@
click=
"playVideo(index)"
>
...
...
@@ -674,7 +789,6 @@ onHide(() => {
<view
class=
"fontsize_28 mt-1 mb-2 font-13"
>
{{
video
.
title
}}
</view>
<view
class=
"flex justify-between text-25 color-#686868"
>
<view
class=
"mr-1 flex-center"
>
<!--
<image
class=
"mt-0.2 mr-1 w-30 h-26"
src=
"/static/images/news/views.png"
/>
-->
<view
class=
"flex-center text-24 lh-24rpx"
>
{{
video
.
viewCount
||
0
}}
次播放
</view>
</view>
<text>
{{
dayjs
(
video
.
publishDate
).
format
(
'MM-DD'
)
}}
</text>
...
...
@@ -689,7 +803,10 @@ onHide(() => {
@fullscreenchange="handleFullscreenChange($event, index)" class="!hidden">
</video>
</fui-waterfall-item>
</fui-waterfall>
</view>
</view>
-->
</view>
</view>
...
...
types/components.d.ts
浏览文件 @
2ed72d94
...
...
@@ -150,8 +150,6 @@ declare module 'vue' {
IframeVideo
:
typeof
import
(
'./../src/components/IframeVideo/index.vue'
)[
'default'
]
Legend
:
typeof
import
(
'./../src/components/Map/Widgets/Legend/src/Legend.vue'
)[
'default'
]
Mapbox
:
typeof
import
(
'./../src/components/Map/Mapbox/index.vue'
)[
'default'
]
RouterLink
:
typeof
import
(
'vue-router'
)[
'RouterLink'
]
RouterView
:
typeof
import
(
'vue-router'
)[
'RouterView'
]
Src
:
typeof
import
(
'./../src/components/Echarts/src/index.vue'
)[
'default'
]
SuccessfulDialog
:
typeof
import
(
'./../src/components/ConfirmDialog/successfulDialog.vue'
)[
'default'
]
Switch
:
typeof
import
(
'./../src/components/Map/Widgets/Switch/src/Switch.vue'
)[
'default'
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论