合并代码

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