hookehuyr

refactor(奖励页面): 移除创建者相关逻辑并简化代码

移除RewardDetail和Rewards页面中与创建者相关的条件渲染和逻辑
简化Rewards页面积分显示逻辑,直接从API获取用户积分
删除未使用的分享功能代码
......@@ -57,7 +57,7 @@
<!-- Bottom Button -->
<view v-if="isCreator" class="fixed bottom-0 left-0 right-0 p-4 bg-white border-t border-gray-100">
<view class="fixed bottom-0 left-0 right-0 p-4 bg-white border-t border-gray-100">
<nut-button
type="primary"
size="large"
......@@ -82,7 +82,6 @@ import { getCouponDetailAPI, redeemCouponAPI } from '@/api/coupon';
// 导入主题颜色
import { THEME_COLORS } from '@/utils/config';
const isCreator = ref(false);
const couponId = ref('');
// 优惠券详情数据
......@@ -191,19 +190,12 @@ const initData = async (options = {}) => {
couponId.value = options.id;
}
// 获取用户信息,判断是否为创建者
const { code, data } = await getUserProfileAPI();
if (code) {
isCreator.value = data?.user?.is_creator || false;
}
// 获取优惠券详情
if (couponId.value) {
await fetchCouponDetail();
}
} catch (error) {
console.error('初始化数据失败:', error);
isCreator.value = false;
}
};
......@@ -215,37 +207,28 @@ useLoad((options) => {
});
useDidShow(() => {
// 页面显示时只获取用户信息,不重新获取优惠券详情
getUserProfileAPI().then(({ code, data }) => {
if (code) {
isCreator.value = data?.user?.is_creator || false;
}
}).catch(error => {
console.error('获取用户信息失败:', error);
isCreator.value = false;
});
});
/**
* 处理分享按钮点击事件
*/
const shareBtnClick = () => {
// 显示分享选项菜单
Taro.showActionSheet({
itemList: ['分享给朋友'],
success: (res) => {
if (res.tapIndex === 0) {
// 分享给朋友
Taro.showToast({
title: '请点击右上角分享给朋友',
icon: 'none',
duration: 2000
});
}
}
});
}
// const shareBtnClick = () => {
// // 显示分享选项菜单
// Taro.showActionSheet({
// itemList: ['分享给朋友'],
// success: (res) => {
// if (res.tapIndex === 0) {
// // 分享给朋友
// Taro.showToast({
// title: '请点击右上角分享给朋友',
// icon: 'none',
// duration: 2000
// });
// }
// }
// });
// }
/**
* 定义分享给朋友的内容
......
<!--
* @Date: 2025-08-27 17:47:26
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-08 13:37:45
* @LastEditTime: 2025-09-13 15:59:26
* @FilePath: /lls_program/src/pages/Rewards/index.vue
* @Description: 文件描述
-->
<template>
<view class="min-h-screen flex flex-col bg-white">
<!-- Blue header background -->
<view v-if="isCreator" class="bg-blue-500 h-48 absolute w-full top-0 left-0 z-0"></view>
<!-- <AppHeader title="兑换中心" :showBack="false" /> -->
<view class="bg-blue-500 h-48 absolute w-full top-0 left-0 z-0"></view>
<!-- Content -->
<view class="relative z-10 flex-1 pb-20">
<!-- Points display -->
<view v-if="isCreator" class="pt-8 pb-8 flex flex-col items-center">
<view class="pt-8 pb-8 flex flex-col items-center">
<h2 class="text-4xl font-bold text-white mb-1">{{ totalPoints }}分</h2>
<p class="text-white text-opacity-80">我的积分</p>
</view>
<!-- Main content -->
<view class="bg-white rounded-t-3xl px-4 pt-5">
<!-- <!~~ Points strategy section ~~>
<view v-if="!isCreator" class="mb-8 bg-gradient-to-br from-blue-50 to-indigo-50 rounded-2xl p-5 shadow-sm border border-blue-100">
<view class="flex justify-between items-center mb-4">
<h3 class="text-lg font-medium text-gray-800">积分攻略</h3>
<view @tap="handleViewAll" class="text-blue-500 text-sm flex items-center hover:text-blue-600">
查看全部
<!~~ <Right size="16" /> ~~>
</view>
</view>
<!~~ Strategy cards ~~>
<view v-if="isStrategyExpanded" class="space-y-3 mb-4 transition-all duration-300">
<view class="bg-white border border-gray-100 p-4 rounded-lg flex items-start shadow-sm">
<view class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
<My size="20" class="text-blue-500" />
</view>
<view>
<h4 class="font-medium">每日同步步数可获得积分</h4>
<p class="text-sm text-gray-600">
每100步可兑换1积分,每日上限200积分
</p>
</view>
</view>
<view class="bg-white border border-gray-100 p-4 rounded-lg flex items-start shadow-sm">
<view class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
<My size="20" class="text-blue-500" />
</view>
<view>
<h4 class="font-medium">家人陪伴健步有奖励积分</h4>
<p class="text-sm text-gray-600">
一起健步晒合影每天可获得额外100积分
</p>
</view>
</view>
<view class="bg-white border border-gray-100 p-4 rounded-lg flex items-start shadow-sm">
<view class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
<My size="20" class="text-blue-500" />
</view>
<view>
<h4 class="font-medium">邀请家人加入家庭,人数达标奖励</h4>
<p class="text-sm text-gray-600">
邀请的家人达到5位,获得500奖励积分
</p>
</view>
</view>
</view>
<!~~ Expand/Collapse button at bottom ~~>
<view @tap="toggleStrategyExpand" class="flex justify-center items-center py-2 cursor-pointer hover:bg-blue-100 rounded-lg transition-colors">
<ArrowUp v-if="isStrategyExpanded" size="16" class="text-gray-500" />
<ArrowDown v-else size="16" class="text-gray-500" />
</view>
</view>-->
<!-- Quick exchange options -->
<!-- Search bar -->
<view class="mb-6">
<view class="relative">
......@@ -126,7 +73,7 @@
</view>
<view class="ml-4 px-4 py-2 bg-blue-500 text-white rounded-lg text-sm flex-shrink-0"
@click="goToRewardDetail(reward)">
{{ isCreator ? reward.points_cost + '分兑换' : '查看' }}
{{ reward.points_cost + '分兑换' }}
</view>
</view>
......@@ -164,8 +111,6 @@ const selectedPoints = ref(null);
const sortOrder = ref('desc'); // 'asc' or 'desc'
const totalPoints = ref(0);
const isCreator = ref(false);
const isStrategyExpanded = ref(false); // 积分攻略展开状态,默认收起
// 页面参数
const pageParams = ref({
......@@ -286,6 +231,7 @@ const fetchCouponList = async (reset = false) => {
const coupons = data?.coupons || [];
if (reset) {
couponList.value = coupons;
totalPoints.value = data?.user_points || 0;
currentPage.value = 0;
} else {
couponList.value = [...couponList.value, ...coupons];
......@@ -312,27 +258,6 @@ const initData = async () => {
id: params.id || ''
};
// 获取用户信息,判断是否为创建者
try {
const { code, data } = await getUserProfileAPI();
if (code) {
isCreator.value = data?.user?.is_creator || false;
// 只有创建者才显示积分并获取家庭数据
if (isCreator.value) {
// 获取家庭首页数据,从中提取总积分
const familyData = await getFamilyDashboardAPI();
if (familyData.code) {
totalPoints.value = familyData.data.family.total_points || 0;
} else {
totalPoints.value = 0;
}
}
}
} catch (error) {
console.error('获取用户信息失败:', error);
isCreator.value = false;
}
// 获取积分兑换相关数据
await Promise.all([
fetchPointRanges(),
......