后端搭建起来

This commit is contained in:
aixianling
2022-12-30 16:34:57 +08:00
parent b8ac23dcfd
commit d1f2a42f1c
3 changed files with 8 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ module.exports = () => async function errorHandler(ctx, next) {
? 'Internal Server Error' ? 'Internal Server Error'
: err.message; : err.message;
// 从 error 对象上读出各个属性,设置到响应中 // 从 error 对象上读出各个属性,设置到响应中
ctx.body = {error}; ctx.body = {code: 1, error};
if (status === 422) { if (status === 422) {
ctx.body.detail = err.errors; ctx.body.detail = err.errors;
} }

View File

@@ -24,10 +24,13 @@ class DbService extends Service {
} }
async list(table, params = {}) { async list(table, params = {}) {
let {current = 0} = params let {current = 0, size = 10} = params
delete params.size
delete params.current
delete params.total
const records = await this.app.mysql.select(table, { const records = await this.app.mysql.select(table, {
where: params, where: params,
limit: params?.size || 10, // 返回数据量 limit: size || 10, // 返回数据量
offset: Math.max(--current, 0), // 数据偏移量 offset: Math.max(--current, 0), // 数据偏移量
}) })
const total = (await this.app.mysql.select(table, {where: params}))?.length || 0 const total = (await this.app.mysql.select(table, {where: params}))?.length || 0

View File

@@ -22,7 +22,8 @@ module.exports = {
}, },
security: { security: {
csrf: { csrf: {
enable: false queryName: "token",
ignore: ctx => ctx.headers.passport == "c799f2d92de34b97"//md5编码:kubbo&flora
} }
} }
} }