mm_os 3.3.1 → 4.0.1

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.
Files changed (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +498 -99
  3. package/README_EN.md +505 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/{core/com → com}/event/README.md +4 -4
  28. package/com/event/com.json +5 -0
  29. package/{core/com → com}/event/config.tpl.json +18 -18
  30. package/com/event/drive.js +59 -0
  31. package/com/event/index.js +409 -0
  32. package/com/event/script.tpl.js +23 -0
  33. package/com/mqtt/com.json +5 -0
  34. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  35. package/com/mqtt/drive.js +676 -0
  36. package/com/mqtt/index.js +822 -0
  37. package/com/mqtt/mm_mqtt.js +425 -0
  38. package/com/mqtt/script.tpl.js +723 -0
  39. package/com/nav/com.json +5 -0
  40. package/com/nav/config.tpl.json +84 -0
  41. package/com/nav/drive.js +702 -0
  42. package/com/nav/index.js +231 -0
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  44. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  45. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  46. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  47. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  48. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  49. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  50. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  51. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  52. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  53. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  54. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  55. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  57. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  58. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  59. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  60. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  61. package/com/nav/viewmodel.js +446 -0
  62. package/com/param/com.json +5 -0
  63. package/{core/com → com}/param/config.tpl.json +7 -1
  64. package/com/param/drive.js +502 -0
  65. package/com/param/index.js +155 -0
  66. package/com/param/script.tpl.js +12 -0
  67. package/com/pendant/com.json +5 -0
  68. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  69. package/com/pendant/drive.js +204 -0
  70. package/com/pendant/index.js +441 -0
  71. package/com/pendant/pendant.html +16 -0
  72. package/com/pendant/script.tpl.js +18 -0
  73. package/com/socket/com.json +5 -0
  74. package/com/socket/config.tpl.json +12 -0
  75. package/com/socket/drive.js +651 -0
  76. package/com/socket/index.js +351 -0
  77. package/com/socket/script.tpl.js +41 -0
  78. package/com/sql/com.json +5 -0
  79. package/{core/com → com}/sql/config.tpl.json +13 -9
  80. package/com/sql/drive.js +1259 -0
  81. package/com/sql/index.js +150 -0
  82. package/com/sql/script.tpl.js +47 -0
  83. package/com/static/com.json +5 -0
  84. package/{core/com → com}/static/config.tpl.json +10 -6
  85. package/com/static/drive.js +194 -0
  86. package/com/static/index.js +226 -0
  87. package/com/static/script.tpl.js +28 -0
  88. package/com/task/com.json +5 -0
  89. package/{core/com → com}/task/config.tpl.json +4 -6
  90. package/com/task/drive.js +405 -0
  91. package/com/task/index.js +148 -0
  92. package/com/task/script.tpl.js +37 -0
  93. package/com/template/com.json +5 -0
  94. package/com/template/config.tpl.json +16 -0
  95. package/com/template/drive.js +80 -0
  96. package/com/template/index.js +141 -0
  97. package/com.js +156 -0
  98. package/common/README.md +2 -0
  99. package/common/handler/msg/handler.json +22 -0
  100. package/common/handler/msg/index.js +23 -0
  101. package/common/handler/player/handler.json +22 -0
  102. package/common/handler/player/index.js +287 -0
  103. package/common/handler/user/handler.json +22 -0
  104. package/common/handler/user/index.js +23 -0
  105. package/common/middleware/web_after/index.js +29 -0
  106. package/common/middleware/web_after/middleware.json +9 -0
  107. package/common/middleware/web_base/index.js +113 -0
  108. package/common/middleware/web_base/middleware.json +19 -0
  109. package/common/middleware/web_before/index.js +33 -0
  110. package/common/middleware/web_before/middleware.json +9 -0
  111. package/common/middleware/web_cors/index.js +87 -0
  112. package/common/middleware/web_cors/middleware.json +24 -0
  113. package/common/middleware/web_error/index.js +119 -0
  114. package/common/middleware/web_error/middleware.json +18 -0
  115. package/common/middleware/web_ip/index.js +15 -0
  116. package/common/middleware/web_ip/middleware.json +14 -0
  117. package/common/middleware/web_logger/index.js +156 -0
  118. package/common/middleware/web_logger/middleware.json +14 -0
  119. package/common/middleware/web_main/index.js +24 -0
  120. package/common/middleware/web_main/middleware.json +9 -0
  121. package/common/middleware/web_static/index.js +73 -0
  122. package/common/middleware/web_static/middleware.json +54 -0
  123. package/common/middleware/web_waf/index.js +385 -0
  124. package/common/middleware/web_waf/middleware.json +13 -0
  125. package/common/model/msg/index.js +88 -0
  126. package/common/model/msg/model.json +401 -0
  127. package/common/model/player/index.js +63 -0
  128. package/common/model/player/model.json +185 -0
  129. package/common/model/user/index.js +11 -0
  130. package/common/model/user/model.json +219 -0
  131. package/core/app/config.tpl.json +67 -0
  132. package/core/app/index.js +632 -0
  133. package/core/app/script.tpl.js +52 -0
  134. package/core/channel/index.js +899 -0
  135. package/core/channel/matcher.js +585 -0
  136. package/core/com/config.tpl.json +16 -0
  137. package/core/com/index.js +74 -0
  138. package/core/com/script.tpl.js +5 -0
  139. package/core/component/component.js +42 -0
  140. package/core/component/config.tpl.json +63 -0
  141. package/core/component/index.js +273 -0
  142. package/core/component/script.tpl.js +19 -0
  143. package/core/controller/config.tpl.json +14 -0
  144. package/core/controller/index.js +373 -0
  145. package/core/controller/script.tpl.js +27 -0
  146. package/core/factory/config.tpl.json +14 -0
  147. package/core/factory/entity.js +275 -0
  148. package/core/factory/index.js +241 -0
  149. package/core/factory/script.tpl.js +16 -0
  150. package/core/game/bat/index.js +137 -0
  151. package/core/game/bat/world.js +622 -0
  152. package/core/game/config.tpl.json +16 -0
  153. package/core/game/entity_admin.js +230 -0
  154. package/core/game/index.js +186 -0
  155. package/core/handler/config.tpl.json +22 -0
  156. package/core/handler/index.js +181 -0
  157. package/core/handler/script.tpl.js +23 -0
  158. package/core/logic/config.tpl.json +14 -0
  159. package/core/logic/index.js +59 -0
  160. package/core/logic/script.tpl.js +19 -0
  161. package/core/middleware/config.tpl.json +16 -0
  162. package/core/middleware/index.js +125 -0
  163. package/core/middleware/script.tpl.js +37 -0
  164. package/core/mod/config.tpl.json +22 -0
  165. package/core/mod/index.js +130 -0
  166. package/core/mod/script.tpl.js +34 -0
  167. package/core/model/config.tpl.json +219 -0
  168. package/core/model/index.js +272 -0
  169. package/core/model/model.js +27 -0
  170. package/core/model/script.tpl.js +20 -0
  171. package/core/notifier/config.tpl.json +14 -0
  172. package/core/notifier/index.js +77 -0
  173. package/core/notifier/script.tpl.js +20 -0
  174. package/core/plugin/config.tpl.json +24 -0
  175. package/core/plugin/index.js +232 -0
  176. package/core/plugin/script.tpl.js +51 -0
  177. package/core/pusher/config.tpl.json +14 -0
  178. package/core/pusher/index.js +161 -0
  179. package/core/pusher/script.tpl.js +20 -0
  180. package/core/room/bat/index.js +170 -0
  181. package/core/room/bat/room.js +524 -0
  182. package/core/room/config.tpl.json +20 -0
  183. package/core/room/index.js +249 -0
  184. package/core/room/room.js +61 -0
  185. package/core/scene/config.tpl.json +14 -0
  186. package/core/scene/index.js +466 -0
  187. package/core/scene/loop.js +1255 -0
  188. package/core/scene/map.js +28 -0
  189. package/core/scene/script.tpl.js +22 -0
  190. package/core/sender/config.tpl.json +14 -0
  191. package/core/sender/index.js +79 -0
  192. package/core/sender/script.tpl.js +20 -0
  193. package/core/service/config.tpl.json +14 -0
  194. package/core/service/index.js +100 -0
  195. package/core/service/script.tpl.js +25 -0
  196. package/core/store/config.tpl.json +26 -0
  197. package/core/store/index.js +1755 -0
  198. package/core/store/script.tpl.js +22 -0
  199. package/core/store/sql.js +1464 -0
  200. package/core/system/config.tpl.json +18 -0
  201. package/core/system/index.js +312 -0
  202. package/core/system/script.tpl.js +77 -0
  203. package/core/view/config.tpl.json +14 -0
  204. package/core/view/index.js +91 -0
  205. package/core/view/script.tpl.js +20 -0
  206. package/core/zone/bat/index.js +725 -0
  207. package/core/zone/config.tpl.json +54 -0
  208. package/core/zone/index.js +614 -0
  209. package/core/zone/script.tpl.js +10 -0
  210. package/core/zone/zone_bat.js +136 -0
  211. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  212. package/index.js +17 -333
  213. package/os.js +57 -0
  214. package/package.json +65 -55
  215. package/server.js +598 -0
  216. package/README.en.md +0 -36
  217. package/conf.json +0 -3
  218. package/core/base/mqtt/index.js +0 -1110
  219. package/core/base/mqtt/lib.js +0 -40
  220. package/core/base/web/index.js +0 -245
  221. package/core/com/api/com.json +0 -4
  222. package/core/com/api/drive.js +0 -668
  223. package/core/com/api/index.js +0 -108
  224. package/core/com/api/oauth.js +0 -158
  225. package/core/com/api/script.js +0 -32
  226. package/core/com/app/README.md +0 -3
  227. package/core/com/app/com.json +0 -4
  228. package/core/com/app/config.tpl.json +0 -16
  229. package/core/com/app/drive.js +0 -309
  230. package/core/com/app/index.js +0 -211
  231. package/core/com/app/script.js +0 -155
  232. package/core/com/cmd/com.json +0 -4
  233. package/core/com/cmd/config.tpl.json +0 -66
  234. package/core/com/cmd/drive.js +0 -513
  235. package/core/com/cmd/index.js +0 -354
  236. package/core/com/cmd/old/5w2h.js +0 -54
  237. package/core/com/cmd/old/drive.js +0 -423
  238. package/core/com/cmd/script.js +0 -11
  239. package/core/com/component/README.md +0 -3
  240. package/core/com/component/com.json +0 -4
  241. package/core/com/component/component.html +0 -16
  242. package/core/com/component/drive.js +0 -197
  243. package/core/com/component/index.js +0 -312
  244. package/core/com/component/script.js +0 -18
  245. package/core/com/db/com.json +0 -4
  246. package/core/com/db/drive.js +0 -1160
  247. package/core/com/db/index.js +0 -176
  248. package/core/com/event/com.json +0 -4
  249. package/core/com/event/drive.js +0 -133
  250. package/core/com/event/index.js +0 -345
  251. package/core/com/event/script.js +0 -26
  252. package/core/com/eventer/com.js +0 -477
  253. package/core/com/eventer/com.json +0 -4
  254. package/core/com/middleware/com.js +0 -154
  255. package/core/com/middleware/com.json +0 -4
  256. package/core/com/middleware/config.tpl.json +0 -8
  257. package/core/com/middleware/script.js +0 -9
  258. package/core/com/mqtt/com.json +0 -4
  259. package/core/com/mqtt/drive.js +0 -600
  260. package/core/com/mqtt/index.js +0 -572
  261. package/core/com/mqtt/mm_mqtt.js +0 -330
  262. package/core/com/mqtt/script.js +0 -604
  263. package/core/com/msg/com.js +0 -296
  264. package/core/com/msg/com.json +0 -4
  265. package/core/com/nav/com.json +0 -4
  266. package/core/com/nav/config.tpl.json +0 -75
  267. package/core/com/nav/drive.js +0 -549
  268. package/core/com/nav/index.js +0 -182
  269. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  270. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  271. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  272. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  273. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  274. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  275. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  276. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  277. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  278. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  279. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  281. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  282. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  283. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  284. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  285. package/core/com/nav/viewmodel.js +0 -296
  286. package/core/com/param/drive.js +0 -366
  287. package/core/com/param/index.js +0 -80
  288. package/core/com/param/script.js +0 -12
  289. package/core/com/param/test.js +0 -98
  290. package/core/com/plugin/README.md +0 -3
  291. package/core/com/plugin/com.json +0 -4
  292. package/core/com/plugin/config.tpl.json +0 -26
  293. package/core/com/plugin/drive.js +0 -536
  294. package/core/com/plugin/index.js +0 -259
  295. package/core/com/plugin/script.js +0 -213
  296. package/core/com/rpc/com.json +0 -4
  297. package/core/com/rpc/drive.js +0 -160
  298. package/core/com/rpc/index.js +0 -87
  299. package/core/com/rpc/rpc.js +0 -118
  300. package/core/com/socket/com.json +0 -4
  301. package/core/com/socket/config.tpl.json +0 -14
  302. package/core/com/socket/drive.js +0 -403
  303. package/core/com/socket/index.js +0 -62
  304. package/core/com/socket/script.js +0 -42
  305. package/core/com/sql/drive.js +0 -1087
  306. package/core/com/sql/index.js +0 -83
  307. package/core/com/sql/script.js +0 -48
  308. package/core/com/static/com.json +0 -4
  309. package/core/com/static/drive.js +0 -220
  310. package/core/com/static/index.js +0 -149
  311. package/core/com/static/script.js +0 -28
  312. package/core/com/task/com.json +0 -4
  313. package/core/com/task/drive.js +0 -403
  314. package/core/com/task/index.js +0 -110
  315. package/core/com/task/script.js +0 -37
  316. package/core/com/timer/com.js +0 -217
  317. package/core/com/timer/com.json +0 -4
  318. package/core/com/tpl/com.js +0 -19
  319. package/core/com/tpl/com.json +0 -4
  320. package/lib/actions.js +0 -50
  321. package/lib/base.js +0 -361
  322. package/lib/com.js +0 -29
  323. package/lib/ref.js +0 -121
  324. package/middleware/cors/index.js +0 -119
  325. package/middleware/cors/middleware.json +0 -20
  326. package/middleware/csrf/index.js +0 -202
  327. package/middleware/csrf/middleware.json +0 -24
  328. package/middleware/ip_firewall/index.js +0 -476
  329. package/middleware/ip_firewall/middleware.json +0 -109
  330. package/middleware/mqtt_base/index.js +0 -10
  331. package/middleware/mqtt_base/middleware.json +0 -11
  332. package/middleware/security_audit/index.js +0 -543
  333. package/middleware/security_audit/middleware.json +0 -48
  334. package/middleware/waf/index.js +0 -343
  335. package/middleware/waf/middleware.json +0 -10
  336. package/middleware/waf_ddos/index.js +0 -520
  337. package/middleware/waf_ddos/middleware.json +0 -38
  338. package/middleware/waf_xss/index.js +0 -269
  339. package/middleware/waf_xss/middleware.json +0 -18
  340. package/middleware/web_after/index.js +0 -33
  341. package/middleware/web_after/middleware.json +0 -10
  342. package/middleware/web_base/index.js +0 -90
  343. package/middleware/web_base/middleware.json +0 -10
  344. package/middleware/web_before/index.js +0 -27
  345. package/middleware/web_before/middleware.json +0 -10
  346. package/middleware/web_check/index.js +0 -28
  347. package/middleware/web_check/middleware.json +0 -10
  348. package/middleware/web_main/index.js +0 -28
  349. package/middleware/web_main/middleware.json +0 -10
  350. package/middleware/web_proxy/index.js +0 -37
  351. package/middleware/web_proxy/middleware.json +0 -10
  352. package/middleware/web_render/index.js +0 -87
  353. package/middleware/web_render/middleware.json +0 -10
  354. package/middleware/web_socket/index.js +0 -34
  355. package/middleware/web_socket/middleware.json +0 -10
  356. package/middleware/web_static/index.js +0 -115
  357. package/middleware/web_static/middleware.json +0 -10
  358. /package/{core/com → com}/api/README.md +0 -0
  359. /package/{core/com → com}/db/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -0,0 +1,502 @@
1
+ const Item = require('mm_machine').Drive;
2
+ const Check = require('mm_check');
3
+
4
+ /**
5
+ * Param参数驱动类
6
+ * @augments {Item}
7
+ * @class
8
+ */
9
+ class Drive extends Item {
10
+ static config = {
11
+ // 函数入口
12
+ 'main': '',
13
+ // 参数过滤
14
+ 'filter': true,
15
+ // 默认监听方法, 当查询参数中出现监听的关键词时,选择以该键值作为请求方式,否则默认为get
16
+ 'method': 'method',
17
+ // 增
18
+ 'add': {
19
+ // body参数
20
+ 'body': [],
21
+ // body中的必填参数
22
+ 'body_required': []
23
+ },
24
+ // 删
25
+ 'del': {
26
+ // url中的query参数
27
+ 'query': [],
28
+ // query中的必填参数
29
+ 'query_required': []
30
+ },
31
+ // 改
32
+ 'set': {
33
+ // url中的query参数
34
+ 'query': [],
35
+ // query中的必填参数
36
+ 'query_required': [],
37
+ // body参数
38
+ 'body': [],
39
+ // body中的必填参数
40
+ 'body_required': [],
41
+ // 不包含参数
42
+ 'body_not': []
43
+ },
44
+ // 查
45
+ 'get': {
46
+ // url中的query参数
47
+ 'query': [],
48
+ // query中的必填参数
49
+ 'query_required': []
50
+ },
51
+ // 导入
52
+ 'import': {
53
+ // body中的参数
54
+ 'body': ['name'],
55
+ // body中的必填参数
56
+ 'body_required': ['file']
57
+ },
58
+ // 导出
59
+ 'export': {
60
+ // url中的query参数
61
+ 'query': [],
62
+ // query中的必填参数
63
+ 'query_required': []
64
+ },
65
+ // 去重
66
+ 'del_req': {
67
+ // query中的必填参数
68
+ 'query_required': ['groupby', 'sort']
69
+ },
70
+ // 合计
71
+ 'sum': {
72
+ // query中的必填参数
73
+ 'query_required': ['field', 'groupby']
74
+ },
75
+ // 总数
76
+ 'count': {
77
+ // query中的必填参数
78
+ 'query_required': ['field', 'groupby']
79
+ },
80
+ // 提交
81
+ // "post": {
82
+ // // url中的query参数
83
+ // "query": [],
84
+ // // query中的必填参数
85
+ // "query_required": [],
86
+ // // body参数
87
+ // "body": [],
88
+ // // body中的必填参数
89
+ // "body_required": [],
90
+ // // 不包含参数
91
+ // "body_not": []
92
+ // },
93
+ // 验证参数集
94
+ 'list': []
95
+ };
96
+
97
+ /**
98
+ * 构造函数
99
+ * @param {object} config 配置参数
100
+ * @param {object} parent 父对象
101
+ * @class
102
+ */
103
+ constructor(config, parent) {
104
+ super({ ...Drive.config, ...config }, parent);
105
+ // 默认启用热更新
106
+ this.mode = 3;
107
+ }
108
+ }
109
+
110
+ /**
111
+ * 获取模板目录
112
+ * @returns {string} 模板目录
113
+ */
114
+ Drive.prototype._getTplDir = function () {
115
+ return __dirname;
116
+ };
117
+
118
+ /**
119
+ * 更新验证对象
120
+ */
121
+ Drive.prototype.updateCheck = function () {
122
+ var lt = this.config.list;
123
+ var len = lt.length;
124
+ for (var i = 0; i < len; i++) {
125
+ var o = lt[i];
126
+ if (!o.load_check) {
127
+ lt[i] = new Check(o);
128
+ lt[i].load_check = true;
129
+ }
130
+ }
131
+ };
132
+
133
+ /**
134
+ * 预设
135
+ */
136
+ Drive.prototype._preset = function () {
137
+ this.updateCheck();
138
+ };
139
+
140
+ /// 新建配置参数模型, 用于动态创建配置时
141
+ Drive.prototype.model = function () {
142
+ return new Check({
143
+ // 参数名
144
+ 'name': 'name',
145
+ // 参数介绍名
146
+ 'title': '名称',
147
+ // 参数做用描述
148
+ 'description': '用户名称,传入字符串',
149
+ // 函数入口
150
+ 'main': '',
151
+ // 是否唯一值, 需配合数据库验证
152
+ 'only': false,
153
+ // 分隔符号, 用于查询时判断多个传参
154
+ 'splitter': '|',
155
+ // 是否主键
156
+ 'key': false,
157
+ // 参数类型 string字符串、number数字、bool布尔、dateTime时间、object对象类型、array数组类型
158
+ 'type': 'string',
159
+ // 数据存储类型 tinyint布尔型(0,1),smallint短整数型,mediumint中整数型,int长整数型,float浮点数型,double双精度型,timestamp时间戳型,date日期型,time时间型,varchar字符串型,text长文本型
160
+ 'dataType': '',
161
+ // 字符串相关验证
162
+ 'string': {
163
+ // 非空
164
+ 'notEmpty': false,
165
+ // 最小长度
166
+ 'min': 0,
167
+ // 最大长度
168
+ 'max': 0,
169
+ // 验证字符串范围, 传入两个成员, 最小长度和最大长度。例如:[0, 0]
170
+ 'range': [],
171
+ // 验证正则表达式
172
+ 'regex': '',
173
+ // 验证与某个参数值是否相同
174
+ 'identical': '',
175
+ // 验证与某个参数值是否不同
176
+ 'different': '',
177
+ // 后缀名, 多个后缀名用“|”分隔
178
+ 'extension': '',
179
+ // 格式验证 email、url、date、dateISO、number、digits、phone
180
+ 'format': ''
181
+ },
182
+ // 数值相关验证
183
+ 'number': {
184
+ // 最小值
185
+ 'min': 0,
186
+ // 最大值
187
+ 'max': 0,
188
+ // 验证字符串范围
189
+ 'range': []
190
+ },
191
+ 'default': ''
192
+ });
193
+ };
194
+
195
+ /**
196
+ * 验证值是否符合
197
+ * @param {object} model 验证模型
198
+ * @param {object} value 被验证的值
199
+ * @param {Array} requireds 必填项名称数组
200
+ * @returns {object} 没通过返回信息,否则返回空
201
+ */
202
+ Drive.prototype.checkVal = function (model, value, requireds) {
203
+ var msg;
204
+ if (value === '' || value === undefined || value === null) {
205
+ if (requireds.has(model.name)) {
206
+ msg = model.msgHead(model) + model.msg('required');
207
+ }
208
+ } else {
209
+ msg = model.run(value);
210
+ if (!msg) {
211
+ msg = this.main(model, value);
212
+ }
213
+ if (msg) {
214
+ return msg;
215
+ }
216
+ }
217
+ return msg;
218
+ };
219
+
220
+ /**
221
+ * 获取模型
222
+ * @param {string} name 名称
223
+ * @returns {object} 配置模型
224
+ */
225
+ Drive.prototype.getCheckModel = function (name) {
226
+ var model;
227
+ var lt = this.config.list;
228
+ for (var i = 0, o; o = lt[i++];) {
229
+ if (o['name'] === name) {
230
+ model = o;
231
+ break;
232
+ }
233
+ }
234
+ return model;
235
+ };
236
+
237
+ /**
238
+ * 执行验证
239
+ * @param {object} params 请求参数集合
240
+ * @param {Array} arr 要验证的参数名数组
241
+ * @param {Array} required 必填项名称数组
242
+ * @returns {string|undefined} 返回验证结果
243
+ */
244
+ Drive.prototype.checkSub = function (params, arr, required) {
245
+ if (!params) {
246
+ return undefined;
247
+ }
248
+ for (var i = 0; i < arr.length; i++) {
249
+ var msg = this._checkParam(params, arr[i], required);
250
+ if (msg) {
251
+ return msg;
252
+ }
253
+ }
254
+ return undefined;
255
+ };
256
+
257
+ /**
258
+ * 检查单个参数
259
+ * @param {object} params 请求参数集合
260
+ * @param {string} key 参数名
261
+ * @param {Array} required 必填项名称数组
262
+ * @returns {string|undefined} 返回验证结果
263
+ * @private
264
+ */
265
+ Drive.prototype._checkParam = function (params, key, required) {
266
+ var o = this.getCheckModel(key);
267
+ if (!o) {
268
+ return undefined;
269
+ }
270
+ var value = params[key];
271
+ var msg = this.checkVal(o, value, required);
272
+ if (msg) {
273
+ return msg;
274
+ }
275
+ if (value && o.string) {
276
+ return this._checkStringRules(o, value, params);
277
+ }
278
+ return undefined;
279
+ };
280
+
281
+ /**
282
+ * 检查字符串规则
283
+ * @param {object} model 验证模型
284
+ * @param {string} value 参数值
285
+ * @param {object} params 请求参数集合
286
+ * @returns {string|undefined} 返回验证结果
287
+ * @private
288
+ */
289
+ Drive.prototype._checkStringRules = function (model, value, params) {
290
+ if (model.string.identical) {
291
+ return this._checkIdenRule(model, value, params);
292
+ } else if (model.string.different) {
293
+ return this._checkDiffRule(model, value, params);
294
+ }
295
+ return undefined;
296
+ };
297
+
298
+ /**
299
+ * 检查相同规则
300
+ * @param {object} model 验证模型
301
+ * @param {string} value 参数值
302
+ * @param {object} params 请求参数集合
303
+ * @returns {string|undefined} 返回验证结果
304
+ * @private
305
+ */
306
+ Drive.prototype._checkIdenRule = function (model, value, params) {
307
+ var iden_key = model.string.identical;
308
+ var val = params[iden_key];
309
+ if (val !== value) {
310
+ var m = this.getCheckModel(iden_key);
311
+ if (m) {
312
+ return model.msg('identical', model.title + '(' + model.name + ')', m.title + '(' + m.name + ')');
313
+ } else {
314
+ return model.msg('identical', model.title + '(' + model.name + ')', iden_key);
315
+ }
316
+ }
317
+ return undefined;
318
+ };
319
+
320
+ /**
321
+ * 检查不同规则
322
+ * @param {object} model 验证模型
323
+ * @param {string} value 参数值
324
+ * @param {object} params 请求参数集合
325
+ * @returns {string|undefined} 返回验证结果
326
+ * @private
327
+ */
328
+ Drive.prototype._checkDiffRule = function (model, value, params) {
329
+ var diff_key = model.string.different;
330
+ var val = params[diff_key];
331
+ if (val === value) {
332
+ var m = this.getCheckModel(diff_key);
333
+ if (m) {
334
+ return model.msg('different', model.title + '(' + model.name + ')', m.title + '(' + m.name + ')');
335
+ } else {
336
+ return model.msg('different', model.title + '(' + model.name + ')', diff_key);
337
+ }
338
+ }
339
+ return undefined;
340
+ };
341
+
342
+ /**
343
+ * 验证参数是否符合
344
+ * @param {object} query url参数集合
345
+ * @param {object} body 正文参数集合
346
+ * @param {string} method 请求方式,get增、del删、set改、get查、import导入、export导出
347
+ * @returns {object} 没通过返回信息,否则返回空
348
+ */
349
+ Drive.prototype.check = function (query, body, method) {
350
+ var m = this._getMethodConfig(method, query);
351
+ var msg = this._checkQueryParams(query, m);
352
+ if (!msg) {
353
+ this._processBodyNot(m, body);
354
+ msg = this._checkBodyParams(body, m);
355
+ }
356
+ return msg;
357
+ };
358
+
359
+ /**
360
+ * 获取方法配置
361
+ * @param {string} method 请求方式
362
+ * @param {object} query url参数集合
363
+ * @returns {object} 方法配置
364
+ * @private
365
+ */
366
+ Drive.prototype._getMethodConfig = function (method, query) {
367
+ var md = method;
368
+ if (md !== 'GET') {
369
+ md = md.toLowerCase();
370
+ }
371
+ var m = this.config[md];
372
+ if (!m) {
373
+ m = this._getConfigFromQuery(query);
374
+ }
375
+ if (!m) {
376
+ m = this.config['get'];
377
+ }
378
+ return m;
379
+ };
380
+
381
+ /**
382
+ * 从查询参数获取方法配置
383
+ * @param {object} query url参数集合
384
+ * @returns {object} 方法配置
385
+ * @private
386
+ */
387
+ Drive.prototype._getConfigFromQuery = function (query) {
388
+ var m_key = this.config.method;
389
+ if (m_key) {
390
+ var md = query[m_key];
391
+ if (md) {
392
+ return this.config[md];
393
+ }
394
+ }
395
+ return null;
396
+ };
397
+
398
+ /**
399
+ * 检查查询参数
400
+ * @param {object} query url参数集合
401
+ * @param {object} config 方法配置
402
+ * @returns {string|undefined} 返回验证结果
403
+ * @private
404
+ */
405
+ Drive.prototype._checkQueryParams = function (query, config) {
406
+ var arr = this._getParamList(config['query'], query);
407
+ var arr_query = config['query_required'] || [];
408
+ arr.addList(arr_query);
409
+ return this.checkSub(query, arr, arr_query);
410
+ };
411
+
412
+ /**
413
+ * 处理不需要的Body参数
414
+ * @param {object} config 方法配置
415
+ * @param {object} body 正文参数集合
416
+ * @private
417
+ */
418
+ Drive.prototype._processBodyNot = function (config, body) {
419
+ var ar = config['body_not'];
420
+ if (ar && body && ar.length > 0) {
421
+ for (var i = 0; i < ar.length; i++) {
422
+ delete body[ar[i]];
423
+ }
424
+ }
425
+ };
426
+
427
+ /**
428
+ * 检查Body参数
429
+ * @param {object} body 正文参数集合
430
+ * @param {object} config 方法配置
431
+ * @returns {string|undefined} 返回验证结果
432
+ * @private
433
+ */
434
+ Drive.prototype._checkBodyParams = function (body, config) {
435
+ var arr = this._getParamList(config['body'], body);
436
+ var arr_body = config['body_required'] || [];
437
+ arr.addList(arr_body);
438
+ return this.checkSub(body, arr, arr_body);
439
+ };
440
+
441
+ /**
442
+ * 获取参数列表
443
+ * @param {Array} configArr 配置中的参数数组
444
+ * @param {object} params 参数集合
445
+ * @returns {Array} 参数列表
446
+ * @private
447
+ */
448
+ Drive.prototype._getParamList = function (configArr, params) {
449
+ if (configArr && configArr.length > 0) {
450
+ return configArr;
451
+ }
452
+ var arr = [];
453
+ for (var k in params) {
454
+ if (arr.indexOf(k) === -1) {
455
+ arr.push(k);
456
+ }
457
+ }
458
+ return arr;
459
+ };
460
+
461
+ /**
462
+ * 取字段
463
+ * @param {object} model 验证模型
464
+ * @returns {string} 返回名称
465
+ */
466
+ Drive.prototype.title = function (model) {
467
+ if (!model.title) {
468
+ return model.name + ' ';
469
+ } else {
470
+ return model.title + '(' + model.name + ') ';
471
+ }
472
+ };
473
+
474
+ /**
475
+ * 验证回调函数
476
+ * @param {object} model 当前的验证模型
477
+ * @param {object} value 当前的验证值
478
+ * @returns {object} 没通过返回信息,否则返回空
479
+ */
480
+ Drive.prototype.main = function (model, value) {
481
+ return null;
482
+ };
483
+
484
+ /**
485
+ * 获取模型
486
+ * @param {string} type 模型类型
487
+ * @returns {object} 返回获取到的模型
488
+ */
489
+ Drive.prototype.getModel = function (type) {
490
+ let model = { ...this.config };
491
+ let dir = this._getDir();
492
+ let l = $.slash;
493
+ let app_name = dir.between('app' + l, l);
494
+ let plugin_name = dir.between('plugin' + l, l);
495
+ let name = dir.basename();
496
+ model.app = app_name;
497
+ model.plugin = plugin_name;
498
+ model.name = model.name || app_name + '_' + name;
499
+ return model;
500
+ };
501
+
502
+ module.exports = Drive;
@@ -0,0 +1,155 @@
1
+ const Manager = require('mm_machine').Manager;
2
+ const Drive = require('./drive');
3
+
4
+ /**
5
+ * 参数类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Param extends Manager {
10
+ /**
11
+ * 配置参数
12
+ * @type {object}
13
+ */
14
+ static config = {
15
+ /**
16
+ * 名称
17
+ * @type {string}
18
+ */
19
+ name: '',
20
+ /**
21
+ * 标题
22
+ * @type {string}
23
+ */
24
+ title: '参数管理',
25
+ /**
26
+ * 描述
27
+ * @type {string}
28
+ */
29
+ description: '这是参数管理器',
30
+ /**
31
+ * 检索文件名
32
+ * @type {string}
33
+ */
34
+ filename: 'param.json',
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: '../common/param'.fullname(__dirname),
45
+ /**
46
+ * 自定义目录,加载项目自定义资源
47
+ * @type {string}
48
+ */
49
+ dir: './app'.fullname(),
50
+ /**
51
+ * 搜索模式 dir按目录搜索 | file按文件名搜索
52
+ * @type {string}
53
+ */
54
+ search_way: 'file',
55
+ /**
56
+ * 是否懒加载
57
+ * @type {boolean}
58
+ */
59
+ lazy_load: true,
60
+ /**
61
+ * 模式
62
+ * 1.生产模式,改变文件不会重新加载
63
+ * 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
64
+ * 3.热重载模式,改变配置文件都会加载配置和脚本
65
+ * 4.重载模式,执行完后重新加载脚本,避免变量污染
66
+ * 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
67
+ * @type {number}
68
+ */
69
+ mode: 3
70
+ };
71
+
72
+ /**
73
+ * 构造函数
74
+ * @param {object} config 配置参数
75
+ * @param {object} parent 父级模块
76
+ */
77
+ constructor(config, parent) {
78
+ super({ ...Param.config, ...config }, parent);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 参数驱动类
84
+ * @type {Drive}
85
+ */
86
+ Param.prototype.Drive = Drive;
87
+
88
+ /**
89
+ * 排序
90
+ */
91
+ Param.prototype.sort = function() {
92
+ let infos = this.getInfos();
93
+ infos.sortBy('asc', 'name');
94
+ };
95
+
96
+ /**
97
+ * 配置对象或配置路径
98
+ * @param {object} db 数据库管理器 (object) 只支持可用sql语句的数据库
99
+ * @param {string} name 名称
100
+ * @param {object} query url参数
101
+ * @param {object} body 正文参数
102
+ * @returns {object} 验证失败返回错误信息,成功返回null
103
+ */
104
+ Param.prototype.run = async function(db, name, query, body) {
105
+ var obj = this.get(name);
106
+ if (obj) {
107
+ // 检查参数状态,状态为0时跳过执行
108
+ if (obj.config && obj.config.state === 0) {
109
+ return null;
110
+ }
111
+ try {
112
+ return await obj.run(db, query, body);
113
+ } catch (error) {
114
+ // 参数验证异常时返回null
115
+ return null;
116
+ }
117
+ }
118
+ return null;
119
+ };
120
+
121
+ exports.Param = Param;
122
+
123
+
124
+ /**
125
+ * Param参数池
126
+ */
127
+ if (!$.pool.param) {
128
+ $.pool.param = {};
129
+ }
130
+
131
+ /**
132
+ * Param管理器,用于创建缓存
133
+ * @param {string} scope 作用域
134
+ * @param {string} title 标题
135
+ * @returns {object} 返回一个缓存类
136
+ */
137
+ function paramAdmin(scope, title) {
138
+ var sc = scope || $.val.scope + '';
139
+ var obj = $.pool.param[sc];
140
+ if (!obj) {
141
+ $.pool.param[sc] = new Param({
142
+ name: sc,
143
+ title: title
144
+ });
145
+ obj = $.pool.param[sc];
146
+ }
147
+ return obj;
148
+ }
149
+
150
+ /**
151
+ * @module 导出Param管理器
152
+ */
153
+ if ($.admin) {
154
+ $.admin.param = paramAdmin;
155
+ }
@@ -0,0 +1,12 @@
1
+
2
+ /**
3
+ * 验证主函数
4
+ * @param {object} model 当前的验证模型
5
+ * @param {object} value 当前的验证值
6
+ * @returns {object} 没通过返回错误信息,否则返回空
7
+ */
8
+ function main(model, value) {
9
+ return null;
10
+ };
11
+
12
+ exports.main = main;
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "pendant",
3
+ "title": "挂件管理器",
4
+ "state": 1
5
+ }