@k3000/s1 0.3.5 → 0.3.7

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/README.md CHANGED
@@ -1,21 +1,67 @@
1
1
  以UDP微服务的形式构建的平台
2
2
 
3
- 1、全局安装 npm i -g @k3000/s1
3
+ #### 1、安装
4
+ 首选全局安装脚本,注意是否有占用全局命令:```bot```
4
5
 
5
- 2、项目预览需要启动的服务:
6
+ ```
7
+ > npm i -g @k3000/s1
8
+ > mkdir mydir
9
+ > cd mydir
10
+ > bot init
11
+ > bot init 1 # 覆盖已有文件
12
+ ```
13
+ #### 2、目录说明
6
14
 
7
- npm run admin #管理后台服务
15
+ _admin、app、file_ 为实例项目,自行根据需求增减。
8
16
 
9
- npm run jwt #用户身份校验
17
+ _bin_ 为构建目录,不要占用。
10
18
 
11
- npm run store1 #存储服务
19
+ _common_ 存放公共模块详见内部 _README.md_,请别随意删除。
12
20
 
13
- npm run proxy #转发服务
21
+ _store1_ 为存储服务详见内部 _README.md_,。
14
22
 
15
- 3、发布 npm run build,打包后存入bin文件夹
23
+ _jwt_ 为用户身份校验服务。
16
24
 
17
- 4、部署 node pm2.mjs
25
+ _proxy_ 为http转发服务。
26
+
27
+ _static_ 为静态资源目录。
28
+
29
+ _ui-dev_ 为管理系统前端项目,构建后放进 _static_ 目录。
30
+
31
+ _“谨慎打开”_ 为要饭文件夹。
32
+
33
+ #### 3、项目预览
34
+ 需要启动的服务:
35
+
36
+ ```
37
+ npm run admin # 管理后台服务
38
+ npm run jwt # 用户身份校验(必要)
39
+ npm run store1 # 存储服务(必要)
40
+ npm run proxy # http转发服务(必要)
41
+ ```
42
+ #### 4、后台管理系统web页面开发
43
+
44
+ 进入`ui-dev`文件夹
45
+
46
+ ```
47
+ > bot update # 初始化目录
48
+ > npm run dev # 执行
49
+ ```
50
+
51
+ #### 4、发布
52
+
53
+ 编辑`build.mjs`文件
54
+
55
+ 执行`npm run build`
56
+
57
+ 打包后存入`bin`文件夹
58
+
59
+ #### 5、部署
60
+
61
+ 把`bin`文件夹里面的文件拷贝到服务器的指定文件夹
62
+
63
+ 然后执行`node pm2.mjs`
18
64
 
19
65
  测试账号:admin
20
66
 
21
- 测试密码:admin123
67
+ 测试密码:admin123
package/admin/README.MD CHANGED
@@ -0,0 +1,47 @@
1
+ 主要用到的类`Admin`、`AdminAuth`和`AdminAuthPerm`。
2
+
3
+ `Admin`普通的管理系统类。
4
+
5
+ `AdminAuth`这个类需要登录授权后才能访问。
6
+
7
+ `AdminAuthPerm`这个类在登录的基础上需要有特定的权限关键字才能访问。
8
+
9
+ ```
10
+ export class User extends AdminAuthPerm {
11
+
12
+ pk = 'userId'
13
+ set = 'sysUser'
14
+ route = '/system/user'
15
+ except = ['deptTree', 'authRole', 'changeStatus']
16
+
17
+ GET(...arg) {
18
+ // 调用默认的GET方法
19
+ const result = this.call(...arg)
20
+ // 这个是处理没有get方法的情况,如请求为/system/user或者/system/user/
21
+ if (result === NoActionParams) return store1.getPostUserList().then(this.addCode200)
22
+ // 这个是处理请求为/system/user/:action但是没有实现action()的情况
23
+ if (NoActionHandle.is(result)) return store1.getUserInfoById(Number.parseInt(result))
24
+ .then(this.addCode200)
25
+
26
+ return result
27
+ }
28
+
29
+ POST(body, ...arg) {
30
+ // 调用默认的POST方法
31
+ const action = this.call(body, ...arg)
32
+ // 满足该条件表示已有相应方法处理,后续不需要再处理
33
+ if (action !== NoActionParams && !NoActionHandle.is(action)) return action
34
+
35
+ ......
36
+ }
37
+
38
+ list(query, {req, res}) {
39
+
40
+ ......
41
+
42
+ return this.page(query, undefined)
43
+ }
44
+ // 非默认方法(GET、POST、PUT、……)可以这样赋值
45
+ resetPwd = store1.resetUserPwd
46
+ }
47
+ ```
package/admin/service.mjs CHANGED
@@ -2,7 +2,7 @@ import createServer from '@k3000/server'
2
2
  import {adminUdpPort as port} from "../common/config.mjs";
3
3
  import {service as pools} from '../common/service.mjs'
4
4
 
5
- /*const service = */createServer({port, type: "udp"}, pools)
5
+ createServer({port, type: "udp"}, pools)
6
6
 
7
7
  console.log('running on ' + port)
8
8
 
@@ -24,7 +24,7 @@ export class User extends AdminAuthPerm {
24
24
 
25
25
  const action = this.call(body, ...arg)
26
26
 
27
- if (action !== NoActionParams || NoActionHandle.is(action)) return action
27
+ if (action !== NoActionParams && !NoActionHandle.is(action)) return action
28
28
 
29
29
  body.createBy = body.userInfo.userName
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k3000/s1",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "sync": "npm link",
package/index.mjs DELETED
@@ -1,28 +0,0 @@
1
-
2
- import { Worker, isMainThread } from 'node:worker_threads';
3
-
4
- const files = [
5
- './proxy/index.mjs',
6
- './admin/index.mjs',
7
- // './app/index.mjs',
8
- './jwt/index.mjs',
9
- './store1/index.mjs',
10
- ]
11
-
12
- const workers = new Set;
13
-
14
- for (const file of files) {
15
-
16
- const path = import.meta.resolve(file).substring(process.platform === "win32" ? 8 : 7)
17
-
18
- workers.add(new Worker(decodeURI(path)))
19
- }
20
-
21
- process.on('beforeExit', () => {
22
-
23
- for (const worker of workers.values()) {
24
-
25
- worker.dispose();
26
- }
27
- })
28
-