miroir de
https://github.com/ialley-workshop-open/uni-halo.git
synchronisé 2026-06-12 21:29:31 +08:00
fix: 修复瞬间视频可同时播放多个视频bug、优化列表加载
Cette révision appartient à :
@@ -12,9 +12,9 @@
|
|||||||
<tm-empty icon="icon-shiliangzhinengduixiang-" label="暂无数据"></tm-empty>
|
<tm-empty icon="icon-shiliangzhinengduixiang-" label="暂无数据"></tm-empty>
|
||||||
</view>
|
</view>
|
||||||
<block v-else>
|
<block v-else>
|
||||||
<block v-for="(moment, index) in dataList" :key="index">
|
|
||||||
<!-- 卡片 -->
|
<!-- 卡片 -->
|
||||||
<tm-translate v-if="moment.spec.visible==='PUBLIC'" animation-name="fadeUp" :wait="calcAniWait()">
|
<tm-translate v-for="(moment, index) in dataList" :key="moment.metadata.name" animation-name="fadeUp"
|
||||||
|
:wait="calcAniWait(index)">
|
||||||
<view class="moment-card">
|
<view class="moment-card">
|
||||||
<view class="head" style="display: flex;align-items: center;">
|
<view class="head" style="display: flex;align-items: center;">
|
||||||
<view class="avatar" style="flex-shrink: 0;">
|
<view class="avatar" style="flex-shrink: 0;">
|
||||||
@@ -37,46 +37,39 @@
|
|||||||
:content="moment.spec.newHtml" :markdown="true" :showLineNumber="true"
|
:content="moment.spec.newHtml" :markdown="true" :showLineNumber="true"
|
||||||
:showLanguageName="true" :copyByLongPress="true" />
|
:showLanguageName="true" :copyByLongPress="true" />
|
||||||
</view>
|
</view>
|
||||||
<view v-if="moment.images.length!==0" class="images"
|
<view v-if="moment.images.length!==0" class="images" :class="['images-'+moment.images.length]">
|
||||||
:class="['images-'+moment.images.length]">
|
<view class="image-item" v-for="(image,mediumIndex) in moment.images" :key="mediumIndex">
|
||||||
<view class="image-item"
|
|
||||||
v-for="(image,mediumIndex) in moment.images"
|
|
||||||
:key="mediumIndex">
|
|
||||||
<image mode="aspectFill" style="width: 100%;height: 100%;border-radius: 6rpx;"
|
<image mode="aspectFill" style="width: 100%;height: 100%;border-radius: 6rpx;"
|
||||||
:src="image.url"
|
:src="image.url" @click="handlePreview(mediumIndex,moment.images)" />
|
||||||
@click="handlePreview(mediumIndex,moment.images)"/>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="moment.audios.length!==0" class="mb-12"
|
<view v-if="moment.audios.length!==0" class="mb-12"
|
||||||
style="display: flex; flex-direction: column; gap: 12rpx 0;padding: 0 24rpx;padding-right:28rpx;">
|
style="display: flex; flex-direction: column; gap: 12rpx 0;padding: 0 24rpx;padding-right:28rpx;">
|
||||||
<audio
|
<audio v-for="(audio,index) in moment.audios" :controls="true" :key="index" :id="audio.url"
|
||||||
v-for="(audio,index) in moment.audios"
|
|
||||||
:controls="true"
|
|
||||||
:key="index"
|
|
||||||
:id="audio.url"
|
|
||||||
:poster="bloggerInfo.avatar"
|
:poster="bloggerInfo.avatar"
|
||||||
:name="'来自' + (startConfig.title||bloggerInfo.nickname) + '的声音'"
|
:name="'来自' + (startConfig.title||bloggerInfo.nickname) + '的声音'"
|
||||||
:author="bloggerInfo.nickname"
|
:author="bloggerInfo.nickname" :src="audio.url"></audio>
|
||||||
:src="audio.url"></audio>
|
|
||||||
</view>
|
</view>
|
||||||
<view v-if="moment.videos.length!==0" class="mb-12"
|
<view v-if="moment.videos.length!==0" class="mb-12"
|
||||||
style="display: flex; flex-direction: column; gap: 12rpx 0;padding: 0 24rpx; ">
|
style="display: flex; flex-direction: column; gap: 12rpx 0;padding: 0 24rpx; ">
|
||||||
<video
|
<video style="width:100%;height: 400rpx;border-radius: 12rpx;"
|
||||||
style="width:100%;height: 400rpx;border-radius: 12rpx;"
|
v-for="(video,index) in moment.videos" :key="index" :src="video.url"
|
||||||
v-for="(video,index) in moment.videos"
|
:id="'video_' + video.id" :show-mute-btn="true" :controls="true"
|
||||||
:key="index" :src="video.url"></video>
|
:show-center-play-btn="true" :enable-progress-gesture="true"
|
||||||
|
@play="onVideoPlay(video.id)" @pause="onVideoPause(video.id)"
|
||||||
|
@ended="onVideoEnded(video.id)"></video>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="moment.spec.tags && moment.spec.tags.length!==0" class="mt-12 px-16 pb-24 flex flex-wrap">
|
<view v-if="moment.spec.tags && moment.spec.tags.length!==0"
|
||||||
<tm-tags
|
class="mt-12 px-16 pb-24 flex flex-wrap">
|
||||||
v-for="(tag,tagIndex) in moment.spec.tags" :key="tagIndex"
|
<tm-tags v-for="(tag,tagIndex) in moment.spec.tags" :key="tagIndex"
|
||||||
:color="randomTagColor()" size="m" model="text">
|
:color="randomTagColor()" size="m" model="text">
|
||||||
{{ tag }}
|
{{ tag }}
|
||||||
</tm-tags>
|
</tm-tags>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</tm-translate>
|
</tm-translate>
|
||||||
</block>
|
<tm-flotbutton @click="fnToTopPage" :width="90" size="xs" color="light-blue" :icon-size="24"
|
||||||
<tm-flotbutton @click="fnToTopPage" :width="90" size="xs" color="light-blue" :icon-size="24" icon="icon-angle-up"></tm-flotbutton>
|
icon="icon-angle-up"></tm-flotbutton>
|
||||||
<view class="load-text">{{ loadMoreText }}</view>
|
<view class="load-text">{{ loadMoreText }}</view>
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
@@ -92,8 +85,12 @@ import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
|
|||||||
|
|
||||||
import MarkdownConfig from '@/common/markdown/markdown.config.js';
|
import MarkdownConfig from '@/common/markdown/markdown.config.js';
|
||||||
import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
|
import mpHtml from '@/components/mp-html/components/mp-html/mp-html.vue';
|
||||||
import {getRandomNumberByRange} from "@/utils/random.js"
|
import {
|
||||||
|
getRandomNumberByRange
|
||||||
|
} from "@/utils/random.js";
|
||||||
|
import {
|
||||||
|
generateUUID
|
||||||
|
} from '@/utils/uuid.js';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
tmSkeleton,
|
tmSkeleton,
|
||||||
@@ -115,7 +112,9 @@ export default {
|
|||||||
dataList: [],
|
dataList: [],
|
||||||
isLoadMore: false,
|
isLoadMore: false,
|
||||||
loadMoreText: '加载中...',
|
loadMoreText: '加载中...',
|
||||||
tagColors: ['orange', 'green', 'red', 'blue']
|
tagColors: ['orange', 'green', 'red', 'blue'],
|
||||||
|
videoContexts: {},
|
||||||
|
currentVideoId: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -139,18 +138,18 @@ export default {
|
|||||||
},
|
},
|
||||||
startConfig() {
|
startConfig() {
|
||||||
return this.haloConfigs.appConfig.startConfig;
|
return this.haloConfigs.appConfig.startConfig;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.fnGetData();
|
this.fnGetData();
|
||||||
},
|
},
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
this.isLoadMore = false;
|
this.isLoadMore = false;
|
||||||
this.queryParams.page = 0;
|
this.queryParams.page = 0;
|
||||||
|
this.videoContexts = {};
|
||||||
|
this.currentVideoId = null;
|
||||||
this.fnGetData();
|
this.fnGetData();
|
||||||
},
|
},
|
||||||
|
|
||||||
onReachBottom(e) {
|
onReachBottom(e) {
|
||||||
if (this.calcAuditModeEnabled) {
|
if (this.calcAuditModeEnabled) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -220,7 +219,7 @@ export default {
|
|||||||
this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
|
this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
|
||||||
this.hasNext = res.hasNext;
|
this.hasNext = res.hasNext;
|
||||||
|
|
||||||
const tempItems = res.items.map(item => {
|
const tempItems = res.items.filter(x => x.spec.visible === 'PUBLIC').map(item => {
|
||||||
item.spec.user = {
|
item.spec.user = {
|
||||||
displayName: this.bloggerInfo.nickname,
|
displayName: this.bloggerInfo.nickname,
|
||||||
avatar: this.$utils.checkAvatarUrl(this.bloggerInfo.avatar)
|
avatar: this.$utils.checkAvatarUrl(this.bloggerInfo.avatar)
|
||||||
@@ -234,7 +233,10 @@ export default {
|
|||||||
.filter(x => x.type === 'PHOTO')
|
.filter(x => x.type === 'PHOTO')
|
||||||
|
|
||||||
item['videos'] = item.spec.content.medium
|
item['videos'] = item.spec.content.medium
|
||||||
.filter(x => x.type === 'VIDEO')
|
.filter(x => x.type === 'VIDEO').map(item => {
|
||||||
|
item.id = generateUUID()
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
|
||||||
item['audios'] = item.spec.content.medium
|
item['audios'] = item.spec.content.medium
|
||||||
.filter(x => x.type === 'AUDIO')
|
.filter(x => x.type === 'AUDIO')
|
||||||
@@ -246,6 +248,11 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.dataList = tempItems;
|
this.dataList = tempItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.createVideoContexts(tempItems);
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@@ -269,14 +276,37 @@ export default {
|
|||||||
const regex = /<a\s+(?:[^>]*?\s+)?class=(['"])[^'"]*?\btag\b[^'"]*?\1[^>]*?>.*?<\/a>/gi;
|
const regex = /<a\s+(?:[^>]*?\s+)?class=(['"])[^'"]*?\btag\b[^'"]*?\1[^>]*?>.*?<\/a>/gi;
|
||||||
const newHtml = htmlString.replace(regex, '');
|
const newHtml = htmlString.replace(regex, '');
|
||||||
return newHtml
|
return newHtml
|
||||||
// .replace(/<[^>]+>\s*<\/[^>]+>/g, '')
|
|
||||||
// .replace(/\s+/g, ' ')
|
|
||||||
// .trim();
|
|
||||||
},
|
},
|
||||||
randomTagColor() {
|
randomTagColor() {
|
||||||
if (!this.calcUseTagRandomColor) return "blue";
|
if (!this.calcUseTagRandomColor) return "blue";
|
||||||
const randomIndex = getRandomNumberByRange(0, this.tagColors.length);
|
const randomIndex = getRandomNumberByRange(0, this.tagColors.length);
|
||||||
return this.tagColors[randomIndex];
|
return this.tagColors[randomIndex];
|
||||||
|
},
|
||||||
|
createVideoContexts(list) {
|
||||||
|
this.stopAllVideos()
|
||||||
|
list.map(item => item.videos).flat().forEach(item => {
|
||||||
|
this.videoContexts[item.id] = uni.createVideoContext(`video_${item.id}`, this);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onVideoPlay(videoId) {
|
||||||
|
this.currentVideoId = videoId;
|
||||||
|
this.stopAllVideos(videoId)
|
||||||
|
},
|
||||||
|
onVideoPause(videoId) {
|
||||||
|
if (this.currentVideoId == videoId) {
|
||||||
|
this.currentVideoId = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onVideoEnded(videoId) {
|
||||||
|
this.currentVideoId = null;
|
||||||
|
},
|
||||||
|
stopAllVideos(excludesVideoId = null) {
|
||||||
|
Object.keys(this.videoContexts).forEach(videoId => {
|
||||||
|
if (!excludesVideoId || excludesVideoId != videoId) {
|
||||||
|
const videoContext = this.videoContexts[videoId]
|
||||||
|
videoContext?.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -345,5 +375,4 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 12rpx;
|
border-radius: 12rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* 生成指定长度的uuid
|
||||||
|
* @param {number} = 长度
|
||||||
|
*/
|
||||||
|
export function generateUUID(length = 36) {
|
||||||
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
let result = '';
|
||||||
|
|
||||||
|
const validLength = Math.max(1, Math.floor(Number(length)) || 36);
|
||||||
|
for (let i = 0; i < validLength; i++) {
|
||||||
|
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Référencer dans un nouveau ticket
Bloquer un utilisateur