chanjs 1.0.38 → 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
@@ -3,7 +3,7 @@
3
3
 
4
4
  Chanjs 是一个基于 Express 构建的轻量级 MVC 框架,完全使用 JavaScript 开发。它体现了函数式编程的概念,提供了卓越的性能、清晰的代码和易于遵循的过程,确保了高可维护性。
5
5
 
6
- ## features
6
+ ## 特点
7
7
 
8
8
  - 基于 Express 构建
9
9
  - 支持 ES6 语法
@@ -65,7 +65,7 @@ Chanjs 是一个基于 Express 构建的轻量级 MVC 框架,完全使用 Java
65
65
  - `beforeStart()` 钩子用于将数据库中的配置合并到配置中
66
66
  - `run()` 启动服务器
67
67
 
68
- ### ### 官方网站
68
+ ### 官方网站
69
69
 
70
70
  使用 Chanjs 开发的 CMS 系统
71
71
  网站:[https://www.chancms.top](https://www.chancms.top)
@@ -76,7 +76,7 @@ Chanjs 是一个基于 Express 构建的轻量级 MVC 框架,完全使用 Java
76
76
  - 多模块 MVC 结构
77
77
  - 插件 MVC 支持
78
78
  - CORS 跨域配置支持
79
- - MySQL 数据库支持
79
+ - 多数据库支持 (PostgreSQL、MySQL / MariaDB、SQLite3、Oracle Database、MSSQL)
80
80
  - 路由控制
81
81
  - Art-template 模板引擎
82
82
  - 静态资源管理
@@ -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.38",
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