chanjs 1.0.37 → 1.0.39

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,22 +1,22 @@
1
1
 
2
- # Chan.js
2
+ # Chanjs
3
3
 
4
- Chan.js is a lightweight MVC framework developed in pure JavaScript based on Express. It embodies functional programming concepts, offering superior performance, clear code, and easy-to-follow processes that ensure high maintainability.
4
+ Chanjs 是一个基于 Express 构建的轻量级 MVC 框架,完全使用 JavaScript 开发。它体现了函数式编程的概念,提供了卓越的性能、清晰的代码和易于遵循的过程,确保了高可维护性。
5
5
 
6
- ## features
6
+ ## 特点
7
7
 
8
- - Built on top of Express
9
- - Supports ES6 syntax
10
- - Modular Design
11
- - Supports multiple module routes
12
- - Supports multiple module views
13
- - Supports multiple module controllers
14
- - Supports multiple module services
15
- - Plugin-based architecture
16
- - Lightweight (core code within 300 lines)
17
- - Long-term maintenance
8
+ - 基于 Express 构建
9
+ - 支持 ES6 语法
10
+ - 模块化设计
11
+ - 多模块化路由
12
+ - 模块化 views
13
+ - 模块化 controllers
14
+ - 模块化 services
15
+ - 插件式架构
16
+ - 轻量级(核心代码在300行以内)
17
+ - 缓存支持
18
18
 
19
- ## Conventions Over Configuration
19
+ ## 约定优于配置
20
20
 
21
21
  ```code
22
22
  |- app
@@ -49,51 +49,51 @@ Chan.js is a lightweight MVC framework developed in pure JavaScript based on Exp
49
49
  |- index.js
50
50
  ```
51
51
 
52
- ### Initialization Process
52
+ ### 初始化过程
53
53
 
54
- - Initialization
55
- - Load configuration
56
- - Load modules
57
- - Load services
58
- - Load controllers
59
- - Load routers
60
- - Load extensions
61
- - Load plugins
62
- - Load services
63
- - Load controllers
64
- - Load routers
65
- - beforeStart() Hook to merge configurations from the database into the configuration
66
- - run() Start the server
54
+ - 初始化
55
+ - 加载配置
56
+ - 加载模块
57
+ - 加载服务
58
+ - 加载控制器
59
+ - 加载路由
60
+ - 加载扩展
61
+ - 加载插件
62
+ - 加载服务
63
+ - 加载控制器
64
+ - 加载路由
65
+ - `beforeStart()` 钩子用于将数据库中的配置合并到配置中
66
+ - `run()` 启动服务器
67
67
 
68
- ### Official Website
68
+ ### 官方网站
69
69
 
70
- A CMS system developed with Chan.js
71
- Website:<https://www.chancms.top>
70
+ 使用 Chanjs 开发的 CMS 系统
71
+ 网站:[https://www.chancms.top](https://www.chancms.top)
72
72
 
73
- ### Highlights
73
+ ### 功能亮点
74
74
 
75
- - Configuration files
76
- - Multi-module MVC structure
77
- - Plugin MVC support
78
- - CORS cross-origin configuration support
79
- - MySQL database support
80
- - Route control
81
- - Art-template template engine
82
- - Static resources management
83
- - Cookie handling
84
- - Logging capabilities
75
+ - 配置文件
76
+ - 多模块 MVC 结构
77
+ - 插件 MVC 支持
78
+ - CORS 跨域配置支持
79
+ - 多数据库支持 (PostgreSQL、MySQL / MariaDB、SQLite3、Oracle Database、MSSQL)
80
+ - 路由控制
81
+ - Art-template 模板引擎
82
+ - 静态资源管理
83
+ - Cookie 处理
84
+ - 日志功能
85
85
 
86
- ### run
86
+ ### 运行
87
87
 
88
88
  ```javascript
89
89
  const Chanjs = require("chanjs");
90
90
  const chan = new Chanjs();
91
- // Load middleware
91
+ // 加载中间件
92
92
  chan.beforeStart(fn);
93
- // Scan modules
93
+ // 扫描模块
94
94
  chan.start();
95
- // Start the server
95
+ // 启动服务器
96
96
  chan.run();
97
97
  ```
98
98
 
99
- This framework is designed for developers who seek a balance between simplicity and functionality, providing a robust foundation for building web applications with ease.
99
+ 该框架专为寻求简单与功能之间平衡的开发者设计,为构建 Web 应用程序提供了一个强大的基础。
@@ -5,7 +5,7 @@ const knex = require('knex');
5
5
  * @param {Function} className - 需要实例化的类。
6
6
  *@returns {Object} 包含绑定方法的对象。
7
7
  */
8
- function bindClass(className) {
8
+ exports.bindClass = function(className) {
9
9
  let obj = {};
10
10
  const cls = new className();
11
11
  Object.getOwnPropertyNames(cls.constructor.prototype).forEach(
@@ -22,7 +22,7 @@ function bindClass(className) {
22
22
  }
23
23
 
24
24
 
25
- function createKnex(opt) {
25
+ exports.createKnex = function(opt) {
26
26
  let config = {
27
27
  host:"localhost",
28
28
  port:"3306",
@@ -63,7 +63,7 @@ function bindClass(className) {
63
63
  * @returns Array
64
64
  * @description 将web模块放到最后加载
65
65
  */
66
- function loadWebToEnd(module=[]){
66
+ exports.loadWebToEnd = function(module=[]){
67
67
  const index = module.indexOf('web');
68
68
  if (index !== -1) {
69
69
  const web = module.splice(index, 1);
@@ -71,8 +71,3 @@ function loadWebToEnd(module=[]){
71
71
  }
72
72
  return module;
73
73
  }
74
- module.exports = {
75
- bindClass,
76
- createKnex,
77
- loadWebToEnd
78
- };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @description
3
+ * 控制器基类
4
+ */
5
+ class Controller {
6
+
7
+ status = {
8
+ 200:"操作成功",
9
+ 201:"操作失败",
10
+ //错误状态码
11
+ 401:"未授权",
12
+ 403:"禁止访问",
13
+ 404:"找不到资源",
14
+ 500:"服务器内部错误",
15
+ //业务状态码
16
+ 1001:"参数错误",
17
+ 1002:"用户名或密码错误",
18
+ 1003:"用户名已存在",
19
+ 1004:"邮箱已存在",
20
+ 1005:"手机号已存在",
21
+ 1006:"验证码错误",
22
+ 1007:"验证码已过期",
23
+ 1008:"验证码发送失败",
24
+ 1009:"验证码发送成功",
25
+ 1010:"用户未登录",
26
+ 1011:"用户未注册",
27
+ 1012:"用户已注册",
28
+ //资源验证码
29
+ 1013:"上传文件超过限制",
30
+ 1014:"操作不允许",
31
+ 1015:"资源不存在",
32
+ //其他状态码
33
+ 9999:"系统内部错误",
34
+
35
+ };
36
+
37
+ constructor() {
38
+
39
+ }
40
+
41
+ // 获取状态
42
+ getStatus() {
43
+ return this.status
44
+ }
45
+
46
+ setTatus(key, val) {
47
+ this.status[key] = val
48
+ }
49
+
50
+ success(res,data = {}) {
51
+ res.json({
52
+ code: 200,
53
+ msg: this.status[200],
54
+ data
55
+ })
56
+ }
57
+
58
+ // 定义一个fail函数,用于返回错误信息
59
+ fail(res,code,data, msg='操作失败') {
60
+ res.json({
61
+ code: code,
62
+ msg: this.status[code] || msg,
63
+ data
64
+ })
65
+ }
66
+ }
67
+
68
+ module.exports = Controller;
package/core/lib/index.js CHANGED
@@ -3,7 +3,7 @@ const cookieParser = require("cookie-parser");
3
3
  const favicon = require("serve-favicon");
4
4
  const morgan = require("morgan");
5
5
  const path = require("path");
6
- const template = require("./middleware/template.js");
6
+ const view = require("./view.js");
7
7
  module.exports = async function (app, config) {
8
8
  const { logger, APP_PATH, cookieKey, static, JSON_LIMIT, appName, version } =
9
9
  config;
@@ -13,7 +13,7 @@ module.exports = async function (app, config) {
13
13
  app.use(cookieParser(cookieKey));
14
14
  app.use(express.json({ limit: JSON_LIMIT }));
15
15
  app.use(express.urlencoded({ extended: false }));
16
- template(app, config);
16
+ view(app, config);
17
17
  if (static.length > 0) {
18
18
  static.forEach((item) => {
19
19
  const { prefix, dir, maxAge } = item;
@@ -2,11 +2,10 @@ class BaseService {
2
2
  /**
3
3
  * @description 构造函数
4
4
  * @param {*} knex - knex实例
5
- * @param {*} model - 模型名称
6
5
  */
7
- constructor(knex, model = "") {
8
- this.knex = knex;
9
- this.model = model;
6
+ constructor() {
7
+ this.knex = Chan.knex || null;
8
+ this.model = ''; // 默认为空字符串
10
9
  }
11
10
 
12
11
  /**
@@ -2,12 +2,12 @@ const express = require("express");
2
2
  const path = require("path");
3
3
  const fs = require("fs");
4
4
  const cors = require("cors");
5
- const config = require("./lib/config/config.js");
6
- const {bindClass,createKnex,loadWebToEnd} = require("./lib/extend/helper.js");
7
- const Controller = require("./lib/controller/controller.js");
8
- const Service = require("./lib/service/service.js");
9
- const cache = require('./lib/extend/cache.js');
10
- const core = require("./lib/index.js");
5
+ const config = require("./core/config.js");
6
+ const {bindClass,createKnex,loadWebToEnd} = require("./core/helper.js");
7
+ const Controller = require("./core/lib/controller.js");
8
+ const Service = require("./core/lib/service.js");
9
+ const cache = require('./core/lib/cache.js');
10
+ const core = require("./core/lib/index.js");
11
11
  /**
12
12
  * @description 基于express封装的mvc框架,遵循约定优于配置原则
13
13
  */
@@ -18,7 +18,7 @@ class Chan {
18
18
  static config = config;
19
19
  static cache = cache;
20
20
  static Controller = Controller;
21
- static Service = Service;
21
+
22
22
  constructor() {
23
23
  this.init();
24
24
  }
@@ -73,6 +73,7 @@ class Chan {
73
73
  Chan[`knex${index}`] = createKnex(item);
74
74
  }
75
75
  })
76
+ Chan.Service = Service;
76
77
  }
77
78
  }
78
79
 
package/package.json CHANGED
@@ -1,32 +1,29 @@
1
1
  {
2
2
  "name": "chanjs",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "chanjs基于express 纯js研发的轻量级mvc框架。",
5
5
  "main": "core/chan.js",
6
6
  "module": "core/chan.js",
7
7
  "keywords": [
8
- "\"chanjs\"",
9
- "\"express mvc\"",
10
- "\"express mysql\"",
11
- "\"express knex\"",
12
- "\"chancms\"",
13
- "\"nodejs\""
8
+ "chanjs",
9
+ "express mvc",
10
+ "express mysql",
11
+ "express knex",
12
+ "chancms",
13
+ "nodejs"
14
14
  ],
15
- "author": "\"明空\"",
15
+ "author": "明空",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "art-template": "^4.13.2",
19
- "body-parser": "^1.20.2",
20
- "cookie-parser": "^1.4.6",
21
- "cors": "^2.8.5",
22
- "express": "^4.19.2",
23
- "express-art-template": "^1.0.1",
24
- "knex": "^3.1.0",
25
- "morgan": "^1.10.0",
26
- "mysql2": "^3.11.0",
27
- "dayjs": "^1.11.12"
28
- },
29
- "__npminstall_done": true,
30
- "_from": "chanjs@1.0.22",
31
- "_resolved": "https://registry.npmmirror.com/chanjs/-/chanjs-1.0.22.tgz"
32
- }
18
+ "art-template": "4.13.2",
19
+ "body-parser": "1.20.2",
20
+ "cookie-parser": "1.4.6",
21
+ "cors": "2.8.5",
22
+ "express": "4.19.2",
23
+ "express-art-template": "1.0.1",
24
+ "knex": "3.1.0",
25
+ "morgan": "1.10.0",
26
+ "mysql2": "3.11.0",
27
+ "dayjs": "1.11.12"
28
+ }
29
+ }
@@ -1,25 +0,0 @@
1
- /**
2
- * @description
3
- * 控制器基类
4
- */
5
- class Controller {
6
- constructor() {}
7
-
8
- download(res, file) {
9
- res.download(file);
10
- }
11
-
12
- success(res, data = null) {
13
- res.json({ code: 200, msg: "success", data: data });
14
- }
15
-
16
- fail(res, msg = "操作失败,请稍后再试") {
17
- res.json({ code: 400, msg: msg });
18
- }
19
-
20
- error(res, msg) {
21
- res.json({ code: 500, msg: msg });
22
- }
23
- }
24
-
25
- module.exports = Controller;
File without changes
File without changes
File without changes