重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
+168
View File
@@ -0,0 +1,168 @@
/**
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const couponApi = require('../../api/coupon')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
/**
* Purpose: getBenefitText supports index.js by holding or executing the get benefit text page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getBenefitText(coupon) {
if (Number(coupon.couponType) === 1) {
return `${coupon.discountValue} 折`
}
return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
/**
* coupons page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
filterOptions: [
{ value: 'all', label: '全部' },
{ value: 'available', label: '未使用' },
{ value: 'used', label: '已使用' },
{ value: 'expired', label: '已过期' }
]
}),
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadCoupons()
},
async loadCoupons() {
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.setData({
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
loading: false
})
return
}
try {
const coupons = await couponApi.listUserCoupons()
const list = Array.isArray(coupons) ? coupons.map(item => ({
...item,
benefitText: getBenefitText(item),
periodText: `${String(item.startTime || '').slice(0, 10)} - ${String(item.endTime || '').slice(0, 10)}`,
sourceText: item.sourceType === 'SYSTEM_VIP' ? 'VIP 自动匹配' : '用户优惠券'
})) : []
this.setData({
coupons: list
})
this.applyFilter(this.data.activeFilter, list)
} catch (error) {
this.setData({
coupons: [],
filteredCoupons: []
})
wx.showToast({
title: error.message || '优惠券加载失败',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* `applyFilter` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
applyFilter(filterValue, sourceCoupons) {
const activeFilter = filterValue || 'all'
const coupons = Array.isArray(sourceCoupons) ? sourceCoupons : this.data.coupons
let filteredCoupons = coupons
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (activeFilter === 'available') {
filteredCoupons = coupons.filter(item => Number(item.status) === 1)
} else if (activeFilter === 'used') {
filteredCoupons = coupons.filter(item => Number(item.status) === 2)
} else if (activeFilter === 'expired') {
filteredCoupons = coupons.filter(item => Number(item.status) === 3)
}
this.setData({
activeFilter,
filteredCoupons
})
},
/**
* `handleFilterChange` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleFilterChange(event) {
const value = event.currentTarget.dataset.value
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!value || value === this.data.activeFilter) {
return
}
this.applyFilter(value)
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/coupons/index')
},
/**
* `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,59 @@
<navigation-bar title="我的优惠券" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell coupons-page" style="{{themeVars}}">
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看优惠券</text>
<text class="empty-desc">登录后查看可用优惠。</text>
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{coupons.length}}">
<view class="page-hero coupons-hero">
<text class="hero-kicker">优惠资产</text>
<text class="hero-title">当前有 {{coupons.length}} 张</text>
<text class="hero-desc">下单前可查看可用优惠。</text>
</view>
<view class="coupon-filter-row">
<view
wx:for="{{filterOptions}}"
wx:key="value"
class="coupon-filter-chip {{activeFilter === item.value ? 'active' : ''}}"
data-value="{{item.value}}"
bindtap="handleFilterChange"
>
{{item.label}}
</view>
</view>
<block wx:if="{{filteredCoupons.length}}">
<view wx:for="{{filteredCoupons}}" wx:key="id" class="page-card coupon-card">
<view class="coupon-top">
<view>
<view class="coupon-title">{{item.couponName}}</view>
<view class="coupon-source">{{item.sourceText}}</view>
</view>
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
</view>
<view class="coupon-benefit">{{item.benefitText}}</view>
<view class="coupon-period">{{item.periodText}}</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">当前筛选下暂无优惠券</text>
<text class="empty-desc">换个筛选试试。</text>
</view>
</block>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载优惠内容</text>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有优惠券</text>
<text class="empty-desc">下单前会自动匹配可用优惠。</text>
</view>
</view>
</view>
@@ -0,0 +1,86 @@
.coupons-hero {
margin-bottom: 20rpx;
}
.coupon-filter-row {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
margin-bottom: 20rpx;
}
.coupon-filter-chip {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 120rpx;
height: 60rpx;
padding: 0 24rpx;
border-radius: 999rpx;
background: var(--theme-card-bg);
border: 1rpx solid var(--theme-border);
color: var(--text-secondary);
font-size: 24rpx;
font-weight: 600;
}
.coupon-filter-chip.active {
background: var(--theme-gradient);
border-color: transparent;
color: #ffffff;
}
.coupon-card + .coupon-card {
margin-top: 20rpx;
}
.coupon-card {
padding: 26rpx 28rpx;
background: var(--theme-gradient-soft);
}
.coupon-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
}
.coupon-title {
font-size: 30rpx;
font-weight: 700;
color: var(--text-primary);
}
.coupon-source {
margin-top: 10rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.coupon-status {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 140rpx;
height: 52rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.8);
color: var(--theme-primary);
font-size: 22rpx;
font-weight: 700;
}
.coupon-benefit {
margin-top: 26rpx;
font-size: 42rpx;
font-weight: 800;
color: var(--theme-primary);
}
.coupon-period {
margin-top: 18rpx;
font-size: 24rpx;
color: var(--text-secondary);
}