hookehuyr

refactor(api): 重构 API 接口层代码

- 简化 API 包装函数(file.js, get_product.js, plan.js)
- 更新计划书 API:新增 addAPI 和 listAPI
- 统一使用 fn(fetch.post/get) 调用方式
- 清理文件头部注释
- 新增计划书 API 文档(docs/api-specs/plan/)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
......@@ -5,6 +5,36 @@
---
## [2026-02-10] - 重构 API 接口层代码
### 重构
- **简化 API 包装函数**
- 将多行包装函数简化为单行表达式
- `file.js`:简化 `fileListAPI``weekHotAPI`
- `get_product.js`:简化 `detailAPI``listAPI`
- `plan.js`:简化 `addAPI``listAPI`
- **更新计划书 API**
- 移除旧的 `submitPlanAPI` 实现
- 新增 `addAPI`(新增计划书)和 `listAPI`(计划书列表)
- 使用统一的 `fn(fetch.post/post/get)` 调用方式
- **清理代码**
- 移除 `file.js``plan.js` 的文件头部注释
### 文档
- **新增计划书 API 文档**`docs/api-specs/plan/` 目录
---
**详细信息**
- **影响文件**: src/api/file.js, src/api/get_product.js, src/api/plan.js, docs/api-specs/plan/
- **技术栈**: API 层重构
- **测试状态**: 待验证
- **备注**: 简化代码结构,统一 API 调用模式
---
## [2026-02-10] - 修复计划书弹窗按钮显示逻辑
### 修复
......
# 新增计划书
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/srv/:
post:
summary: 新增计划书
deprecated: false
description: ''
tags:
- 计划书
parameters:
- name: f
in: query
description: ''
required: false
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: false
example: proposal
schema:
type: string
- name: t
in: query
description: ''
required: false
example: add
schema:
type: string
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
customer_name:
description: 客户姓名
example: 冬一
type: string
customer_gender:
description: 客户性别
example:
type: string
customer_age:
description: 客户年龄
example: '20'
type: string
annual_premium:
description: 年缴保费
example: '5000'
type: string
payment_years:
description: 缴费年限
example: '10'
type: string
currency_type:
description: 币种
example: CNY
type: string
product_id:
description: 产品id
example: '2769884'
type: string
customer_birthday:
description: 出生年月日
example: ''
type: string
allow_reduce_amount:
description: 是否容许减少名义金额
example: ''
type: string
withdrawal_option:
description: 提取选项
example: ''
type: string
withdrawal_start_age:
description: 提取开始年龄
example: ''
type: string
withdrawal_period:
description: 提取期(年)
example: ''
type: string
total_premium:
description: 总保费金额
example: ''
type: string
examples: {}
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
msg:
type: string
data:
type: object
properties:
order_id:
type: string
required:
- order_id
x-apifox-orders:
- order_id
required:
- code
- msg
- data
x-apifox-orders:
- code
- msg
- data
example:
code: 1
msg: 计划书申请提交成功
data:
order_id: '2769902'
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 计划书
x-apifox-status: developing
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-417310981-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers:
- url: https://manulife.onwall.cn
description: 正式环境
security: []
```
# 计划书列表
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/srv/:
get:
summary: 计划书列表
deprecated: false
description: ''
tags:
- 计划书
parameters:
- name: f
in: query
description: ''
required: false
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: false
example: proposal
schema:
type: string
- name: t
in: query
description: ''
required: false
example: list
schema:
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
msg:
type: string
data:
type: object
properties:
list:
type: array
items:
type: object
properties:
id:
type: integer
customer_name:
type: string
title: 申请人
product_name:
type: string
title: 产品名
created_time:
type: string
title: 创建时间
order_status:
type: string
title: 状态
categories:
type: array
items:
type: string
title: 分类
proposal_files:
type: array
items:
type: object
properties:
id:
type: integer
file_url:
type: string
title: 地址
file_name:
type: string
title: 名称
file_size:
type: integer
title: 大小
created_time:
type: string
title: 创建时间
x-apifox-orders:
- id
- file_url
- file_name
- file_size
- created_time
title: 生成的计划书
x-apifox-orders:
- id
- customer_name
- product_name
- created_time
- order_status
- categories
- proposal_files
title: 几乎书列表
total:
type: integer
title: 总数
required:
- list
- total
x-apifox-orders:
- list
- total
required:
- code
- msg
- data
x-apifox-orders:
- code
- msg
- data
example:
code: 1
msg: 获取成功
data:
list:
- id: 123
customer_name: 张三
product_name: 终身寿险
created_time: '2026-02-09 10:30:00'
order_status: '3'
categories:
- 寿险
- 长期
proposal_files:
- id: 456
file_url: https://example.com/file.pdf
file_name: 计划书.pdf
file_size: 1024000
created_time: '2026-02-09 11:00:00'
total: 1
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 计划书
x-apifox-status: developing
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-417311013-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers:
- url: https://manulife.onwall.cn
description: 正式环境
security: []
```
/*
* @Date: 2026-02-06 18:10:17
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-02-06 18:12:50
* @FilePath: /manulife-weapp/src/api/file.js
* @Description: 文件相关 API
*/
import { fn, fetch } from '@/api/fn';
const Api = {
......@@ -14,11 +7,11 @@ const Api = {
/**
* @description 文档列表
* @remark
* @remark
* @param {Object} params 请求参数
* @param {string} params.client_id (可选) 主体id
* @param {string} params.limit (可选)
* @param {string} params.page (可选)
* @param {string} params.limit (可选)
* @param {string} params.page (可选)
* @param {string} params.cid (可选) 分类id
* @param {string} params.child_id (可选) 只有一层分类时,筛选数据用
* @param {string} params.keyword (可选) 搜索关键词
......@@ -56,7 +49,7 @@ const Api = {
}>;
}>;
list: Array<{
id: integer; //
id: integer; //
name: string; // 附件名称
value: string; // 附件地址
extension: string; // 后缀名
......@@ -69,9 +62,7 @@ const Api = {
* };
* }>}
*/
export const fileListAPI = (params) => {
return fn(fetch.get(Api.FileList, params));
};
export const fileListAPI = (params) => fn(fetch.get(Api.FileList, params));
/**
* @description 本周热门资料
......@@ -90,11 +81,9 @@ export const fileListAPI = (params) => {
size: string; // 文件大小
read_people_count: integer; // 学习人数
read_people_percent: number; // 学习人数比例
is_favorite: string; //
is_favorite: string; //
}>;
* };
* }>}
*/
export const weekHotAPI = (params) => {
return fn(fetch.get(Api.WeekHot, params));
};
export const weekHotAPI = (params) => fn(fetch.get(Api.WeekHot, params));
......
......@@ -7,7 +7,7 @@ const Api = {
/**
* @description 产品详情
* @remark
* @remark
* @param {Object} params 请求参数
* @param {string} params.client_id (可选) 主体id
* @param {string} params.i 产品id
......@@ -18,11 +18,11 @@ const Api = {
id: integer; // 产品id
product_name: string; // 产品名
recommend: string; // 推荐位: normal-普通, hot-热卖
status: string; //
created_by: integer; //
created_time: string; //
updated_by: integer; //
updated_time: string; //
status: string; //
created_by: integer; //
created_time: string; //
updated_by: integer; //
updated_time: string; //
form_sn: string; // 关联表单sn
product_description: string; // 产品描述
categories: Array<{
......@@ -45,17 +45,15 @@ const Api = {
* };
* }>}
*/
export const detailAPI = (params) => {
return fn(fetch.get(Api.Detail, params));
};
export const detailAPI = (params) => fn(fetch.get(Api.Detail, params));
/**
* @description 产品列表
* @remark
* @remark
* @param {Object} params 请求参数
* @param {string} params.client_id (可选) 主体id
* @param {string} params.limit (可选)
* @param {string} params.page (可选)
* @param {string} params.limit (可选)
* @param {string} params.page (可选)
* @param {string} params.cid (可选) 分类id
* @param {string} params.recommend (可选) 推荐位: normal-普通, hot-热卖
* @param {string} params.keyword (可选) 搜索
......@@ -71,7 +69,7 @@ export const detailAPI = (params) => {
id: integer; // 产品id
product_name: string; // 产品名
recommend: string; // 推荐位: normal-普通, hot-热卖
form_sn: string; //
form_sn: string; //
created_time: string; // 创建时间
categories: Array<{
id: string; // 分类id
......@@ -89,6 +87,4 @@ export const detailAPI = (params) => {
* };
* }>}
*/
export const listAPI = (params) => {
return fn(fetch.get(Api.List, params));
};
export const listAPI = (params) => fn(fetch.get(Api.List, params));
......
/**
* 计划书 API 接口
*
* @description 计划书相关的 API 接口定义
* @module api/plan
* @author Claude Code
* @created 2026-02-06
*/
import { fn } from './fn'
import { fn, fetch } from '@/api/fn';
const Api = {
Submit: '/srv/?a=submit_plan&t=submit'
Add: '/srv/?a=proposal&t=add',
List: '/srv/?a=proposal&t=list',
}
/**
* 提交计划书
*
* @description 提交计划书表单数据到后端,生成计划书 PDF
* @param {Object} params - 请求参数
* @param {number} params.product_id - 产品 ID
* @param {string} params.template - 模版标识(form_sn)
* @param {Object} params.form_data - 表单数据
* @param {string} params.form_data.gender - 性别("男" | "女")
* @param {number} params.form_data.age - 年龄
* @param {string} params.form_data.birthday - 出生日期(格式:YYYY-MM-DD)
* @param {string} params.form_data.smoker - 是否吸烟("是" | "否")
* @param {number} params.form_data.coverage - 保额(单位:分)
* @param {string} params.form_data.payment_period - 缴费年期
* @description 新增计划书
* @remark
* @param {Object} params 请求参数
* @param {string} params.customer_name (可选) 客户姓名
* @param {string} params.customer_gender (可选) 客户性别
* @param {string} params.customer_age (可选) 客户年龄
* @param {string} params.annual_premium (可选) 年缴保费
* @param {string} params.payment_years (可选) 缴费年限
* @param {string} params.currency_type (可选) 币种
* @param {string} params.product_id (可选) 产品id
* @param {string} params.customer_birthday (可选) 出生年月日
* @param {string} params.allow_reduce_amount (可选) 是否容许减少名义金额
* @param {string} params.withdrawal_option (可选) 提取选项
* @param {string} params.withdrawal_start_age (可选) 提取开始年龄
* @param {string} params.withdrawal_period (可选) 提取期(年)
* @param {string} params.total_premium (可选) 总保费金额
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
* plan_id: number; // 计划书 ID
* status: string; // 状态:processing | generated
* estimated_time: number; // 预计生成时间(秒)
order_id: string; //
* };
* }>}
*
* @example
* const res = await submitPlanAPI({
* product_id: 1,
* template: 'life-insurance-wiop3e',
* form_data: {
* gender: '男',
* age: 18,
* birthday: '1990-01-01',
* smoker: '否',
* coverage: 100000, // 1000.00 元(单位:分)
* payment_period: '10 年(0-70 岁)'
* }
* })
*
* if (res.code === 1) {
* console.log('计划书 ID:', res.data.plan_id)
* console.log('预计生成时间:', res.data.estimated_time, '秒')
* }
*/
export const submitPlanAPI = (params) => fn({
url: Api.Submit,
method: 'POST',
data: params
})
export const addAPI = (params) => fn(fetch.post(Api.Add, params));
// 注意:查询计划书状态功能暂不需要
// 计划书生成是半自动流程(小程序 → 公司 → 手动上传 → 用户查看)
// 用户在"我的计划书"页面查看生成的计划书
/**
* @description 计划书列表
* @remark
* @param {Object} params 请求参数
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
list: Array<{
id: integer; //
customer_name: string; // 申请人
product_name: string; // 产品名
created_time: string; // 创建时间
order_status: string; // 状态
categories: Array<string>; // 分类
proposal_files: Array<{
id: integer; //
file_url: string; // 地址
file_name: string; // 名称
file_size: integer; // 大小
created_time: string; // 创建时间
}>;
}>;
total: integer; // 总数
* };
* }>}
*/
export const listAPI = (params) => fn(fetch.get(Api.List, params));
......