hookehuyr

feat(api): 支持 t 参数并重构 API 生成流程

- 修改 generateApiFromOpenAPI.js 支持 t 参数(接口功能)
- t 参数与 a 参数(文件夹)共同构成 URL 路径
- 在 JSDoc 中过滤 a、f、t 参数,避免重复传递
- 重构 OpenAPI 文档结构,按模块组织(user/wechat/feedback/news)
- 重新生成所有 API 文件,包含正确的 URL 结构

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
# 意见反馈列表
## 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: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: true
example: feedback
schema:
type: string
- name: t
in: query
description: ''
required: true
example: list
schema:
type: string
- name: page
in: query
description: 页码,从0开始
required: true
example: '0'
schema:
type: string
- name: limit
in: query
description: 每页数量
required: true
example: '10'
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
title: 订单ID
status:
type: integer
title: 状态
description: 3=待处理, 5=已处理
category:
type: string
title: 反馈类别
description: 1=功能建议, 3=界面设计, 5=车辆新鲜, 7=其他问题
images:
type: string
title: 图片
contact:
type: string
title: 联系方式
note:
type: string
title: 反馈内容
reply:
type: string
title: 回复
reply_time:
type: string
title: 回复时间
x-apifox-orders:
- id
- status
- category
- images
- contact
- note
- reply
- reply_time
required:
- reply
required:
- list
x-apifox-orders:
- list
required:
- code
- msg
- data
x-apifox-orders:
- code
- msg
- data
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 意见反馈
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906670-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
# 提交意见反馈
## 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: true
example: jiangedianlv
schema:
type: string
- name: a
in: query
description: ''
required: true
example: common
schema:
type: string
- name: t
in: query
description: ''
required: true
example: submit_feedback
schema:
type: string
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
f:
example: manulife
type: string
a:
example: feedback
type: string
t:
example: add
type: string
category:
description: 反馈类别。1=功能建议, 3=界面设计, 5=车辆新鲜, 7=其他问题
example: '1'
type: string
note:
description: 反馈内容
example: '3'
type: string
contact:
description: 用户留下的联系方式
example: '3'
type: string
images:
description: 图片
type: string
required:
- f
- a
- t
- category
- note
- contact
- images
examples: {}
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
msg:
type: string
required:
- code
- msg
x-apifox-orders:
- code
- msg
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 意见反馈
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906671-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
# 消息详情
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/:
get:
summary: 消息详情
deprecated: false
description: ''
tags:
- 消息
parameters:
- name: f
in: query
description: ''
required: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: true
example: website_msg
schema:
type: string
- name: t
in: query
description: ''
required: true
example: detail
schema:
type: string
- name: i
in: query
description: 消息ID
required: true
example: '817677'
schema:
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
msg:
type: string
data:
type: array
items:
type: object
properties:
id:
type: integer
title: 消息id
note:
type: string
title: 消息内容
created_time:
type: string
title: 发消息的时间
status:
type: string
title: 状态
description: send=以发送未读取,read=已读取
x-apifox-orders:
- id
- note
- created_time
- status
required:
- note
- created_time
- status
required:
- code
- msg
- data
x-apifox-orders:
- code
- msg
- data
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 消息
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906673-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
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: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: true
example: website_msg
schema:
type: string
- name: t
in: query
description: ''
required: true
example: my_list
schema:
type: string
- name: page
in: query
description: ''
required: true
example: '0'
schema:
type: string
- name: limit
in: query
description: ''
required: true
example: '10'
schema:
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
msg:
type: string
data:
type: array
items:
type: object
properties:
id:
type: integer
title: 消息id
note:
type: string
title: 消息内容
created_time:
type: string
title: 发消息的时间
status:
type: string
title: 状态
description: send=以发送未读取,read=已读取
x-apifox-orders:
- id
- note
- created_time
- status
required:
- note
- created_time
- status
required:
- code
- msg
- data
x-apifox-orders:
- code
- msg
- data
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 消息
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906672-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
# 获取订单详情
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/srv/:
get:
summary: 获取订单详情
description: 根据订单ID获取订单详细信息
tags:
- 订单管理
parameters:
- name: f
in: query
example: behalo
- name: a
in: query
example: order_detail
- name: id
in: query
description: 订单ID
required: true
example: 123
schema:
type: integer
responses:
'200':
description: 成功返回订单详情
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 0=失败,1=成功
msg:
type: string
description: 错误信息
data:
type: object
properties:
order:
type: object
properties:
id:
type: integer
description: 订单ID
order_no:
type: string
description: 订单号
total_amount:
type: number
description: 订单总金额
status:
type: string
description: 订单状态
items:
type: array
description: 订单商品列表
items:
type: object
properties:
product_id:
type: integer
description: 商品ID
product_name:
type: string
description: 商品名称
quantity:
type: integer
description: 购买数量
price:
type: number
description: 商品单价
```
# 获取订单列表
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/srv/:
get:
summary: 获取订单列表
description: 分页获取用户的订单列表
tags:
- 订单管理
parameters:
- name: f
in: query
example: behalo
- name: a
in: query
example: order_list
- name: page
in: query
description: 页码
example: 1
schema:
type: integer
- name: pageSize
in: query
description: 每页数量
example: 10
schema:
type: integer
responses:
'200':
description: 成功返回订单列表
content:
application/json:
schema:
type: object
properties:
code:
type: integer
title: 状态码
description: 0=失败,1=成功
msg:
type: string
title: 消息
data:
type: object
properties:
list:
type: array
items:
type: object
properties:
id:
type: integer
description: 订单ID
order_no:
type: string
description: 订单号
status:
type: string
description: 订单状态
total_amount:
type: number
description: 订单金额
```
# 查询我的信息
# 获取个人信息
## OpenAPI Specification
......@@ -10,24 +10,31 @@ info:
paths:
/srv/:
get:
summary: 查询我的信息
summary: 获取个人信息
deprecated: false
description: ''
tags:
- 个人信息
- 用户
parameters:
- name: f
in: query
description: ''
required: false
example: behalo
required: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: false
example: user_info
required: true
example: user
schema:
type: string
- name: t
in: query
description: ''
required: true
example: get_profile
schema:
type: string
responses:
......@@ -40,11 +47,8 @@ paths:
properties:
code:
type: integer
title: 状态
description: 0=失败,1=成功
msg:
type: string
title: 错误信息
data:
type: object
properties:
......@@ -53,53 +57,26 @@ paths:
properties:
id:
type: integer
description: 用户ID
name:
title: 用户ID
avatar_url:
type: string
description: 姓名
mobile:
title: 头像
name:
type: string
description: 手机号
title: 姓名
x-apifox-orders:
- id
- name
- mobile
nullable: true
checkin:
type: object
properties:
total_days:
type: integer
title: 累计打卡天数
consecutive_days:
type: integer
title: 连续打卡天数
longest_consecutive_days:
type: integer
title: 最长连续打卡天数
x-apifox-orders:
- total_days
- consecutive_days
- longest_consecutive_days
- avatar_url
title: 用户信息
required:
- total_days
- longest_consecutive_days
- consecutive_days
unread_msg_count:
type: integer
title: 未读的消息数量
is_teacher:
type: boolean
title: 是不是老师
- id
- avatar_url
- name
x-apifox-orders:
- user
- checkin
- unread_msg_count
- is_teacher
required:
- checkin
- unread_msg_count
- is_teacher
- user
x-apifox-orders:
- code
- msg
......@@ -112,16 +89,14 @@ paths:
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 个人信息
x-apifox-status: tested
x-run-in-apifox: https://app.apifox.com/web/project/6084040/apis/api-275317513-run
x-apifox-folder: 用户
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906668-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers:
- url: https://oa-dev.onwall.cn
description: 测试环境
servers: []
security: []
```
......
# 修改我的信息
# 登录并绑定openid
## OpenAPI Specification
......@@ -10,24 +10,31 @@ info:
paths:
/srv/:
post:
summary: 修改我的信息
summary: 登录并绑定openid
deprecated: false
description: ''
tags:
- 个人信息
- 用户
parameters:
- name: user-id
in: header
- name: f
in: query
description: ''
required: false
example: '1033954'
required: true
example: manulife
schema:
type: string
- name: user-token
in: header
- name: a
in: query
description: ''
required: false
example: WN2BD9XQ7CRSVQ92FMB62V9C9OHHRBL38L2NS4GJ#1033954#50
required: true
example: user
schema:
type: string
- name: t
in: query
description: ''
required: true
example: login
schema:
type: string
requestBody:
......@@ -36,32 +43,19 @@ paths:
schema:
type: object
properties:
f:
example: behalo
type: string
a:
example: user_edit
uuid:
example: 预约核销1
type: string
name:
description: 姓名
example: 汪小雨XXXX
password:
example: '000000'
type: string
avatar:
description: 头像
openid:
description: 要绑定的小程序openid
example: ''
type: string
mobile:
description: 手机号
example: ''
type: string
sms_code:
description: 短信验证码
example: '8888'
type: string
idcard:
description: 身份证
example: '12345678'
type: string
required:
- uuid
- password
examples: {}
responses:
'200':
......@@ -73,11 +67,9 @@ paths:
properties:
code:
type: integer
title: 状态
description: 0=失败,1=成功
msg:
type: string
title: 错误信息
x-apifox-orders:
- code
- msg
......@@ -88,16 +80,14 @@ paths:
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 个人信息
x-apifox-status: tested
x-run-in-apifox: https://app.apifox.com/web/project/6084040/apis/api-275318897-run
x-apifox-folder: 用户
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906666-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers:
- url: https://oa-dev.onwall.cn
description: 测试环境
servers: []
security: []
```
......
# 退出登录
## 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: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: true
example: user
schema:
type: string
- name: t
in: query
description: ''
required: true
example: logout
schema:
type: string
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties: {}
examples: {}
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 0=失败,1=成功
msg:
type: string
x-apifox-orders:
- code
- msg
required:
- code
- msg
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 用户
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906667-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
# 更新个人资料
## 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: true
example: manulife
schema:
type: string
- name: a
in: query
description: ''
required: true
example: user
schema:
type: string
- name: t
in: query
description: ''
required: true
example: update_profile
schema:
type: string
requestBody:
content:
application/json:
schema:
type: object
properties:
avatar_url:
type: string
required:
- avatar_url
x-apifox-orders:
- avatar_url
example:
avatar_url: http://.../new_avatar.jpg
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 0=失败,1=成功
msg:
type: string
x-apifox-orders:
- code
- msg
required:
- code
- msg
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 用户
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906669-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
# 小程序授权
## OpenAPI Specification
```yaml
openapi: 3.0.1
info:
title: ''
version: 1.0.0
paths:
/srv/:
post:
summary: 小程序授权
deprecated: false
description: |
# 登录流程设计
- 先小程序授权
- 如果返回 user 为空,则需要调用登录接口
- 如果返回 user 非空,则不需要调用登录接口,授权接口内部按照openid绑定的账号,自动登录
tags:
- 微信
parameters:
- name: f
in: query
description: ''
required: true
example: manulife
schema:
type: string
- name: a
in: query
description: 文件夹名称
required: true
example: openid
schema:
type: string
- name: t
in: query
description: 接口的具体功能
required: true
example: wxapp
schema:
type: string
- name: code
in: query
description: ''
required: true
example: ''
schema:
type: string
- name: openid
in: query
description: 指定一个openid用来测试
required: true
example: oAHBN10P-hn-vF1cTY4tQeStQFmU
schema:
type: string
responses:
'200':
description: ''
content:
application/json:
schema:
type: object
properties:
code:
type: integer
description: 0=失败,1=成功
msg:
type: string
data:
type: object
properties:
user:
type: object
properties:
id:
type: integer
title: 用户ID
avatar_url:
type: string
title: 头像
name:
type: string
title: 姓名
x-apifox-orders:
- id
- name
- avatar_url
title: openid绑定的用户信息
required:
- id
- avatar_url
- name
x-apifox-orders:
- user
required:
- user
x-apifox-orders:
- code
- msg
- data
required:
- code
- msg
- data
headers: {}
x-apifox-name: 成功
x-apifox-ordering: 0
security: []
x-apifox-folder: 微信
x-apifox-status: released
x-run-in-apifox: https://app.apifox.com/web/project/7792797/apis/api-413906665-run
components:
schemas: {}
responses: {}
securitySchemes: {}
servers: []
security: []
```
......@@ -59,6 +59,193 @@ function toPascalCase(str) {
}
/**
* 简单的英文到中文翻译
* @param {string} text - 英文文本
* @returns {string} - 中文文本
*/
function translateToChinese(text) {
if (!text) return '';
// 常见技术术语翻译字典(优先级从高到低)
const dictionary = {
// 短语和完整句子
'mini program authorization': '小程序授权',
'login flow design': '登录流程设计',
// 短语
'mini program': '小程序',
'mini-program': '小程序',
'wechat': '微信',
'weixin': '微信',
'openid': 'OpenID',
// 动词和常用词
'authorize': '授权',
'authorization': '授权',
'login': '登录',
'logout': '登出',
'register': '注册',
'call': '调用',
'return': '返回',
'using': '使用',
'bound to': '绑定到',
'according to': '根据',
// 名词
'user': '用户',
'code': '授权码',
'token': '令牌',
'session': '会话',
'request': '请求',
'response': '响应',
'interface': '接口',
'api': '接口',
'account': '账号',
'openid': 'OpenID',
// 描述性词汇
'first': '首先',
'then': '然后',
'if': '如果',
'else': '否则',
'need': '需要',
'should': '应该',
'must': '必须',
// 状态
'success': '成功',
'fail': '失败',
'error': '错误',
'empty': '空',
'non-empty': '非空',
// 属性
'avatar': '头像',
'name': '姓名',
'id': 'ID',
'info': '信息',
'data': '数据',
'flow': '流程',
'design': '设计',
// 其他
'internal': '内部',
'automatically': '自动',
'specify': '指定',
'testing': '测试',
'used for': '用于',
'bound with': '绑定',
};
let translated = text;
// 按照字典进行替换(优先匹配长词)
const sortedKeys = Object.keys(dictionary).sort((a, b) => b.length - a.length);
sortedKeys.forEach(key => {
const regex = new RegExp(key, 'gi');
translated = translated.replace(regex, dictionary[key]);
});
return translated;
}
/**
* 格式化描述文本(翻译+格式化)
* @param {string} description - 原始描述
* @returns {string} - 格式化后的描述
*/
function formatDescription(description) {
if (!description) return '';
// 移除 markdown 格式符号(如 # 标题)
let formatted = description
.replace(/^#+\s*/gm, '') // 移除标题符号
.replace(/\*\*(.*?)\*\*/g, '$1') // 移除加粗
.replace(/\*(.*?)\*/g, '$1') // 移除斜体
.replace(/`([^`]+)`/g, '$1') // 移除行内代码
.trim();
// 先进行整句翻译(常见句式)
formatted = translateSentences(formatted);
return formatted;
}
/**
* 翻译常见句式
* @param {string} text - 文本
* @returns {string} - 翻译后的文本
*/
function translateSentences(text) {
if (!text) return '';
// 常见句式翻译(按优先级排序,长的先匹配)
const sentences = {
// 完整句子
'# 登录流程设计': '# 登录流程设计',
'# Login Flow Design': '# 登录流程设计',
// 常见句式
'Authorize mini program first': '先进行小程序授权',
'If user is empty, call login API': '如果返回 user 为空,则需要调用登录接口',
'If user is not empty, no need to call login API': '如果返回 user 非空,则不需要调用登录接口',
'the authorization API will automatically login using the account bound to openid': '授权接口内部按照 openid 绑定的账号,自动登录',
'Specify an openid for testing': '指定一个 openid 用来测试',
'User information bound to openid': 'openid 绑定的用户信息',
'0=fail, 1=success': '0=失败,1=成功',
};
let translated = text;
// 按长度排序(长句优先)
const sortedKeys = Object.keys(sentences).sort((a, b) => b.length - a.length);
sortedKeys.forEach(key => {
const regex = new RegExp(escapeRegExp(key), 'gi');
translated = translated.replace(regex, sentences[key]);
});
// 最后进行单词级别的补充翻译
translated = translateWords(translated);
return translated;
}
/**
* 转义正则表达式特殊字符
* @param {string} string - 字符串
* @returns {string} - 转义后的字符串
*/
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
/**
* 单词级别的翻译(补充)
* @param {string} text - 文本
* @returns {string} - 翻译后的文本
*/
function translateWords(text) {
const dictionary = {
'mini program': '小程序',
'wechat': '微信',
'openid': 'OpenID',
'user': '用户',
'authorization': '授权',
'login': '登录',
'avatar': '头像',
'name': '姓名',
};
let translated = text;
Object.entries(dictionary).forEach(([key, value]) => {
const regex = new RegExp(key, 'gi');
translated = translated.replace(regex, value);
});
return translated;
}
/**
* 解析对象属性,生成字段描述
* @param {object} properties - 属性对象
* @param {number} indent - 缩进级别
......@@ -147,8 +334,8 @@ function generateParamJSDoc(parameters, bodyParams, method) {
// POST 请求使用 body 参数
if (method === 'POST' && bodyParams && bodyParams.length > 0) {
// 过滤掉 a 和 f 参数
const filteredParams = bodyParams.filter(p => p.name !== 'a' && p.name !== 'f');
// 过滤掉 a、f 和 t 参数(这些参数已硬编码到 URL 中)
const filteredParams = bodyParams.filter(p => p.name !== 'a' && p.name !== 'f' && p.name !== 't');
filteredParams.forEach((param) => {
const type = param.type || 'any';
......@@ -159,8 +346,13 @@ function generateParamJSDoc(parameters, bodyParams, method) {
}
// GET 请求使用 query 参数
else if (method === 'GET' && parameters && parameters.length > 0) {
// 只保留 query 参数,过滤 header 参数
const queryParams = parameters.filter(p => p.in === 'query' && p.name !== 'a' && p.name !== 'f');
// 只保留 query 参数,过滤 header 参数和 a、f、t 参数
const queryParams = parameters.filter(p =>
p.in === 'query' &&
p.name !== 'a' &&
p.name !== 'f' &&
p.name !== 't'
);
queryParams.forEach((param) => {
const type = param.schema?.type || 'any';
......@@ -243,29 +435,38 @@ function parseOpenAPIDocument(openapiDoc, fileName) {
const parameters = apiInfo.parameters || [];
const queryParams = {};
let actionValue = '';
let typeValue = ''; // t 参数
// 提取 body 参数(用于 POST 请求)
const requestBody = apiInfo.requestBody;
const bodyParams = extractRequestParams(requestBody);
// 对于 POST 请求,从 requestBody 中提取 action
// 对于 POST 请求,从 requestBody 中提取 action 和 type
if (requestBody && bodyParams.length > 0) {
const actionParam = bodyParams.find(p => p.name === 'a');
if (actionParam) {
actionValue = actionParam.example || '';
}
const typeParam = bodyParams.find(p => p.name === 't');
if (typeParam) {
typeValue = typeParam.example || '';
}
}
// 对于 GET 请求,从 query 参数中提取 action
if (!actionValue && parameters.length > 0) {
// 对于 GET 请求,从 query 参数中提取 action 和 type
if (parameters.length > 0) {
parameters.forEach((param) => {
if (param.in === 'query') {
queryParams[param.name] = param.example || param.schema?.default || '';
// 提取 action 参数(通常是 'a' 参数)
if (param.name === 'a') {
if (param.name === 'a' && !actionValue) {
actionValue = param.example || '';
}
// 提取 type 参数('t' 参数)
if (param.name === 't' && !typeValue) {
typeValue = param.example || '';
}
}
});
}
......@@ -278,6 +479,7 @@ function parseOpenAPIDocument(openapiDoc, fileName) {
description: apiInfo.description || '',
method: method.toUpperCase(),
action: actionValue,
type: typeValue, // 保存 t 参数
queryParams,
parameters, // 保存完整的参数信息用于生成 JSDoc(GET 请求)
bodyParams, // 保存 requestBody 参数用于生成 JSDoc(POST 请求)
......@@ -307,9 +509,16 @@ function generateApiFileContent(moduleName, apis) {
// 生成函数名(驼峰命名 + API 后缀)
const functionName = toCamelCase(api.fileName) + 'API';
// 构建 URL,包含 a 和 t 参数
let url = '/srv/?';
const params = [];
if (api.action) params.push(`a=${api.action}`);
if (api.type) params.push(`t=${api.type}`);
url += params.join('&');
// 添加常量定义
apiConstants.push(
` ${constantName}: '/srv/?a=${api.action}',`
` ${constantName}: '${url}',`
);
// 生成详细的 JSDoc 注释
......@@ -318,8 +527,14 @@ function generateApiFileContent(moduleName, apis) {
// 添加函数定义
const fetchMethod = api.method === 'GET' ? 'fetch.get' : 'fetch.post';
// 格式化描述
const formattedDesc = formatDescription(api.description);
// 生成 JSDoc 注释(包含描述)
const comment = `/**
* @description: ${api.summary}
* @description ${api.summary}
* @remark ${formattedDesc}
${paramJSDoc}
${returnJSDoc}
*/`;
......
import { fn, fetch } from '@/api/fn';
const Api = {
List: '/srv/?a=feedback&t=list',
SubmitFeedback: '/srv/?a=feedback&t=add',
}
/**
* @description 意见反馈列表
* @remark
* @param {Object} params 请求参数
* @param {string} params.page 页码,从0开始
* @param {string} params.limit 每页数量
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
* list: Array<{
* id: integer; // 订单ID
* status: integer; // 3=待处理, 5=已处理
* category: string; // 1=功能建议, 3=界面设计, 5=车辆新鲜, 7=其他问题
* images: string; // 图片
* contact: string; // 联系方式
* note: string; // 反馈内容
* reply: string; // 回复
* reply_time: string; // 回复时间
* }>;
* };
* }>}
*/
export const listAPI = (params) => fn(fetch.get(Api.List, params));
/**
* @description 提交意见反馈
* @remark
* @param {Object} params 请求参数
* @param {string} params.category 反馈类别。1=功能建议, 3=界面设计, 5=车辆新鲜, 7=其他问题
* @param {string} params.note 反馈内容
* @param {string} params.contact 用户留下的联系方式
* @param {string} params.images 图片
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: any;
* }>}
*/
export const submitFeedbackAPI = (params) => fn(fetch.post(Api.SubmitFeedback, params));
import { fn, fetch } from '@/api/fn';
const Api = {
Detail: '/srv/?a=website_msg&t=detail',
MyList: '/srv/?a=website_msg&t=my_list',
}
/**
* @description 消息详情
* @remark
* @param {Object} params 请求参数
* @param {string} params.i 消息ID
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: any;
* }>}
*/
export const detailAPI = (params) => fn(fetch.get(Api.Detail, params));
/**
* @description 我的消息列表
* @remark
* @param {Object} params 请求参数
* @param {string} params.page
* @param {string} params.limit
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: any;
* }>}
*/
export const myListAPI = (params) => fn(fetch.get(Api.MyList, params));
import { fn, fetch } from '@/api/fn';
const Api = {
EditUserInfo: '/srv/?a=user_edit',
GetUserInfo: '/srv/?a=user_info',
GetProfile: '/srv/?a=user&t=get_profile',
Login: '/srv/?a=user&t=login',
Logout: '/srv/?a=user&t=logout',
UpdateProfile: '/srv/?a=user&t=update_profile',
}
/**
* @description: 修改我的信息
* @description 获取个人信息
* @remark
* @param {Object} params 请求参数
* @param {string} params.name (可选) 姓名
* @param {string} params.avatar (可选) 头像
* @param {string} params.mobile (可选) 手机号
* @param {string} params.sms_code (可选) 短信验证码
* @param {string} params.idcard (可选) 身份证
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
* user: {
* id: integer; // 用户ID
* avatar_url: string; // 头像
* name: string; // 姓名
* };
* };
* }>}
*/
export const getProfileAPI = (params) => fn(fetch.get(Api.GetProfile, params));
/**
* @description 登录并绑定openid
* @remark
* @param {Object} params 请求参数
* @param {string} params.uuid
* @param {string} params.password
* @param {string} params.openid (可选) 要绑定的小程序openid
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: any;
* }>}
*/
export const editUserInfoAPI = (params) => fn(fetch.post(Api.EditUserInfo, params));
export const loginAPI = (params) => fn(fetch.post(Api.Login, params));
/**
* @description: 查询我的信息
* @description 退出登录
* @remark
* @param {Object} params 请求参数
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
* user: {
* id: integer; // 用户ID
* name: string; // 姓名
* mobile: string; // 手机号
* };
* checkin: {
* total_days: integer; // 累计打卡天数
* consecutive_days: integer; // 连续打卡天
* longest_consecutive_days: integer; // 最长连续打卡天数
* };
* unread_msg_count: integer; // 未读的消息数量
* is_teacher: boolean; // 是不是老师
* };
* data: any;
* }>}
*/
export const logoutAPI = (params) => fn(fetch.post(Api.Logout, params));
/**
* @description 更新个人资料
* @remark
* @param {Object} params 请求参
* @param {string} params.avatar_url
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: any;
* }>}
*/
export const getUserInfoAPI = (params) => fn(fetch.get(Api.GetUserInfo, params));
export const updateProfileAPI = (params) => fn(fetch.post(Api.UpdateProfile, params));
......
import { fn, fetch } from '@/api/fn';
const Api = {
MiniProgramAuth: '/srv/?a=openid&t=wxapp',
}
/**
* @description 小程序授权
* @remark 登录流程设计
- 先小程序授权
- 如果返回 用户 为空,则需要调用登录接口
- 如果返回 用户 非空,则不需要调用登录接口,授权接口内部按照OpenID绑定的账号,自动登录
* @param {Object} params 请求参数
* @returns {Promise<{
* code: number; // 状态码
* msg: string; // 消息
* data: {
* user: {
* id: integer; // 用户ID
* avatar_url: string; // 头像
* name: string; // 姓名
* };
* };
* }>}
*/
export const miniProgramAuthAPI = (params) => fn(fetch.post(Api.MiniProgramAuth, params));
/*
* @Date: 2026-01-29 10:48:35
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-29 17:56:45
* @LastEditTime: 2026-02-02 15:28:09
* @FilePath: /manulife-weapp/src/utils/config.js
* @Description: 文件描述
*/
......@@ -24,10 +24,11 @@ const BASE_URL = process.env.NODE_ENV === 'production'
* 接口默认公共参数(避免在多个文件里硬编码)
* - f:业务模块标识(请修改为您的业务模块)
* - client_name:客户端标识(请修改为您的应用名称)
* - a: 文件夹名称
* - t :接口的具体功能
*/
export const REQUEST_DEFAULT_PARAMS = {
f: 'YOUR_MODULE', // 🔧 修改为业务模块标识
client_name: 'YOUR_APP', // 🔧 修改为应用名称
f: 'manulife', // 🔧 修改为业务模块标识
}
/**
......