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 @@ ...@@ -5,6 +5,36 @@
5 5
6 --- 6 ---
7 7
8 +## [2026-02-10] - 重构 API 接口层代码
9 +
10 +### 重构
11 +- **简化 API 包装函数**
12 + - 将多行包装函数简化为单行表达式
13 + - `file.js`:简化 `fileListAPI``weekHotAPI`
14 + - `get_product.js`:简化 `detailAPI``listAPI`
15 + - `plan.js`:简化 `addAPI``listAPI`
16 +
17 +- **更新计划书 API**
18 + - 移除旧的 `submitPlanAPI` 实现
19 + - 新增 `addAPI`(新增计划书)和 `listAPI`(计划书列表)
20 + - 使用统一的 `fn(fetch.post/post/get)` 调用方式
21 +
22 +- **清理代码**
23 + - 移除 `file.js``plan.js` 的文件头部注释
24 +
25 +### 文档
26 +- **新增计划书 API 文档**`docs/api-specs/plan/` 目录
27 +
28 +---
29 +
30 +**详细信息**
31 +- **影响文件**: src/api/file.js, src/api/get_product.js, src/api/plan.js, docs/api-specs/plan/
32 +- **技术栈**: API 层重构
33 +- **测试状态**: 待验证
34 +- **备注**: 简化代码结构,统一 API 调用模式
35 +
36 +---
37 +
8 ## [2026-02-10] - 修复计划书弹窗按钮显示逻辑 38 ## [2026-02-10] - 修复计划书弹窗按钮显示逻辑
9 39
10 ### 修复 40 ### 修复
......
1 +# 新增计划书
2 +
3 +## OpenAPI Specification
4 +
5 +```yaml
6 +openapi: 3.0.1
7 +info:
8 + title: ''
9 + version: 1.0.0
10 +paths:
11 + /srv/:
12 + post:
13 + summary: 新增计划书
14 + deprecated: false
15 + description: ''
16 + tags:
17 + - 计划书
18 + parameters:
19 + - name: f
20 + in: query
21 + description: ''
22 + required: false
23 + example: manulife
24 + schema:
25 + type: string
26 + - name: a
27 + in: query
28 + description: ''
29 + required: false
30 + example: proposal
31 + schema:
32 + type: string
33 + - name: t
34 + in: query
35 + description: ''
36 + required: false
37 + example: add
38 + schema:
39 + type: string
40 + requestBody:
41 + content:
42 + application/x-www-form-urlencoded:
43 + schema:
44 + type: object
45 + properties:
46 + customer_name:
47 + description: 客户姓名
48 + example: 冬一
49 + type: string
50 + customer_gender:
51 + description: 客户性别
52 + example:
53 + type: string
54 + customer_age:
55 + description: 客户年龄
56 + example: '20'
57 + type: string
58 + annual_premium:
59 + description: 年缴保费
60 + example: '5000'
61 + type: string
62 + payment_years:
63 + description: 缴费年限
64 + example: '10'
65 + type: string
66 + currency_type:
67 + description: 币种
68 + example: CNY
69 + type: string
70 + product_id:
71 + description: 产品id
72 + example: '2769884'
73 + type: string
74 + customer_birthday:
75 + description: 出生年月日
76 + example: ''
77 + type: string
78 + allow_reduce_amount:
79 + description: 是否容许减少名义金额
80 + example: ''
81 + type: string
82 + withdrawal_option:
83 + description: 提取选项
84 + example: ''
85 + type: string
86 + withdrawal_start_age:
87 + description: 提取开始年龄
88 + example: ''
89 + type: string
90 + withdrawal_period:
91 + description: 提取期(年)
92 + example: ''
93 + type: string
94 + total_premium:
95 + description: 总保费金额
96 + example: ''
97 + type: string
98 + examples: {}
99 + responses:
100 + '200':
101 + description: ''
102 + content:
103 + application/json:
104 + schema:
105 + type: object
106 + properties:
107 + code:
108 + type: integer
109 + msg:
110 + type: string
111 + data:
112 + type: object
113 + properties:
114 + order_id:
115 + type: string
116 + required:
117 + - order_id
118 + x-apifox-orders:
119 + - order_id
120 + required:
121 + - code
122 + - msg
123 + - data
124 + x-apifox-orders:
125 + - code
126 + - msg
127 + - data
128 + example:
129 + code: 1
130 + msg: 计划书申请提交成功
131 + data:
132 + order_id: '2769902'
133 + headers: {}
134 + x-apifox-name: 成功
135 + x-apifox-ordering: 0
136 + security: []
137 + x-apifox-folder: 计划书
138 + x-apifox-status: developing
139 + x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-417310981-run
140 +components:
141 + schemas: {}
142 + responses: {}
143 + securitySchemes: {}
144 +servers:
145 + - url: https://manulife.onwall.cn
146 + description: 正式环境
147 +security: []
148 +
149 +```
1 +# 计划书列表
2 +
3 +## OpenAPI Specification
4 +
5 +```yaml
6 +openapi: 3.0.1
7 +info:
8 + title: ''
9 + version: 1.0.0
10 +paths:
11 + /srv/:
12 + get:
13 + summary: 计划书列表
14 + deprecated: false
15 + description: ''
16 + tags:
17 + - 计划书
18 + parameters:
19 + - name: f
20 + in: query
21 + description: ''
22 + required: false
23 + example: manulife
24 + schema:
25 + type: string
26 + - name: a
27 + in: query
28 + description: ''
29 + required: false
30 + example: proposal
31 + schema:
32 + type: string
33 + - name: t
34 + in: query
35 + description: ''
36 + required: false
37 + example: list
38 + schema:
39 + type: string
40 + responses:
41 + '200':
42 + description: ''
43 + content:
44 + application/json:
45 + schema:
46 + type: object
47 + properties:
48 + code:
49 + type: integer
50 + msg:
51 + type: string
52 + data:
53 + type: object
54 + properties:
55 + list:
56 + type: array
57 + items:
58 + type: object
59 + properties:
60 + id:
61 + type: integer
62 + customer_name:
63 + type: string
64 + title: 申请人
65 + product_name:
66 + type: string
67 + title: 产品名
68 + created_time:
69 + type: string
70 + title: 创建时间
71 + order_status:
72 + type: string
73 + title: 状态
74 + categories:
75 + type: array
76 + items:
77 + type: string
78 + title: 分类
79 + proposal_files:
80 + type: array
81 + items:
82 + type: object
83 + properties:
84 + id:
85 + type: integer
86 + file_url:
87 + type: string
88 + title: 地址
89 + file_name:
90 + type: string
91 + title: 名称
92 + file_size:
93 + type: integer
94 + title: 大小
95 + created_time:
96 + type: string
97 + title: 创建时间
98 + x-apifox-orders:
99 + - id
100 + - file_url
101 + - file_name
102 + - file_size
103 + - created_time
104 + title: 生成的计划书
105 + x-apifox-orders:
106 + - id
107 + - customer_name
108 + - product_name
109 + - created_time
110 + - order_status
111 + - categories
112 + - proposal_files
113 + title: 几乎书列表
114 + total:
115 + type: integer
116 + title: 总数
117 + required:
118 + - list
119 + - total
120 + x-apifox-orders:
121 + - list
122 + - total
123 + required:
124 + - code
125 + - msg
126 + - data
127 + x-apifox-orders:
128 + - code
129 + - msg
130 + - data
131 + example:
132 + code: 1
133 + msg: 获取成功
134 + data:
135 + list:
136 + - id: 123
137 + customer_name: 张三
138 + product_name: 终身寿险
139 + created_time: '2026-02-09 10:30:00'
140 + order_status: '3'
141 + categories:
142 + - 寿险
143 + - 长期
144 + proposal_files:
145 + - id: 456
146 + file_url: https://example.com/file.pdf
147 + file_name: 计划书.pdf
148 + file_size: 1024000
149 + created_time: '2026-02-09 11:00:00'
150 + total: 1
151 + headers: {}
152 + x-apifox-name: 成功
153 + x-apifox-ordering: 0
154 + security: []
155 + x-apifox-folder: 计划书
156 + x-apifox-status: developing
157 + x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-417311013-run
158 +components:
159 + schemas: {}
160 + responses: {}
161 + securitySchemes: {}
162 +servers:
163 + - url: https://manulife.onwall.cn
164 + description: 正式环境
165 +security: []
166 +
167 +```
1 -/*
2 - * @Date: 2026-02-06 18:10:17
3 - * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2026-02-06 18:12:50
5 - * @FilePath: /manulife-weapp/src/api/file.js
6 - * @Description: 文件相关 API
7 - */
8 import { fn, fetch } from '@/api/fn'; 1 import { fn, fetch } from '@/api/fn';
9 2
10 const Api = { 3 const Api = {
...@@ -69,9 +62,7 @@ const Api = { ...@@ -69,9 +62,7 @@ const Api = {
69 * }; 62 * };
70 * }>} 63 * }>}
71 */ 64 */
72 -export const fileListAPI = (params) => { 65 +export const fileListAPI = (params) => fn(fetch.get(Api.FileList, params));
73 - return fn(fetch.get(Api.FileList, params));
74 -};
75 66
76 /** 67 /**
77 * @description 本周热门资料 68 * @description 本周热门资料
...@@ -95,6 +86,4 @@ export const fileListAPI = (params) => { ...@@ -95,6 +86,4 @@ export const fileListAPI = (params) => {
95 * }; 86 * };
96 * }>} 87 * }>}
97 */ 88 */
98 -export const weekHotAPI = (params) => { 89 +export const weekHotAPI = (params) => fn(fetch.get(Api.WeekHot, params));
99 - return fn(fetch.get(Api.WeekHot, params));
100 -};
......
...@@ -45,9 +45,7 @@ const Api = { ...@@ -45,9 +45,7 @@ const Api = {
45 * }; 45 * };
46 * }>} 46 * }>}
47 */ 47 */
48 -export const detailAPI = (params) => { 48 +export const detailAPI = (params) => fn(fetch.get(Api.Detail, params));
49 - return fn(fetch.get(Api.Detail, params));
50 -};
51 49
52 /** 50 /**
53 * @description 产品列表 51 * @description 产品列表
...@@ -89,6 +87,4 @@ export const detailAPI = (params) => { ...@@ -89,6 +87,4 @@ export const detailAPI = (params) => {
89 * }; 87 * };
90 * }>} 88 * }>}
91 */ 89 */
92 -export const listAPI = (params) => { 90 +export const listAPI = (params) => fn(fetch.get(Api.List, params));
93 - return fn(fetch.get(Api.List, params));
94 -};
......
1 -/** 1 +import { fn, fetch } from '@/api/fn';
2 - * 计划书 API 接口
3 - *
4 - * @description 计划书相关的 API 接口定义
5 - * @module api/plan
6 - * @author Claude Code
7 - * @created 2026-02-06
8 - */
9 -
10 -import { fn } from './fn'
11 2
12 const Api = { 3 const Api = {
13 - Submit: '/srv/?a=submit_plan&t=submit' 4 + Add: '/srv/?a=proposal&t=add',
5 + List: '/srv/?a=proposal&t=list',
14 } 6 }
15 7
16 /** 8 /**
17 - * 提交计划书 9 + * @description 新增计划书
18 - * 10 + * @remark
19 - * @description 提交计划书表单数据到后端,生成计划书 PDF 11 + * @param {Object} params 请求参数
20 - * @param {Object} params - 请求参数 12 + * @param {string} params.customer_name (可选) 客户姓名
21 - * @param {number} params.product_id - 产品 ID 13 + * @param {string} params.customer_gender (可选) 客户性别
22 - * @param {string} params.template - 模版标识(form_sn) 14 + * @param {string} params.customer_age (可选) 客户年龄
23 - * @param {Object} params.form_data - 表单数据 15 + * @param {string} params.annual_premium (可选) 年缴保费
24 - * @param {string} params.form_data.gender - 性别("男" | "女") 16 + * @param {string} params.payment_years (可选) 缴费年限
25 - * @param {number} params.form_data.age - 年龄 17 + * @param {string} params.currency_type (可选) 币种
26 - * @param {string} params.form_data.birthday - 出生日期(格式:YYYY-MM-DD) 18 + * @param {string} params.product_id (可选) 产品id
27 - * @param {string} params.form_data.smoker - 是否吸烟("是" | "否") 19 + * @param {string} params.customer_birthday (可选) 出生年月日
28 - * @param {number} params.form_data.coverage - 保额(单位:分) 20 + * @param {string} params.allow_reduce_amount (可选) 是否容许减少名义金额
29 - * @param {string} params.form_data.payment_period - 缴费年期 21 + * @param {string} params.withdrawal_option (可选) 提取选项
22 + * @param {string} params.withdrawal_start_age (可选) 提取开始年龄
23 + * @param {string} params.withdrawal_period (可选) 提取期(年)
24 + * @param {string} params.total_premium (可选) 总保费金额
30 * @returns {Promise<{ 25 * @returns {Promise<{
31 * code: number; // 状态码 26 * code: number; // 状态码
32 * msg: string; // 消息 27 * msg: string; // 消息
33 * data: { 28 * data: {
34 - * plan_id: number; // 计划书 ID 29 + order_id: string; //
35 - * status: string; // 状态:processing | generated
36 - * estimated_time: number; // 预计生成时间(秒)
37 * }; 30 * };
38 * }>} 31 * }>}
39 - *
40 - * @example
41 - * const res = await submitPlanAPI({
42 - * product_id: 1,
43 - * template: 'life-insurance-wiop3e',
44 - * form_data: {
45 - * gender: '男',
46 - * age: 18,
47 - * birthday: '1990-01-01',
48 - * smoker: '否',
49 - * coverage: 100000, // 1000.00 元(单位:分)
50 - * payment_period: '10 年(0-70 岁)'
51 - * }
52 - * })
53 - *
54 - * if (res.code === 1) {
55 - * console.log('计划书 ID:', res.data.plan_id)
56 - * console.log('预计生成时间:', res.data.estimated_time, '秒')
57 - * }
58 */ 32 */
59 -export const submitPlanAPI = (params) => fn({ 33 +export const addAPI = (params) => fn(fetch.post(Api.Add, params));
60 - url: Api.Submit,
61 - method: 'POST',
62 - data: params
63 -})
64 34
65 -// 注意:查询计划书状态功能暂不需要 35 +/**
66 -// 计划书生成是半自动流程(小程序 → 公司 → 手动上传 → 用户查看) 36 + * @description 计划书列表
67 -// 用户在"我的计划书"页面查看生成的计划书 37 + * @remark
38 + * @param {Object} params 请求参数
39 + * @returns {Promise<{
40 + * code: number; // 状态码
41 + * msg: string; // 消息
42 + * data: {
43 + list: Array<{
44 + id: integer; //
45 + customer_name: string; // 申请人
46 + product_name: string; // 产品名
47 + created_time: string; // 创建时间
48 + order_status: string; // 状态
49 + categories: Array<string>; // 分类
50 + proposal_files: Array<{
51 + id: integer; //
52 + file_url: string; // 地址
53 + file_name: string; // 名称
54 + file_size: integer; // 大小
55 + created_time: string; // 创建时间
56 + }>;
57 + }>;
58 + total: integer; // 总数
59 + * };
60 + * }>}
61 + */
62 +export const listAPI = (params) => fn(fetch.get(Api.List, params));
......