yuheng/src/schema/module.schema.js
2025-05-06 10:28:07 +08:00

238 lines
9.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { page, pageSize, sortOrder, module, sortBy, description, sort } from "#schema/atomSchema";
import errorAtomSchema from "#schema/error.atomSchema";
// 系统模块分页查询
export const moduleListSchema = {
tags: ['系统管理'],
summary: '获取系统模块列表',
description: '支持分页和条件查询系统模块数据',
querystring: {
type: 'object',
properties: {
page: {
...page, // 保持原有校验规则
description: '页码从1开始不传则返回全量'
},
pageSize: {
...pageSize,
description: '每页条数(不传则返回全量)'
},
name: {
type: 'string',
nullable: true,
maxLength: 32,
description: '模块名称模糊查询',
errorMessage: {
maxLength: '模块名称不能超过32个字符'
}
},
moduleKey: {
type: 'string',
nullable: true,
maxLength: 255,
description: '模块Key精确查询',
errorMessage: {
maxLength: '模块Key不能超过255个字符'
}
},
status: {
type: 'integer',
nullable: true,
enum: [0, 1],
default: 0,
description: '状态过滤0-正常 1-禁用)',
errorMessage: {
type: '状态参数必须是整数',
enum: '状态值只能是0或1'
}
},
sortBy,
sortOrder,
}
},
response: {
200: {
type: 'object',
properties: {
code: { type: 'number', enum: [200] },
data: {
type: 'object',
properties: {
total: {
type: 'integer',
examples: [150],
description: '总记录数(仅分页模式返回)'
},
list: {
type: 'array',
items: {
type: 'object',
properties: {
id: { type: 'integer', examples: [1] },
version: { type: 'integer', examples: [0] },
name: { type: 'string', examples: ['用户管理模块'] },
moduleKey: { type: 'string', examples: ['user_management'] },
description: { type: ['string', 'null'], examples: ['用户权限管理模块'] },
sort: { type: 'integer', examples: [10] },
status: { type: 'integer', enum: [0, 1] },
createdUser: { type: 'string', examples: [1001] },
updatedUser: { type: 'string', examples: [1001] },
createdBy: { type: 'string', examples: [1001] },
updatedBy: { type: ['string', 'null'], examples: [1002] },
createdAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-15T08:23:45.000Z']
},
updatedAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-16T09:34:12.000Z']
}
},
required: ['id', 'name', 'moduleKey', 'description']
}
}
},
required: ['list']
},
message: { type: 'string' }
}
},
400: errorAtomSchema['400'],
},
security: [{ apiKey: [] }]
};
// 系统模块创建
export const moduleCreateSchema = {
tags: ['系统管理'],
summary: '创建系统模块',
description: '创建新的系统功能模块',
body: {
type: 'object',
required: ['name', 'moduleKey'],
properties: {
name: module.name,
moduleKey: module.moduleKey,
description,
sort,
status: module.status
}
},
response: {
201: {
type: 'object',
properties: {
code: { type: 'number', enum: [201] },
data: {
type: 'object',
properties: {
id: { type: 'integer', examples: [1] },
version: { type: 'integer', examples: [0] },
name: { type: 'string', examples: ['用户管理模块'] },
moduleKey: { type: 'string', examples: ['user_management'] },
description: { type: ['string', 'null'], examples: ['用户权限管理模块'] },
sort: { type: 'integer', examples: [10] },
status: { type: 'integer', enum: [0, 1] },
createdBy: { type: 'string', examples: [1001] },
updatedBy: { type: ['string', 'null'], examples: [1002] },
createdAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-15T08:23:45.000Z']
},
updatedAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-16T09:34:12.000Z']
}
}
}
}
},
400: errorAtomSchema['400'],
409: errorAtomSchema['409']
},
security: [{ apiKey: [] }]
};
// 系统模块修改 schema
export const moduleUpdateSchema = {
tags: ['系统管理'],
summary: '修改系统模块',
description: '修改系统模块信息(支持部分字段更新)',
body: {
type: 'object',
properties: {
name: {
...module.name,
nullable: true // 允许传空值
},
moduleKey: {
...module.moduleKey,
nullable: true
},
description: {
...description,
nullable: true
},
sort: {
...sort,
default: null, // 允许传空值
nullable: true
},
status: {
...module.status,
default: null, // 允许传空值
nullable: true
}
},
anyOf: [ // 至少更新一个字段
{ required: ['name'] },
{ required: ['moduleKey'] },
{ required: ['description'] },
{ required: ['sort'] },
{ required: ['status'] }
]
},
response: {
200: {
type: 'object',
properties: {
code: { type: 'number', enum: [200] },
data: {
type: 'object',
properties: {
id: { type: 'integer', examples: [1] },
version: { type: 'integer', examples: [0] },
name: { type: 'string', examples: ['用户管理模块'] },
moduleKey: { type: 'string', examples: ['user_management'] },
description: { type: ['string', 'null'], examples: ['用户权限管理模块'] },
sort: { type: 'integer', examples: [10] },
status: { type: 'integer', enum: [0, 1] },
createdUser: { type: 'string', examples: [1001] },
updatedUser: { type: 'string', examples: [1001] },
createdBy: { type: 'string', examples: [1001] },
updatedBy: { type: ['string', 'null'], examples: [1002] },
createdAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-15T08:23:45.000Z']
},
updatedAt: {
type: 'string',
format: 'date-time',
examples: ['2023-07-16T09:34:12.000Z']
}
},
},
message: { type:'string' }
}
},
400: errorAtomSchema['400'],
404: errorAtomSchema['404'],
409: errorAtomSchema['409']
},
security: [{ apiKey: [] }]
};