mm_tpl 2.2.0 → 2.2.2

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.
@@ -6,7 +6,11 @@
6
6
  </head>
7
7
  <body>
8
8
  <div>游戏主题</div>
9
- <div><div class="bar_user"><div>您好吗?</div><div>你好!</div></div>
9
+ <div><div class="bar_user"><div>您好吗?</div><div>你好!</div>
10
+ <div>用户ID:1</div>
11
+ <div>当前项目ID:2</div>
12
+ </div>
13
+
10
14
  <div class="bar">导航栏</div>
11
15
  <style>
12
16
  .bar {
package/hook.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const {
2
2
  types
3
- } = require("node:util");
3
+ } = require("util");
4
4
 
5
5
  class Hook {
6
6
  constructor() {
package/index.js CHANGED
@@ -70,7 +70,7 @@ class Tpl {
70
70
  * 错误提示
71
71
  */
72
72
  this.error = null;
73
-
73
+
74
74
  /**
75
75
  * 初始化
76
76
  */
@@ -95,6 +95,17 @@ Tpl.prototype.set_config = function(config) {
95
95
  }
96
96
  };
97
97
 
98
+
99
+ /**
100
+ * 初始化
101
+ * @param {String} name 名称
102
+ * @param {Object} req 请求参数
103
+ * @param {Object} args 附加参数
104
+ */
105
+ Tpl.prototype.runFunc = function(name, req, ...args) {
106
+ return $.hook.runFunc(name, this.viewBag, req, ...args);
107
+ }
108
+
98
109
  /**
99
110
  * 初始化
100
111
  * @param {Object} config 配置参数
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_tpl",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "这是超级美眉模板帮助类模块,用于MVC模式下的视图渲染",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,4 +1,9 @@
1
- <div class="bar_user">${@hook_filter('test', hook_action('test', '好的'), '真的')}</div>
1
+ <div class="bar_user">
2
+ ${@hook_filter('test', hook_action('test', '好的'), '真的')}
3
+ <div>用户ID:${viewBag.user_id}</div>
4
+ <div>当前项目ID:${viewBag.project_id}</div>
5
+ </div>
6
+
2
7
  <div class="bar">导航栏</div>
3
8
  <style>
4
9
  .bar {
package/test.js CHANGED
@@ -47,16 +47,16 @@ async function test() {
47
47
  tpl.current_theme = "game";
48
48
  tpl.dir = "";
49
49
 
50
- $.hook.addFunc('list', async function(viewBag, req, type) {
51
- console.log(viewBag, req, type);
52
- });
53
-
54
- await $.hook.runFunc('list', tpl.viewBag, {
55
- query: {
56
- a: 1,
57
- b: 2
50
+ $.hook.addFunc('list', async function(m, req, type) {
51
+ var query = req.query;
52
+ if (query.user_id) {
53
+ m.user_id = query.user_id;
58
54
  }
59
- }, 'article');
55
+ if (query.project_id) {
56
+ m.project_id = query.project_id;
57
+ }
58
+ console.log(m);
59
+ });
60
60
 
61
61
  $.hook.addAction('test', function(m, param) {
62
62
  // console.log(param, m);
@@ -75,6 +75,13 @@ async function test() {
75
75
  // $.hook.delAction('test', "测试动作1");
76
76
  // $.hook.delFilter('test', "测试过滤");
77
77
 
78
+ await tpl.runFunc('list', {
79
+ query: {
80
+ user_id: 1,
81
+ project_id: 2
82
+ }
83
+ }, 'article');
84
+
78
85
  // 渲染视图(并缓存)
79
86
  var body = tpl.view("./test", {
80
87
  arr: [123, 234]
@@ -84,7 +91,6 @@ async function test() {
84
91
  // 缓存文件名
85
92
  cache_filename: "./test"
86
93
  });
87
-
88
94
  // 删除指定目录的缓存文件
89
95
  // tpl.clear_cache('./mall');
90
96
  console.log(body);