绿满眶商城微信小程序-uniapp
xiangpei
2025-05-27 3b238b10eabf4ccb01af3955492c16b68526c9bd
关注作者功能
2个文件已修改
39 ■■■■■ 已修改文件
api/video.js 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tabbar/index/home.vue 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/video.js
@@ -47,3 +47,16 @@
    data: data
  });
}
/**
 * 关注作者
 *
 * @param params
 */
 export function subscribe(authorId) {
  return http.request({
    url: "/lmk/my-subscribe/subscribe/" + authorId,
    method: Method.POST,
    needToken: true
  });
}
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) => {