refactor(backend): 重构动物相关 API 接口

- 更新了动物数据结构和相关类型定义
- 优化了动物列表、详情、创建、更新和删除接口
- 新增了更新动物状态接口
- 移除了与认领记录相关的接口
-调整了 API 响应结构
This commit is contained in:
ylweng
2025-08-31 00:45:46 +08:00
parent 0cad74b06f
commit 8e5295b572
111 changed files with 15290 additions and 1972 deletions

View File

@@ -2,7 +2,7 @@
const config = {
// 开发环境
development: {
baseURL: 'http://localhost:3000/api',
baseURL: 'http://localhost:3100/api',
timeout: 10000
},
// 生产环境

View File

@@ -38,39 +38,69 @@
</template>
<script>
import { animalService } from '../../api/services.js'
export default {
data() {
return {
animal: {
id: 1,
name: '小羊驼',
species: '羊驼',
price: 1000,
location: '西藏牧场',
images: [
'/static/animals/alpaca1.jpg',
'/static/animals/alpaca2.jpg'
],
description: '这是一只可爱的羊驼,性格温顺,喜欢与人互动。',
adoptionInfo: '认养后您将获得:\n1. 专属认养证书\n2. 定期照片和视频\n3. 牧场参观机会'
id: null,
name: '',
species: '',
price: 0,
location: '',
images: [],
description: '',
adoptionInfo: ''
}
}
},
onLoad(options) {
const id = options.id
if (id) {
this.loadAnimalDetail(id)
}
},
methods: {
handleAdopt() {
async loadAnimalDetail(id) {
try {
const data = await animalService.getDetail(id)
this.animal = data
} catch (error) {
console.error('获取动物详情失败:', error)
uni.showToast({
title: '获取数据失败',
icon: 'none'
})
}
},
async handleAdopt() {
uni.showModal({
title: '确认认养',
content: '确定要认养这只可爱的' + this.animal.name + '吗?',
success: (res) => {
success: async (res) => {
if (res.confirm) {
uni.showToast({
title: '认养成功',
icon: 'success'
})
try {
await animalService.adopt(this.animal.id, {})
uni.showToast({
title: '认养成功',
icon: 'success'
})
} catch (error) {
console.error('认养失败:', error)
uni.showToast({
title: '认养失败',
icon: 'none'
})
}
}
}
})
},
handleContact() {
uni.makePhoneCall({
phoneNumber: '13800138000'
@@ -111,24 +141,23 @@ export default {
}
.species {
font-size: 28rpx;
color: #666;
}
.price {
font-size: 28rpx;
color: #ff9500;
color: #ff6b35;
font-weight: bold;
}
.location {
font-size: 26rpx;
color: #999;
font-size: 28rpx;
}
.section {
padding: 30rpx;
border-top: 1rpx solid #eee;
background: #fff;
margin-bottom: 20rpx;
}
.section-title {
@@ -136,16 +165,13 @@ export default {
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
display: block;
}
.description, .adoption-info {
font-size: 28rpx;
color: #666;
line-height: 1.6;
}
.adoption-info {
white-space: pre-line;
font-size: 28rpx;
}
.action-bar {
@@ -153,26 +179,25 @@ export default {
bottom: 0;
left: 0;
right: 0;
display: flex;
padding: 20rpx;
height: 120rpx;
background: #fff;
box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
display: flex;
border-top: 1rpx solid #eee;
}
.btn {
flex: 1;
margin: 0 10rpx;
font-size: 28rpx;
border: none;
font-size: 32rpx;
}
.adopt {
background-color: #ff2d55;
background: #ff6b35;
color: #fff;
}
.contact {
background-color: #fff;
color: #ff2d55;
border: 1rpx solid #ff2d55;
background: #007aff;
color: #fff;
}
</style>

View File

@@ -51,283 +51,160 @@
<uni-icons type="sound" size="16" color="#ff9500"></uni-icons>
<swiper class="notice-swiper" vertical autoplay circular :interval="3000">
<swiper-item v-for="(notice, index) in notices" :key="index">
<text class="notice-text">{{notice}}</text>
<text class="notice-text">{{ notice.title }}</text>
</swiper-item>
</swiper>
<uni-icons type="arrowright" size="14" color="#ccc"></uni-icons>
</view>
<!-- 推荐旅行计划 -->
<view class="section">
<!-- 推荐内容 -->
<view class="recommend-section">
<!-- 推荐旅行计划 -->
<view class="section-header">
<text class="section-title">推荐旅行计划</text>
<text class="section-more" @click="navigateTo('/pages/travel/list')">更多</text>
<text class="section-title">热门旅行计划</text>
<text class="more" @click="navigateTo('/pages/travel/list')">更多 ></text>
</view>
<scroll-view class="plan-list" scroll-x="true" show-scrollbar="false">
<view class="plan-card" v-for="(plan, index) in travelPlans" :key="index" @click="navigateTo(`/pages/travel/detail?id=${plan.id}`)">
<image :src="plan.coverImage" mode="aspectFill" class="plan-image" />
<view class="plan-info">
<text class="plan-destination">{{ plan.destination }}</text>
<text class="plan-date">{{ plan.startDate }} - {{ plan.endDate }}</text>
<view class="plan-meta">
<text class="plan-budget">¥{{ plan.budget }}</text>
<text class="plan-members">{{ plan.currentMembers }}/{{ plan.maxMembers }}</text>
</view>
</view>
<scroll-view class="horizontal-scroll" scroll-x="true">
<view class="scroll-item" v-for="(travel, index) in recommendedTravels" :key="index" @click="navigateToTravelDetail(travel.id)">
<image :src="travel.coverImage" class="item-image" />
<text class="item-title">{{ travel.destination }}</text>
<text class="item-price">¥{{ travel.budget }}</text>
</view>
</scroll-view>
</view>
<!-- 热门动物 -->
<view class="section">
<!-- 热门动物 -->
<view class="section-header">
<text class="section-title">热门动物</text>
<text class="section-more" @click="navigateTo('/pages/animal/list')">更多</text>
<text class="more" @click="navigateTo('/pages/animal/list')">更多 ></text>
</view>
<view class="animal-grid">
<view class="animal-card" v-for="(animal, index) in animals" :key="index" @click="navigateTo(`/pages/animal/detail?id=${animal.id}`)">
<image :src="animal.image" mode="aspectFill" class="animal-image" />
<view class="animal-tag" v-if="animal.isHot">热门</view>
<view class="animal-info">
<text class="animal-name">{{ animal.name }}</text>
<text class="animal-species">{{ animal.species }}</text>
<text class="animal-price">¥{{ animal.price }}</text>
</view>
</view>
</view>
</view>
<!-- 送花服务 -->
<view class="section">
<view class="section-header">
<text class="section-title">精选花束</text>
<text class="section-more" @click="navigateTo('/pages/flower/list')">更多</text>
</view>
<scroll-view class="flower-list" scroll-x="true" show-scrollbar="false">
<view class="flower-card" v-for="(flower, index) in flowers" :key="index" @click="navigateTo(`/pages/flower/detail?id=${flower.id}`)">
<image :src="flower.image" mode="aspectFill" class="flower-image" />
<view class="flower-info">
<text class="flower-name">{{ flower.name }}</text>
<text class="flower-desc">{{ flower.description }}</text>
<text class="flower-price">¥{{ flower.price }}</text>
</view>
<scroll-view class="horizontal-scroll" scroll-x="true">
<view class="scroll-item" v-for="(animal, index) in hotAnimals" :key="index" @click="navigateToAnimalDetail(animal.id)">
<image :src="animal.image" class="item-image" />
<text class="item-title">{{ animal.name }}</text>
<text class="item-price">¥{{ animal.price }}</text>
</view>
</scroll-view>
</view>
<!-- 底部导航栏 -->
<view class="tab-bar">
<view class="tab-item active">
<uni-icons type="home" size="24" color="#007aff"></uni-icons>
<text class="tab-text">首页</text>
</view>
<view class="tab-item" @click="navigateTo('/pages/discover/index')">
<uni-icons type="compass" size="24" color="#999"></uni-icons>
<text class="tab-text">发现</text>
</view>
<view class="tab-item" @click="navigateTo('/pages/message/index')">
<uni-icons type="chat" size="24" color="#999"></uni-icons>
<text class="tab-text">消息</text>
<view class="badge" v-if="unreadCount > 0">{{unreadCount > 99 ? '99+' : unreadCount}}</view>
</view>
<view class="tab-item" @click="navigateTo('/pages/user/center')">
<uni-icons type="person" size="24" color="#999"></uni-icons>
<text class="tab-text">我的</text>
<!-- 精选花束 -->
<view class="section-header">
<text class="section-title">精选花束</text>
<text class="more" @click="navigateTo('/pages/flower/list')">更多 ></text>
</view>
<scroll-view class="horizontal-scroll" scroll-x="true">
<view class="scroll-item" v-for="(flower, index) in featuredFlowers" :key="index" @click="navigateToFlowerDetail(flower.id)">
<image :src="flower.image" class="item-image" />
<text class="item-title">{{ flower.name }}</text>
<text class="item-price">¥{{ flower.price }}</text>
</view>
</scroll-view>
</view>
</view>
</template>
<script>
import { homeService } from '../../api/services.js'
export default {
data() {
return {
banners: [
{ image: '/static/banners/banner1.jpg', link: '/pages/travel/list' },
{ image: '/static/banners/banner2.jpg', link: '/pages/animal/list' },
{ image: '/static/banners/banner3.jpg', link: '/pages/flower/list' }
],
notices: [
'欢迎来到结伴客,找到志同道合的旅伴!',
'新用户注册即送50积分可兑换精美礼品',
'推荐好友加入双方各得30积分奖励'
],
travelPlans: [
{
id: 1,
destination: '西藏拉萨',
startDate: '10月1日',
endDate: '10月7日',
budget: 5000,
currentMembers: 3,
maxMembers: 6,
coverImage: '/static/travel/tibet.jpg'
},
{
id: 2,
destination: '云南大理',
startDate: '10月5日',
endDate: '10月12日',
budget: 3500,
currentMembers: 2,
maxMembers: 4,
coverImage: '/static/travel/yunnan.jpg'
},
{
id: 3,
destination: '新疆喀什',
startDate: '10月10日',
endDate: '10月20日',
budget: 6000,
currentMembers: 4,
maxMembers: 8,
coverImage: '/static/travel/xinjiang.jpg'
},
{
id: 4,
destination: '青海湖',
startDate: '10月15日',
endDate: '10月20日',
budget: 4000,
currentMembers: 2,
maxMembers: 5,
coverImage: '/static/travel/qinghai.jpg'
}
],
animals: [
{
id: 1,
name: '小羊驼',
species: '羊驼',
price: 1000,
isHot: true,
image: '/static/animals/alpaca.jpg'
},
{
id: 2,
name: '小绵羊',
species: '绵羊',
price: 800,
isHot: false,
image: '/static/animals/sheep.jpg'
},
{
id: 3,
name: '小花猪',
species: '猪',
price: 600,
isHot: true,
image: '/static/animals/pig.jpg'
},
{
id: 4,
name: '小公鸡',
species: '鸡',
price: 300,
isHot: false,
image: '/static/animals/chicken.jpg'
}
],
flowers: [
{
id: 1,
name: '浪漫玫瑰',
description: '11朵红玫瑰',
price: 199,
image: '/static/flowers/rose.jpg'
},
{
id: 2,
name: '向日葵花束',
description: '9朵向日葵',
price: 179,
image: '/static/flowers/sunflower.jpg'
},
{
id: 3,
name: '百合花束',
description: '7朵白百合',
price: 229,
image: '/static/flowers/lily.jpg'
}
],
unreadCount: 5
banners: [],
notices: [],
recommendedTravels: [],
hotAnimals: [],
featuredFlowers: []
}
},
onLoad() {
// 获取系统信息设置状态栏高度
const systemInfo = uni.getSystemInfoSync();
this.statusBarHeight = systemInfo.statusBarHeight;
// 加载数据
this.loadData();
onShow() {
this.loadHomeData()
},
methods: {
loadData() {
// 实际开发中这里应该从API获取数据
console.log('加载首页数据');
async loadHomeData() {
try {
// 获取轮播图
const banners = await homeService.getBanners()
this.banners = banners
// 获取公告
const notices = await homeService.getNotices()
this.notices = notices
// 获取推荐旅行计划
const travels = await homeService.getRecommendedTravels()
this.recommendedTravels = travels
// 获取热门动物
const animals = await homeService.getHotAnimals()
this.hotAnimals = animals
// 获取精选花束
const flowers = await homeService.getFeaturedFlowers()
this.featuredFlowers = flowers
} catch (error) {
console.error('获取首页数据失败:', error)
uni.showToast({
title: '数据加载失败',
icon: 'none'
})
}
},
navigateTo(url) {
uni.navigateTo({
url: url
});
uni.navigateTo({ url })
},
navigateToSearch() {
uni.navigateTo({
url: '/pages/search/index'
});
uni.navigateTo({ url: '/pages/search/index' })
},
navigateToTravelDetail(id) {
uni.navigateTo({ url: `/pages/travel/detail?id=${id}` })
},
navigateToAnimalDetail(id) {
uni.navigateTo({ url: `/pages/animal/detail?id=${id}` })
},
navigateToFlowerDetail(id) {
uni.navigateTo({ url: `/pages/flower/detail?id=${id}` })
}
}
}
</script>
<style>
/* 移除图标字体相关样式 */
/* 页面样式 */
<style scoped>
.container {
min-height: 100vh;
background-color: #f8f9fa;
padding-bottom: 100rpx; /* 为底部导航留出空间 */
padding-bottom: 20rpx;
}
.status-bar {
height: var(--status-bar-height);
width: 100%;
background-color: #fff;
}
.search-bar {
padding: 20rpx 30rpx;
background-color: #ffffff;
background-color: #fff;
}
.search-input {
display: flex;
align-items: center;
background: #f5f5f5;
border-radius: 50rpx;
padding: 15rpx 30rpx;
}
.search-input .iconfont {
font-size: 32rpx;
color: #999;
margin-right: 10rpx;
}
.search-input input {
flex: 1;
font-size: 28rpx;
height: 60rpx;
background-color: #f0f0f0;
border-radius: 30rpx;
padding: 0 20rpx;
}
.placeholder {
font-size: 28rpx;
color: #999;
}
.banner-swiper {
height: 300rpx;
margin: 0 30rpx 30rpx;
border-radius: 20rpx;
overflow: hidden;
}
.banner-image {
@@ -337,21 +214,21 @@ export default {
.feature-grid {
display: flex;
justify-content: space-around;
padding: 20rpx 30rpx 30rpx;
background-color: #ffffff;
background-color: #fff;
padding: 30rpx 0;
margin-bottom: 20rpx;
}
.feature-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
.feature-icon {
width: 100rpx;
height: 100rpx;
width: 80rpx;
height: 80rpx;
border-radius: 50%;
display: flex;
align-items: center;
@@ -359,40 +236,20 @@ export default {
margin-bottom: 15rpx;
}
.feature-icon .iconfont {
font-size: 50rpx;
.travel {
background-color: #e6f1ff;
}
.feature-icon.travel {
background-color: rgba(0, 122, 255, 0.1);
.animal {
background-color: #ffe6eb;
}
.feature-icon.travel .iconfont {
color: #007aff;
.flower {
background-color: #fff5e6;
}
.feature-icon.animal {
background-color: rgba(255, 45, 85, 0.1);
}
.feature-icon.animal .iconfont {
color: #ff2d55;
}
.feature-icon.flower {
background-color: rgba(255, 149, 0, 0.1);
}
.feature-icon.flower .iconfont {
color: #ff9500;
}
.feature-icon.promotion {
background-color: rgba(52, 199, 89, 0.1);
}
.feature-icon.promotion .iconfont {
color: #34c759;
.promotion {
background-color: #e6f9ed;
}
.feature-text {
@@ -403,285 +260,80 @@ export default {
.notice-bar {
display: flex;
align-items: center;
background-color: #fff8e6;
padding: 15rpx 30rpx;
margin: 0 30rpx 20rpx;
border-radius: 10rpx;
}
.notice-bar .iconfont {
font-size: 32rpx;
color: #ff9500;
margin-right: 15rpx;
background-color: #fff;
margin-bottom: 20rpx;
}
.notice-swiper {
height: 40rpx;
flex: 1;
height: 40rpx;
margin: 0 10rpx;
}
.notice-text {
font-size: 24rpx;
font-size: 26rpx;
color: #ff9500;
line-height: 40rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.section {
margin-bottom: 30rpx;
background-color: #ffffff;
padding: 30rpx 0;
.recommend-section {
background-color: #fff;
padding: 0 30rpx 30rpx;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 30rpx 20rpx;
margin: 30rpx 0 20rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
position: relative;
padding-left: 20rpx;
}
.section-title::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 8rpx;
height: 30rpx;
background-color: #007aff;
border-radius: 4rpx;
}
.section-more {
font-size: 24rpx;
color: #999;
}
.plan-list {
white-space: nowrap;
padding: 0 30rpx;
}
.plan-card {
display: inline-block;
width: 300rpx;
margin-right: 20rpx;
background: #ffffff;
border-radius: 15rpx;
overflow: hidden;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
}
.plan-image {
width: 100%;
height: 180rpx;
}
.plan-info {
padding: 15rpx;
}
.plan-destination {
display: block;
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.plan-date {
display: block;
font-size: 22rpx;
color: #666;
margin-bottom: 10rpx;
}
.plan-meta {
display: flex;
justify-content: space-between;
align-items: center;
}
.plan-budget {
.more {
font-size: 26rpx;
color: #ff9500;
font-weight: bold;
}
.plan-members {
font-size: 22rpx;
color: #999;
}
.animal-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 20rpx;
padding: 0 30rpx;
.horizontal-scroll {
white-space: nowrap;
margin-bottom: 30rpx;
}
.animal-card {
background: #ffffff;
border-radius: 15rpx;
overflow: hidden;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
position: relative;
.scroll-item {
display: inline-block;
width: 200rpx;
margin-right: 20rpx;
vertical-align: top;
}
.animal-image {
width: 100%;
.item-image {
width: 200rpx;
height: 200rpx;
}
.animal-tag {
position: absolute;
top: 15rpx;
right: 15rpx;
background-color: #ff2d55;
color: #fff;
font-size: 20rpx;
padding: 5rpx 10rpx;
border-radius: 10rpx;
}
.animal-info {
padding: 15rpx;
}
.animal-name {
display: block;
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 5rpx;
}
.animal-species {
display: block;
font-size: 22rpx;
color: #999;
margin-bottom: 10rpx;
}
.animal-price {
.item-title {
display: block;
font-size: 26rpx;
color: #ff9500;
font-weight: bold;
}
.flower-list {
white-space: nowrap;
padding: 0 30rpx;
}
.flower-card {
display: inline-block;
width: 240rpx;
margin-right: 20rpx;
background: #ffffff;
border-radius: 15rpx;
overflow: hidden;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
}
.flower-image {
width: 100%;
height: 240rpx;
}
.flower-info {
padding: 15rpx;
}
.flower-name {
display: block;
font-size: 26rpx;
font-weight: bold;
color: #333;
margin-bottom: 5rpx;
}
.flower-desc {
display: block;
font-size: 22rpx;
color: #999;
margin-bottom: 10rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.flower-price {
display: block;
font-size: 26rpx;
color: #ff9500;
.item-price {
font-size: 24rpx;
color: #ff6b35;
font-weight: bold;
}
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 100rpx;
background-color: #ffffff;
display: flex;
box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.tab-item {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.tab-item .iconfont {
font-size: 40rpx;
color: #999;
margin-bottom: 5rpx;
}
.tab-item.active .iconfont {
color: #007aff;
}
.tab-text {
font-size: 20rpx;
color: #999;
}
.tab-item.active .tab-text {
color: #007aff;
}
.badge {
position: absolute;
top: 0;
right: 50%;
transform: translateX(10rpx);
background-color: #ff2d55;
color: #fff;
font-size: 20rpx;
min-width: 32rpx;
height: 32rpx;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
padding: 0 6rpx;
}
</style>

View File

@@ -36,36 +36,69 @@
</template>
<script>
import { travelService } from '../../api/services.js'
export default {
data() {
return {
plan: {
id: 1,
destination: '西藏',
startDate: '10月1日',
endDate: '10月7日',
budget: 5000,
coverImage: '/static/travel/tibet.jpg',
schedule: [
'拉萨市区游览,参观布达拉宫、大昭寺',
'前往纳木错,欣赏圣湖美景',
'林芝地区游览,参观雅鲁藏布大峡谷',
'返回拉萨,自由活动',
'日喀则地区游览,参观扎什伦布寺',
'珠峰大本营一日游',
'返回拉萨,结束行程'
],
requirements: '1. 年龄18-35岁\n2. 身体健康,能适应高原环境\n3. 有团队精神,乐于分享'
id: null,
destination: '',
startDate: '',
endDate: '',
budget: 0,
coverImage: '',
schedule: [],
requirements: ''
}
}
},
onLoad(options) {
const id = options.id
if (id) {
this.loadTravelDetail(id)
}
},
methods: {
handleJoin() {
uni.showToast({
title: '已申请加入',
icon: 'success'
async loadTravelDetail(id) {
try {
const data = await travelService.getDetail(id)
this.plan = data
} catch (error) {
console.error('获取旅行计划详情失败:', error)
uni.showToast({
title: '获取数据失败',
icon: 'none'
})
}
},
async handleJoin() {
uni.showModal({
title: '确认加入',
content: '确定要加入这个旅行计划吗?',
success: async (res) => {
if (res.confirm) {
try {
await travelService.join(this.plan.id)
uni.showToast({
title: '申请已提交',
icon: 'success'
})
} catch (error) {
console.error('加入计划失败:', error)
uni.showToast({
title: '申请失败',
icon: 'none'
})
}
}
}
})
},
handleContact() {
uni.makePhoneCall({
phoneNumber: '13800138000'
@@ -99,12 +132,12 @@ export default {
justify-content: space-between;
margin-top: 20rpx;
color: #666;
font-size: 28rpx;
}
.section {
padding: 30rpx;
border-top: 1rpx solid #eee;
background: #fff;
margin-bottom: 20rpx;
}
.section-title {
@@ -112,28 +145,27 @@ export default {
font-weight: bold;
color: #333;
margin-bottom: 20rpx;
display: block;
}
.schedule {
margin-bottom: 30rpx;
margin-bottom: 20rpx;
}
.day {
font-size: 28rpx;
font-weight: bold;
color: #007aff;
margin-bottom: 10rpx;
display: block;
}
.content {
font-size: 28rpx;
color: #666;
line-height: 1.6;
line-height: 1.5;
}
.requirements {
font-size: 28rpx;
color: #666;
white-space: pre-line;
line-height: 1.6;
}
@@ -142,26 +174,25 @@ export default {
bottom: 0;
left: 0;
right: 0;
display: flex;
padding: 20rpx;
height: 100rpx;
background: #fff;
box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
display: flex;
border-top: 1rpx solid #eee;
}
.btn {
flex: 1;
margin: 0 10rpx;
font-size: 28rpx;
border: none;
font-size: 32rpx;
}
.join {
background-color: #007aff;
background: #007aff;
color: #fff;
}
.contact {
background-color: #fff;
color: #007aff;
border: 1rpx solid #007aff;
background: #34c759;
color: #fff;
}
</style>

View File

@@ -39,20 +39,22 @@
</template>
<script>
import { userService, orderService } from '../../api/services.js'
export default {
data() {
return {
user: {
avatar: '/static/user/avatar.jpg',
nickname: '旅行爱好者',
memberLevel: '黄金会员'
nickname: '',
memberLevel: ''
},
orderStatus: [
{ type: 'all', text: '全部订单', count: 5 },
{ type: 'unpaid', text: '待付款', count: 1 },
{ type: 'undelivered', text: '待发货', count: 1 },
{ type: 'delivered', text: '待收货', count: 2 },
{ type: 'completed', text: '已完成', count: 1 }
{ type: 'all', text: '全部订单', count: 0 },
{ type: 'unpaid', text: '待付款', count: 0 },
{ type: 'undelivered', text: '待发货', count: 0 },
{ type: 'delivered', text: '待收货', count: 0 },
{ type: 'completed', text: '已完成', count: 0 }
],
functions: [
{ icon: 'heart', text: '我的认养', url: '/pages/user/adoptions' },
@@ -63,10 +65,45 @@ export default {
]
}
},
onShow() {
this.loadUserProfile()
this.loadOrderStats()
},
methods: {
async loadUserProfile() {
try {
const data = await userService.getProfile()
this.user = {
...this.user,
...data
}
} catch (error) {
console.error('获取用户信息失败:', error)
}
},
async loadOrderStats() {
try {
// 这里应该调用一个专门获取订单统计的接口
// 暂时使用模拟数据
/*
const stats = await orderService.getStats()
this.orderStatus = this.orderStatus.map(item => ({
...item,
count: stats[item.type] || 0
}))
*/
} catch (error) {
console.error('获取订单统计失败:', error)
}
},
navigateTo(url) {
uni.navigateTo({ url })
},
navigateToOrder(type) {
uni.navigateTo({ url: `/pages/user/orders?type=${type}` })
}
@@ -103,16 +140,13 @@ export default {
.username {
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
.member-level {
font-size: 24rpx;
color: #ff9500;
background-color: #fff8e6;
padding: 4rpx 16rpx;
border-radius: 20rpx;
align-self: flex-start;
font-size: 28rpx;
color: #ff6b35;
}
.order-status {
@@ -130,7 +164,8 @@ export default {
}
.count {
font-size: 32rpx;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
@@ -148,13 +183,17 @@ export default {
display: flex;
align-items: center;
padding: 30rpx;
border-bottom: 1rpx solid #f5f5f5;
border-bottom: 1rpx solid #eee;
}
.function-item .text {
.function-item:last-child {
border-bottom: none;
}
.text {
flex: 1;
margin-left: 20rpx;
font-size: 28rpx;
font-size: 30rpx;
color: #333;
}
</style>

View File

@@ -11,7 +11,7 @@
>
<text>{{ tab.text }}</text>
</view>
</view>
</tab-bar>
<!-- 订单列表 -->
<scroll-view
@@ -49,256 +49,191 @@
</view>
</view>
<!-- 订单底部 -->
<view class="order-footer">
<text class="order-total">{{ order.count }}件商品 合计¥{{ order.price * order.count }}</text>
<view class="order-actions">
<button
v-if="order.status === 'unpaid'"
class="action-btn primary"
@click.stop="payOrder(order.id)"
>立即付款</button>
<button
v-if="order.status === 'delivered'"
class="action-btn primary"
@click.stop="confirmReceive(order.id)"
>确认收货</button>
<button
v-if="order.status === 'completed'"
class="action-btn"
@click.stop="reviewOrder(order.id)"
>评价</button>
<button
class="action-btn"
@click.stop="deleteOrder(order.id)"
>删除订单</button>
</view>
<!-- 订单操作 -->
<view class="order-actions">
<button
v-for="action in getAvailableActions(order.status)"
:key="action.type"
class="action-btn"
:class="action.type"
@click.stop="handleAction(action.type, order)"
>
{{ action.text }}
</button>
</view>
</view>
<!-- 加载更多 -->
<view v-if="loading" class="loading">
<!-- 加载更多提示 -->
<view class="load-more" v-if="loading">
<text>加载中...</text>
</view>
<view v-if="noMore && orders.length > 0" class="no-more">
<text>没有更多订单了</text>
<view class="load-more" v-else-if="hasMore">
<text>上拉加载更多</text>
</view>
<view class="load-more" v-else-if="orders.length > 0">
<text>没有更多了</text>
</view>
</scroll-view>
</view>
</template>
<script>
import { orderService } from '../../api/services.js'
export default {
data() {
return {
tabs: [
{ text: '全部', type: 'all' },
{ text: '待付款', type: 'unpaid' },
{ text: '待发货', type: 'undelivered' },
{ text: '待收货', type: 'delivered' },
{ text: '已完成', type: 'completed' }
],
currentTab: 0,
tabs: [
{ type: 'all', text: '全部' },
{ type: 'unpaid', text: '待付款' },
{ type: 'undelivered', text: '待发货' },
{ type: 'delivered', text: '待收货' },
{ type: 'completed', text: '已完成' }
],
orders: [],
page: 1,
loading: false,
noMore: false
hasMore: true,
page: 1,
pageSize: 10,
statusFilter: 'all'
}
},
onLoad(options) {
// 如果有传入类型参数,切换到对应选项卡
if (options.type) {
const index = this.tabs.findIndex(tab => tab.type === options.type)
if (index !== -1) {
this.currentTab = index
const tabIndex = this.tabs.findIndex(tab => tab.type === options.type)
if (tabIndex !== -1) {
this.currentTab = tabIndex
this.statusFilter = options.type
}
}
this.loadOrders()
},
methods: {
switchTab(index) {
if (this.currentTab === index) return
this.currentTab = index
this.page = 1
this.orders = []
this.noMore = false
this.loadOrders()
},
loadOrders() {
if (this.loading || this.noMore) return
async loadOrders() {
if (this.loading || !this.hasMore) return
this.loading = true
// 模拟API请求
setTimeout(() => {
const type = this.tabs[this.currentTab].type
const newOrders = this.getMockOrders(type, this.page)
try {
const params = {
page: this.page,
pageSize: this.pageSize
}
if (newOrders.length === 0) {
this.noMore = true
if (this.statusFilter !== 'all') {
params.status = this.statusFilter
}
const data = await orderService.getList(params)
const newOrders = data.orders || data
if (this.page === 1) {
this.orders = newOrders
} else {
this.orders = [...this.orders, ...newOrders]
this.page++
}
this.hasMore = newOrders.length === this.pageSize
this.page++
} catch (error) {
console.error('获取订单列表失败:', error)
uni.showToast({
title: '获取订单失败',
icon: 'none'
})
} finally {
this.loading = false
}, 1000)
}
},
loadMore() {
async loadMore() {
if (this.hasMore && !this.loading) {
this.loadOrders()
}
},
switchTab(index) {
this.currentTab = index
this.statusFilter = this.tabs[index].type
this.page = 1
this.orders = []
this.hasMore = true
this.loadOrders()
},
getMockOrders(type, page) {
// 模拟数据实际应从API获取
const allOrders = [
{
id: '1001',
type: 'travel',
status: 'unpaid',
title: '西藏旅行计划',
description: '10月1日-10月7日',
price: 5000,
count: 1,
image: '/static/travel/tibet.jpg'
},
{
id: '1002',
type: 'animal',
status: 'undelivered',
title: '小羊驼认养',
description: '认养期限1年',
price: 1000,
count: 1,
image: '/static/animals/alpaca.jpg'
},
{
id: '1003',
type: 'flower',
status: 'delivered',
title: '浪漫玫瑰花束',
description: '11朵红玫瑰',
price: 199,
count: 1,
image: '/static/flowers/rose.jpg'
},
{
id: '1004',
type: 'flower',
status: 'completed',
title: '向日葵花束',
description: '9朵向日葵',
price: 179,
count: 1,
image: '/static/flowers/sunflower.jpg'
}
]
// 根据类型筛选
let filteredOrders = allOrders
if (type !== 'all') {
filteredOrders = allOrders.filter(order => order.status === type)
}
// 分页
const pageSize = 5
const start = (page - 1) * pageSize
const end = page * pageSize
return filteredOrders.slice(start, end)
},
getOrderTypeName(type) {
const typeMap = {
const types = {
travel: '旅行计划',
animal: '动物认养',
flower: '送花服务'
}
return typeMap[type] || '订单'
return types[type] || '未知类型'
},
getStatusText(status) {
const statusMap = {
const statuses = {
unpaid: '待付款',
undelivered: '待发货',
delivered: '待收货',
completed: '已完成'
completed: '已完成',
cancelled: '已取消'
}
return statusMap[status] || '未知状态'
return statuses[status] || '未知状态'
},
getAvailableActions(status) {
const actions = {
unpaid: [
{ type: 'cancel', text: '取消订单' },
{ type: 'pay', text: '立即付款' }
],
undelivered: [
{ type: 'cancel', text: '取消订单' }
],
delivered: [
{ type: 'confirm', text: '确认收货' }
],
completed: [],
cancelled: []
}
return actions[status] || []
},
async handleAction(actionType, order) {
try {
switch (actionType) {
case 'cancel':
await orderService.cancel(order.id)
uni.showToast({ title: '订单已取消' })
break
case 'pay':
// 跳转到支付页面
uni.navigateTo({ url: `/pages/payment/index?orderId=${order.id}` })
return
case 'confirm':
await orderService.confirm(order.id)
uni.showToast({ title: '已确认收货' })
break
}
// 重新加载订单列表
this.page = 1
this.orders = []
this.hasMore = true
this.loadOrders()
} catch (error) {
console.error('操作失败:', error)
uni.showToast({
title: '操作失败',
icon: 'none'
})
}
},
navigateToDetail(id) {
uni.navigateTo({
url: `/pages/user/order-detail?id=${id}`
})
},
payOrder(id) {
uni.showModal({
title: '支付提示',
content: '确定要支付此订单吗?',
success: (res) => {
if (res.confirm) {
// 模拟支付流程
uni.showLoading({
title: '支付中...'
})
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '支付成功',
icon: 'success'
})
// 更新订单状态
this.updateOrderStatus(id, 'undelivered')
}, 1500)
}
}
})
},
confirmReceive(id) {
uni.showModal({
title: '确认收货',
content: '确认已收到商品吗?',
success: (res) => {
if (res.confirm) {
uni.showToast({
title: '确认成功',
icon: 'success'
})
// 更新订单状态
this.updateOrderStatus(id, 'completed')
}
}
})
},
reviewOrder(id) {
uni.navigateTo({
url: `/pages/user/review?id=${id}`
})
},
deleteOrder(id) {
uni.showModal({
title: '删除订单',
content: '确定要删除此订单吗?',
success: (res) => {
if (res.confirm) {
// 从列表中移除
const index = this.orders.findIndex(order => order.id === id)
if (index !== -1) {
this.orders.splice(index, 1)
uni.showToast({
title: '删除成功',
icon: 'success'
})
}
}
}
})
},
updateOrderStatus(id, newStatus) {
const order = this.orders.find(order => order.id === id)
if (order) {
order.status = newStatus
}
uni.navigateTo({ url: `/pages/order/detail?id=${id}` })
}
}
}
@@ -306,101 +241,78 @@ export default {
<style scoped>
.container {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #f8f9fa;
min-height: 100vh;
}
.tab-bar {
display: flex;
background-color: #fff;
border-bottom: 1rpx solid #eee;
position: sticky;
top: 0;
z-index: 10;
}
.tab-item {
flex: 1;
height: 80rpx;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
padding: 30rpx 0;
font-size: 28rpx;
color: #666;
position: relative;
}
.tab-item.active {
color: #007aff;
}
.tab-item.active::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 40rpx;
height: 4rpx;
background-color: #007aff;
border-bottom: 4rpx solid #007aff;
}
.order-list {
flex: 1;
padding: 20rpx;
height: calc(100vh - 100rpx);
}
.empty-tip {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.empty-image {
width: 200rpx;
height: 200rpx;
margin-bottom: 20rpx;
margin-bottom: 30rpx;
}
.order-item {
background-color: #fff;
margin: 20rpx;
border-radius: 10rpx;
margin-bottom: 20rpx;
overflow: hidden;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}
.order-header {
display: flex;
justify-content: space-between;
padding: 20rpx;
border-bottom: 1rpx solid #f5f5f5;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #eee;
}
.order-type {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.order-status {
font-size: 28rpx;
color: #ff9500;
color: #ff6b35;
}
.order-content {
display: flex;
padding: 20rpx;
border-bottom: 1rpx solid #f5f5f5;
padding: 30rpx;
}
.order-image {
width: 160rpx;
height: 160rpx;
border-radius: 8rpx;
width: 150rpx;
height: 150rpx;
border-radius: 10rpx;
margin-right: 20rpx;
}
@@ -408,73 +320,65 @@ export default {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.order-title {
font-size: 28rpx;
font-size: 30rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
.order-desc {
font-size: 24rpx;
color: #999;
font-size: 24rpx;
margin-bottom: 10rpx;
}
.order-price-box {
display: flex;
justify-content: space-between;
margin-top: auto;
}
.order-price {
font-size: 28rpx;
color: #ff2d55;
color: #ff6b35;
font-weight: bold;
}
.order-count {
font-size: 24rpx;
color: #999;
}
.order-footer {
padding: 20rpx;
}
.order-total {
font-size: 24rpx;
color: #666;
text-align: right;
margin-bottom: 20rpx;
}
.order-actions {
display: flex;
justify-content: flex-end;
padding: 20rpx 30rpx;
border-top: 1rpx solid #eee;
}
.action-btn {
padding: 10rpx 20rpx;
margin-left: 20rpx;
font-size: 24rpx;
padding: 0 30rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 6rpx;
font-size: 26rpx;
border: 1rpx solid #ddd;
background-color: #fff;
color: #666;
}
.action-btn.primary {
background-color: #007aff;
color: #fff;
border: none;
.action-btn.cancel {
color: #ff3b30;
border-color: #ff3b30;
}
.loading, .no-more {
.action-btn.pay, .action-btn.confirm {
color: #007aff;
border-color: #007aff;
}
.load-more {
text-align: center;
padding: 20rpx 0;
font-size: 24rpx;
padding: 30rpx;
color: #999;
font-size: 26rpx;
}
</style>

View File

@@ -0,0 +1 @@
{"version":3,"file":"config.js","sources":["api/config.js"],"sourcesContent":["// API基础配置\nconst config = {\n // 开发环境\n development: {\n baseURL: 'http://localhost:3100/api',\n timeout: 10000\n },\n // 生产环境\n production: {\n baseURL: 'https://api.jiebanke.com/api',\n timeout: 15000\n }\n}\n\n// 获取当前环境配置\nconst getConfig = () => {\n const env = process.env.NODE_ENV || 'development'\n return config[env]\n}\n\n// API端点\nconst endpoints = {\n // 用户相关\n USER: {\n LOGIN: '/auth/login',\n REGISTER: '/auth/register',\n PROFILE: '/user/profile',\n UPDATE_PROFILE: '/user/profile',\n UPLOAD_AVATAR: '/user/avatar'\n },\n \n // 旅行计划\n TRAVEL: {\n LIST: '/travel/list',\n DETAIL: '/travel/detail',\n CREATE: '/travel/create',\n JOIN: '/travel/join',\n MY_PLANS: '/travel/my-plans',\n SEARCH: '/travel/search'\n },\n \n // 动物认养\n ANIMAL: {\n LIST: '/animal/list',\n DETAIL: '/animal/detail',\n ADOPT: '/animal/adopt',\n MY_ANIMALS: '/animal/my-animals',\n CATEGORIES: '/animal/categories'\n },\n \n // 送花服务\n FLOWER: {\n LIST: '/flower/list',\n DETAIL: '/flower/detail',\n ORDER: '/flower/order',\n MY_ORDERS: '/flower/my-orders',\n CATEGORIES: '/flower/categories'\n },\n \n // 订单管理\n ORDER: {\n LIST: '/order/list',\n DETAIL: '/order/detail',\n CANCEL: '/order/cancel',\n PAY: '/order/pay',\n CONFIRM: '/order/confirm'\n },\n \n // 支付相关\n PAYMENT: {\n CREATE: '/payment/create',\n QUERY: '/payment/query',\n REFUND: '/payment/refund'\n },\n \n // 系统相关\n SYSTEM: {\n CONFIG: '/system/config',\n NOTICE: '/system/notice',\n FEEDBACK: '/system/feedback'\n }\n}\n\nexport default {\n ...getConfig(),\n endpoints\n}"],"names":[],"mappings":";AACA,MAAM,SAAS;AAAA;AAAA,EAEb,aAAa;AAAA,IACX,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AAAA;AAAA,EAEA,YAAY;AAAA,IACV,SAAS;AAAA,IACT,SAAS;AAAA,EACX;AACF;AAGA,MAAM,YAAY,MAAM;AACtB,QAAM,MAAM;AACZ,SAAO,OAAO,GAAG;AACnB;AAGA,MAAM,YAAY;AAAA;AAAA,EAEhB,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS;AAAA,IACT,gBAAgB;AAAA,IAChB,eAAe;AAAA,EACjB;AAAA;AAAA,EAGA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU;AAAA,IACV,QAAQ;AAAA,EACV;AAAA;AAAA,EAGA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,YAAY;AAAA,IACZ,YAAY;AAAA,EACd;AAAA;AAAA,EAGA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,WAAW;AAAA,IACX,YAAY;AAAA,EACd;AAAA;AAAA,EAGA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,SAAS;AAAA,EACX;AAAA;AAAA,EAGA,SAAS;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,QAAQ;AAAA,EACV;AAAA;AAAA,EAGA,QAAQ;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;AAEA,MAAe,WAAA;AAAA,EACb,GAAG,UAAU;AAAA,EACb;AACF;;"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
"use strict";
const config = {
// 开发环境
development: {
baseURL: "http://localhost:3100/api",
timeout: 1e4
},
// 生产环境
production: {
baseURL: "https://api.jiebanke.com/api",
timeout: 15e3
}
};
const getConfig = () => {
const env = "development";
return config[env];
};
const endpoints = {
// 用户相关
USER: {
LOGIN: "/auth/login",
REGISTER: "/auth/register",
PROFILE: "/user/profile",
UPDATE_PROFILE: "/user/profile",
UPLOAD_AVATAR: "/user/avatar"
},
// 旅行计划
TRAVEL: {
LIST: "/travel/list",
DETAIL: "/travel/detail",
CREATE: "/travel/create",
JOIN: "/travel/join",
MY_PLANS: "/travel/my-plans",
SEARCH: "/travel/search"
},
// 动物认养
ANIMAL: {
LIST: "/animal/list",
DETAIL: "/animal/detail",
ADOPT: "/animal/adopt",
MY_ANIMALS: "/animal/my-animals",
CATEGORIES: "/animal/categories"
},
// 送花服务
FLOWER: {
LIST: "/flower/list",
DETAIL: "/flower/detail",
ORDER: "/flower/order",
MY_ORDERS: "/flower/my-orders",
CATEGORIES: "/flower/categories"
},
// 订单管理
ORDER: {
LIST: "/order/list",
DETAIL: "/order/detail",
CANCEL: "/order/cancel",
PAY: "/order/pay",
CONFIRM: "/order/confirm"
},
// 支付相关
PAYMENT: {
CREATE: "/payment/create",
QUERY: "/payment/query",
REFUND: "/payment/refund"
},
// 系统相关
SYSTEM: {
CONFIG: "/system/config",
NOTICE: "/system/notice",
FEEDBACK: "/system/feedback"
}
};
const config$1 = {
...getConfig(),
endpoints
};
exports.config = config$1;
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/config.js.map

View File

@@ -0,0 +1,182 @@
"use strict";
const common_vendor = require("../common/vendor.js");
const api_config = require("./config.js");
const requestQueue = [];
let isRefreshing = false;
class Request {
constructor() {
this.baseURL = api_config.config.baseURL;
this.timeout = api_config.config.timeout;
this.interceptors = {
request: [],
response: []
};
}
// 添加请求拦截器
addRequestInterceptor(interceptor) {
this.interceptors.request.push(interceptor);
}
// 添加响应拦截器
addResponseInterceptor(interceptor) {
this.interceptors.response.push(interceptor);
}
// 执行请求拦截器
async runRequestInterceptors(config) {
for (const interceptor of this.interceptors.request) {
config = await interceptor(config);
}
return config;
}
// 执行响应拦截器
async runResponseInterceptors(response) {
for (const interceptor of this.interceptors.response) {
response = await interceptor(response);
}
return response;
}
// 核心请求方法
async request(options) {
try {
const requestConfig = {
url: options.url.startsWith("http") ? options.url : `${this.baseURL}${options.url}`,
method: options.method || "GET",
header: {
"Content-Type": "application/json",
...options.header
},
data: options.data,
timeout: this.timeout
};
const finalConfig = await this.runRequestInterceptors(requestConfig);
const response = await common_vendor.index.request(finalConfig);
const finalResponse = await this.runResponseInterceptors(response);
return finalResponse[1];
} catch (error) {
common_vendor.index.__f__("error", "at api/request.js:69", "Request error:", error);
throw error;
}
}
// GET请求
get(url, data = {}, options = {}) {
return this.request({
url,
method: "GET",
data,
...options
});
}
// POST请求
post(url, data = {}, options = {}) {
return this.request({
url,
method: "POST",
data,
...options
});
}
// PUT请求
put(url, data = {}, options = {}) {
return this.request({
url,
method: "PUT",
data,
...options
});
}
// DELETE请求
delete(url, data = {}, options = {}) {
return this.request({
url,
method: "DELETE",
data,
...options
});
}
// 上传文件
upload(url, filePath, formData = {}, options = {}) {
return new Promise((resolve, reject) => {
common_vendor.index.uploadFile({
url: `${this.baseURL}${url}`,
filePath,
name: "file",
formData,
success: resolve,
fail: reject,
...options
});
});
}
// 下载文件
download(url, options = {}) {
return new Promise((resolve, reject) => {
common_vendor.index.downloadFile({
url: `${this.baseURL}${url}`,
success: resolve,
fail: reject,
...options
});
});
}
}
const request = new Request();
request.addRequestInterceptor(async (config) => {
const token = common_vendor.index.getStorageSync("token");
if (token) {
config.header.Authorization = `Bearer ${token}`;
}
return config;
});
request.addResponseInterceptor(async (response) => {
const { statusCode, data } = response;
if (statusCode === 200) {
if (data.code === 0) {
return data.data;
} else {
const error = new Error(data.message || "业务错误");
error.code = data.code;
throw error;
}
} else if (statusCode === 401) {
return handleTokenExpired(response);
} else {
throw new Error(`网络错误: ${statusCode}`);
}
});
async function handleTokenExpired(response) {
if (isRefreshing) {
return new Promise((resolve) => {
requestQueue.push(() => resolve(request.request(response.config)));
});
}
isRefreshing = true;
const refreshToken = common_vendor.index.getStorageSync("refreshToken");
if (!refreshToken) {
common_vendor.index.navigateTo({ url: "/pages/auth/login" });
throw new Error("请重新登录");
}
try {
const result = await request.post(api_config.config.endpoints.USER.REFRESH_TOKEN, {
refreshToken
});
common_vendor.index.setStorageSync("token", result.token);
common_vendor.index.setStorageSync("refreshToken", result.refreshToken);
const retryResponse = await request.request(response.config);
processRequestQueue();
return retryResponse;
} catch (error) {
common_vendor.index.removeStorageSync("token");
common_vendor.index.removeStorageSync("refreshToken");
common_vendor.index.navigateTo({ url: "/pages/auth/login" });
throw error;
} finally {
isRefreshing = false;
}
}
function processRequestQueue() {
while (requestQueue.length > 0) {
const retry = requestQueue.shift();
retry();
}
}
exports.request = request;
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/request.js.map

View File

@@ -0,0 +1,18 @@
"use strict";
require("../common/vendor.js");
const api_request = require("./request.js");
require("./config.js");
const homeService = {
// 获取首页数据
getHomeData: () => api_request.request.get("/home/data"),
// 获取轮播图
getBanners: () => api_request.request.get("/home/banners"),
// 获取推荐旅行计划
getRecommendedTravels: () => api_request.request.get("/home/recommended-travels"),
// 获取热门动物
getHotAnimals: () => api_request.request.get("/home/hot-animals"),
// 获取精选花束
getFeaturedFlowers: () => api_request.request.get("/home/featured-flowers")
};
exports.homeService = homeService;
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/services.js.map