mm_os 3.3.1 → 4.0.0

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 +491 -99
  3. package/README_EN.md +498 -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 +58 -58
  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,405 @@
1
+ const Item = require('mm_machine').Drive;
2
+
3
+ /**
4
+ * 延迟
5
+ * @param {number} milli_seconds 毫秒
6
+ */
7
+ function sleep(milli_seconds) {
8
+ var end_time = new Date().getTime() + milli_seconds;
9
+ while (new Date().getTime() < end_time) { }
10
+ }
11
+
12
+ /**
13
+ * 计算时间差
14
+ * @param {string} start_time 开始时间
15
+ * @param {string} end_time 结束时间
16
+ * @returns {number} 返回间隔时长
17
+ */
18
+ function span(start_time, end_time) {
19
+ var stime = Date.parse(start_time);
20
+ var etime = Date.parse(end_time);
21
+ return etime - stime;
22
+ };
23
+
24
+ /**
25
+ * 转为时间
26
+ * @param {string} time_str 时间字符串
27
+ * @returns {Date} 时间类型
28
+ */
29
+ function toTime(time_str) {
30
+ var str = time_str.replace('T', ' ').replace('Z', '').replaceAll('.', '/').replaceAll('-', '/');
31
+ return new Date(str);
32
+ };
33
+
34
+ /**
35
+ * 定时器类函数
36
+ */
37
+ class Drive extends Item {
38
+ static config = {
39
+ // 应用名称 例如:demo_app
40
+ 'app': 'server',
41
+ // 插件名称 例如:demo_plugin
42
+ 'plugin': 'sys',
43
+ // 执行次数
44
+ 'num': 10,
45
+ // 时间间隔(毫秒ms)
46
+ 'interval': 1000,
47
+ // 等待时长(毫秒ms)
48
+ 'wait': 0,
49
+ // 执行时间
50
+ 'time': '',
51
+ // 执行开始日期
52
+ 'date_start': '',
53
+ // 执行结束日期
54
+ 'date_end': ''
55
+ };
56
+
57
+ /**
58
+ * 构造函数
59
+ * @param {object} config 配置参数
60
+ * @param {object} parent 父对象
61
+ * @class
62
+ */
63
+ constructor(config, parent) {
64
+ super({ ...Drive.config, ...config }, parent);
65
+
66
+ // 更新配置并重载脚本
67
+ this.mode = 3;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * 预设
73
+ */
74
+ Drive.prototype._preset = function () {
75
+ /// 状态
76
+ this.state = 'start';
77
+ /// 等候器
78
+ this.timeout;
79
+ /// 定时执行器
80
+ this.interval;
81
+ /// 当前执行次数
82
+ this.num = 1;
83
+ };
84
+
85
+ /**
86
+ * 设置等待执行
87
+ * @param {Function} func 回调函数
88
+ */
89
+ Drive.prototype.setTimeout = function (func) {
90
+ if (func) {
91
+ this.timeout = setTimeout(func, this.config.wait);
92
+ }
93
+ };
94
+
95
+ /**
96
+ * 设置间隔执行
97
+ * @param {Function} func 回调函数
98
+ */
99
+ Drive.prototype.setInterval = async function (func) {
100
+ sleep(this.config.wait);
101
+ this.interval = setInterval(func, this.config.interval);
102
+ };
103
+
104
+ /**
105
+ * 创建时间匹配函数
106
+ * @param {string} time 时间字符串
107
+ * @param {Function} func 回调函数
108
+ * @returns {Function} 时间匹配函数
109
+ */
110
+ Drive.prototype._createTimeFn = function (time, func) {
111
+ if (!time) return func;
112
+ if (time.indexOf(' ') !== -1) {
113
+ return this._createDateTimeFn(time, func);
114
+ }
115
+ return this._createTimeOnlyFn(time, func);
116
+ };
117
+
118
+ /**
119
+ * 创建日期时间匹配函数
120
+ * @param {string} time 时间字符串
121
+ * @param {Function} func 回调函数
122
+ * @returns {Function} 时间匹配函数
123
+ */
124
+ Drive.prototype._createDateTimeFn = function (time, func) {
125
+ if (time.indexOf('-') !== -1) {
126
+ var arr = time.split('-');
127
+ var fmt = arr.length > 2 ? 'yyyy-MM-dd hh:mm:ss' : 'MM-dd hh:mm:ss';
128
+ return function () {
129
+ if (new Date().toStr(fmt) === time) func();
130
+ };
131
+ }
132
+ var arr = time.split(':');
133
+ var fmt = arr.length == 3 ? 'dd hh:mm:ss' : (arr.length == 2 ? 'dd hh:mm' : 'dd hh');
134
+ return function () {
135
+ if (new Date().toStr(fmt) === time) func();
136
+ };
137
+ };
138
+
139
+ /**
140
+ * 创建仅时间匹配函数
141
+ * @param {string} time 时间字符串
142
+ * @param {Function} func 回调函数
143
+ * @returns {Function} 时间匹配函数
144
+ */
145
+ Drive.prototype._createTimeOnlyFn = function (time, func) {
146
+ var arr = time.split(':');
147
+ var fmt = arr.length == 3 ? 'hh:mm:ss' : (arr.length == 2 ? 'hh:mm' : 'mm');
148
+ return function () {
149
+ if (new Date().toStr(fmt) === time) func();
150
+ };
151
+ };
152
+
153
+ /**
154
+ * 创建带开始时间的执行函数
155
+ * @param {Function} fn 原始函数
156
+ * @param {number} start 开始时间
157
+ * @param {number} end 结束时间
158
+ * @returns {Function} 执行函数
159
+ */
160
+ Drive.prototype._createStartFn = function (fn, start, end) {
161
+ var _this = this;
162
+ if (end) {
163
+ return function () {
164
+ var now = new Date();
165
+ if (span(now, end) >= 0 && span(now, start) <= 0) fn();
166
+ else if (span(now, end) < 0) {
167
+ _this.clearSub();
168
+ _this.notify(_this.config.name, 'time_end');
169
+ }
170
+ };
171
+ }
172
+ return function () {
173
+ if (span(new Date(), start) <= 0) fn();
174
+ };
175
+ };
176
+
177
+ /**
178
+ * 创建带结束时间的执行函数
179
+ * @param {Function} fn 原始函数
180
+ * @param {number} end 结束时间
181
+ * @returns {Function} 执行函数
182
+ */
183
+ Drive.prototype._createEndFn = function (fn, end) {
184
+ var _this = this;
185
+ return function () {
186
+ if (span(new Date(), end) >= 0) fn();
187
+ else {
188
+ _this.clearSub();
189
+ _this.notify(_this.config.name, 'time_end');
190
+ }
191
+ };
192
+ };
193
+
194
+ /**
195
+ * 设置时期执行
196
+ * @param {Function} func 回调函数
197
+ * @returns {object} 执行结果
198
+ */
199
+ Drive.prototype.setPeriod = function (func) {
200
+ var cg = this.config;
201
+ var fn = this._createTimeFn(cg.time, func);
202
+ if (cg.date_start) {
203
+ return this._createStartFn(fn, toTime(cg.date_start), cg.date_end ? toTime(cg.date_end) : null);
204
+ }
205
+ if (cg.date_end) {
206
+ return this._createEndFn(fn, toTime(cg.date_end));
207
+ }
208
+ return fn;
209
+ };
210
+
211
+ /**
212
+ * 设置按次数执行
213
+ * @param {Function} func 回调函数
214
+ * @returns {object} 执行结果
215
+ */
216
+ Drive.prototype.setNum = function (func) {
217
+ var _this = this;
218
+ return function () {
219
+ if (_this.state === 'start') {
220
+ try {
221
+ if (_this.config.num < 1) {
222
+ func();
223
+ } else if (_this.num < _this.config.num) {
224
+ func();
225
+ _this.num += 1;
226
+ } else {
227
+ func();
228
+ _this.clear();
229
+ _this.notify(_this.config.name, 'completed');
230
+ }
231
+ } catch (err) {
232
+ _this.log('error', '定时任务执行失败!', _this.config.name, err);
233
+ }
234
+ }
235
+ };
236
+ };
237
+
238
+ /**
239
+ * 结束定时器
240
+ */
241
+ Drive.prototype.end = function () {
242
+ // 当前状态为结束
243
+ this.state = 'end';
244
+ this.notify(this.config.name, 'suspend');
245
+ this.clear();
246
+ };
247
+
248
+ /**
249
+ * 清除定时器(子函数)
250
+ */
251
+ Drive.prototype.clearSub = function () {
252
+ if (this.interval) {
253
+ clearInterval(this.interval);
254
+ }
255
+ if (this.timeout) {
256
+ clearTimeout(this.timeout);
257
+ }
258
+ };
259
+
260
+ /**
261
+ * 清除定时器
262
+ * @param {number} millisecond 时间间隔, 单位: 毫秒
263
+ */
264
+ Drive.prototype.clear = function (millisecond) {
265
+ if (millisecond) {
266
+ var _this = this;
267
+ setTimeout(() => {
268
+ _this.clearSub();
269
+ }, millisecond);
270
+ } else {
271
+ this.clearSub();
272
+ }
273
+ };
274
+
275
+ /**
276
+ * 执行线程
277
+ * @returns {object} 当前类
278
+ */
279
+ Drive.prototype.main = async function () {
280
+ this.log('debug', '定时任务(默认), 执行中...');
281
+ };
282
+
283
+ /**
284
+ * 执行线程
285
+ * @param {Function} func 回调函数
286
+ * @returns {object} 当前类
287
+ */
288
+ Drive.prototype.run = async function (func) {
289
+ this.init();
290
+ if (func) {
291
+ await this.setInterval(this.setPeriod(this.setNum(func)));
292
+ } else {
293
+ await this.setInterval(this.setPeriod(this.setNum(() => {
294
+ this.main();
295
+ })));
296
+ }
297
+ return this;
298
+ };
299
+
300
+ /**
301
+ * 初始化定时器
302
+ */
303
+ Drive.prototype.init = function () {
304
+ // 当前执行次数
305
+ this.num = 1;
306
+ // 当前状态为开启
307
+ this.state = 'start';
308
+ this.notify(this.config.name, 'init');
309
+ };
310
+
311
+ /**
312
+ * 启动定时器
313
+ */
314
+ Drive.prototype.start = function () {
315
+ // 当前状态为开启
316
+ this.state = 'start';
317
+ this.notify(this.config.name, 'start');
318
+ };
319
+
320
+ /**
321
+ * 暂停定时器
322
+ */
323
+ Drive.prototype.stop = function () {
324
+ // 当前状态为开启
325
+ this.state = 'stop';
326
+ this.notify(this.config.name, 'stop');
327
+ };
328
+
329
+ /**
330
+ * 通知函数, 当定时器执行完最后一次时, 会调用通知函数
331
+ * @param {string} name 名称
332
+ * @param {string} state 状态
333
+ */
334
+ Drive.prototype.notify = function (name, state) {
335
+ // switch (state) {
336
+ // case "init":
337
+ // this.log('debug', '初始化');
338
+ // break;
339
+ // case "start":
340
+ // this.log('debug', '开始执行');
341
+ // break;
342
+ // case "stop":
343
+ // this.log('debug', '已暂停');
344
+ // break;
345
+ // case "suspend":
346
+ // // 主动中断
347
+ // this.log('debug', '已中断');
348
+ // break;
349
+ // case "time_end":
350
+ // this.log('debug', '已到期');
351
+ // break;
352
+ // case "completed":
353
+ // this.log('debug', '已完成');
354
+ // break;
355
+ // default:
356
+ // break;
357
+ // }
358
+ };
359
+
360
+ /**
361
+ * 销毁资源
362
+ */
363
+ Drive.prototype.dispose = function () {
364
+ this.clearSub();
365
+ this.interval = undefined;
366
+ this.timeout = undefined;
367
+ };
368
+
369
+ /**
370
+ * 获取插件
371
+ * @param {string} app 应用名称
372
+ * @param {string} name 插件名称
373
+ * @returns {object} 返回获取到的插件
374
+ */
375
+ Drive.prototype.plugin = function (app, name) {
376
+ var l = $.slash;
377
+ var app_name = app || this.config_file.between('app' + l, l);
378
+ var plugin_name = name || this.config_file.between('plugin' + l, l);
379
+ var plus;
380
+ var plugins = $.pool.plugin[app_name];
381
+ if (plugins) {
382
+ plus = plugins.get(plugin_name);
383
+ }
384
+ return plus;
385
+ };
386
+
387
+ /**
388
+ * 获取模型
389
+ * @param {string} type 模型类型
390
+ * @returns {object} 返回获取到的模型
391
+ */
392
+ Drive.prototype.getModel = function (type) {
393
+ let model = { ...this.config };
394
+ let dir = this._getDir();
395
+ let l = $.slash;
396
+ let app_name = dir.between('app' + l, l);
397
+ let plugin_name = dir.between('plugin' + l, l);
398
+ let name = dir.basename();
399
+ model.app = app_name;
400
+ model.plugin = plugin_name;
401
+ model.name = model.name || app_name + '_' + name;
402
+ return model;
403
+ };
404
+
405
+ module.exports = Drive;
@@ -0,0 +1,148 @@
1
+ const Manager = require('mm_machine').Manager;
2
+ const Drive = require('./drive');
3
+
4
+ /**
5
+ * 任务类
6
+ * @augments {Manager}
7
+ * @class
8
+ */
9
+ class Task 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: 'task.json',
35
+ /**
36
+ * 模板目录
37
+ * @type {string}
38
+ */
39
+ tpl_dir: __dirname,
40
+ /**
41
+ * 基础目录
42
+ * @type {string}
43
+ */
44
+ base_dir: '../common/task'.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: false,
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({ ...Task.config, ...config }, parent);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 任务驱动类
84
+ * @type {Drive}
85
+ */
86
+ Task.prototype.Drive = Drive;
87
+
88
+ /**
89
+ * 执行任务
90
+ * @param {string} name 要执行的名称
91
+ */
92
+ Task.prototype.run = async function (name) {
93
+ if (name) {
94
+ let mod = this.getMod(name);
95
+ if (mod) {
96
+ await mod.run();
97
+ }
98
+ } else {
99
+ let infos = this.getInfos();
100
+ for (var i = 0, info; info = infos[i++];) {
101
+ if (info.state === 1) {
102
+ try {
103
+ let mod = this.getMod(info.name);
104
+ if (mod) {
105
+ await mod.run();
106
+ }
107
+ } catch (error) {
108
+ this.log('error', '定时任务错误', info.name, error);
109
+ }
110
+ }
111
+ }
112
+ }
113
+ };
114
+
115
+ exports.Task = Task;
116
+
117
+ /**
118
+ * Task模板池
119
+ */
120
+ if (!$.pool.task) {
121
+ $.pool.task = {};
122
+ }
123
+
124
+ /**
125
+ * Task管理器,用于创建缓存
126
+ * @param {string} scope 作用域
127
+ * @param {string} title 标题
128
+ * @returns {object} 返回一个缓存类
129
+ */
130
+ function taskAdmin(scope, title) {
131
+ var sc = scope || $.val.scope + '';
132
+ var obj = $.pool.task[sc];
133
+ if (!obj) {
134
+ $.pool.task[sc] = new Task({
135
+ name: sc,
136
+ title: title
137
+ });
138
+ obj = $.pool.task[sc];
139
+ }
140
+ return obj;
141
+ }
142
+
143
+ /**
144
+ * @module 导出Task管理器
145
+ */
146
+ if ($.admin) {
147
+ $.admin.task = taskAdmin;
148
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 定时任务函数
3
+ */
4
+ exports.main = async function main() {
5
+ this.log('debug', '定时任务, 执行中...');
6
+ };
7
+
8
+ /**
9
+ * 执行结果通知
10
+ * @param {string} name 任务名称
11
+ * @param {string} state 状态
12
+ */
13
+ exports.notify = async function(name, state) {
14
+ switch (state) {
15
+ case 'init':
16
+ this.log('debug', '任务-初始化');
17
+ break;
18
+ case 'start':
19
+ this.log('debug', '任务-开始执行');
20
+ break;
21
+ case 'stop':
22
+ this.log('debug', '任务-已暂停');
23
+ break;
24
+ case 'suspend':
25
+ // 主动中断
26
+ this.log('debug', '任务-已中断');
27
+ break;
28
+ case 'time_end':
29
+ this.log('debug', '任务-已到期');
30
+ break;
31
+ case 'completed':
32
+ this.log('debug', '任务-已完成');
33
+ break;
34
+ default:
35
+ break;
36
+ }
37
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "模板管理器",
3
+ "script": "./index.js",
4
+ "state": 1
5
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ // 模板名称
3
+ "name": "",
4
+ // 模板标题
5
+ "title": "",
6
+ // 描述
7
+ "description": "",
8
+ // 版本号
9
+ "version": "1.0.0",
10
+ // 预览图片
11
+ "preview": "",
12
+ // 预览图片(大图)
13
+ "preview_large": "",
14
+ // git仓库地址
15
+ "git": ""
16
+ }
@@ -0,0 +1,80 @@
1
+ const compressing = require('compressing');
2
+ const Item = require('mm_machine').Item;
3
+
4
+ /**
5
+ * 主题模板驱动类
6
+ * @extends {Item}
7
+ * @class
8
+ */
9
+ class Drive extends Item {
10
+ static config = {
11
+ "name": "",
12
+ "title": "",
13
+ "preview": "",
14
+ "preview_large": "",
15
+ "description": "",
16
+ "version": "1.0.0",
17
+ "git": ""
18
+ };
19
+
20
+ /**
21
+ * 主题模板驱动类
22
+ * @param {object} config 主题模板配置
23
+ * @param {object} parent 父项
24
+ */
25
+ constructor(config, parent) {
26
+ super({ ...Drive.config, ...config }, parent);
27
+ // this.default_file = "./template.json";
28
+ // dir, "/static/template".fullname()
29
+ }
30
+ }
31
+
32
+ /**
33
+ * 压缩主题模板
34
+ */
35
+ Drive.prototype.zip = async function (zip_dir = "/static/file/zip/") {
36
+ var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
37
+ file.addDir();
38
+ var done = await compressing.zip.compressDir(this._getDir(), file);
39
+ if (file.hasFile()) {
40
+ return file;
41
+ }
42
+ return null;
43
+ };
44
+
45
+ /**
46
+ * 下载主题模板包
47
+ */
48
+ Drive.prototype.download = async function () {
49
+
50
+ };
51
+
52
+ /**
53
+ * 更新主题模板
54
+ */
55
+ Drive.prototype.update = async function () {
56
+
57
+ };
58
+
59
+ /**
60
+ * 获取模型
61
+ * @param {string} type 模型类型
62
+ * @returns {object} 返回获取到的模型
63
+ */
64
+ Drive.prototype.getModel = function (type) {
65
+ let model = { ...this.config };
66
+ let dir = this._getDir();
67
+ let l = $.slash;
68
+ let app_name = dir.between('app' + l, l);
69
+ let plugin_name = dir.between('plugin' + l, l);
70
+ let name = dir.basename();
71
+ model.app = app_name;
72
+ model.plugin = plugin_name;
73
+ model.name = model.name || app_name + '_' + name;
74
+ return model;
75
+ };
76
+
77
+ module.exports = {
78
+ Drive
79
+ };
80
+