refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,400 @@
|
||||
<template>
|
||||
<view class="popup-box" v-if="show" @click="onMaskClick">
|
||||
<view class="popup-mask"></view>
|
||||
<view ref="commentPanelRef" class="comment-panel" @click.stop
|
||||
@touchstart="onPanelTouchStart" @touchmove="onPanelTouchMove" @touchend="onPanelTouchEnd">
|
||||
<view class="comment-panel-header">
|
||||
<text class="comment-panel-title">评论 {{commentList.length}}</text>
|
||||
<view class="comment-panel-close" @click="handleClose">
|
||||
<text class="close-text">✕</text>
|
||||
</view>
|
||||
</view>
|
||||
<scroll-view ref="commentScrollRef" class="comment-scroll" :direction="scrollDirection" bounces="true">
|
||||
<view class="comment-list">
|
||||
<view class="comment-item" v-for="(comment, index) in commentList" :key="index">
|
||||
<view class="comment-avatar">
|
||||
<text class="avatar-text">{{comment.user.charAt(0)}}</text>
|
||||
</view>
|
||||
<view class="comment-content">
|
||||
<text class="comment-user">{{comment.user}}</text>
|
||||
<text class="comment-text">{{comment.content}}</text>
|
||||
<text class="comment-time">{{comment.time}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view class="comment-input-box" :style="'transform: translateY(-' + keyboardHeight + 'px);'">
|
||||
<input
|
||||
class="comment-input"
|
||||
v-model="commentInput"
|
||||
placeholder="说点什么..."
|
||||
@confirm="submitComment"
|
||||
:adjust-position="false"
|
||||
@keyboardheightchange="onKeyboardHeightChange"
|
||||
/>
|
||||
<view class="comment-send-btn" :class="{ 'disabled': !canSend }" @click="submitComment">
|
||||
<text class="send-text">发送</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 当前 uni-app x 框架在 iOS、Android 上报的键盘高度均已包含底部安全区,键盘弹出时隐藏额外占位 -->
|
||||
<view v-if="keyboardHeight == 0" class="safe-area-inset-bottom"></view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
/**
|
||||
* @description: 作为竖滑视频页的评论面板,支持展示评论列表、输入评论并同步更新评论数量。
|
||||
* @logic: 面板根据父页面传入的显示状态决定是否弹出,初始化预置评论列表;用户输入并发送评论后,把数量变化通过事件回传给父页面。
|
||||
* @optimization: 评论面板只在父页面需要时显示,并通过事件把数量变化回传给父页面,避免父子页面维护重复状态。
|
||||
*/
|
||||
type CommentItem = { user : string, content : string, time : string }
|
||||
|
||||
const props = defineProps<{
|
||||
show: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
countChange: [count: number]
|
||||
}>()
|
||||
|
||||
const commentList = ref([] as CommentItem[])
|
||||
const commentInput = ref("" as string)
|
||||
const keyboardHeight = ref(0 as number)
|
||||
|
||||
// 滚动到顶再下拉关闭(与 half-screen 一致)
|
||||
let panelMove = false
|
||||
let panelStartY = 0
|
||||
let panelOffset = 0
|
||||
let panelHeight = 0
|
||||
let lastTouchY = 0
|
||||
let lastTouchY2 = 0
|
||||
let bAnimating = false
|
||||
const commentPanelRef = ref<UniElement | null>(null)
|
||||
const commentScrollRef = ref<UniScrollViewElement | null>(null)
|
||||
const scrollDirection = ref('vertical')
|
||||
|
||||
// 计算是否可以发送
|
||||
const canSend = computed(() => {
|
||||
return commentInput.value.trim().length > 0
|
||||
})
|
||||
|
||||
// 初始化评论数据
|
||||
function initComments() {
|
||||
commentList.value = [
|
||||
{ user: "用户A", content: "这个视频太棒了!", time: "2分钟前" },
|
||||
{ user: "用户B", content: "学到了很多,感谢分享", time: "5分钟前" },
|
||||
{ user: "用户C", content: "期待更多精彩内容", time: "10分钟前" },
|
||||
{ user: "用户D", content: "点赞支持!", time: "15分钟前" },
|
||||
{ user: "用户E", content: "很有用的教程", time: "20分钟前" },
|
||||
{ user: "用户F", content: "很有用的教程", time: "20分钟前" },
|
||||
{ user: "用户G", content: "很有用的教程", time: "20分钟前" },
|
||||
{ user: "用户H", content: "很有用的教程", time: "20分钟前" },
|
||||
{ user: "用户I", content: "很有用的教程", time: "20分钟前" },
|
||||
{ user: "用户J", content: "很有用的教程", time: "20分钟前" }
|
||||
]
|
||||
emit('countChange', commentList.value.length)
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
keyboardHeight.value = 0
|
||||
panelMove = false
|
||||
panelStartY = 0
|
||||
panelOffset = 0
|
||||
// #ifdef APP
|
||||
commentScrollRef.value?.setAttribute('direction', 'vertical')
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
scrollDirection.value = 'vertical'
|
||||
// #endif
|
||||
commentPanelRef.value?.style?.setProperty('transform', '')
|
||||
commentPanelRef.value?.style?.setProperty('transition-property', 'none')
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function measurePanelHeight() {
|
||||
commentPanelRef.value?.getBoundingClientRectAsync()?.then((rect: DOMRect) => {
|
||||
panelHeight = rect.height
|
||||
})
|
||||
}
|
||||
|
||||
function onPanelTouchStart(_event : TouchEvent) {
|
||||
commentPanelRef.value?.style?.setProperty('transition-duration', '0')
|
||||
}
|
||||
|
||||
function onPanelTouchMove(e : TouchEvent) {
|
||||
if (bAnimating) return
|
||||
let top : number = commentScrollRef.value?.scrollTop ?? 0
|
||||
let p = e.touches[0]
|
||||
lastTouchY2 = lastTouchY
|
||||
lastTouchY = p.screenY
|
||||
if (top <= 0.01 || panelMove) {
|
||||
if (panelStartY == 0) {
|
||||
panelStartY = p.screenY
|
||||
}
|
||||
let offset = p.screenY - panelStartY
|
||||
if (offset > 0) {
|
||||
panelMove = true
|
||||
// #ifdef APP
|
||||
commentScrollRef.value?.setAttribute('direction', 'none')
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
scrollDirection.value = 'none'
|
||||
// #endif
|
||||
commentPanelRef.value?.style?.setProperty('transform', 'translateY(' + offset.toFixed(2) + 'px)')
|
||||
panelOffset = offset
|
||||
} else if (panelOffset > 0) {
|
||||
offset = panelStartY - p.screenY
|
||||
if (offset > panelOffset) {
|
||||
offset = 0
|
||||
panelMove = false
|
||||
}
|
||||
// #ifdef APP
|
||||
commentScrollRef.value?.setAttribute('direction', 'vertical')
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
scrollDirection.value = 'vertical'
|
||||
// #endif
|
||||
commentPanelRef.value?.style?.setProperty('transform', 'translateY(' + offset.toFixed(2) + 'px)')
|
||||
panelOffset = offset
|
||||
}
|
||||
}
|
||||
// #ifdef WEB
|
||||
e.preventDefault()
|
||||
// #endif
|
||||
}
|
||||
|
||||
function resumePanel() {
|
||||
const time = 300
|
||||
commentPanelRef.value?.style?.setProperty('transition-duration', time.toString() + 'ms')
|
||||
commentPanelRef.value?.style?.setProperty('transition-timing-function', 'ease-in-out')
|
||||
commentPanelRef.value?.style?.setProperty('transition-property', 'transform')
|
||||
commentPanelRef.value?.style?.setProperty('transform', 'translateY(0px)')
|
||||
panelMove = false
|
||||
// #ifdef APP
|
||||
commentScrollRef.value?.setAttribute('direction', 'vertical')
|
||||
// #endif
|
||||
// #ifdef WEB || MP
|
||||
scrollDirection.value = 'vertical'
|
||||
// #endif
|
||||
panelStartY = 0
|
||||
panelOffset = 0
|
||||
setTimeout(() => {
|
||||
bAnimating = false
|
||||
commentPanelRef.value?.style?.setProperty('transition-property', 'none')
|
||||
}, time)
|
||||
bAnimating = true
|
||||
}
|
||||
|
||||
function onPanelTouchEnd(_event : TouchEvent) {
|
||||
panelStartY = 0
|
||||
if (bAnimating) return
|
||||
let top : number = commentScrollRef.value?.scrollTop ?? 0
|
||||
let bHide = panelHeight > 0 && (panelHeight - panelOffset) < panelHeight / 4
|
||||
if (bHide) {
|
||||
bHide = lastTouchY2 > 0 && lastTouchY2 <= lastTouchY
|
||||
} else if (top <= 0.01) {
|
||||
bHide = (lastTouchY - lastTouchY2) > 3
|
||||
}
|
||||
if (bHide) {
|
||||
handleClose()
|
||||
} else if (panelOffset > 0) {
|
||||
resumePanel()
|
||||
}
|
||||
}
|
||||
|
||||
function onMaskClick() {
|
||||
handleClose()
|
||||
}
|
||||
|
||||
function onKeyboardHeightChange(event : UniInputKeyboardHeightChangeEvent) {
|
||||
keyboardHeight.value = event.detail.height
|
||||
}
|
||||
|
||||
function submitComment() {
|
||||
if (commentInput.value.trim() == "") {
|
||||
return
|
||||
}
|
||||
const timeStr = "刚刚"
|
||||
const newComment : CommentItem = {
|
||||
user: "我",
|
||||
content: commentInput.value,
|
||||
time: timeStr
|
||||
}
|
||||
commentList.value.unshift(newComment)
|
||||
commentInput.value = ""
|
||||
emit('countChange', commentList.value.length)
|
||||
}
|
||||
|
||||
// 弹窗打开时测量面板高度(用于下拉关闭阈值)
|
||||
watch((): boolean => props.show, (val: boolean) => {
|
||||
if (val) {
|
||||
nextTick(() => {
|
||||
measurePanelHeight()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化
|
||||
initComments()
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* 弹窗容器 */
|
||||
.popup-box {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.popup-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
.comment-panel {
|
||||
position: absolute;
|
||||
top: 200px;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
background-color: #1a1a1a;
|
||||
border-top-left-radius: 20px;
|
||||
border-top-right-radius: 20px;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.comment-panel-header {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 15px 20px;
|
||||
border-bottom-width: 1px;
|
||||
border-bottom-color: #333333;
|
||||
}
|
||||
|
||||
.comment-panel-title {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.comment-panel-close {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.close-text {
|
||||
font-size: 20px;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.comment-scroll {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.comment-list {
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.comment-item {
|
||||
flex-direction: row;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.comment-avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 18px;
|
||||
background-color: #007aff;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.avatar-text {
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.comment-content {
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.comment-user {
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: #ffffff;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.comment-text {
|
||||
font-size: 14px;
|
||||
color: #e0e0e0;
|
||||
line-height: 20px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.comment-time {
|
||||
font-size: 12px;
|
||||
color: #888888;
|
||||
}
|
||||
|
||||
.comment-input-box {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding: 10px 15px;
|
||||
border-top-width: 1px;
|
||||
border-top-color: #333333;
|
||||
background-color: #1a1a1a;
|
||||
transition-property: transform;
|
||||
transition-duration: 0.1s;
|
||||
transition-timing-function: ease-out;
|
||||
}
|
||||
|
||||
.safe-area-inset-bottom {
|
||||
height: env(safe-area-inset-bottom);
|
||||
flex-shrink: 0;
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
|
||||
.comment-input {
|
||||
flex: 1;
|
||||
height: 36px;
|
||||
padding: 0 10px;
|
||||
background-color: #2c2c2c;
|
||||
color: #ffffff;
|
||||
border-radius: 18px;
|
||||
font-size: 14px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.comment-send-btn {
|
||||
padding: 8px 20px;
|
||||
background-color: #007aff;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.comment-send-btn.disabled {
|
||||
background-color: #444444;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.send-text {
|
||||
color: #ffffff;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,136 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
|
||||
const PAGE_PATH = '/pages/template/vertical-video-feed/vertical-video-feed'
|
||||
|
||||
jest.setTimeout(60000)
|
||||
|
||||
describe('vertical-video-feed', () => {
|
||||
if (!isAndroid) {
|
||||
it('only support android', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (isDom2) {
|
||||
it('skip dom2', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
let page
|
||||
|
||||
async function openPage() {
|
||||
page = await program.reLaunch(PAGE_PATH)
|
||||
await page.waitFor('view')
|
||||
await page.waitFor(2000)
|
||||
}
|
||||
|
||||
async function waitForState(getter, matcher, timeout = 8000) {
|
||||
const start = Date.now()
|
||||
await page.waitFor(async () => {
|
||||
const value = await page.callMethod(getter)
|
||||
return matcher(value) || Date.now() - start > timeout
|
||||
})
|
||||
return await page.callMethod(getter)
|
||||
}
|
||||
|
||||
async function switchToVideo(index) {
|
||||
const swiper = await page.$('swiper')
|
||||
try {
|
||||
await swiper.swipeTo(index)
|
||||
await page.waitFor(1000)
|
||||
} catch (_) {
|
||||
// Fall back when element.swipeTo is not supported in current environment.
|
||||
}
|
||||
|
||||
const current = await page.callMethod('jest_getCurrent')
|
||||
if (current != index) {
|
||||
await page.callMethod('jest_switchTo', index)
|
||||
}
|
||||
|
||||
return await waitForState('jest_getCurrent', (value) => value == index)
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await openPage()
|
||||
})
|
||||
|
||||
if (!isAppWebView) {
|
||||
it('screenshot', async () => {
|
||||
const image = await program.screenshot({
|
||||
fullPage: true,
|
||||
})
|
||||
expect(image).toSaveImageSnapshot()
|
||||
})
|
||||
}
|
||||
|
||||
it('can play after tapping video', async () => {
|
||||
await openPage()
|
||||
const videoCover = await page.$('.video-cover')
|
||||
let stateList = await page.callMethod('jest_getStateList')
|
||||
|
||||
if (stateList[0] == 'play') {
|
||||
await videoCover.tap()
|
||||
stateList = await waitForState('jest_getStateList', (value) => value != null && value[0] == 'pause')
|
||||
expect(stateList[0]).toBe('pause')
|
||||
}
|
||||
|
||||
await videoCover.tap()
|
||||
stateList = await waitForState('jest_getStateList', (value) => value != null && value[0] == 'play')
|
||||
expect(stateList[0]).toBe('play')
|
||||
})
|
||||
|
||||
it('can switch up two videos with supported method', async () => {
|
||||
await openPage()
|
||||
expect(await page.callMethod('jest_getCurrent')).toBe(0)
|
||||
|
||||
let current = await switchToVideo(1)
|
||||
expect(current).toBe(1)
|
||||
|
||||
current = await switchToVideo(2)
|
||||
expect(current).toBe(2)
|
||||
})
|
||||
|
||||
it('can switch down back to original video with supported method', async () => {
|
||||
await openPage()
|
||||
let current = await switchToVideo(2)
|
||||
expect(current).toBe(2)
|
||||
|
||||
current = await switchToVideo(1)
|
||||
expect(current).toBe(1)
|
||||
|
||||
current = await switchToVideo(0)
|
||||
expect(current).toBe(0)
|
||||
})
|
||||
|
||||
it('can open comment list', async () => {
|
||||
await openPage()
|
||||
const commentBtn = await page.$('.comment-btn')
|
||||
await commentBtn.tap()
|
||||
const isPanelShown = await waitForState('jest_isCommentPanelShown', (value) => value == true)
|
||||
expect(isPanelShown).toBe(true)
|
||||
|
||||
const panel = await page.$('.comment-panel')
|
||||
const { height } = await panel.size()
|
||||
expect(height).toBeGreaterThan(0)
|
||||
|
||||
const commentItems = await page.$$('.comment-item')
|
||||
expect(commentItems.length).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('can close comment list by tapping mask', async () => {
|
||||
await openPage()
|
||||
const commentBtn = await page.$('.comment-btn')
|
||||
await commentBtn.tap()
|
||||
let isPanelShown = await waitForState('jest_isCommentPanelShown', (value) => value == true)
|
||||
expect(isPanelShown).toBe(true)
|
||||
|
||||
const mask = await page.$('.popup-mask')
|
||||
await mask.tap()
|
||||
isPanelShown = await waitForState('jest_isCommentPanelShown', (value) => value == false)
|
||||
expect(isPanelShown).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,382 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<uni-back-arrow-circle class="back" arrow-class="arrow"></uni-back-arrow-circle>
|
||||
<swiper class="swiper" :current="current" :circular="index != 0" :vertical="true" @change="onSwiperChange"
|
||||
@transition="onTransition">
|
||||
<swiper-item class="swiper-item" v-for="(item,i) in visibleList" :key="i">
|
||||
<video @click="changeState(i)" ref="video" class="video-box" :id="'video-'+i"
|
||||
@loadstart="onLoadstart(i)" :src="item.src" :poster="item.poster_src" :autoplay="false"
|
||||
:show-progress="false" :show-fullscreen-btn="false" :show-play-btn="false"
|
||||
:show-center-play-btn="false" :loop="true" @play="onPlay(i)" @pause="onPause(i)" :http-cache="true"></video>
|
||||
<view class="video-cover" @click="changeState(i)">
|
||||
<image v-if="stateList[i] === 'pause'" class="play-btn" src="/static/template/swiper-vertical-video/play.png"
|
||||
mode="widthFix"></image>
|
||||
</view>
|
||||
<view class="video-info" v-if="showDebugInfo">
|
||||
<text class="video-info-text">容器:第 {{i}} 个</text>
|
||||
<text class="video-info-text">内容:{{item.content}}</text>
|
||||
</view>
|
||||
<!-- 评论按钮 -->
|
||||
<view class="comment-btn" @click="openCommentPanel">
|
||||
<view class="comment-icon">
|
||||
<text class="comment-icon-text">💬</text>
|
||||
</view>
|
||||
<text class="comment-count">{{commentCount}}</text>
|
||||
</view>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view class="debug-info" v-if="showDebugInfo">
|
||||
<text class="status-text">debug-info 播放状态:</text>
|
||||
<text class="status-text" v-for="(value,index) in stateList">第{{index+1}}个:{{ value }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 评论面板 -->
|
||||
<comment-panel :show="showCommentPanel" @close="closeCommentPanel" @countChange="onCommentCountChange"></comment-panel>
|
||||
</view>
|
||||
</template>
|
||||
<script setup lang="uts">
|
||||
/**
|
||||
* @description: 支持上下滑动切换短视频内容,并在当前视频上叠加评论入口的竖滑视频流页面。
|
||||
* @logic: 页面只维护当前可见的 3 个视频容器,用户上下滑动 swiper 时更新可见数据和播放状态,点击评论按钮打开评论面板。
|
||||
* @optimization: 通过只保留 3 个可见视频容器并复用数据窗口,降低连续视频流场景下的组件创建和视频上下文数量。
|
||||
*/
|
||||
|
||||
type ListItem = { _id : string, content : string, src : string, poster_src : string }
|
||||
let page : number = 0,
|
||||
currentPageIsShow : boolean = true;
|
||||
|
||||
import { state, setNetless } from '@/store/index.uts'
|
||||
import CommentPanel from './comment-panel.uvue'
|
||||
|
||||
const $videoContextMap = new Map<string, VideoContext>()
|
||||
const list = ref([] as ListItem[])
|
||||
const visibleList = ref([] as ListItem[])// 提高性能 可见的只有3个
|
||||
const current = ref(0 as number)
|
||||
const index = ref(0)
|
||||
const stateList = ref(["pause", "unPlay", "unPlay"] as string[])
|
||||
const showDebugInfo = ref(false as boolean)
|
||||
|
||||
// 评论相关
|
||||
const showCommentPanel = ref(false as boolean)
|
||||
const commentCount = ref(0 as number)
|
||||
|
||||
function openCommentPanel() {
|
||||
showCommentPanel.value = true
|
||||
}
|
||||
|
||||
function closeCommentPanel() {
|
||||
showCommentPanel.value = false
|
||||
}
|
||||
|
||||
function onCommentCountChange(count : number) {
|
||||
commentCount.value = count
|
||||
}
|
||||
|
||||
function getVideoContext(idx : number) : VideoContext {
|
||||
let videoContext : VideoContext | null = $videoContextMap.get('video-' + idx)
|
||||
if (videoContext == null) {
|
||||
videoContext = uni.createVideoContext('video-' + idx) as VideoContext
|
||||
$videoContextMap.set('video-' + idx, videoContext)
|
||||
}
|
||||
return videoContext
|
||||
}
|
||||
|
||||
function doPlay(idx : number) {
|
||||
console.log("doPlay video" + idx);
|
||||
getVideoContext(idx).play()
|
||||
}
|
||||
|
||||
function doStop(idx : number) {
|
||||
console.log("doStop video-" + idx);
|
||||
getVideoContext(idx).stop();
|
||||
// TODO 临时方案:解决.stop()时触发了doPause的问题
|
||||
setTimeout(() => {
|
||||
stateList.value[idx] = 'unPlay'
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
function doPause(idx : number) {
|
||||
getVideoContext(idx).pause()
|
||||
console.log("doPause video-" + idx);
|
||||
}
|
||||
|
||||
function changeState(idx : number) {
|
||||
if (stateList.value[idx] === 'play') {
|
||||
doPause(idx)
|
||||
} else {
|
||||
doPlay(current.value)
|
||||
}
|
||||
}
|
||||
|
||||
function onLoadstart(idx : number) {
|
||||
console.error("onLoadstart video" + idx);
|
||||
}
|
||||
|
||||
function onPause(idx : number) {
|
||||
stateList.value[idx] = 'pause'
|
||||
console.log('onPause', idx);
|
||||
}
|
||||
|
||||
function onPlay(idx : number) {
|
||||
if (current.value != idx || !currentPageIsShow) {
|
||||
onPause(idx)
|
||||
} else {
|
||||
stateList.value[idx] = 'play'
|
||||
console.log('onPlay', idx);
|
||||
}
|
||||
}
|
||||
|
||||
function getData() : ListItem[] {
|
||||
let videoUrlList = state.netless
|
||||
? [
|
||||
'/static/test-video/10second-demo.mp4',
|
||||
'/static/test-video/10second-demo.mp4',
|
||||
'/static/test-video/10second-demo.mp4'
|
||||
]
|
||||
: [
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/video/uts-5-16.mp4',
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/video/uni-ai-5-16.mp4',
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/video/uni-verify-5-16.mp4'
|
||||
] as string[]
|
||||
|
||||
let posterSrcList = state.netless
|
||||
? [
|
||||
'/static/shuijiao.jpg',
|
||||
'/static/logo.jpg',
|
||||
'/static/shuijiao.jpg'
|
||||
]
|
||||
: [
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/dark-uni-uts-01.png',
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/dark-uni-ai-01.png',
|
||||
'https://web-ext-storage.dcloud.net.cn/uni-app-x/dark-uni-verify-01.jpg'
|
||||
] as string[]
|
||||
|
||||
|
||||
let listData = [] as ListItem[];
|
||||
for (let i = 0; i < 6; i++) {
|
||||
let idx = list.value.length + i;
|
||||
let listItem : ListItem = {
|
||||
"_id": "a00" + idx,
|
||||
"content": "这是第" + idx + "条数据,url地址" + videoUrlList[i % 3],
|
||||
"src": videoUrlList[i % 3],
|
||||
"poster_src": posterSrcList[i % 3]
|
||||
}
|
||||
listData.push(listItem)
|
||||
}
|
||||
return listData
|
||||
}
|
||||
|
||||
function onSwiperChange(e : SwiperChangeEvent) {
|
||||
// console.error('SwiperChangeEvent',e.detail.current);
|
||||
current.value = e.detail.current;
|
||||
}
|
||||
|
||||
function onTransition(/*e : SwiperTransitionEvent*/) {
|
||||
// console.log('onTransition e.detail.dx', e.detail.dx);
|
||||
}
|
||||
|
||||
watch(current, (curr : number, oldCurrent : number) => {
|
||||
let changeNumber = curr - oldCurrent
|
||||
if (changeNumber == 1 || changeNumber == -2) {
|
||||
// console.error('向右');
|
||||
index.value++
|
||||
} else {
|
||||
// console.error('向左');
|
||||
index.value--
|
||||
}
|
||||
// //翻页(3项为一页)
|
||||
if (Math.abs(changeNumber) == 2) {
|
||||
// console.log('翻页');
|
||||
page = Math.floor(index.value / 3);
|
||||
// console.log(index.value);
|
||||
// console.log('page',page);
|
||||
// console.log('slice',3*page,3*page+3);
|
||||
if (list.value.length < 3 * page + 3) {
|
||||
let listData : ListItem[] = getData()
|
||||
list.value.push(...listData)
|
||||
}
|
||||
|
||||
let visible = list.value.slice(3 * page, 3 * page + 3)
|
||||
// 换数据
|
||||
visibleList.value = visible
|
||||
}
|
||||
|
||||
stateList.value.forEach((_ : string, idx : number) => {
|
||||
if (idx === curr) {
|
||||
doPlay(curr)
|
||||
} else {
|
||||
// 除了选中的其他已经播放的都需要停止
|
||||
doStop(idx)
|
||||
console.log('index:' + idx + '已被执行停止');
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// #ifdef APP-HARMONY
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
setNetless(res.networkType === 'none')
|
||||
// #endif
|
||||
list.value = getData()
|
||||
visibleList.value = list.value.slice(0, 3)
|
||||
// #ifdef APP || MP
|
||||
// 非web端,一启动完成,就播放第一个。因为 web端浏览器限制不支持自动播放
|
||||
// 鸿蒙 vapor 模式下,v-for 后 nextTick 后 nativeView init 事件还没有触发,因此延时 30ms
|
||||
nextTick(() => {
|
||||
setTimeout(() => doPlay(0), 30)
|
||||
})
|
||||
// #endif
|
||||
// #ifdef APP-HARMONY
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
onPageShow(() => {
|
||||
currentPageIsShow = true
|
||||
})
|
||||
|
||||
onHide(() => {
|
||||
currentPageIsShow = false
|
||||
console.log('pages-onHide');
|
||||
doPause(current.value)
|
||||
})
|
||||
|
||||
onBackPress((): boolean => {
|
||||
if (showCommentPanel.value) {
|
||||
closeCommentPanel()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
doPause(current.value)
|
||||
})
|
||||
|
||||
function jest_getStateList() : string[] {
|
||||
return stateList.value
|
||||
}
|
||||
|
||||
function jest_getCurrent() : number {
|
||||
return current.value
|
||||
}
|
||||
|
||||
function jest_isCommentPanelShown() : boolean {
|
||||
return showCommentPanel.value
|
||||
}
|
||||
|
||||
function jest_switchTo(idx : number) {
|
||||
current.value = idx
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
jest_getStateList,
|
||||
jest_getCurrent,
|
||||
jest_isCommentPanelShown,
|
||||
jest_switchTo
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.swiper,
|
||||
.swiper-item,
|
||||
.video-box,
|
||||
.video-cover {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* .swiper-item {
|
||||
position: relative;
|
||||
} */
|
||||
|
||||
.video-box {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.video-cover {
|
||||
position: absolute;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
.play-btn {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.video-info {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.video-info-text {
|
||||
font-size: 14px;
|
||||
color: red;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.debug-info {
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
width: 100%;
|
||||
background-color: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.status-text {
|
||||
color: red;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.back{
|
||||
position: absolute;
|
||||
/* #ifdef APP || MP */
|
||||
top: var(--status-bar-height);
|
||||
/* #endif */
|
||||
/* #ifdef WEB */
|
||||
top: 10px;
|
||||
/* #endif */
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* uni-back-arrow-circle组件 自定义样式 */
|
||||
.arrow {
|
||||
border-left-color: #FFFFFF !important;
|
||||
border-bottom-color: #FFFFFF !important;
|
||||
}
|
||||
|
||||
/* 评论按钮 */
|
||||
.comment-btn {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
bottom: 80px;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.comment-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 20px;
|
||||
background-color: rgba(0, 0, 0, 0.3);
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.comment-icon-text {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.comment-count {
|
||||
font-size: 12px;
|
||||
color: #ffffff;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户