合并代码

This commit is contained in:
szz
2025-08-01 09:34:06 +08:00
parent e18ed68d30
commit c9b74c2a5c

View File

@@ -14,7 +14,7 @@
:loop="true" :loop="true"
> >
<swiper-slide v-for="(item, index) in carouselItems" :key="index"> <swiper-slide v-for="(item, index) in carouselItems" :key="index">
<img :src="item.image" :alt="item.title" class="carousel-img"> <img :src="item.image" :alt="item.title" class="carousel-img" />
<div class="carousel-title">{{ item.title }}</div> <div class="carousel-title">{{ item.title }}</div>
</swiper-slide> </swiper-slide>
</swiper> </swiper>
@@ -31,7 +31,7 @@
v-slot="{ navigate }" v-slot="{ navigate }"
> >
<div @click="navigate" class="header-item-content"> <div @click="navigate" class="header-item-content">
<img :src="item.image" :alt="item.text" class="header-image"> <img :src="item.image" :alt="item.text" class="header-image" />
<div class="header-text">{{ item.text }}</div> <div class="header-text">{{ item.text }}</div>
</div> </div>
</router-link> </router-link>
@@ -63,7 +63,11 @@
<div class="hot-news"> <div class="hot-news">
<div class="news-title">热门资讯</div> <div class="news-title">热门资讯</div>
<div class="news-list"> <div class="news-list">
<div class="news-item" v-for="(item, index) in newsItems" :key="index"> <div
class="news-item"
v-for="(item, index) in newsItems"
:key="index"
>
<span class="news-dot"></span> {{ item }} <span class="news-dot"></span> {{ item }}
</div> </div>
</div> </div>
@@ -73,71 +77,85 @@
</template> </template>
<script> <script>
import { Swiper, SwiperSlide } from 'swiper/vue' import { Swiper, SwiperSlide } from 'swiper/vue';
import { Autoplay, Pagination } from 'swiper' import { Autoplay, Pagination } from 'swiper';
import { ref, onMounted, onUnmounted } from 'vue' import { ref, onMounted, onUnmounted } from 'vue';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus';
import { transferAPI } from '../utils/api' import { transferAPI } from '../utils/api';
import 'swiper/css' import 'swiper/css';
import 'swiper/css/autoplay' import 'swiper/css/autoplay';
import 'swiper/css/pagination' import 'swiper/css/pagination';
export default { export default {
components: { components: {
Swiper, Swiper,
SwiperSlide SwiperSlide,
}, },
setup() { setup() {
// 响应式数据 // 响应式数据
const userPoints = ref(0) const userPoints = ref(0);
const carouselItems = ref([ const carouselItems = ref([
{ image: '/imgs/top/1.jpg', title: '限时优惠活动' }, { image: '/imgs/top/1.jpg', title: '限时优惠活动' },
{ image: '/imgs/top/2.jpg', title: '新用户专享' }, { image: '/imgs/top/2.jpg', title: '新用户专享' },
{ image: '/imgs/top/3.jpg', title: '积分兑换' } { image: '/imgs/top/3.jpg', title: '积分兑换' },
]) ]);
const headerItems = ref([ const headerItems = ref([
{ image: "/imgs/mainpage/交易记录.png", text: "交易记录", path: "/transfers" }, {
{ image: "/imgs/mainpage/订单查询.png", text: "订单查询", path: "/points-history" }, image: '/imgs/mainpage/交易记录.png',
{ image: "/imgs/mainpage/客服中心.png", text: "客服中心", path: "/support" }, text: '交易记录',
{ image: "/imgs/mainpage/系统公告.png", text: "系统公告", path: "/announcements" } path: '/transfers',
]) },
{
image: '/imgs/mainpage/订单查询.png',
text: '订单查询',
path: '/points-history',
},
{
image: '/imgs/mainpage/客服中心.png',
text: '客服中心',
path: '/support',
},
{
image: '/imgs/mainpage/系统公告.png',
text: '系统公告',
path: '/announcements',
},
]);
const newsItems = ref([ const newsItems = ref([
"最新活动:双十一特惠", '最新活动:双十一特惠',
"商城新品上架", '商城新品上架',
"积分兑换规则更新", '积分兑换规则更新',
"VIP会员特权升级" 'VIP会员特权升级',
]) ]);
// 获取用户积分 // 获取用户积分
const getUserPoints = async () => { const getUserPoints = async () => {
try { try {
// 使用封装好的API获取用户账户信息 // 使用封装好的API获取用户账户信息
const response = await transferAPI.getUserAccount() const {data} = await transferAPI.getUserAccount();
console.log(data);
// 根据实际API响应结构调整以下是几种可能的取值方式 // 根据实际API响应结构调整以下是几种可能的取值方式
userPoints.value = response.data.balance || // 方式1如果返回balance字段 userPoints.value = data.data.points || 0;
response.data.points || // 方式2如果返回points字段
response.data.currentPoints || // 方式3如果返回currentPoints字段
0 // 默认值
} catch (error) { } catch (error) {
console.error('获取积分信息失败', error) console.error('获取积分信息失败', error);
userPoints.value = 0 userPoints.value = 0;
ElMessage.error('获取积分信息失败,请稍后重试') ElMessage.error('获取积分信息失败,请稍后重试');
} }
} };
// 定时刷新积分 // 定时刷新积分
let refreshInterval let refreshInterval;
onMounted(() => { onMounted(() => {
getUserPoints() getUserPoints();
// 每5分钟刷新一次积分可根据需求调整时间 // 每5分钟刷新一次积分可根据需求调整时间
refreshInterval = setInterval(getUserPoints, 5 * 60 * 1000) refreshInterval = setInterval(getUserPoints, 5 * 60 * 1000);
}) });
onUnmounted(() => { onUnmounted(() => {
clearInterval(refreshInterval) clearInterval(refreshInterval);
}) });
return { return {
modules: [Autoplay, Pagination], modules: [Autoplay, Pagination],
@@ -145,14 +163,13 @@ export default {
carouselItems, carouselItems,
headerItems, headerItems,
newsItems, newsItems,
getUserPoints // 如果需要外部调用可以暴露 getUserPoints, // 如果需要外部调用可以暴露
} };
} },
} };
</script> </script>
<style scoped> <style scoped>
/* 基础样式 */ /* 基础样式 */
:root { :root {
--primary-color: #4361ee; --primary-color: #4361ee;