From 547d61c1333a6af1e376538472d2f14d3c8c116f Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期三, 18 六月 2025 09:38:45 +0800
Subject: [PATCH] uview不分包
---
pages/video/home-page.vue | 328 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 235 insertions(+), 93 deletions(-)
diff --git a/pages/video/home-page.vue b/pages/video/home-page.vue
index 9f9ddbf..1e29861 100644
--- a/pages/video/home-page.vue
+++ b/pages/video/home-page.vue
@@ -4,14 +4,11 @@
<view class="user-header">
<view class="user-avatar-container">
<image class="user-avatar" :src="userInfo.avatar" mode="aspectFill"></image>
- <view class="edit-icon" @click="editProfile" v-if="isSelf">
- <uni-icons type="compose" size="20" color="#666"></uni-icons>
- </view>
</view>
<view class="user-info">
<view class="user-name">{{userInfo.nickName}}</view>
<view class="user-id">ID: {{userInfo.userId}}</view>
- <view class="user-desc">{{userInfo.motto || '杩欎釜浜哄緢鎳掞紝浠�涔堥兘娌$暀涓媬'}}</view>
+ <view class="user-desc">{{userInfo.motto || '娌℃湁绛惧悕锛屼篃寰堜釜鎬'}}</view>
</view>
<view class="stats-container">
<view class="stat-item" @click="navigateToFollow('fans')">
@@ -38,6 +35,10 @@
{{userInfo.hasSub ? '鍙栨秷鍏虫敞' : '鍏虫敞'}}
</button>
</view>
+
+ <view class="edit-icon" @click="editInfo" v-if="userInfo.self">
+ <uni-icons type="compose" size="20" color="#666"></uni-icons>缂栬緫涓婚〉淇℃伅
+ </view>
</view>
<!-- 浣滃搧/鍠滄鍒囨崲 -->
@@ -47,7 +48,7 @@
:class="{active: currentTab === 'works'}"
@click="switchTab('works')"
>
- 浣滃搧
+ 浣滃搧{{`(${videoTotal})`}}
</view>
<view
class="tab-item"
@@ -59,38 +60,79 @@
</view>
<!-- 瑙嗛鍒楄〃 -->
- <view class="video-list">
- <view
- class="video-item"
- v-for="(item, index) in videoList"
- :key="item.id"
- @click="playVideo(index)"
- >
- <image class="video-cover" :src="item.cover" mode="aspectFill"></image>
- <view class="video-info">
- <view class="video-stats">
- <view class="stat">
- <uni-icons type="heart" size="14" color="#fff"></uni-icons>
- <text>{{item.collectNum}}</text>
- </view>
- </view>
- </view>
- </view>
- </view>
+ <scroll-view class="video-list" scroll-y :show-scrollbar="false" @scrolltolower="getPage" v-show="currentTab === 'works' && videoList.length > 0">
+ <view
+ class="video-item"
+ v-for="(item, index) in videoList"
+ :key="item.id"
+ >
+ <image class="video-cover" @click="playAuthorVideo(index)" :src="item.coverUrl" mode="aspectFill"></image>
+ <view class="video-info">
+ <view class="video-stats">
+ <view class="stat">
+ <uni-icons type="heart" size="16" color="#fff"></uni-icons>
+ <text>{{item.collectNum}}</text>
+ <view class="more-op">
+ <dropdown-menu
+ :options="item.options"
+ placement="top"
+ theme-color="#07C160"
+ @change="handleChange"
+ ></dropdown-menu>
+ </view>
+ </view>
+ </view>
+ </view>
+ </view>
+ </scroll-view>
+ <scroll-view class="video-list" scroll-y :show-scrollbar="false" @scrolltolower="getPage" v-show="currentTab === 'likes' && collectVideoList.length > 0">
+ <view class="video-container">
+ <view
+ class="video-item"
+ v-for="(item, index) in collectVideoList"
+ :key="item.id"
+ @click="playCollectVideo(index)"
+ >
+ <image class="video-cover" :src="item.coverUrl" mode="aspectFill"></image>
+ <view class="video-info">
+ <view class="video-stats">
+ <view class="stat">
+ <uni-icons type="heart" size="16" color="#fff"></uni-icons>
+ <text>{{item.collectNum}}</text>
+ </view>
+ </view>
+ </view>
+ </view>
+ </view>
+ </scroll-view>
<!-- 绌虹姸鎬� -->
- <view class="empty-state" v-if="videoList.length === 0">
- <image src="/static/images/empty.png" mode="aspectFit" class="empty-image"></image>
- <text class="empty-text">{{currentTab === 'works' ? '浣犺繕娌℃湁鍙戝竷浣滃搧鍝' : '浣犺繕娌℃湁鐐硅禐浣滃搧鍝'}}</text>
+ <view class="empty-state" v-if="videoList.length === 0 && currentTab === 'works'">
+ <!-- <image src="/static/images/empty.png" mode="aspectFit" class="empty-image"></image> -->
+ <text class="empty-text">杩樻湭鍙戝竷浣滃搧鍝</text>
</view>
+ <!-- 绌虹姸鎬� -->
+ <view class="empty-state" v-if="collectVideoList.length === 0 && currentTab === 'likes'">
+ <!-- <image src="/static/images/empty.png" mode="aspectFit" class="empty-image"></image> -->
+ <text class="empty-text">杩樻病鏈夌偣璧炰綔鍝佸摝~</text>
+ </view>
</view>
</template>
<script>
-import {getAuthorInfo, getAuthorVideoPage} from '@/api/user.js'
+import DropdownMenu from '@/components/dropdown-menu.vue'
+
+import {getAuthorInfo, getAuthorVideoPage, getAuthorCollectVideoPage} from '@/api/user.js'
+import {subscribe, unSubscribe} from '@/api/video.js'
export default {
+ components: {DropdownMenu},
data() {
return {
+ options: [
+ { command: 1, label: '鍖椾含' },
+ { command: 2, label: '涓婃捣' },
+ { command: 3, label: '骞垮窞' }
+ ],
currentTab: 'works', // works: 浣滃搧, likes: 鍠滄
authorId: '',
userInfo: {
@@ -109,8 +151,20 @@
pageNumber: 1,
pageSize: 10
},
- videoList: []
+ collectVideoQuery: {
+ authorId: '',
+ pageNumber: 1,
+ pageSize: 10
+ },
+ videoTotal: 0,
+ videoList: [], // 浣滃搧
+ collectVideoList: [], // 鏀惰棌
+ nomoreVideo: false,
+ nomoreCollectVideo: false
}
+ },
+ onShow() {
+ this.getAuthorInfo();
},
onLoad(option) {
this.authorId = option.authorId;
@@ -118,75 +172,151 @@
this.getAuthorVideoPage();
},
methods: {
+ handleChange(value) {
+ console.log('閫変腑鍊�:', value)
+ },
+ getPage() {
+ if(this.currentTab === 'works') {
+ if(this.nomoreVideo) {
+ return;
+ }
+ getAuthorVideoPage(this.videoQuery).then(res => {
+ if(this.videoQuery.pageNumber === 1) {
+ this.videoList = res.data.data
+ } else {
+ this.videoList = [
+ ...this.videoList,
+ ...res.data.data.filter(
+ (newItem) => !this.videoList.some((oldItem) => oldItem.id === newItem.id)
+ ),
+ ];
+ }
+ if(res.data.data.length < this.videoQuery.pageSize) {
+ this.nomoreVideo = true;
+ } else {
+ this.videoQuery.pageNumber += 1;
+ }
+ })
+ } else if(this.currentTab === 'likes') {
+ if(this.nomoreCollectVideo) {
+ return;
+ }
+ getAuthorCollectVideoPage(this.collectVideoQuery).then(res => {
+ if(this.collectVideoQuery.pageNumber === 1) {
+ this.collectVideoList = res.data.data
+ } else {
+ this.collectVideoList = [
+ ...this.collectVideoList,
+ ...res.data.data.filter(
+ (newItem) => !this.collectVideoList.some((oldItem) => oldItem.id === newItem.id)
+ ),
+ ];
+ }
+ if(res.data.data.length < this.collectVideoQuery.pageSize) {
+ this.nomoreCollectVideo = true;
+ } else {
+ this.collectVideoQuery.pageNumber += 1;
+ }
+ })
+ }
+ },
// 鑾峰彇涓汉淇℃伅
async getAuthorInfo() {
getAuthorInfo(this.authorId).then(res => {
this.userInfo = res.data.data
})
},
+ // 鑾峰彇浣滆�呬綔鍝�
async getAuthorVideoPage() {
this.videoQuery.authorId = this.authorId;
getAuthorVideoPage(this.videoQuery).then(res => {
- if(this.videoQuery.pageNumber === 1) {
- this.videoList = res.data.data
- } else {
- this.videoList = [
- ...this.videoList,
- ...res.data.data.filter(
- (newItem) => !this.videoList.some((oldItem) => oldItem.id === newItem.id)
- ),
- ];
+ this.videoList = res.data.data
+ this.videoTotal = res.data.total
+ if(res.data.data.length < this.videoQuery.pageSize) {
+ this.nomoreVideo = true;
}
})
},
- // 鑾峰彇浣滃搧淇℃伅
// 鍒囨崲鍏虫敞鐘舵��
toggleFollow() {
- // 妯℃嫙璇锋眰鏈嶅姟鍣�
- uni.showLoading({
- title: '澶勭悊涓�...'
- });
-
- setTimeout(() => {
- this.isFollowed = !this.isFollowed;
-
- // 鏇存柊绮変笣鏁�
- if(this.isFollowed) {
- this.userInfo.fansCount++;
- uni.showToast({
- title: '鍏虫敞鎴愬姛',
- icon: 'success'
- });
- } else {
- this.userInfo.fansCount--;
- uni.showToast({
- title: '宸插彇娑堝叧娉�',
- icon: 'none'
- });
- }
-
- uni.hideLoading();
- }, 500);
+ if(this.userInfo.hasSub) {
+ // 鍙栨秷鍏虫敞
+ unSubscribe(this.authorId).then(res => {
+ uni.showToast({
+ title: '宸插彇娑堝叧娉�',
+ icon: 'none'
+ });
+ this.userInfo.hasSub = false
+ this.userInfo.fansNum -= 1;
+ })
+ } else {
+ // 鍏虫敞
+ subscribe(this.authorId).then(res => {
+ uni.showToast({
+ title: '鍏虫敞鎴愬姛',
+ icon: 'success'
+ });
+ this.userInfo.hasSub = true
+ this.userInfo.fansNum += 1;
+ })
+ }
},
// 鍒囨崲浣滃搧/鍠滄tab
switchTab(tab) {
+ if(this.currentTab === tab) {
+ return
+ }
this.currentTab = tab;
- // 杩欓噷搴旇鏍规嵁tab鍒囨崲璇锋眰涓嶅悓鐨勬暟鎹�
- // this.loadVideoList();
+ if(tab === 'works') {
+ this.collectVideoList = []
+ this.videoQuery.pageNumber = 1
+ this.getAuthorVideoPage()
+ } else if(tab === 'likes') {
+ this.videoList = []
+ this.collectVideoQuery.pageNumber = 1
+ this.getAuthorCollectVideoPage()
+ }
},
-
- // 鎾斁瑙嗛
- playVideo(index) {
- const videoItem = this.videoList[index];
+ // 鑾峰彇浣滆�呯殑鏀惰棌瑙嗛
+ async getAuthorCollectVideoPage() {
+ this.collectVideoQuery.authorId = this.authorId
+ getAuthorCollectVideoPage(this.collectVideoQuery).then(res => {
+ this.collectVideoList = res.data.data
+ if(res.data.data.length < this.collectVideoQuery.pageSize) {
+ this.nomoreCollectVideo = true;
+ }
+ })
+ },
+ // 鎾斁浣滆�呰棰�
+ playAuthorVideo(index) {
+ const playInfo = {
+ videoList: this.videoList,
+ nomore: this.nomoreVideo,
+ pageNumber: this.videoQuery.pageNumber,
+ playIndex: index
+ }
+ uni.setStorageSync("playInfo", playInfo)
uni.navigateTo({
- url: `/pages/video/play?id=${videoItem.id}`
+ url: `/pages/video/video-play?authorId=${this.authorId}&videoFrom=author`
});
},
-
- // 缂栬緫涓汉璧勬枡
- editProfile() {
+ // 鎾斁鏀惰棌瑙嗛
+ playAuthorVideo(index) {
+ const playInfo = {
+ videoList: this.collectVideoList,
+ nomore: this.nomoreCollectVideo,
+ pageNumber: this.collectVideoQuery.pageNumber,
+ playIndex: index
+ }
+ uni.setStorageSync("playInfo", playInfo)
uni.navigateTo({
- url: '/pages/user/edit'
+ url: `/pages/video/video-play?authorId=${this.authorId}&videoFrom=collect`
+ });
+ },
+ // 缂栬緫涓汉璧勬枡
+ editInfo() {
+ uni.navigateTo({
+ url: `/pages/video/home-page-edit?authorId=${this.authorId}&avatar=${this.userInfo.avatar}&motto=${this.userInfo.motto || ''}&nickName=${this.userInfo.nickName}`
});
},
@@ -208,9 +338,12 @@
</script>
<style lang="scss" scoped>
+body {
+ background-color: #fff !important;
+}
.container {
padding-bottom: 20rpx;
- background-color: #f5f5f5;
+ background-color: white;
min-height: 100vh;
}
@@ -238,16 +371,13 @@
.edit-icon {
position: absolute;
- right: 0;
- bottom: 0;
+ right: 30rpx;
+ top: 30rpx;
background-color: #fff;
- border-radius: 50%;
- width: 40rpx;
height: 40rpx;
display: flex;
justify-content: center;
align-items: center;
- box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
}
.user-info {
@@ -300,7 +430,7 @@
.tab-bar {
display: flex;
background-color: #fff;
- margin-bottom: 20rpx;
+ padding-bottom: 20rpx;
}
.tab-item {
@@ -330,9 +460,10 @@
}
.video-list {
- display: flex;
- flex-wrap: wrap;
+ width: calc(100% - 20rpx);
padding: 0 10rpx;
+ height: calc(100vh - 554rpx);
+ background-color: #fff;
}
.video-item {
@@ -344,18 +475,21 @@
.video-cover {
width: 100%;
- height: 350rpx;
+ height: 500rpx;
border-radius: 10rpx;
display: block;
}
.video-info {
+ display: flex;
+ height: 60rpx;
+ align-items: center;
+ font-size: 24rpx;
+ width: 100%;
+ padding-right: 20rpx;
+ box-sizing: border-box;
position: absolute;
bottom: 20rpx;
- left: 20rpx;
- right: 20rpx;
- color: #fff;
- font-size: 24rpx;
}
.video-title {
@@ -369,17 +503,25 @@
.video-stats {
display: flex;
+ width: 100%;
}
.stat {
display: flex;
+ width: 100%;
align-items: center;
- margin-right: 20rpx;
- text-shadow: 0 0 5rpx rgba(0, 0, 0, 0.5);
+ position: relative;
+}
+
+.more-op {
+ position: absolute;
+ right: 0;
}
.stat text {
margin-left: 5rpx;
+ color: #fff;
+ font-size: 14px;
}
.empty-state {
@@ -427,8 +569,8 @@
}
}
-/* 濡傛灉鏄嚜宸辩殑涓婚〉锛岄殣钘忓叧娉ㄦ寜閽� */
-.user-header {
- position: relative;
+.video-container {
+ display: flex;
+ flex-wrap: wrap
}
</style>
\ No newline at end of file
--
Gitblit v1.8.0