befly-tpl 3.9.2 → 3.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/apis/article/articleDel.ts +0 -33
- package/apis/article/articleDetail.ts +0 -26
- package/apis/article/articleIns.ts +0 -47
- package/apis/article/articleList.ts +0 -45
- package/apis/article/articleUpd.ts +0 -55
- package/apis/article/increment.ts +0 -37
- package/apis/user/login.ts +0 -54
- package/apis/user/userList.ts +0 -38
- package/tables/article.json +0 -11
- package/tables/user.json +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-tpl",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.4",
|
|
4
4
|
"description": "Befly 3.0 TypeScript Template",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
],
|
|
32
32
|
"type": "module",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@befly-addon/admin": "1.0.
|
|
35
|
-
"befly": "3.8.
|
|
34
|
+
"@befly-addon/admin": "1.0.11",
|
|
35
|
+
"befly": "3.8.3"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"bun": ">=1.3.0"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "51d86162e5f0b94ecc44a833a98ebf97c27f7bd6"
|
|
41
41
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 删除文章接口(软删除)
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes, No } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '删除文章',
|
|
9
|
-
auth: false,
|
|
10
|
-
fields: {
|
|
11
|
-
// id 会自动从默认字段合并
|
|
12
|
-
},
|
|
13
|
-
required: ['id'],
|
|
14
|
-
handler: async (befly, ctx) => {
|
|
15
|
-
// 检查文章是否存在
|
|
16
|
-
const article = await befly.db.getOne({
|
|
17
|
-
table: 'article',
|
|
18
|
-
where: { id: ctx.body.id }
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (!article) {
|
|
22
|
-
return No('文章不存在');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 软删除
|
|
26
|
-
const result = await befly.db.delData({
|
|
27
|
-
table: 'article',
|
|
28
|
-
where: { id: ctx.body.id }
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return Yes('删除成功', { affected: result });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取文章详情接口
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes, No } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '获取文章详情',
|
|
9
|
-
auth: false,
|
|
10
|
-
fields: {
|
|
11
|
-
// id 会自动从默认字段合并
|
|
12
|
-
},
|
|
13
|
-
required: ['id'],
|
|
14
|
-
handler: async (befly, ctx) => {
|
|
15
|
-
const article = await befly.db.getOne({
|
|
16
|
-
table: 'article',
|
|
17
|
-
where: { id: ctx.body.id }
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
if (!article) {
|
|
21
|
-
return No('文章不存在');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return Yes('获取成功', article);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建文章接口 - TypeScript 示例
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes } from 'befly';
|
|
6
|
-
|
|
7
|
-
import articleTable from '../../tables/article.json';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
name: '创建文章',
|
|
11
|
-
auth: false,
|
|
12
|
-
fields: {
|
|
13
|
-
title: articleTable.title,
|
|
14
|
-
content: articleTable.content,
|
|
15
|
-
summary: articleTable.summary,
|
|
16
|
-
coverImage: articleTable.coverImage,
|
|
17
|
-
author: articleTable.author,
|
|
18
|
-
category: articleTable.category,
|
|
19
|
-
tags: articleTable.tags,
|
|
20
|
-
viewCount: articleTable.viewCount,
|
|
21
|
-
status: articleTable.status
|
|
22
|
-
},
|
|
23
|
-
required: ['title', 'content'],
|
|
24
|
-
handler: async (befly, ctx) => {
|
|
25
|
-
const userId = ctx.jwt?.userId || '1'; // 临时使用固定ID测试
|
|
26
|
-
|
|
27
|
-
// 插入文章
|
|
28
|
-
const articleId = await befly.db.insData({
|
|
29
|
-
table: 'article',
|
|
30
|
-
data: {
|
|
31
|
-
title: ctx.body.title,
|
|
32
|
-
content: ctx.body.content,
|
|
33
|
-
summary: ctx.body.summary,
|
|
34
|
-
coverImage: ctx.body.coverImage,
|
|
35
|
-
author: ctx.body.author,
|
|
36
|
-
category: ctx.body.category,
|
|
37
|
-
tags: ctx.body.tags,
|
|
38
|
-
viewCount: ctx.body.viewCount || 0,
|
|
39
|
-
status: ctx.body.status,
|
|
40
|
-
authorId: parseInt(userId),
|
|
41
|
-
published: 0
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return Yes('创建成功', { articleId });
|
|
46
|
-
}
|
|
47
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取文章列表接口 - TypeScript 示例
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '获取文章列表',
|
|
9
|
-
auth: false,
|
|
10
|
-
fields: {
|
|
11
|
-
// page, limit, keyword 会自动从默认字段合并
|
|
12
|
-
categoryId: '分类ID|number|0|999999|null|0|null',
|
|
13
|
-
authorId: '作者ID|number|0|999999|null|0|null',
|
|
14
|
-
published: '是否发布|number|0|1|null|0|^(0|1)'
|
|
15
|
-
},
|
|
16
|
-
handler: async (befly, ctx) => {
|
|
17
|
-
// 构建查询条件
|
|
18
|
-
let where = params.where || {};
|
|
19
|
-
|
|
20
|
-
// 兼容旧的查询参数
|
|
21
|
-
if (params.categoryId) {
|
|
22
|
-
where.categoryId = params.categoryId;
|
|
23
|
-
}
|
|
24
|
-
if (params.authorId) {
|
|
25
|
-
where.authorId = params.authorId;
|
|
26
|
-
}
|
|
27
|
-
if (params.keyword) {
|
|
28
|
-
where.title = { $like: `%${params.keyword}%` };
|
|
29
|
-
}
|
|
30
|
-
if (typeof params.published !== 'undefined') {
|
|
31
|
-
where.published = params.published;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 查询文章列表
|
|
35
|
-
const result = await befly.db.getList({
|
|
36
|
-
table: 'article',
|
|
37
|
-
where,
|
|
38
|
-
page: params.page || 1,
|
|
39
|
-
limit: params.limit || 10,
|
|
40
|
-
orderBy: params.orderBy || ['createdAt#DESC']
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
return Yes('查询成功', result);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 更新文章接口
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes, No } from 'befly';
|
|
6
|
-
|
|
7
|
-
import articleTable from '../../tables/article.json';
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
name: '更新文章',
|
|
11
|
-
auth: false,
|
|
12
|
-
fields: {
|
|
13
|
-
// id 会自动从默认字段合并
|
|
14
|
-
title: articleTable.title,
|
|
15
|
-
content: articleTable.content,
|
|
16
|
-
summary: articleTable.summary,
|
|
17
|
-
coverImage: articleTable.coverImage,
|
|
18
|
-
author: articleTable.author,
|
|
19
|
-
category: articleTable.category,
|
|
20
|
-
tags: articleTable.tags,
|
|
21
|
-
viewCount: articleTable.viewCount,
|
|
22
|
-
status: articleTable.status
|
|
23
|
-
},
|
|
24
|
-
required: ['id'],
|
|
25
|
-
handler: async (befly, ctx) => {
|
|
26
|
-
// 检查文章是否存在
|
|
27
|
-
const article = await befly.db.getOne({
|
|
28
|
-
table: 'article',
|
|
29
|
-
where: { id: ctx.body.id }
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
if (!article) {
|
|
33
|
-
return No('文章不存在');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 更新文章
|
|
37
|
-
const result = await befly.db.updData({
|
|
38
|
-
table: 'article',
|
|
39
|
-
where: { id: ctx.body.id },
|
|
40
|
-
data: {
|
|
41
|
-
title: ctx.body.title,
|
|
42
|
-
content: ctx.body.content,
|
|
43
|
-
summary: ctx.body.summary,
|
|
44
|
-
coverImage: ctx.body.coverImage,
|
|
45
|
-
author: ctx.body.author,
|
|
46
|
-
category: ctx.body.category,
|
|
47
|
-
tags: ctx.body.tags,
|
|
48
|
-
viewCount: ctx.body.viewCount,
|
|
49
|
-
status: ctx.body.status
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return Yes('更新成功', { affected: result });
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 文章字段增量接口
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes, No } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '文章字段增量',
|
|
9
|
-
auth: false,
|
|
10
|
-
fields: {
|
|
11
|
-
// id 会自动从默认字段合并
|
|
12
|
-
field: '字段名|string|1|50|null|1|^[a-zA-Z_][a-zA-Z0-9_]*$',
|
|
13
|
-
value: '自增值|number|-999999|999999|1|0|null'
|
|
14
|
-
},
|
|
15
|
-
required: ['id', 'field'],
|
|
16
|
-
handler: async (befly, ctx) => {
|
|
17
|
-
// 检查文章是否存在
|
|
18
|
-
const article = await befly.db.getOne({
|
|
19
|
-
table: 'article',
|
|
20
|
-
where: { id: ctx.body.id }
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (!article) {
|
|
24
|
-
return No('文章不存在');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// 执行自增
|
|
28
|
-
const result = await befly.db.increment({
|
|
29
|
-
table: 'article',
|
|
30
|
-
where: { id: ctx.body.id },
|
|
31
|
-
field: ctx.body.field,
|
|
32
|
-
value: ctx.body.value || 1
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return Yes('自增成功', { affected: result });
|
|
36
|
-
}
|
|
37
|
-
};
|
package/apis/user/login.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 用户登录接口 - TypeScript 示例
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes, No, Cipher, Jwt } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '用户登录',
|
|
9
|
-
auth: false, // 公开接口
|
|
10
|
-
fields: {
|
|
11
|
-
username: '用户名|string|3|50|null|0|^[a-zA-Z0-9_]+$',
|
|
12
|
-
password: '密码|string|6|500|null|0|null'
|
|
13
|
-
},
|
|
14
|
-
required: ['username', 'password'],
|
|
15
|
-
handler: async (befly, ctx) => {
|
|
16
|
-
// 查询用户
|
|
17
|
-
const user = await befly.db.getOne({
|
|
18
|
-
table: 'user',
|
|
19
|
-
where: { username: ctx.body.username }
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
if (!user) {
|
|
23
|
-
return No('用户名或密码错误');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 验证密码
|
|
27
|
-
const isValid = await Cipher.verifyPassword(ctx.body.password, user.password);
|
|
28
|
-
if (!isValid) {
|
|
29
|
-
return No('用户名或密码错误');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 生成 JWT Token
|
|
33
|
-
const token = await Jwt.sign(
|
|
34
|
-
{
|
|
35
|
-
userId: user.id.toString(),
|
|
36
|
-
username: user.username,
|
|
37
|
-
role: user.role
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
expiresIn: '7d'
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// 返回用户信息(不包含密码)
|
|
45
|
-
const { password: _, ...userWithoutPassword } = user;
|
|
46
|
-
|
|
47
|
-
const response = {
|
|
48
|
-
token,
|
|
49
|
-
user: userWithoutPassword
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return Yes('登录成功', response);
|
|
53
|
-
}
|
|
54
|
-
};
|
package/apis/user/userList.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取用户列表接口 - TypeScript 示例
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Yes } from 'befly';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
name: '获取用户列表',
|
|
9
|
-
auth: true, // 需要登录(权限由角色接口列表控制)
|
|
10
|
-
fields: {
|
|
11
|
-
// page, limit, keyword 会自动从默认字段合并
|
|
12
|
-
role: '角色|string|0|20|null|0|^(admin|user|guest)$'
|
|
13
|
-
},
|
|
14
|
-
handler: async (befly, ctx) => {
|
|
15
|
-
const params = ctx.body as GetUsersRequest;
|
|
16
|
-
|
|
17
|
-
// 构建查询条件
|
|
18
|
-
const where = {};
|
|
19
|
-
if (params.role) {
|
|
20
|
-
where.role = params.role;
|
|
21
|
-
}
|
|
22
|
-
if (params.keyword) {
|
|
23
|
-
where.username = { $like: `%${params.keyword}%` };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 查询用户列表(不返回密码字段)
|
|
27
|
-
const result = await befly.db.getList({
|
|
28
|
-
table: 'user',
|
|
29
|
-
fields: ['id', 'username', 'email', 'role', 'avatar', 'nickname', 'createdAt', 'updatedAt'],
|
|
30
|
-
where,
|
|
31
|
-
page: params.page || 1,
|
|
32
|
-
limit: params.limit || 10,
|
|
33
|
-
orderBy: ['createdAt#DESC']
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return Yes('查询成功', result);
|
|
37
|
-
}
|
|
38
|
-
};
|
package/tables/article.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "标题|string|1|200|null|1|null",
|
|
3
|
-
"content": "内容|text|null|null|null|0|null",
|
|
4
|
-
"summary": "摘要|string|0|500|null|0|null",
|
|
5
|
-
"coverImage": "封面图|string|0|500|null|0|null",
|
|
6
|
-
"author": "作者|string|1|50|佚名|0|null",
|
|
7
|
-
"category": "分类|string|1|50|默认|1|null",
|
|
8
|
-
"tags": "标签|array_string|0|10|null|0|null",
|
|
9
|
-
"viewCount": "浏览量|number|0|999999999|0|0|null",
|
|
10
|
-
"status": "状态|string|1|20|draft|1|^(draft|published|archived)$"
|
|
11
|
-
}
|
package/tables/user.json
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"username": "用户名|string|3|50|null|1|^[a-zA-Z0-9_]+$",
|
|
3
|
-
"password": "密码|string|6|500|null|0|null",
|
|
4
|
-
"email": "邮箱|string|5|100|null|1|^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",
|
|
5
|
-
"role": "角色|string|1|20|user|1|^(admin|user|guest)$",
|
|
6
|
-
"nickname": "昵称|string|0|50|null|0|null",
|
|
7
|
-
"avatar": "头像|string|0|500|null|0|null"
|
|
8
|
-
}
|