mm_os 1.3.4 → 1.3.5
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.en.md +36 -0
- package/README.md +25 -166
- package/conf.json +3 -0
- package/core/base/index.js +29 -0
- package/core/base/mqtt/index.js +268 -0
- package/core/base/mqtt/lib.js +40 -0
- package/core/base/web/index.js +110 -0
- package/core/com/api/com.json +4 -0
- package/{bin → core}/com/api/config.tpl.json +9 -7
- package/{bin → core}/com/api/drive.js +239 -64
- package/{bin → core}/com/api/index.js +8 -9
- package/{bin → core}/com/api/oauth.js +23 -14
- package/core/com/api/script.js +32 -0
- package/core/com/db/com.json +4 -0
- package/{bin → core}/com/db/drive.js +99 -65
- package/{bin → core}/com/db/index.js +2 -2
- package/core/com/event/com.json +4 -0
- package/{bin → core}/com/event/config.tpl.json +2 -2
- package/core/com/event/drive.js +125 -0
- package/{bin → core}/com/event/index.js +5 -10
- package/core/com/event/script.js +26 -0
- package/core/com/eventer/com.js +450 -0
- package/core/com/eventer/com.json +4 -0
- package/core/com/middleware/com.js +128 -0
- package/core/com/middleware/com.json +4 -0
- package/core/com/middleware/config.tpl.json +8 -0
- package/core/com/middleware/script.js +9 -0
- package/core/com/mqtt/com.json +4 -0
- package/core/com/mqtt/config.tpl.json +12 -0
- package/core/com/mqtt/drive.js +139 -0
- package/core/com/mqtt/index.js +138 -0
- package/core/com/mqtt/script.js +33 -0
- package/core/com/msg/com.js +296 -0
- package/core/com/msg/com.json +4 -0
- package/{bin → core}/com/nav/drive.js +42 -17
- package/{bin → core}/com/nav/index.js +4 -4
- package/core/com/nav/tpl/admin_pc/page_channel.vue +299 -0
- package/core/com/nav/tpl/admin_pc/page_config.vue +279 -0
- package/core/com/nav/tpl/admin_pc/page_config_form.vue +194 -0
- package/core/com/nav/tpl/admin_pc/page_default.vue +287 -0
- package/core/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/core/com/nav/tpl/admin_pc/page_lang.vue +265 -0
- package/core/com/nav/tpl/admin_pc/page_nav.vue +313 -0
- package/core/com/nav/tpl/admin_pc/page_table.vue +285 -0
- package/core/com/nav/tpl/admin_pc/page_type.vue +313 -0
- package/core/com/nav/tpl/dev_pc/page_channel.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_config.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_form.vue +162 -0
- package/core/com/nav/tpl/dev_pc/page_nav.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_table.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_type.vue +253 -0
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_pc/page_list.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_nav.vue +221 -221
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_view.vue +8 -8
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_phone/page_list.vue +231 -231
- package/{bin/com/nav/tpl/admin_pc → core/com/nav/tpl/home_phone}/page_nav.vue +236 -220
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_view.vue +8 -8
- package/core/com/nav/viewmodel.js +296 -0
- package/{bin → core}/com/param/config.tpl.json +24 -0
- package/{bin → core}/com/param/drive.js +47 -15
- package/core/com/plugin/com.json +4 -0
- package/core/com/plugin/config.tpl.json +20 -0
- package/{bin → core}/com/plugin/drive.js +5 -8
- package/{bin → core}/com/plugin/index.js +11 -56
- package/core/com/socket/README.md +47 -0
- package/core/com/socket/com.json +4 -0
- package/core/com/socket/config.tpl.json +14 -0
- package/{bin → core}/com/socket/drive.js +74 -51
- package/{bin → core}/com/socket/index.js +4 -2
- package/{bin → core}/com/socket/script.js +8 -6
- package/core/com/sql/config.tpl.json +70 -0
- package/{bin → core}/com/sql/drive.js +281 -58
- package/core/com/static/com.json +4 -0
- package/core/com/static/config.tpl.json +20 -0
- package/{bin → core}/com/static/drive.js +6 -4
- package/{bin → core}/com/static/index.js +5 -1
- package/core/com/task/com.json +4 -0
- package/core/com/task/config.tpl.json +24 -0
- package/core/com/task/drive.js +374 -0
- package/{bin → core}/com/task/index.js +14 -20
- package/core/com/task/script.js +37 -0
- package/core/com/timer/com.js +217 -0
- package/core/com/timer/com.json +4 -0
- package/core/com/tpl/com.js +19 -0
- package/core/com/tpl/com.json +4 -0
- package/index.js +161 -740
- package/lib/actions.js +50 -0
- package/lib/app.js +73 -0
- package/lib/base.js +355 -0
- package/lib/com.js +31 -0
- package/lib/game.js +31 -0
- package/lib/ref.js +121 -0
- package/middleware/cors/index.js +57 -0
- package/middleware/cors/middleware.json +7 -0
- package/middleware/mqtt_base/index.js +10 -0
- package/middleware/mqtt_base/middleware.json +8 -0
- package/{waf.js → middleware/waf/index.js} +12 -2
- package/middleware/waf/middleware.json +9 -0
- package/middleware/web_base/index.js +67 -0
- package/middleware/web_base/middleware.json +9 -0
- package/middleware/web_event/index.js +411 -0
- package/middleware/web_event/middleware.json +10 -0
- package/middleware/web_proxy/index.js +24 -0
- package/middleware/web_proxy/middleware.json +9 -0
- package/middleware/web_router/index.js +33 -0
- package/middleware/web_router/middleware.json +10 -0
- package/middleware/web_socket/index.js +21 -0
- package/middleware/web_socket/middleware.json +9 -0
- package/middleware/web_static/index.js +26 -0
- package/middleware/web_static/middleware.json +9 -0
- package/nodemon.json +12 -2
- package/package.json +56 -66
- package/.gitattributes +0 -5
- package/bin/com/README.md +0 -2
- package/bin/com/api/script.js +0 -14
- package/bin/com/cmd/README.md +0 -3
- package/bin/com/cmd/config.tpl.json +0 -41
- package/bin/com/cmd/drive.js +0 -512
- package/bin/com/cmd/index.js +0 -213
- package/bin/com/cmd/old/5w2h.js +0 -54
- package/bin/com/cmd/old/drive.js +0 -423
- package/bin/com/cmd/script.js +0 -11
- package/bin/com/event/drive.js +0 -69
- package/bin/com/event/script.js +0 -12
- package/bin/com/nav/tpl/admin_pc/page_channel.vue +0 -234
- package/bin/com/nav/tpl/admin_pc/page_default.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_form.vue +0 -152
- package/bin/com/nav/tpl/admin_pc/page_table.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_type.vue +0 -234
- package/bin/com/nav/tpl/home_phone/page_nav.vue +0 -221
- package/bin/com/nav/viewmodel.js +0 -161
- package/bin/com/plugin/config.tpl.json +0 -11
- package/bin/com/socket/config.tpl.json +0 -8
- package/bin/com/sql/config.tpl.json +0 -34
- package/bin/com/static/config.tpl.json +0 -11
- package/bin/com/task/config.tpl.json +0 -13
- package/bin/com/task/drive.js +0 -288
- package/bin/com/task/script.js +0 -38
- package/bin/com.js +0 -74
- package/bin/mm.conf +0 -48
- package/bin/static/404.html +0 -52
- package/bin/static/README.md +0 -1
- package/bin/static/css/font-awesome.min.css +0 -7
- package/bin/static/css/mm_base.css +0 -220
- package/bin/static/css/mm_common.css +0 -518
- package/bin/static/css/mm_component.css +0 -307
- package/bin/static/css/mm_expand.css +0 -634
- package/bin/static/css/mm_theme.css +0 -291
- package/bin/static/css/new_file.css +0 -79
- package/bin/static/css/swiper.min.css +0 -12
- package/bin/static/favicon.ico +0 -0
- package/bin/static/font/FontAwesome.otf +0 -0
- package/bin/static/font/HelveticaNeue.eot +0 -0
- package/bin/static/font/HelveticaNeue.otf +0 -0
- package/bin/static/font/HelveticaNeue.svg +0 -1273
- package/bin/static/font/HelveticaNeue.woff +0 -0
- package/bin/static/font/HelveticaNeue.woff2 +0 -0
- package/bin/static/font/fontawesome-webfont.eot +0 -0
- package/bin/static/font/fontawesome-webfont.svg +0 -2671
- package/bin/static/font/fontawesome-webfont.ttf +0 -0
- package/bin/static/font/fontawesome-webfont.woff +0 -0
- package/bin/static/font/fontawesome-webfont.woff2 +0 -0
- package/bin/static/h5.html +0 -325
- package/bin/static/highlight/highlight.pack.js +0 -2
- package/bin/static/highlight/styles/a11y-dark.css +0 -99
- package/bin/static/highlight/styles/a11y-light.css +0 -99
- package/bin/static/highlight/styles/agate.css +0 -108
- package/bin/static/highlight/styles/an-old-hope.css +0 -89
- package/bin/static/highlight/styles/androidstudio.css +0 -66
- package/bin/static/highlight/styles/arduino-light.css +0 -88
- package/bin/static/highlight/styles/arta.css +0 -73
- package/bin/static/highlight/styles/ascetic.css +0 -45
- package/bin/static/highlight/styles/atelier-cave-dark.css +0 -83
- package/bin/static/highlight/styles/atelier-cave-light.css +0 -85
- package/bin/static/highlight/styles/atelier-dune-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-dune-light.css +0 -69
- package/bin/static/highlight/styles/atelier-estuary-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-estuary-light.css +0 -84
- package/bin/static/highlight/styles/atelier-forest-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-forest-light.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-light.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-plateau-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-plateau-light.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-light.css +0 -84
- package/bin/static/highlight/styles/atelier-seaside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-seaside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-light.css +0 -69
- package/bin/static/highlight/styles/atom-one-dark-reasonable.css +0 -77
- package/bin/static/highlight/styles/atom-one-dark.css +0 -96
- package/bin/static/highlight/styles/atom-one-light.css +0 -96
- package/bin/static/highlight/styles/brown-paper.css +0 -64
- package/bin/static/highlight/styles/brown-papersq.png +0 -0
- package/bin/static/highlight/styles/codepen-embed.css +0 -60
- package/bin/static/highlight/styles/color-brewer.css +0 -71
- package/bin/static/highlight/styles/darcula.css +0 -77
- package/bin/static/highlight/styles/dark.css +0 -63
- package/bin/static/highlight/styles/darkula.css +0 -6
- package/bin/static/highlight/styles/default.css +0 -99
- package/bin/static/highlight/styles/docco.css +0 -97
- package/bin/static/highlight/styles/dracula.css +0 -76
- package/bin/static/highlight/styles/far.css +0 -71
- package/bin/static/highlight/styles/foundation.css +0 -88
- package/bin/static/highlight/styles/github-gist.css +0 -79
- package/bin/static/highlight/styles/github.css +0 -99
- package/bin/static/highlight/styles/gml.css +0 -78
- package/bin/static/highlight/styles/googlecode.css +0 -89
- package/bin/static/highlight/styles/grayscale.css +0 -101
- package/bin/static/highlight/styles/gruvbox-dark.css +0 -108
- package/bin/static/highlight/styles/gruvbox-light.css +0 -108
- package/bin/static/highlight/styles/hopscotch.css +0 -83
- package/bin/static/highlight/styles/hybrid.css +0 -102
- package/bin/static/highlight/styles/idea.css +0 -97
- package/bin/static/highlight/styles/ir-black.css +0 -73
- package/bin/static/highlight/styles/isbl-editor-dark.css +0 -112
- package/bin/static/highlight/styles/isbl-editor-light.css +0 -112
- package/bin/static/highlight/styles/kimbie.dark.css +0 -74
- package/bin/static/highlight/styles/kimbie.light.css +0 -74
- package/bin/static/highlight/styles/lightfair.css +0 -87
- package/bin/static/highlight/styles/magula.css +0 -70
- package/bin/static/highlight/styles/mono-blue.css +0 -59
- package/bin/static/highlight/styles/monokai-sublime.css +0 -83
- package/bin/static/highlight/styles/monokai.css +0 -70
- package/bin/static/highlight/styles/nord.css +0 -309
- package/bin/static/highlight/styles/obsidian.css +0 -88
- package/bin/static/highlight/styles/ocean.css +0 -74
- package/bin/static/highlight/styles/paraiso-dark.css +0 -72
- package/bin/static/highlight/styles/paraiso-light.css +0 -72
- package/bin/static/highlight/styles/pojoaque.css +0 -83
- package/bin/static/highlight/styles/pojoaque.jpg +0 -0
- package/bin/static/highlight/styles/purebasic.css +0 -96
- package/bin/static/highlight/styles/qtcreator_dark.css +0 -83
- package/bin/static/highlight/styles/qtcreator_light.css +0 -83
- package/bin/static/highlight/styles/railscasts.css +0 -106
- package/bin/static/highlight/styles/rainbow.css +0 -85
- package/bin/static/highlight/styles/routeros.css +0 -108
- package/bin/static/highlight/styles/school-book.css +0 -69
- package/bin/static/highlight/styles/school-book.png +0 -0
- package/bin/static/highlight/styles/shades-of-purple.css +0 -97
- package/bin/static/highlight/styles/solarized-dark.css +0 -84
- package/bin/static/highlight/styles/solarized-light.css +0 -84
- package/bin/static/highlight/styles/sunburst.css +0 -102
- package/bin/static/highlight/styles/tomorrow-night-blue.css +0 -75
- package/bin/static/highlight/styles/tomorrow-night-bright.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night-eighties.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night.css +0 -75
- package/bin/static/highlight/styles/tomorrow.css +0 -72
- package/bin/static/highlight/styles/vs.css +0 -68
- package/bin/static/highlight/styles/vs2015.css +0 -115
- package/bin/static/highlight/styles/xcode.css +0 -104
- package/bin/static/highlight/styles/xt256.css +0 -92
- package/bin/static/highlight/styles/zenburn.css +0 -80
- package/bin/static/highlight/vue-highlight.js +0 -29
- package/bin/static/ifame.html +0 -24
- package/bin/static/img/add.png +0 -0
- package/bin/static/img/avatar.png +0 -0
- package/bin/static/img/banner_2.png +0 -0
- package/bin/static/img/default.png +0 -0
- package/bin/static/img/loading.svg +0 -1
- package/bin/static/img/logo.png +0 -0
- package/bin/static/img/logo1.png +0 -0
- package/bin/static/img/logo_gray.png +0 -0
- package/bin/static/img/logo_round.png +0 -0
- package/bin/static/img/mm.ico +0 -0
- package/bin/static/img/mm.jpg +0 -0
- package/bin/static/img/select.png +0 -0
- package/bin/static/img/web.png +0 -0
- package/bin/static/index.html +0 -12
- package/bin/static/js/clipboard.min.js +0 -257
- package/bin/static/js/css.min.js +0 -1
- package/bin/static/js/echarts.js +0 -22
- package/bin/static/js/html5.min.js +0 -1
- package/bin/static/js/jquery.lazyload.min.js +0 -2
- package/bin/static/js/jquery.min.js +0 -4189
- package/bin/static/js/jquery.scrollstop.min.js +0 -2
- package/bin/static/js/mm-requirejs-vue.js +0 -283
- package/bin/static/js/mm_check.js +0 -490
- package/bin/static/js/mm_flexble.js +0 -112
- package/bin/static/js/mm_picker.js +0 -1417
- package/bin/static/js/mm_pinyinlite.js +0 -873
- package/bin/static/js/mm_sdk.js +0 -2841
- package/bin/static/js/mm_ui_expand.js +0 -468
- package/bin/static/js/mm_vue.js +0 -376
- package/bin/static/js/mm_vue_ui.js +0 -2375
- package/bin/static/js/mm_websocket.js +0 -145
- package/bin/static/js/require.js +0 -5
- package/bin/static/js/sortable.min.js +0 -3
- package/bin/static/js/swiper.min.js +0 -13
- package/bin/static/js/text.min.js +0 -1
- package/bin/static/js/vue-router.min.js +0 -6
- package/bin/static/js/vue.js +0 -12338
- package/bin/static/js/vuedraggable.min.js +0 -2
- package/bin/static/js/vuex.min.js +0 -6
- package/bin/static/src/components/bar/mm_action.vue +0 -19
- package/bin/static/src/components/bar/mm_buy.vue +0 -19
- package/bin/static/src/components/bar/mm_chat.vue +0 -18
- package/bin/static/src/components/bar/mm_count.vue +0 -18
- package/bin/static/src/components/bar/mm_filter.vue +0 -18
- package/bin/static/src/components/bar/mm_search.vue +0 -18
- package/bin/static/src/components/bar/mm_sort.vue +0 -18
- package/bin/static/src/components/bar/mm_tag.vue +0 -18
- package/bin/static/src/components/bar/mm_title.vue +0 -19
- package/bin/static/src/components/content/mm_pre.vue +0 -70
- package/bin/static/src/components/expand/mm_drag.vue +0 -39
- package/bin/static/src/components/item/mm_article.vue +0 -115
- package/bin/static/src/components/item/mm_base.vue +0 -26
- package/bin/static/src/components/item/mm_contact.vue +0 -25
- package/bin/static/src/components/item/mm_goods.vue +0 -23
- package/bin/static/src/components/item/mm_img.vue +0 -21
- package/bin/static/src/components/item/mm_media.vue +0 -18
- package/bin/static/src/components/item/mm_message.vue +0 -18
- package/bin/static/src/components/item/mm_music.vue +0 -95
- package/bin/static/src/components/item/mm_news.vue +0 -22
- package/bin/static/src/components/item/mm_number.vue +0 -26
- package/bin/static/src/components/item/mm_question.vue +0 -35
- package/bin/static/src/components/item/mm_user.vue +0 -22
- package/bin/static/src/components/item/mm_video.vue +0 -95
- package/bin/static/src/components/slide/mm_slide_card.vue +0 -64
- package/bin/static/src/components/slide/mm_slide_img.vue +0 -47
- package/bin/static/src/components/slide/mm_slide_page.vue +0 -8
- package/bin/static/src/components/slide/mm_slide_text.vue +0 -54
- package/bin/static/src/main.js +0 -84
- package/bin/static/src/mixins/form.js +0 -223
- package/bin/static/src/mixins/item.js +0 -242
- package/bin/static/src/mixins/list.js +0 -244
- package/bin/static/src/mixins/page.js +0 -1011
- package/bin/static/src/mm_component.js +0 -74
- package/bin/static/src/router.js +0 -72
- package/bin/static/src/store/user.js +0 -75
- package/bin/static/src/store/web.js +0 -50
- package/bin/static/user/1/number_info.xlsx +0 -0
- package/bin/static/w3c.html +0 -94
- package/init.js +0 -55
- package/update.md +0 -1
- /package/{bin → core}/com/api/README.md +0 -0
- /package/{bin → core}/com/api/rpc.js +0 -0
- /package/{bin → core}/com/db/README.md +0 -0
- /package/{bin → core}/com/event/README.md +0 -0
- /package/{bin/com/socket → core/com/mqtt}/README.md +0 -0
- /package/{bin → core}/com/nav/README.md +0 -0
- /package/{bin → core}/com/nav/config.tpl.json +0 -0
- /package/{bin → core}/com/param/README.md +0 -0
- /package/{bin → core}/com/param/index.js +0 -0
- /package/{bin → core}/com/param/script.js +0 -0
- /package/{bin → core}/com/param/test.js +0 -0
- /package/{bin → core}/com/plugin/README.md +0 -0
- /package/{bin → core}/com/plugin/script.js +0 -0
- /package/{bin → core}/com/sql/README.md +0 -0
- /package/{bin → core}/com/sql/index.js +0 -0
- /package/{bin → core}/com/sql/script.js +0 -0
- /package/{bin → core}/com/static/README.md +0 -0
- /package/{bin → core}/com/static/script.js +0 -0
- /package/{bin → core}/com/task/README.md +0 -0
- /package/{bin/rps.bat → rps.bat} +0 -0
- /package/{bin/tps.bat → tps.bat} +0 -0
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
const {
|
|
2
|
+
types
|
|
3
|
+
} = require("node:util");
|
|
4
|
+
|
|
5
|
+
class Eventer {
|
|
6
|
+
/**
|
|
7
|
+
* 构造函数
|
|
8
|
+
* @param {Object} config 配置参数
|
|
9
|
+
*/
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.dict = {};
|
|
12
|
+
this.list_add = [];
|
|
13
|
+
this.list_del = [];
|
|
14
|
+
this.autoId = 1;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 模型
|
|
20
|
+
*/
|
|
21
|
+
Eventer.prototype.model = function() {
|
|
22
|
+
return {
|
|
23
|
+
// 定时器ID
|
|
24
|
+
id: 0,
|
|
25
|
+
// 消息类型
|
|
26
|
+
type: "发动攻击时",
|
|
27
|
+
// 时态
|
|
28
|
+
tense: "main",
|
|
29
|
+
// 总执行次数 -1为无限次
|
|
30
|
+
count: 0,
|
|
31
|
+
// 执行次数
|
|
32
|
+
num: 0,
|
|
33
|
+
// 状态 1启用,2暂停,0结束
|
|
34
|
+
state: 1,
|
|
35
|
+
// 参数
|
|
36
|
+
param: {},
|
|
37
|
+
// 回调函数
|
|
38
|
+
func: function() {}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 添加事件
|
|
44
|
+
* @param {String} type 事件类型
|
|
45
|
+
* @param {Function} func 回调函数
|
|
46
|
+
* @param {Object} param 回调附加参数
|
|
47
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|main执行|after执行后
|
|
48
|
+
* @param {Number} count 执行次数
|
|
49
|
+
*/
|
|
50
|
+
Eventer.prototype.add = function(type, func, param, tense, count = -1) {
|
|
51
|
+
var id = this.autoId;
|
|
52
|
+
var info = {
|
|
53
|
+
id,
|
|
54
|
+
type,
|
|
55
|
+
tense: tense || "main",
|
|
56
|
+
num: 0,
|
|
57
|
+
state: 1,
|
|
58
|
+
count,
|
|
59
|
+
param,
|
|
60
|
+
func
|
|
61
|
+
};
|
|
62
|
+
this.list_add.push(info);
|
|
63
|
+
this.autoId++;
|
|
64
|
+
return id;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 执行全部事件前
|
|
69
|
+
*/
|
|
70
|
+
Eventer.prototype.do_before = function() {
|
|
71
|
+
// 追加事件
|
|
72
|
+
var list = this.list_add;
|
|
73
|
+
for (var i = 0; i < list.length; i++) {
|
|
74
|
+
var o = list[i];
|
|
75
|
+
var dt = this.dict[o.type];
|
|
76
|
+
if (!dt) {
|
|
77
|
+
this.dict[o.type] = {
|
|
78
|
+
before: [],
|
|
79
|
+
check: [],
|
|
80
|
+
main: [],
|
|
81
|
+
after: []
|
|
82
|
+
};
|
|
83
|
+
dt = this.dict[o.type];
|
|
84
|
+
}
|
|
85
|
+
var lt = dt[o.tense];
|
|
86
|
+
if (lt) {
|
|
87
|
+
lt.add(o);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
this.list_add.clear();
|
|
91
|
+
|
|
92
|
+
// 移除事件
|
|
93
|
+
var list = this.list_del;
|
|
94
|
+
for (var i = 0; i < list.length; i++) {
|
|
95
|
+
var o = list[i];
|
|
96
|
+
var dt = this.dict[o.type];
|
|
97
|
+
if (dt) {
|
|
98
|
+
var lt = dt[o.tense];
|
|
99
|
+
if (lt) {
|
|
100
|
+
lt.del({
|
|
101
|
+
id: o.id
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (!dt.before.length && !dt.check.length && !dt.main.length && !dt.after.length) {
|
|
105
|
+
delete this.dict[o.type];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.list_del.clear();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 执行全部事件后
|
|
114
|
+
*/
|
|
115
|
+
Eventer.prototype.do_after = function() {
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 执行事件
|
|
121
|
+
*/
|
|
122
|
+
Eventer.prototype.doing = async function(o, msg) {
|
|
123
|
+
o.num++;
|
|
124
|
+
var ret;
|
|
125
|
+
try {
|
|
126
|
+
ret = o.func(msg, o.param, o.num);
|
|
127
|
+
if (types.isPromise(ret)) {
|
|
128
|
+
ret = await ret;
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
console.error(err);
|
|
132
|
+
}
|
|
133
|
+
if (o.num === o.count) {
|
|
134
|
+
this.list_del.push(o.id);
|
|
135
|
+
}
|
|
136
|
+
return ret;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 运行事件
|
|
141
|
+
* @param {Array} list 列表
|
|
142
|
+
* @param {String} type 类型
|
|
143
|
+
* @param {Object} msg 事件消息
|
|
144
|
+
* @param {Boolean} isBreak 是否中断
|
|
145
|
+
*/
|
|
146
|
+
Eventer.prototype.run_sub = async function(list, msg, isBreak = false) {
|
|
147
|
+
var ret;
|
|
148
|
+
if (list) {
|
|
149
|
+
for (var i = 0; i < list.length; i++) {
|
|
150
|
+
var o = list[i];
|
|
151
|
+
// 判断是否启用状态
|
|
152
|
+
if (o.state == 1) {
|
|
153
|
+
// 判断是否还需要执行
|
|
154
|
+
if (o.count < 0 || o.num < o.count) {
|
|
155
|
+
ret = await this.doing(o, msg);
|
|
156
|
+
if (ret && isBreak) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} else if (!o.state) {
|
|
161
|
+
this.list_del.push({
|
|
162
|
+
id: o.id,
|
|
163
|
+
type: o.type,
|
|
164
|
+
tense: o.tense
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return ret;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 运行事件
|
|
174
|
+
* @param {String} type 类型
|
|
175
|
+
* @param {Object} msg 事件消息
|
|
176
|
+
*/
|
|
177
|
+
Eventer.prototype.run = async function(type, msg) {
|
|
178
|
+
this.do_before();
|
|
179
|
+
var ret;
|
|
180
|
+
var dt = this.dict[type];
|
|
181
|
+
if (dt) {
|
|
182
|
+
ret = await this.run_sub(dt.before, msg, false);
|
|
183
|
+
ret = await this.run_sub(dt.check, msg, true);
|
|
184
|
+
if (ret) {
|
|
185
|
+
return ret
|
|
186
|
+
}
|
|
187
|
+
ret = await this.run_sub(dt.main, msg, false);
|
|
188
|
+
if (ret) {
|
|
189
|
+
var ret_new = await this.run_sub(dt.after, msg, false);
|
|
190
|
+
ret = ret_new || ret;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.do_after();
|
|
194
|
+
return ret;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 设置状态
|
|
199
|
+
* @param {Array} lt
|
|
200
|
+
* @param {Object} id
|
|
201
|
+
* @param {Object} state
|
|
202
|
+
*/
|
|
203
|
+
Eventer.prototype.setState_sub = function(lt, id, state) {
|
|
204
|
+
var obj;
|
|
205
|
+
if (lt) {
|
|
206
|
+
if (id) {
|
|
207
|
+
// 如果传入了ID,处理该ID事项
|
|
208
|
+
obj = lt.getObj({
|
|
209
|
+
id
|
|
210
|
+
});
|
|
211
|
+
if (obj) {
|
|
212
|
+
obj.state = state;
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
// 否则全部处理
|
|
216
|
+
for (var i = 0; i < lt.length; i++) {
|
|
217
|
+
var o = lt[i];
|
|
218
|
+
o.state = state;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return obj;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 设置事件状态
|
|
227
|
+
* @param {Number} id 类型
|
|
228
|
+
* @param {String} type 类型
|
|
229
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|main执行|after执行后
|
|
230
|
+
* @param {Number} state 状态
|
|
231
|
+
*/
|
|
232
|
+
Eventer.prototype.setState = function(id, type, tense, state) {
|
|
233
|
+
if (type) {
|
|
234
|
+
// 如果传入了类型,处理该类事件
|
|
235
|
+
var dt = this.dict[type];
|
|
236
|
+
var obj;
|
|
237
|
+
if (dt) {
|
|
238
|
+
if (tense) {
|
|
239
|
+
// 如果传入了时态,处理该事件下该时态的事
|
|
240
|
+
obj = this.setState_sub(dt[tense], id, state);
|
|
241
|
+
} else {
|
|
242
|
+
obj = this.setState_sub(dt.before, id, state);
|
|
243
|
+
if (!obj) {
|
|
244
|
+
obj = this.setState_sub(dt.check, id, state);
|
|
245
|
+
if (!obj) {
|
|
246
|
+
obj = this.setState_sub(dt.main, id, state);
|
|
247
|
+
if (!obj) {
|
|
248
|
+
obj = this.setState_sub(dt.after, id, state);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (obj) {
|
|
255
|
+
obj.state = state;
|
|
256
|
+
} else {
|
|
257
|
+
if (id) {
|
|
258
|
+
obj = this.list_add.getObj({
|
|
259
|
+
id
|
|
260
|
+
});
|
|
261
|
+
if (obj) {
|
|
262
|
+
obj.state = state;
|
|
263
|
+
}
|
|
264
|
+
} else if (tense) {
|
|
265
|
+
var lt = this.list_add.get({
|
|
266
|
+
type,
|
|
267
|
+
tense
|
|
268
|
+
});
|
|
269
|
+
for (var i = 0; i < lt.length; i++) {
|
|
270
|
+
var o = lt[i];
|
|
271
|
+
o.state = state;
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
var lt = this.list_add.get({
|
|
275
|
+
type
|
|
276
|
+
});
|
|
277
|
+
for (var i = 0; i < lt.length; i++) {
|
|
278
|
+
var o = lt[i];
|
|
279
|
+
o.state = state;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
var obj;
|
|
285
|
+
for (var k in this.dict) {
|
|
286
|
+
var dt = this.dict[k];
|
|
287
|
+
if (dt) {
|
|
288
|
+
if (tense) {
|
|
289
|
+
obj = this.setState_sub(dt[tense], id, state);
|
|
290
|
+
} else {
|
|
291
|
+
obj = this.setState_sub(dt.before, id, state);
|
|
292
|
+
if (!obj) {
|
|
293
|
+
obj = this.setState_sub(dt.check, id, state);
|
|
294
|
+
if (!obj) {
|
|
295
|
+
obj = this.setState_sub(dt.main, id, state);
|
|
296
|
+
if (!obj) {
|
|
297
|
+
obj = this.setState_sub(dt.after, id, state);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (obj) {
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!obj) {
|
|
308
|
+
if (id) {
|
|
309
|
+
obj = this.list_add.getObj({
|
|
310
|
+
id
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (obj) {
|
|
315
|
+
obj.state = state;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 开启
|
|
322
|
+
* @param {Number|String} id 名称或ID
|
|
323
|
+
* @param {String} type 事件类型
|
|
324
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
325
|
+
*/
|
|
326
|
+
Eventer.prototype.start = function(id, type, tense) {
|
|
327
|
+
this.setState(id, type, tense, 1);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 暂停
|
|
332
|
+
* @param {Number|String} id 名称或ID
|
|
333
|
+
* @param {String} type 事件类型
|
|
334
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
335
|
+
*/
|
|
336
|
+
Eventer.prototype.stop = function(id, type, tense) {
|
|
337
|
+
this.setState(id, type, tense, 2);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* 结束
|
|
342
|
+
* @param {Number|String} id 名称或ID
|
|
343
|
+
* @param {String} type 事件类型
|
|
344
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
345
|
+
*/
|
|
346
|
+
Eventer.prototype.end = function(id, type, tense) {
|
|
347
|
+
this.setState(id, type, tense, 0);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 删除事件-子程序
|
|
352
|
+
* @param {Object} lt
|
|
353
|
+
*/
|
|
354
|
+
Eventer.prototype.del_sub = function(lt) {
|
|
355
|
+
if (lt) {
|
|
356
|
+
for (var i = 0; i < lt.length; i++) {
|
|
357
|
+
var o = lt[i];
|
|
358
|
+
this.list_del.push({
|
|
359
|
+
id: o.id,
|
|
360
|
+
type: o.type,
|
|
361
|
+
tense: o.tense
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* 删除事件
|
|
369
|
+
* @param {Number|String} id 名称或ID
|
|
370
|
+
* @param {String} type 事件类型
|
|
371
|
+
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
372
|
+
*/
|
|
373
|
+
Eventer.prototype.del = function(id, type, tense) {
|
|
374
|
+
if (type) {
|
|
375
|
+
if (id) {
|
|
376
|
+
if (tense) {
|
|
377
|
+
this.list_del.push({
|
|
378
|
+
id,
|
|
379
|
+
type,
|
|
380
|
+
tense
|
|
381
|
+
});
|
|
382
|
+
} else {
|
|
383
|
+
this.list_del.push({
|
|
384
|
+
id,
|
|
385
|
+
type,
|
|
386
|
+
tense: "before"
|
|
387
|
+
});
|
|
388
|
+
this.list_del.push({
|
|
389
|
+
id,
|
|
390
|
+
type,
|
|
391
|
+
tense: "check"
|
|
392
|
+
});
|
|
393
|
+
this.list_del.push({
|
|
394
|
+
id,
|
|
395
|
+
type,
|
|
396
|
+
tense: "main"
|
|
397
|
+
});
|
|
398
|
+
this.list_del.push({
|
|
399
|
+
id,
|
|
400
|
+
type,
|
|
401
|
+
tense: "after"
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
} else {
|
|
405
|
+
var dt = this.dict[type];
|
|
406
|
+
if (dt) {
|
|
407
|
+
if (tense) {
|
|
408
|
+
this.del_sub(dt[tense]);
|
|
409
|
+
} else {
|
|
410
|
+
this.del_sub(dt.before);
|
|
411
|
+
this.del_sub(dt.check);
|
|
412
|
+
this.del_sub(dt.main);
|
|
413
|
+
this.del_sub(dt.after);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} else if (id) {
|
|
418
|
+
var obj;
|
|
419
|
+
for (var k in this.dict) {
|
|
420
|
+
var dt = this.dict[k];
|
|
421
|
+
if (dt) {
|
|
422
|
+
for (var t in dt) {
|
|
423
|
+
var lt = dt[t];
|
|
424
|
+
if (lt) {
|
|
425
|
+
obj = lt.getObj({
|
|
426
|
+
id
|
|
427
|
+
});
|
|
428
|
+
if (obj) {
|
|
429
|
+
break
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
if (!obj) {
|
|
436
|
+
obj = this.list_add.getObj({
|
|
437
|
+
id
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
if (obj) {
|
|
441
|
+
obj.state = 0;
|
|
442
|
+
this.list_del.push({
|
|
443
|
+
id: obj.id,
|
|
444
|
+
type: obj.type
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
module.exports = Eventer;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
class Middleware {
|
|
2
|
+
/**
|
|
3
|
+
* 构造函数
|
|
4
|
+
* @param {Object} config 配置参数
|
|
5
|
+
*/
|
|
6
|
+
constructor(config) {
|
|
7
|
+
// 中间件列表
|
|
8
|
+
this.list = [];
|
|
9
|
+
|
|
10
|
+
this.config = Object.assign({
|
|
11
|
+
path: "./middleware".fullname($.runPath),
|
|
12
|
+
file: "middleware.json",
|
|
13
|
+
mode: "web"
|
|
14
|
+
}, config);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 新建脚本
|
|
21
|
+
* @param {String} 文件
|
|
22
|
+
*/
|
|
23
|
+
Middleware.prototype.new_script = function(file) {
|
|
24
|
+
var fl = __dirname + "/script.js";
|
|
25
|
+
if (fl.hasFile()) {
|
|
26
|
+
var text = fl.loadText();
|
|
27
|
+
if (text) {
|
|
28
|
+
var l = $.slash;
|
|
29
|
+
if (file.indexOf('middleware' + l) !== -1) {
|
|
30
|
+
var name = file.between('middleware' + l, l);
|
|
31
|
+
text = text.replaceAll("{0}", name);
|
|
32
|
+
}
|
|
33
|
+
file.saveText(text);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 新建配置
|
|
40
|
+
* @param {String} 文件
|
|
41
|
+
*/
|
|
42
|
+
Middleware.prototype.new_config = function(file) {
|
|
43
|
+
var fl = __dirname + "/config.tpl.json";
|
|
44
|
+
if (fl.hasFile()) {
|
|
45
|
+
var text = fl.loadText();
|
|
46
|
+
if (text) {
|
|
47
|
+
var l = $.slash;
|
|
48
|
+
if (file.indexOf('middleware' + l) !== -1) {
|
|
49
|
+
var name = file.between('middleware' + l, l);
|
|
50
|
+
text = text.replaceAll("{0}", name);
|
|
51
|
+
}
|
|
52
|
+
file.saveText(text);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 加载配置
|
|
59
|
+
* @param {String} file 配置文件路径
|
|
60
|
+
*/
|
|
61
|
+
Middleware.prototype.load = function(file) {
|
|
62
|
+
var f = this.config.file;
|
|
63
|
+
var config = file.loadJson();
|
|
64
|
+
if (config) {
|
|
65
|
+
var cg = this.list.getObj({
|
|
66
|
+
name: config.name
|
|
67
|
+
});
|
|
68
|
+
if (cg) {
|
|
69
|
+
$.push(cg, config, true);
|
|
70
|
+
} else {
|
|
71
|
+
cg = {
|
|
72
|
+
func_file: file.replace(f, 'index.js')
|
|
73
|
+
}
|
|
74
|
+
$.push(cg, config, true);
|
|
75
|
+
this.list.push(cg);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
this.new_config(file);
|
|
79
|
+
}
|
|
80
|
+
var script_file = file.replace('middleware.json', 'index.js');
|
|
81
|
+
if (!script_file.hasFile()) {
|
|
82
|
+
this.new_script(script_file);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 遍历加载配置
|
|
88
|
+
* @param {Object} path
|
|
89
|
+
*/
|
|
90
|
+
Middleware.prototype.each_load = function(path) {
|
|
91
|
+
if (path.hasDir()) {
|
|
92
|
+
var dirs = $.dir.getAll(path);
|
|
93
|
+
// 遍历目录路径
|
|
94
|
+
var file = this.config.file;
|
|
95
|
+
dirs.map((d) => {
|
|
96
|
+
this.load(d + file);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 排序
|
|
103
|
+
*/
|
|
104
|
+
Middleware.prototype.sort = function() {
|
|
105
|
+
return this.list.sortBy('asc', 'sort');
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 遍历加载配置
|
|
110
|
+
*/
|
|
111
|
+
Middleware.prototype.init = function(path) {
|
|
112
|
+
this.each_load("../../../middleware/".fullname(__dirname));
|
|
113
|
+
if (path) {
|
|
114
|
+
this.each_load(path);
|
|
115
|
+
}
|
|
116
|
+
this.each_load(this.config.path);
|
|
117
|
+
var p = "./middleware".fullname($.runPath);
|
|
118
|
+
if (this.config.path !== p) {
|
|
119
|
+
this.each_load(p);
|
|
120
|
+
}
|
|
121
|
+
this.sort();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (!$.middleware) {
|
|
125
|
+
$.middleware = new Middleware();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = Middleware;
|