Commit b1adc77e by 张立顺

feat 二手车优惠券功能开发

1 parent 7f17ba9a
# aus-front/app 项目技术栈与用法梳理
本文档归纳本工程(`aus-front/app`)使用的框架、构建方式与常见用法,便于新成员上手与后续维护。
## 1. 核心框架
| 层级 | 技术 | 说明 |
|------|------|------|
| 跨端框架 | **uni-app 3.x**(`@dcloudio/uni-*`) | 基于 DCloud 官方 Vue 3 预设(`package.json` 中项目名为 `uni-preset-vue`) |
| 视图层 | **Vue 3.4**(`createSSRApp`) | 入口 [src/main.ts](src/main.ts) 使用 `createSSRApp`,符合 uni-app 3 标准写法 |
| 构建工具 | **Vite 5** + **`@dcloudio/vite-plugin-uni`** | [vite.config.ts](vite.config.ts) 注册 `uni()`,并对 `@dcloudio/uni-ui` 做 `transpileDependencies` |
| 语言 | **TypeScript 4.9** | [tsconfig.json](tsconfig.json) 开启 `experimentalDecorators` / `emitDecoratorMetadata`,路径别名 `@/*` → `src/*` |
| 样式 | **Sass/SCSS** | `devDependencies` 含 `sass`、`sass-loader`;[src/App.vue](src/App.vue) 使用 `<style lang="scss">` 及条件编译注释(如 `/* #ifdef MP-WEIXIN */`) |
### uni-app 在本项目中的典型用法
- **应用配置**:[src/manifest.json](src/manifest.json) — `vueVersion: "3"`、微信小程序 `mp-weixin`(含 `appid`、权限、`lazyCodeLoading` 等)。
- **页面路由**:[src/pages.json](src/pages.json) — 主包 `pages`、分包 `subPackages`(如 `module/auction`)、各页 `navigationStyle` / 下拉刷新等。
- **生命周期与 API**:页面/应用级通过 `@dcloudio/uni-app` 的 `onLaunch`、`onShow` 等;业务中大量使用 `uni.*`(导航、存储、定位等),与微信小程序能力对齐。
```mermaid
flowchart LR
subgraph build [构建]
Vite[Vite 5]
UniPlugin[vite-plugin-uni]
end
subgraph runtime [运行时]
Vue3[Vue 3 createSSRApp]
UniRuntime[uni 全局 API]
end
Vite --> UniPlugin
UniPlugin --> Vue3
Vue3 --> UniRuntime
```
## 2. 构建与运行目标
[package.json](package.json) 中 `scripts` 表明主要支持:
- **H5**:`dev:h5` / `build:h5`(可选 `ssr`)
- **微信小程序**:`dev:mp-weixin` / `build:mp-weixin`
- 另有 **QQ 小程序**、**custom** 平台占位
依赖中同时存在 `@dcloudio/uni-h5`、`uni-mp-weixin`、`uni-mp-toutiao`、`uni-mp-xhs` 等,说明工程可按平台打包;脚本与 manifest 当前最明确的是 **H5 + 微信小程序**。
**环境变量**:根目录存在 `.env.development`、`.env.production`;代码通过 **`import.meta.env.VITE_APP_API_URL`**、**`VITE_APP_API_BASE_URL`** 注入后端地址(见 [src/main.ts](src/main.ts))。
## 3. UI 与组件库
- **uview-plus**:在 `main.ts` 中 `app.use(uviewPlus)`,TypeScript `types` 含 `uview-plus/types`。
- **@dcloudio/uni-ui**:Vite 配置中显式转译;可与 uni 内置组件配合。
- **@vant/weapp**、**@vant/area-data**:面向小程序侧的 Vant 能力/省市区数据(具体引用以各页面 import 为准)。
## 4. 状态管理、国际化、工具库
- **Vuex 4**:[src/store/index.ts](src/store/index.ts) 使用 `new Vuex.Store`,维护 `currentCity`、`cacheAccounts` 等;`changeCity` mutation 内同步 `uni.setStorageSync`。
- **vue-i18n 9**:`main.ts` 中 `createI18n`(`legacy: false`,`globalInjection: true`),文案来自 [src/common/i18n](src/common/i18n)。
- **dayjs**:`main.ts` 扩展 `duration`;`App.vue` 与拦截器等处用于时间处理。
- **crypto-js、pinyin-pro**:加密与拼音相关工具依赖。
## 5. 网络层用法
- **axios 0.19.x** + **`axios-miniprogram-adapter`**:在 `main.ts` 创建实例并设置 `adapter: mpAdapter`,使请求在微信小程序等环境可用。
- **CustomTokenInterceptor**([src/common/CustomTokenInterceptor.ts](src/common/CustomTokenInterceptor.ts)):挂请求/响应拦截器,注入 `Authorization: Bearer ...`,并与 [src/common/AuthService.ts](src/common/AuthService.ts) 联动。
- **全局挂载**:`app.config.globalProperties.axios`、`$apiUrl`、`$baseUrl`、`$auth`、`$filters`、`$store`。
[src/App.vue](src/App.vue) 内为 **百度地图逆地理编码** 单独再建了一个指向 `https://api.map.baidu.com` 的 axios 实例(同样使用小程序 adapter),用于启动时定位城市。
## 6. 业务与代码组织特点
- **本地共享包 `lib`**:`package.json` 中 `"lib": "file:../lib"`,store 与拦截器等从 `lib/src/...` 引用实体与配置(如 `Account`、`AutumnConfig`),前后端或多端共用领域模型。
- **组件写法混用**:
- 新式:[src/App.vue](src/App.vue) 使用 `<script setup lang="ts">`。
- 类组件:**vue-facing-decorator** — 多个页面/模块使用 `@Component`、`@Prop`、`@Hook` 等(例如 [src/pages/tabbar/home/LikeAuctionVehicles.vue](src/pages/tabbar/home/LikeAuctionVehicles.vue)、`AuctionSessionPage.vue` 等),与 Vue 3 兼容的 class 风格并存。
## 7. 其他工程行为(从入口可见)
- **路由包装**:`main.ts` 中重写 `uni.navigateTo`、`redirectTo`、`switchTab`,在切换 Tab 时调用 `BurialPoint` 做埋点。
- **类型**:`@dcloudio/types`、`miniprogram-api-typings` 支撑 `uni` 与小程序 API 类型。
---
**结论**:该项目是 **uni-app 3 + Vue 3 + Vite** 的跨端应用,**主战场为微信小程序与 H5**;状态用 **Vuex**,接口用 **axios + 小程序 adapter + 自定义 Token 拦截器**,UI 以 **uview-plus / uni-ui** 为主,并混用 **`<script setup>`** 与 **vue-facing-decorator 类组件**;业务实体部分来自同仓 **`../lib`** 包。
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
"devDependencies": { "devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.4.0", "@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0", "@typescript-eslint/parser": "^5.4.0",
"autumn-vue": "~0.4.47",
"eslint": "^7.0.0", "eslint": "^7.0.0",
"eslint-plugin-node": "~11.1.0", "eslint-plugin-node": "~11.1.0",
"eslint-plugin-promise": "~4.2.1", "eslint-plugin-promise": "~4.2.1",
......
import type {AxiosResponse, AxiosStatic} from 'axios';
// region 前端扩展导入包(类型定义;实体入 lib 后可改为从 lib 引用)
// endregion
// region 请求/响应类型(与后端 OpenAPI 对齐;baseURL 见 `VITE_APP_API_URL`,一般为 `.../app/api/`,此处为相对路径 `coupon/...`)
/** POST coupon/verify — 核销优惠券 */
export interface CouponVerifyReq {
couponId: string;
orderId: number;
orderCode: string;
transactionAmount: number;
vehicleId?: number;
vehicleInfo?: string;
}
export interface CouponVerifyResp {
couponId: string;
orderId: number;
actualDeduction: number;
}
/** GET coupon/popup — 获取待展示弹窗 */
export interface CouponPopupItem {
couponId: string;
templateName: string;
faceAmount: number;
validEndTime: string;
distributionSource: string;
}
export interface CouponPopupResp {
popupType: number;
couponList: CouponPopupItem[];
}
export interface UsedCouponInfo {
couponId: string;
templateName: string;
faceAmount: number;
actualDeduction: number;
deductionType: number;
usageTime: string;
}
export interface OrderCouponItem {
couponId: string;
templateName: string;
couponType: number;
deductionType: number;
faceAmount: number;
thresholdAmount: number;
actualDeduction: number;
validStartTime: string;
validEndTime: string;
receiveTime: string;
available: boolean;
unavailableReason: string | null;
recommended: boolean;
usedByCurrentOrder: boolean;
usedCouponInfo?: UsedCouponInfo;
}
export interface CouponOrderInfo {
orderId: number;
orderCode: string;
vehicleName: string;
sourceNo: string;
}
export interface MyCouponItem {
id: number;
couponId: string;
templateId: number;
templateName: string;
couponType: number;
faceAmount: number;
thresholdAmount: number;
deductionType: number;
status: number;
validStartTime: string;
validEndTime: string;
nuclearTime: string;
nuclearOrderId: number;
distributionType: number;
distributionSource: string;
createTime: string;
description: string;
approachingExpiry: boolean;
orderInfo?: CouponOrderInfo;
}
export type CouponDetail = MyCouponItem;
export interface CouponActivityPriceRangeRespVO {
id: number;
priceMin: number;
priceMax: number;
templateId: number;
}
export interface LatestCouponActivityResp {
id: number;
activityId: string;
activityName: string;
activityType: number;
validStartTime: string;
validEndTime: string;
templateId: number;
distributionQuantity: number;
targetType: number;
sendNotification: number;
status: number;
remark: string;
createTime: string;
updateTime: string;
totalGrantCount: number;
usedCount: number;
writeOffRate: number;
priceRanges: CouponActivityPriceRangeRespVO[];
}
export interface CouponCountResp {
unusedCount: number;
verifiedCount: number;
expiredCount: number;
}
export const CouponListQueryStatus = {
UNUSED: 1,
VERIFIED: 2,
EXPIRED: 3,
} as const;
// endregion
/**
* 优惠券(Coupon)接口
* @since 2026-04-16
*/
export class CouponController {
/**
* 核销优惠券
* @param body 订单与券实例、成交价等
*/
static verifyCoupon(axios: AxiosStatic, body: CouponVerifyReq): Promise<AxiosResponse<CouponVerifyResp>> {
return axios.post('coupon/verify', body);
}
/**
* 获取待展示弹窗(首页)
*/
static getCouponPopup(axios: AxiosStatic): Promise<AxiosResponse<CouponPopupResp>> {
return axios.get('coupon/popup');
}
/**
* 获取订单可用优惠券列表
* @param orderId 订单 ID
*/
static getOrderCoupons(axios: AxiosStatic, orderId: number): Promise<AxiosResponse<OrderCouponItem[]>> {
return axios.get(`coupon/order-coupons/${orderId}`);
}
/**
* 我的优惠券列表
* @param status 1 待使用;2 已核销;3 已过期
*/
static getMyCouponList(axios: AxiosStatic, status: number): Promise<AxiosResponse<MyCouponItem[]>> {
return axios.get('coupon/list', {params: {status}});
}
/**
* 当前创建时间最新的可用优惠券活动
*/
static getLatestCouponActivity(axios: AxiosStatic): Promise<AxiosResponse<LatestCouponActivityResp>> {
return axios.get('coupon/latest-activity');
}
/**
* 优惠券详情
* @param couponId 优惠券实例 ID
*/
static getCouponDetail(axios: AxiosStatic, couponId: string): Promise<AxiosResponse<CouponDetail>> {
return axios.get(`coupon/detail/${encodeURIComponent(couponId)}`);
}
/**
* 各状态优惠券数量统计
*/
static getCouponCount(axios: AxiosStatic): Promise<AxiosResponse<CouponCountResp>> {
return axios.get('coupon/count');
}
// region 前端扩展代码区
// endregion
}
<template>
<view class="coupon-page">
<view class="coupon-placeholder">
<image class="coupon-placeholder__img" src="https://img02.glsx.com.cn/aus/images/empty.png" mode="widthFix"/>
<text class="coupon-placeholder__text">暂无优惠券</text>
</view>
</view>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
@Component({})
export default class CouponPage extends Vue {
}
</script>
<style lang="scss" scoped>
.coupon-page {
min-height: 100vh;
background-color: #f8f9fc;
padding-top: 24px;
}
.coupon-placeholder {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 80px;
}
.coupon-placeholder__img {
width: 144px;
margin-bottom: 16px;
}
.coupon-placeholder__text {
font-size: 14px;
color: #969799;
}
</style>
...@@ -227,6 +227,13 @@ ...@@ -227,6 +227,13 @@
} }
}, },
{ {
"path": "CouponPage",
"style": {
"navigationBarTitleText": "优惠卡券",
"enablePullDownRefresh": false
}
},
{
"path": "CancelOrderPage", "path": "CancelOrderPage",
"style": { "style": {
"navigationBarTitleText": "取消订单", "navigationBarTitleText": "取消订单",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!