| | |
| | | import { onLoad } from '@dcloudio/uni-app' |
| | | import { useGlobal } from '@/composables/useGlobal' |
| | | const { $http, $message, $store } = useGlobal() |
| | | // 在 film-detail.vue 的 script setup 部分添加 |
| | | import { useUserStore } from '@/store/user' |
| | | |
| | | import { FilmInfo, FilmPicture, CommentDTO } from '@/types/index' |
| | | import { formatRelativeTime } from '@/utils/time' |
| | |
| | | } |
| | | |
| | | // film-detail.vue |
| | | const showCommentLayer = (parentId?: number | string) => { |
| | | // const showCommentLayer = (parentId?: number | string) => { |
| | | // console.log('点击了评论按钮',parentId) |
| | | // if (typeof parentId === 'object') { |
| | | // parentId = '' |
| | | // } |
| | | // commentShow.value = true |
| | | // // 如果有parentId,说明是回复评论,需要设置parentId |
| | | // // 如果没有parentId,说明是直接评论,不需要设置parentId |
| | | // commentParendId.value = parentId ? String(parentId) : '' |
| | | // } |
| | | // 修改 showCommentLayer 函数 |
| | | const showCommentLayer = async (parentId?: number | string) => { |
| | | // 检查是否登录 |
| | | const isLoggedIn = await checkLogin() |
| | | if (!isLoggedIn) return |
| | | |
| | | console.log('点击了评论按钮',parentId) |
| | | if (typeof parentId === 'object') { |
| | | parentId = '' |
| | |
| | | } |
| | | } |
| | | |
| | | // const toggleLike = async () => { |
| | | // console.log("toggleLike",filmInfo.value) |
| | | // if (!filmInfo.value) return |
| | | // |
| | | // const api = liked.value ? '/v2/film-likes/filmLikes/edit' : '/v2/film-likes/filmLikes/edit' |
| | | // |
| | | // try { |
| | | // const res = await $http.request('post', api, { |
| | | // data: { filmId: filmInfo.value.id } |
| | | // }) |
| | | // |
| | | // if (res.code === 0) { |
| | | // // 更新本地状态 |
| | | // liked.value = !liked.value |
| | | // filmInfo.value.voLikeCount += liked.value ? 1 : -1 |
| | | // |
| | | // // 提示信息 |
| | | // $message.showToast(liked.value ? '点赞成功' : '取消点赞') |
| | | // } |
| | | // } catch (error) { |
| | | // console.error('点赞失败:', error) |
| | | // $message.showToast('操作失败') |
| | | // } |
| | | // } |
| | | // |
| | | // const toggleFavorite = async () => { |
| | | // console.log("toggleFavorite",filmInfo.value) |
| | | // if (!filmInfo.value) return |
| | | // |
| | | // const api = collected.value ? '/v2/film-collects/filmCollects/edit' : '/v2/film-collects/filmCollects/edit' |
| | | // |
| | | // try { |
| | | // const res = await $http.request('post', api, { |
| | | // data: { filmId: filmInfo.value.id } |
| | | // }) |
| | | // |
| | | // if (res.code === 0) { |
| | | // // 更新本地状态 |
| | | // collected.value = !collected.value |
| | | // filmInfo.value.voCollectCount += collected.value ? 1 : -1 |
| | | // |
| | | // // 提示信息 |
| | | // $message.showToast(collected.value ? '收藏成功' : '取消收藏') |
| | | // } |
| | | // } catch (error) { |
| | | // console.error('收藏失败:', error) |
| | | // $message.showToast('操作失败') |
| | | // } |
| | | // } |
| | | |
| | | // 修改 toggleLike 函数 |
| | | const toggleLike = async () => { |
| | | // 检查是否登录 |
| | | const isLoggedIn = await checkLogin() |
| | | if (!isLoggedIn) return |
| | | |
| | | console.log("toggleLike",filmInfo.value) |
| | | if (!filmInfo.value) return |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // 修改 toggleFavorite 函数 |
| | | const toggleFavorite = async () => { |
| | | // 检查是否登录 |
| | | const isLoggedIn = await checkLogin() |
| | | if (!isLoggedIn) return |
| | | |
| | | console.log("toggleFavorite",filmInfo.value) |
| | | if (!filmInfo.value) return |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | const checkLogin = async () => { |
| | | const userStore = useUserStore() |
| | | try { |
| | | await userStore.getCurrentInfo() |
| | | if (userStore.hasLogin) { |
| | | return true |
| | | } else { |
| | | showLoginModal() |
| | | return false |
| | | } |
| | | } catch (err) { |
| | | console.error('验证登录状态失败:', err) |
| | | showLoginModal() |
| | | return false |
| | | } |
| | | } |
| | | |
| | | const showLoginModal = () => { |
| | | uni.showModal({ |
| | | title: '登录提示', |
| | | content: '该操作需要登录,是否前往登录?', |
| | | confirmText: '去登录', |
| | | success: (res) => { |
| | | if(res.confirm) uni.navigateTo({ url: '/pages/login/login' }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | // 小程序分享配置 |
| | | defineExpose({ |
| | | onShareAppMessage() { |