绿满眶商城微信小程序-uniapp
xiangpei
2025-05-27 3b238b10eabf4ccb01af3955492c16b68526c9bd
pages/tabbar/index/home.vue
@@ -75,7 +75,7 @@
         <view class="avatar-container">
            <image class="avatar" :src="item.authorAvatar" mode="aspectFill"></image>
            <!-- 关注图标 - 使用绝对定位 -->
            <view class="follow-icon">
            <view v-if="!item.subscribeThisAuthor" class="follow-icon" @click="subscribeAuth(index, item.authorId)">
             <text class="iconfont">&#xe629;</text>
            </view>
         </view>
@@ -96,7 +96,7 @@
</template>
<script>
import { getRecommendVideos, savePlayRecord } from "@/api/video.js";
import { getRecommendVideos, savePlayRecord, subscribe } from "@/api/video.js";
import { changeCollect } from "@/api/collect.js";
export default {
  data() {
@@ -142,6 +142,28 @@
    this.initVideoContexts();
  },
  methods: {
     // 关注作者
     subscribeAuth(index, authorId) {
      this.videoList.forEach(video => {
         if(video.authorId === authorId) {
            video.subscribeThisAuthor = true
         }
      })
      subscribe(authorId).then(res => {
         if(res.data.code === 200) {
            uni.showToast({
              title: '关注成功~',
              icon: 'none'
            });
         } else {
            this.videoList.forEach(video => {
               if(video.authorId === authorId) {
                  video.subscribeThisAuthor = false
               }
            })
         }
      })
     },
    // 初始化视频上下文
    initVideoContexts() {
      this.videoContexts = this.videoList.map((_, index) => {