feat: 添加微信端 API 文档和字典表初始化脚本
- 新增 openapi-wx.yaml 文件,定义微信端接口文档,包括用户统计、token 刷新、微信登录和用户资料更新等接口。 - 新增 pocketbase.dictionary.js 脚本,用于初始化和校验字典表结构,确保与预期一致。
This commit is contained in:
@@ -204,7 +204,7 @@
|
||||
|
||||
- `POST /pb/api/dictionary/list`
|
||||
- 支持按 `dict_name` 模糊搜索
|
||||
- 返回字典全量信息,并将 `dict_word_enum`、`dict_word_description`、`dict_word_sort_order` 组装为 `items`
|
||||
- 返回字典全量信息,并将 `dict_word_enum`、`dict_word_description`、`dict_word_image`、`dict_word_sort_order` 组装为 `items`
|
||||
- `POST /pb/api/dictionary/detail`
|
||||
- 按 `dict_name` 查询单条字典
|
||||
- `POST /pb/api/dictionary/create`
|
||||
@@ -216,8 +216,9 @@
|
||||
|
||||
说明:
|
||||
|
||||
- `dict_word_enum`、`dict_word_description`、`dict_word_sort_order` 已统一改为 JSON 字符串持久化,其中 `dict_word_sort_order` 已改为 `text` 类型。
|
||||
- 查询时统一聚合为:`items: [{ enum, description, sortOrder }]`
|
||||
- `dict_word_enum`、`dict_word_description`、`dict_word_image`、`dict_word_sort_order` 已统一改为 JSON 字符串持久化,其中 `dict_word_sort_order` 已改为 `text` 类型。
|
||||
- 字典项图片需先调用 `/pb/api/attachment/upload` 上传,再把返回的 `attachments_id` 写入 `dict_word_image` 对应位置。
|
||||
- 查询时统一聚合为:`items: [{ enum, description, image, imageUrl, imageAttachment, sortOrder }]`
|
||||
|
||||
### 附件管理接口
|
||||
|
||||
@@ -267,11 +268,16 @@
|
||||
- `document_id` 可不传,由服务端自动生成
|
||||
- `document_title`、`document_type` 为必填;其余字段均允许为空
|
||||
- `document_image`、`document_video` 支持传入多个已存在的 `attachments_id`
|
||||
- `document_type` 前端从单个字典来源中多选枚举值,最终按 `system_dict_id@dict_word_enum|...` 保存
|
||||
- `document_keywords`、`document_product_categories`、`document_application_scenarios`、`document_hotel_type` 统一从固定字典多选并按 `|` 保存
|
||||
- 其中 `document_product_categories` 改为从 `文档-产品关联文档` 读取,`document_application_scenarios` 改为从 `文档-筛选依据` 读取,`document_hotel_type` 改为从 `文档-适用场景` 读取
|
||||
- `document_status` 仅保留 `有效` / `过期` 两种状态,并由生效日期与到期日期自动计算
|
||||
- 成功后会写入一条文档操作历史,类型为 `create`
|
||||
- `POST /pb/api/document/update`
|
||||
- 按 `document_id` 更新文档
|
||||
- `document_title`、`document_type` 为必填;其余字段均允许为空
|
||||
- 若传入附件字段,则会校验多个 `attachments_id` 是否都存在
|
||||
- 多选字段的持久化格式与新增接口一致
|
||||
- 成功后会写入一条文档操作历史,类型为 `update`
|
||||
- `POST /pb/api/document/delete`
|
||||
- 按 `document_id` 真删除文档
|
||||
@@ -325,6 +331,8 @@
|
||||
- 指定字典查询
|
||||
- 行内编辑基础字段
|
||||
- 弹窗编辑枚举项
|
||||
- 为每个枚举项单独上传图片,并保存对应 `attachments_id`
|
||||
- 回显字典项图片缩略图与文件流链接
|
||||
- 新增 / 删除字典
|
||||
- 返回主页
|
||||
- 文档管理页支持:
|
||||
|
||||
1408
pocket-base/spec/openapi-manage.yaml
Normal file
1408
pocket-base/spec/openapi-manage.yaml
Normal file
File diff suppressed because it is too large
Load Diff
419
pocket-base/spec/openapi-wx.yaml
Normal file
419
pocket-base/spec/openapi-wx.yaml
Normal file
@@ -0,0 +1,419 @@
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
title: BAI PocketBase WeChat API
|
||||
version: 1.0.0-wx
|
||||
description: |
|
||||
面向微信端的小程序接口文档。
|
||||
本文档只包含微信登录、微信资料完善,以及微信端会共用的系统接口。
|
||||
license:
|
||||
name: Proprietary
|
||||
identifier: LicenseRef-Proprietary
|
||||
servers:
|
||||
- url: https://bai-api.blv-oa.com
|
||||
description: 生产环境
|
||||
- url: http://localhost:8090
|
||||
description: PocketBase 本地环境
|
||||
tags:
|
||||
- name: 系统
|
||||
description: 微信端共用系统接口
|
||||
- name: 微信认证
|
||||
description: 微信登录、资料完善与 token 刷新接口
|
||||
paths:
|
||||
/pb/api/system/users-count:
|
||||
post:
|
||||
operationId: postSystemUsersCount
|
||||
security: []
|
||||
tags:
|
||||
- 系统
|
||||
summary: 查询用户总数
|
||||
description: 统计 `tbl_auth_users` 集合中的记录总数。
|
||||
responses:
|
||||
'200':
|
||||
description: 查询成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UsersCountResponse'
|
||||
'400':
|
||||
description: 请求参数错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'500':
|
||||
description: 服务端错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
/pb/api/system/refresh-token:
|
||||
post:
|
||||
operationId: postSystemRefreshToken
|
||||
security:
|
||||
- bearerAuth: []
|
||||
- {}
|
||||
tags:
|
||||
- 系统
|
||||
summary: 刷新认证 token
|
||||
description: |
|
||||
当当前 `Authorization` 仍有效时,直接基于当前 auth 用户续签。
|
||||
当 token 失效时,可传入 `users_wx_code` 走微信 code 重新签发。
|
||||
requestBody:
|
||||
required: false
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/SystemRefreshTokenRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: 刷新成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/RefreshTokenResponse'
|
||||
'400':
|
||||
description: 参数错误或微信 code 换取失败
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'401':
|
||||
description: token 无效,且未提供有效的 `users_wx_code`
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'404':
|
||||
description: 当前用户不存在
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'415':
|
||||
description: 请求体不是 JSON
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'429':
|
||||
description: 请求过于频繁
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'500':
|
||||
description: 服务端错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
/pb/api/wechat/login:
|
||||
post:
|
||||
operationId: postWechatLogin
|
||||
security: []
|
||||
tags:
|
||||
- 微信认证
|
||||
summary: 微信登录或首次注册
|
||||
description: |
|
||||
使用微信 `users_wx_code` 换取微信 openid。
|
||||
若 `tbl_auth_users` 中不存在对应用户,则自动创建新 auth 用户并返回 token。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/WechatLoginRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: 登录或注册成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/AuthSuccessResponse'
|
||||
'400':
|
||||
description: 参数错误或保存用户失败
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'401':
|
||||
description: 认证失败
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'415':
|
||||
description: 请求体不是 JSON
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'429':
|
||||
description: 请求过于频繁
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'500':
|
||||
description: 服务端错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
/pb/api/wechat/profile:
|
||||
post:
|
||||
operationId: postWechatProfile
|
||||
security:
|
||||
- bearerAuth: []
|
||||
tags:
|
||||
- 微信认证
|
||||
summary: 更新微信用户资料
|
||||
description: |
|
||||
基于当前 `Authorization` 对应的 auth 用户更新昵称、手机号和头像。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/WechatProfileRequest'
|
||||
responses:
|
||||
'200':
|
||||
description: 更新成功
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/WechatProfileResponse'
|
||||
'400':
|
||||
description: 参数错误、手机号已被占用或资料更新失败
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'401':
|
||||
description: token 无效或缺少 openid
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'415':
|
||||
description: 请求体不是 JSON
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'429':
|
||||
description: 请求过于频繁
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
'500':
|
||||
description: 服务端错误
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ErrorResponse'
|
||||
components:
|
||||
securitySchemes:
|
||||
bearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
bearerFormat: JWT
|
||||
schemas:
|
||||
ApiResponseBase:
|
||||
type: object
|
||||
required:
|
||||
- code
|
||||
- msg
|
||||
- data
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
example: 200
|
||||
msg:
|
||||
type: string
|
||||
example: 操作成功
|
||||
data:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
ErrorResponse:
|
||||
type: object
|
||||
required:
|
||||
- code
|
||||
- msg
|
||||
- data
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
example: 400
|
||||
msg:
|
||||
type: string
|
||||
example: 请求失败
|
||||
data:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
CompanyInfo:
|
||||
anyOf:
|
||||
- type: object
|
||||
additionalProperties: true
|
||||
- type: 'null'
|
||||
UserInfo:
|
||||
type: object
|
||||
properties:
|
||||
pb_id:
|
||||
type: string
|
||||
users_convers_id:
|
||||
type: string
|
||||
users_id:
|
||||
type: string
|
||||
users_idtype:
|
||||
type: string
|
||||
enum:
|
||||
- WeChat
|
||||
- ManagePlatform
|
||||
users_id_number:
|
||||
type: string
|
||||
users_type:
|
||||
type: string
|
||||
users_name:
|
||||
type: string
|
||||
users_status:
|
||||
type:
|
||||
- string
|
||||
- number
|
||||
users_rank_level:
|
||||
type:
|
||||
- number
|
||||
- integer
|
||||
users_auth_type:
|
||||
type:
|
||||
- number
|
||||
- integer
|
||||
users_phone:
|
||||
type: string
|
||||
users_phone_masked:
|
||||
type: string
|
||||
users_level:
|
||||
type: string
|
||||
users_picture:
|
||||
type: string
|
||||
openid:
|
||||
type: string
|
||||
description: 全平台统一身份标识
|
||||
company_id:
|
||||
type: string
|
||||
users_parent_id:
|
||||
type: string
|
||||
users_promo_code:
|
||||
type: string
|
||||
usergroups_id:
|
||||
type: string
|
||||
company:
|
||||
$ref: '#/components/schemas/CompanyInfo'
|
||||
created:
|
||||
type: string
|
||||
updated:
|
||||
type: string
|
||||
WechatLoginRequest:
|
||||
type: object
|
||||
required:
|
||||
- users_wx_code
|
||||
properties:
|
||||
users_wx_code:
|
||||
type: string
|
||||
description: 微信小程序登录临时凭证 code
|
||||
example: 0a1b2c3d4e5f6g
|
||||
WechatProfileRequest:
|
||||
type: object
|
||||
required:
|
||||
- users_name
|
||||
- users_phone_code
|
||||
- users_picture
|
||||
properties:
|
||||
users_name:
|
||||
type: string
|
||||
example: 张三
|
||||
users_phone_code:
|
||||
type: string
|
||||
example: 2b7d9f2e3c4a5b6d7e8f
|
||||
users_picture:
|
||||
type: string
|
||||
example: https://example.com/avatar.png
|
||||
SystemRefreshTokenRequest:
|
||||
type: object
|
||||
properties:
|
||||
users_wx_code:
|
||||
type:
|
||||
- string
|
||||
- 'null'
|
||||
description: |
|
||||
可选。
|
||||
当前 token 失效时,可通过该 code 重新签发 token。
|
||||
example: 0a1b2c3d4e5f6g
|
||||
AuthSuccessData:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
enum:
|
||||
- register_success
|
||||
- login_success
|
||||
is_info_complete:
|
||||
type: boolean
|
||||
user:
|
||||
$ref: '#/components/schemas/UserInfo'
|
||||
AuthSuccessResponse:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/ApiResponseBase'
|
||||
- type: object
|
||||
required:
|
||||
- token
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/components/schemas/AuthSuccessData'
|
||||
token:
|
||||
type: string
|
||||
description: PocketBase 原生 auth token
|
||||
WechatProfileResponseData:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
enum:
|
||||
- update_success
|
||||
user:
|
||||
$ref: '#/components/schemas/UserInfo'
|
||||
WechatProfileResponse:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/ApiResponseBase'
|
||||
- type: object
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/components/schemas/WechatProfileResponseData'
|
||||
RefreshTokenResponse:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/ApiResponseBase'
|
||||
- type: object
|
||||
required:
|
||||
- token
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
example: {}
|
||||
token:
|
||||
type: string
|
||||
description: 新签发的 PocketBase 原生 auth token
|
||||
UsersCountData:
|
||||
type: object
|
||||
properties:
|
||||
total_users:
|
||||
type: integer
|
||||
example: 128
|
||||
UsersCountResponse:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/ApiResponseBase'
|
||||
- type: object
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/components/schemas/UsersCountData'
|
||||
@@ -292,6 +292,17 @@ components:
|
||||
description:
|
||||
type: string
|
||||
example: 启用
|
||||
image:
|
||||
type: string
|
||||
description: 对应图片附件的 `attachments_id`,允许为空
|
||||
example: ATT-1743037200000-abc123
|
||||
imageUrl:
|
||||
type: string
|
||||
description: 根据 `image -> tbl_attachments` 自动解析出的图片文件流链接
|
||||
imageAttachment:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/AttachmentRecord'
|
||||
nullable: true
|
||||
sortOrder:
|
||||
type: integer
|
||||
example: 1
|
||||
@@ -355,6 +366,7 @@ components:
|
||||
items:
|
||||
type: array
|
||||
minItems: 1
|
||||
description: 每项会分别序列化写入 `dict_word_enum`、`dict_word_description`、`dict_word_image`、`dict_word_sort_order`
|
||||
items:
|
||||
$ref: '#/components/schemas/DictionaryItem'
|
||||
DictionaryDeleteRequest:
|
||||
@@ -457,6 +469,7 @@ components:
|
||||
type: string
|
||||
document_type:
|
||||
type: string
|
||||
description: 多选时按 `system_dict_id@dict_word_enum|...` 保存
|
||||
document_title:
|
||||
type: string
|
||||
document_subtitle:
|
||||
@@ -520,7 +533,7 @@ components:
|
||||
type: string
|
||||
document_keywords:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 固定字典多选字段,使用 `|` 分隔
|
||||
document_share_count:
|
||||
type: number
|
||||
document_download_count:
|
||||
@@ -529,6 +542,7 @@ components:
|
||||
type: number
|
||||
document_status:
|
||||
type: string
|
||||
description: 文档状态,仅允许 `有效` 或 `过期`,由系统根据生效日期和到期日期自动计算;当两者都为空时默认 `有效`
|
||||
document_embedding_status:
|
||||
type: string
|
||||
document_embedding_error:
|
||||
@@ -539,13 +553,13 @@ components:
|
||||
type: string
|
||||
document_product_categories:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 固定字典多选字段,使用 `|` 分隔
|
||||
document_application_scenarios:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 固定字典多选字段,使用 `|` 分隔
|
||||
document_hotel_type:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 固定字典多选字段,使用 `|` 分隔
|
||||
document_remark:
|
||||
type: string
|
||||
created:
|
||||
@@ -564,6 +578,7 @@ components:
|
||||
example: active
|
||||
document_type:
|
||||
type: string
|
||||
description: 支持按存储值过滤;多选时格式为 `system_dict_id@dict_word_enum|...`
|
||||
example: 说明书
|
||||
DocumentDetailRequest:
|
||||
type: object
|
||||
@@ -590,6 +605,7 @@ components:
|
||||
example: 2027-03-27
|
||||
document_type:
|
||||
type: string
|
||||
description: 必填;前端显示为字典项描述,存库时按 `system_dict_id@dict_word_enum|...` 保存
|
||||
document_title:
|
||||
type: string
|
||||
document_subtitle:
|
||||
@@ -618,7 +634,7 @@ components:
|
||||
type: string
|
||||
document_keywords:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 从 `文档-关键词` 字典多选后使用 `|` 分隔保存
|
||||
document_share_count:
|
||||
type: number
|
||||
document_download_count:
|
||||
@@ -627,6 +643,7 @@ components:
|
||||
type: number
|
||||
document_status:
|
||||
type: string
|
||||
description: 文档状态,仅允许 `有效` 或 `过期`,由系统根据生效日期和到期日期自动计算;当两者都为空时默认 `有效`
|
||||
document_embedding_status:
|
||||
type: string
|
||||
document_embedding_error:
|
||||
@@ -637,13 +654,13 @@ components:
|
||||
type: string
|
||||
document_product_categories:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 从 `文档-产品关联文档` 字典多选后使用 `|` 分隔保存
|
||||
document_application_scenarios:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 从 `文档-筛选依据` 字典多选后使用 `|` 分隔保存
|
||||
document_hotel_type:
|
||||
type: string
|
||||
description: 多值字段,使用 `|` 分隔
|
||||
description: 从 `文档-适用场景` 字典多选后使用 `|` 分隔保存
|
||||
document_remark:
|
||||
type: string
|
||||
DocumentDeleteRequest:
|
||||
@@ -1005,7 +1022,7 @@ paths:
|
||||
description: |
|
||||
仅允许 `ManagePlatform` 用户访问。
|
||||
`system_dict_id` 由服务端自动生成;`dict_name` 必须唯一;
|
||||
`items` 会分别序列化写入 `dict_word_enum`、`dict_word_description`、`dict_word_sort_order` 三个字段。
|
||||
`items` 会分别序列化写入 `dict_word_enum`、`dict_word_description`、`dict_word_image`、`dict_word_sort_order` 四个字段。
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
|
||||
Reference in New Issue
Block a user