mm_os 1.3.4 → 1.3.6
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
package/lib/actions.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const Ref = require("./ref.js");
|
|
2
|
+
|
|
3
|
+
class Action {
|
|
4
|
+
constructor(obj) {
|
|
5
|
+
return this.init(obj);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 实例对象
|
|
11
|
+
* @param {Object} obj
|
|
12
|
+
*/
|
|
13
|
+
Action.prototype.ref = function(obj) {
|
|
14
|
+
return new Ref(obj);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 初始化
|
|
19
|
+
* @param {Object} obj
|
|
20
|
+
*/
|
|
21
|
+
Action.prototype.init = function(obj) {
|
|
22
|
+
var act = this.ref(obj);
|
|
23
|
+
return new Proxy(act, {
|
|
24
|
+
get: (target, prop) => {
|
|
25
|
+
var value = target[prop];
|
|
26
|
+
if (value !== undefined) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
value = target.data[prop];
|
|
30
|
+
if (value !== undefined) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
return target.methods[prop];
|
|
34
|
+
},
|
|
35
|
+
set: function(target, prop, value) {
|
|
36
|
+
if (target[prop] !== undefined) {
|
|
37
|
+
target[prop] = value;
|
|
38
|
+
} else if (target.data[prop] !== undefined) {
|
|
39
|
+
target.data[prop] = value;
|
|
40
|
+
} else if (target.methods[prop] !== undefined) {
|
|
41
|
+
target.methods[prop] = value;
|
|
42
|
+
} else {
|
|
43
|
+
target[prop] = value;
|
|
44
|
+
}
|
|
45
|
+
return true
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = Action;
|
package/lib/app.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const Base = require("./base.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 应用管理器
|
|
5
|
+
*/
|
|
6
|
+
class App extends Base {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.path = "/app".fullname();
|
|
10
|
+
// 文件拓展名
|
|
11
|
+
this.extension = "app.json";
|
|
12
|
+
// 文件存放目录
|
|
13
|
+
this.dir = "/app";
|
|
14
|
+
// 重新加载
|
|
15
|
+
this.reload = false;
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 补全脚本
|
|
22
|
+
* @param {Object} action
|
|
23
|
+
*/
|
|
24
|
+
App.prototype.fullAction = function(action) {
|
|
25
|
+
if (action.data.state === undefined) {
|
|
26
|
+
action.data.state = 1;
|
|
27
|
+
}
|
|
28
|
+
if (!action.methods.init_before) {
|
|
29
|
+
action.init_before = function() {
|
|
30
|
+
// 创建插件
|
|
31
|
+
this.plugin = $.plugin_admin(action.key, action.name + "插件");
|
|
32
|
+
this.plugin.update(action.jsonFile.dirname());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return action;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 应用管理器初始化后
|
|
40
|
+
*/
|
|
41
|
+
App.prototype.init_after = function() {
|
|
42
|
+
for (var k in this.dict) {
|
|
43
|
+
var cs = this.dict[k];
|
|
44
|
+
var key = cs.jsonFile.dirname().basename();
|
|
45
|
+
cs.key = key;
|
|
46
|
+
this[key] = cs;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 初始化应用
|
|
52
|
+
*/
|
|
53
|
+
App.prototype.initApp = async function() {
|
|
54
|
+
for (var k in this.dict) {
|
|
55
|
+
var o = this.dict[k];
|
|
56
|
+
if (o.state) {
|
|
57
|
+
try {
|
|
58
|
+
await o.run('init');
|
|
59
|
+
} catch (e) {
|
|
60
|
+
$.log.error("初始化应用错误", e);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 安装应用
|
|
68
|
+
*/
|
|
69
|
+
App.prototype.install = async function(name, ...args) {
|
|
70
|
+
return await this.exec(name, 'install', ...args);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = App;
|
package/lib/base.js
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
const conf = require("mm_config");
|
|
2
|
+
const Actions = require("./actions.js");
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
function rmdir(dir) {
|
|
7
|
+
var list = fs.readdirSync(dir);
|
|
8
|
+
for (var i = 0; i < list.length; i++) {
|
|
9
|
+
var filename = path.join(dir, list[i]);
|
|
10
|
+
var stat = fs.statSync(filename);
|
|
11
|
+
|
|
12
|
+
if (filename == "." || filename == "..") {
|
|
13
|
+
// pass these files
|
|
14
|
+
} else if (stat.isDirectory()) {
|
|
15
|
+
// rmdir recursively
|
|
16
|
+
rmdir(filename);
|
|
17
|
+
} else {
|
|
18
|
+
// rm fiilename
|
|
19
|
+
fs.unlinkSync(filename);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
fs.rmdirSync(dir);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 系统基础类
|
|
27
|
+
*/
|
|
28
|
+
class Base {
|
|
29
|
+
/**
|
|
30
|
+
* 构造函数
|
|
31
|
+
*/
|
|
32
|
+
constructor() {
|
|
33
|
+
// 字典
|
|
34
|
+
this.dict = {};
|
|
35
|
+
// 检索路径
|
|
36
|
+
this.path = "";
|
|
37
|
+
// 文件拓展名
|
|
38
|
+
this.extension = "*.json";
|
|
39
|
+
// 检索路径
|
|
40
|
+
this.dir = "/data";
|
|
41
|
+
// 重新加载
|
|
42
|
+
this.reload = true;
|
|
43
|
+
// 识别用的主键
|
|
44
|
+
this.key = "name";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Base.prototype.init_after = function() {
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 初始化地区
|
|
54
|
+
* @param {Boolean} reset 是否重新初始化,true则全部重新初始化
|
|
55
|
+
*/
|
|
56
|
+
Base.prototype.init = function(reset = false) {
|
|
57
|
+
var files = this.getFiles();
|
|
58
|
+
for (var i = 0; i < files.length; i++) {
|
|
59
|
+
var file = files[i];
|
|
60
|
+
this.load(file, reset);
|
|
61
|
+
}
|
|
62
|
+
this.init_after(reset);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 获取文件
|
|
67
|
+
*/
|
|
68
|
+
Base.prototype.getFiles = function() {
|
|
69
|
+
var files = [];
|
|
70
|
+
if (this.path) {
|
|
71
|
+
// 模块自带路径
|
|
72
|
+
var path = "../core".fullname(__dirname);
|
|
73
|
+
files = $.file.getAll(path, this.extension);
|
|
74
|
+
// 自定义路径
|
|
75
|
+
var path_2 = this.path.fullname(__dirname);
|
|
76
|
+
path_2.addDir();
|
|
77
|
+
var files_2 = $.file.getAll(path_2, this.extension);
|
|
78
|
+
files.addList(files_2);
|
|
79
|
+
}
|
|
80
|
+
return files;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 脚本实例
|
|
85
|
+
* @param {Object} obj 对象
|
|
86
|
+
*/
|
|
87
|
+
Base.prototype.script = function(obj) {
|
|
88
|
+
return new Actions(obj);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 补全脚本
|
|
93
|
+
* @param {Object} action
|
|
94
|
+
*/
|
|
95
|
+
Base.prototype.fullAction = function(action) {
|
|
96
|
+
return action;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 加载配置及脚本程序
|
|
101
|
+
* @param {String} jsonFile 配置文件名
|
|
102
|
+
* @param {Boolean} reload 是否重载,true为重载
|
|
103
|
+
*/
|
|
104
|
+
Base.prototype.load = function(jsonFile, reload = false) {
|
|
105
|
+
if (jsonFile.indexOf($.slash + "tpl") !== -1) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
// 加载json配置
|
|
109
|
+
var m = this.loadJson(jsonFile);
|
|
110
|
+
if (m) {
|
|
111
|
+
var cache = {};
|
|
112
|
+
var methods = {};
|
|
113
|
+
var jsFile;
|
|
114
|
+
// 加载脚本
|
|
115
|
+
if (m.script) {
|
|
116
|
+
if (m.script.indexOf(this.dir) === 0) {
|
|
117
|
+
jsFile = ("." + m.script).fullname($.gamePath);
|
|
118
|
+
} else {
|
|
119
|
+
jsFile = m.script.fullname(jsonFile.dirname());
|
|
120
|
+
}
|
|
121
|
+
if (!jsFile.hasFile()) {
|
|
122
|
+
jsFile = "";
|
|
123
|
+
}
|
|
124
|
+
var js;
|
|
125
|
+
if (reload) {
|
|
126
|
+
js = this.reLoadJS(jsFile);
|
|
127
|
+
} else {
|
|
128
|
+
js = this.loadJS(jsFile);
|
|
129
|
+
}
|
|
130
|
+
cache = js.cache;
|
|
131
|
+
methods = js.methods;
|
|
132
|
+
}
|
|
133
|
+
var action = this.script({
|
|
134
|
+
data: m,
|
|
135
|
+
methods
|
|
136
|
+
});
|
|
137
|
+
for (var k in cache) {
|
|
138
|
+
action[k] = cache[k]
|
|
139
|
+
}
|
|
140
|
+
action.jsonFile = jsonFile;
|
|
141
|
+
this.dict[m[this.key]] = this.fullAction(action);
|
|
142
|
+
return this.dict[m[this.key]];
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 加载JSON配置
|
|
149
|
+
* @param {String} file 文件名
|
|
150
|
+
*/
|
|
151
|
+
Base.prototype.loadJson = function(file) {
|
|
152
|
+
return conf(file.loadJson(), file);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 加载JS
|
|
157
|
+
* @param {String} file 文件名
|
|
158
|
+
*/
|
|
159
|
+
Base.prototype.loadJS = function(file) {
|
|
160
|
+
var cache = {};
|
|
161
|
+
var methods = {};
|
|
162
|
+
if (file && file.hasFile()) {
|
|
163
|
+
try {
|
|
164
|
+
var js = require(file);
|
|
165
|
+
if (js) {
|
|
166
|
+
for (var k in js) {
|
|
167
|
+
var val = js[k];
|
|
168
|
+
if (typeof(val) == "function") {
|
|
169
|
+
methods[k] = val
|
|
170
|
+
} else {
|
|
171
|
+
cache[k] = val
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
cache.jsFile = file;
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error("loadJS error", file);
|
|
178
|
+
console.error(err);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
cache,
|
|
183
|
+
methods
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 卸载JS
|
|
189
|
+
* @param {String} file 文件名
|
|
190
|
+
*/
|
|
191
|
+
Base.prototype.unLoadJS = function(file) {
|
|
192
|
+
// 用完后卸载模块
|
|
193
|
+
var name = require.resolve(file);
|
|
194
|
+
delete require.cache[name];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 重新加载JS
|
|
199
|
+
* @param {String} file 文件名
|
|
200
|
+
*/
|
|
201
|
+
Base.prototype.reLoadJS = function(file) {
|
|
202
|
+
// 先卸载
|
|
203
|
+
this.unLoadJS(file);
|
|
204
|
+
// 再加载
|
|
205
|
+
return this.loadJS(file);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* 查询索引
|
|
210
|
+
*/
|
|
211
|
+
Base.prototype.index = function() {
|
|
212
|
+
var arr = [];
|
|
213
|
+
var rx = /[\u4e00-\u9fa5]/g;
|
|
214
|
+
for (var k in this.dict) {
|
|
215
|
+
if (rx.test(k)) {
|
|
216
|
+
arr.push(k);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return arr;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 查询
|
|
224
|
+
* @param {String} name 名称或ID
|
|
225
|
+
* @param {Object} model 默认对象
|
|
226
|
+
*/
|
|
227
|
+
Base.prototype.get = function(name, model) {
|
|
228
|
+
var obj = this.dict[name];
|
|
229
|
+
if (!obj) {
|
|
230
|
+
if (model) {
|
|
231
|
+
return this.add(name, model);
|
|
232
|
+
} else {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return obj;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 获取类
|
|
241
|
+
* @param {String} query 查询条件
|
|
242
|
+
*/
|
|
243
|
+
Base.prototype.getClass = function(query) {
|
|
244
|
+
var cs;
|
|
245
|
+
for (var k in this.dict) {
|
|
246
|
+
var o = this.dict[k];
|
|
247
|
+
if ($.as(o, query)) {
|
|
248
|
+
cs = o;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return cs;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* 运行脚本
|
|
257
|
+
* @param {String} name 名称
|
|
258
|
+
* @param {String} func_name 执行方法
|
|
259
|
+
* @param {Object} args 参数集合
|
|
260
|
+
* @returns {Object} 返回执行结果
|
|
261
|
+
*/
|
|
262
|
+
Base.prototype.run = function(name, func_name, ...args) {
|
|
263
|
+
var tip;
|
|
264
|
+
var cs = this.dict[name];
|
|
265
|
+
if (cs) {
|
|
266
|
+
if (!cs.jsFile) {
|
|
267
|
+
return "执行错误!原因:脚本文件不存在!\n" + cs.script;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
// var act = Object.assign({}, cs);
|
|
271
|
+
tip = cs.run(func_name, ...args);
|
|
272
|
+
} catch (e) {
|
|
273
|
+
console.error(e);
|
|
274
|
+
tip = "执行错误!原因:" + e.message;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (this.reload) {
|
|
278
|
+
if (process.env.NODE_ENV == "development" || $.config.mode == "dev") {
|
|
279
|
+
// 用完后重载模块
|
|
280
|
+
var {
|
|
281
|
+
methods,
|
|
282
|
+
cache
|
|
283
|
+
} = this.reLoadJS(cs.jsFile);
|
|
284
|
+
cs.methods = methods;
|
|
285
|
+
for (var k in cache) {
|
|
286
|
+
cs[k] = cache[k]
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
tip = `【${name}】不存在!`
|
|
292
|
+
}
|
|
293
|
+
return tip;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 创建
|
|
298
|
+
* @param {String} name 名称
|
|
299
|
+
* @param {Object} model 数据模型
|
|
300
|
+
*/
|
|
301
|
+
Base.prototype.add = function(name, model) {
|
|
302
|
+
var file = ("./" + name + "/" + this.extension).fullname(this.path);
|
|
303
|
+
file.addDir();
|
|
304
|
+
var f = file.replace($.slash + name + $.slash, $.slash + 'tpl' + $.slash);
|
|
305
|
+
var m = f.loadJson();
|
|
306
|
+
if (model) {
|
|
307
|
+
model = Object.assign(m || {}, model, {
|
|
308
|
+
name
|
|
309
|
+
});
|
|
310
|
+
} else {
|
|
311
|
+
model = Object.assign(m || {}, {
|
|
312
|
+
name
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
file.saveJson(model);
|
|
316
|
+
return this.load(file);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 删除
|
|
321
|
+
* @param {String} idOrName
|
|
322
|
+
*/
|
|
323
|
+
Base.prototype.del = function(idOrName) {
|
|
324
|
+
var obj = this.dict[idOrName];
|
|
325
|
+
if (!obj) {
|
|
326
|
+
return idOrName + " 不存在!";
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
var dir = obj.jsonFile.dirname();
|
|
330
|
+
rmdir(dir);
|
|
331
|
+
delete this.dict[idOrName];
|
|
332
|
+
} catch (err) {
|
|
333
|
+
$.log.error("删除应用失败", err);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* 修改
|
|
339
|
+
* @param {String} idOrName 唯一标识或名称
|
|
340
|
+
* @param {Object} model 模型
|
|
341
|
+
* @returns 返回true或false
|
|
342
|
+
*/
|
|
343
|
+
Base.prototype.set = function(idOrName, model) {
|
|
344
|
+
if (model) {
|
|
345
|
+
var obj = this.dict[idOrName];
|
|
346
|
+
if (obj) {
|
|
347
|
+
Object.assign(obj, model);
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
return `【${idOrName}】不存在!`;
|
|
351
|
+
}
|
|
352
|
+
return "要修改的数据不能为空!";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
module.exports = Base;
|
package/lib/com.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const Base = require("./base.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 公共开发
|
|
5
|
+
*/
|
|
6
|
+
class Com extends Base {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.path = "/com".fullname();
|
|
10
|
+
// 文件拓展名
|
|
11
|
+
this.extension = "com.json";
|
|
12
|
+
// 文件存放目录
|
|
13
|
+
this.dir = "/com";
|
|
14
|
+
// 重新加载
|
|
15
|
+
this.reload = false;
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 公共初始化后
|
|
22
|
+
*/
|
|
23
|
+
Com.prototype.init_after = function() {
|
|
24
|
+
for (var k in this.dict) {
|
|
25
|
+
var cs = this.dict[k];
|
|
26
|
+
var key = cs.jsonFile.dirname().basename();
|
|
27
|
+
this[key] = cs;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = Com;
|
package/lib/game.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const Base = require("./base.js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 游戏管理器
|
|
5
|
+
*/
|
|
6
|
+
class Game extends Base {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.path = "/game".fullname();
|
|
10
|
+
// 文件拓展名
|
|
11
|
+
this.extension = "game.json";
|
|
12
|
+
// 文件存放目录
|
|
13
|
+
this.dir = "/game";
|
|
14
|
+
// 重新加载
|
|
15
|
+
this.reload = false;
|
|
16
|
+
this.init();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 游戏管理器初始化后
|
|
22
|
+
*/
|
|
23
|
+
Game.prototype.init_after = function() {
|
|
24
|
+
for (var k in this.dict) {
|
|
25
|
+
var cs = this.dict[k];
|
|
26
|
+
var key = cs.jsonFile.dirname().basename();
|
|
27
|
+
this[key] = cs;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = Game;
|
package/lib/ref.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const {
|
|
2
|
+
types
|
|
3
|
+
} = require("util");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 行为器
|
|
7
|
+
*/
|
|
8
|
+
class Ref {
|
|
9
|
+
/**
|
|
10
|
+
* 构造函数
|
|
11
|
+
* @param {Object} obj 对象
|
|
12
|
+
*/
|
|
13
|
+
constructor(obj) {
|
|
14
|
+
this.msg = [];
|
|
15
|
+
this._init(obj);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 初始化
|
|
21
|
+
* @param {Object} config 配置参数
|
|
22
|
+
* @returns {Object} 执行结果
|
|
23
|
+
*/
|
|
24
|
+
Ref.prototype._init = function(obj) {
|
|
25
|
+
Object.assign(this, obj);
|
|
26
|
+
this.data = this.data || {};
|
|
27
|
+
this.methods = this.methods || {};
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 运行当前类函数
|
|
33
|
+
* @param {String} name 函数名
|
|
34
|
+
* @param {Object} args 参数集合
|
|
35
|
+
* @returns {Object} 执行结果
|
|
36
|
+
*/
|
|
37
|
+
Ref.prototype.run = async function(name, ...args) {
|
|
38
|
+
var ret;
|
|
39
|
+
var key = name + "_before";
|
|
40
|
+
if (this[key]) {
|
|
41
|
+
ret = this[key](...args);
|
|
42
|
+
if (types.isPromise(ret)) {
|
|
43
|
+
ret = await ret
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
key = name + "_check";
|
|
47
|
+
if (this[key]) {
|
|
48
|
+
ret = this[key](...args);
|
|
49
|
+
if (types.isPromise(ret)) {
|
|
50
|
+
ret = await ret
|
|
51
|
+
}
|
|
52
|
+
if (ret) {
|
|
53
|
+
return ret;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (this[name]) {
|
|
58
|
+
ret = this[name](...args);
|
|
59
|
+
if (types.isPromise(ret)) {
|
|
60
|
+
ret = await ret
|
|
61
|
+
}
|
|
62
|
+
if (ret) {
|
|
63
|
+
key = name + "_after";
|
|
64
|
+
if (this[key]) {
|
|
65
|
+
ret = this[key](...args);
|
|
66
|
+
if (types.isPromise(ret)) {
|
|
67
|
+
ret = await ret
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return ret;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 执行子脚本函数
|
|
77
|
+
* @param {String} name 名称
|
|
78
|
+
* @param {String} func_name 执行方法
|
|
79
|
+
* @param {Object} args 参数集合
|
|
80
|
+
* @returns {Object} 返回执行结果
|
|
81
|
+
*/
|
|
82
|
+
Ref.prototype.exec = async function(name, func_name, ...args) {
|
|
83
|
+
var cs = this.dict[name];
|
|
84
|
+
var ret;
|
|
85
|
+
var key = func_name + "_before";
|
|
86
|
+
if (cs[key]) {
|
|
87
|
+
ret = cs[key](...args);
|
|
88
|
+
if (types.isPromise(ret)) {
|
|
89
|
+
ret = await ret
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
key = func_name + "_check";
|
|
93
|
+
if (cs[key]) {
|
|
94
|
+
ret = cs[key](...args);
|
|
95
|
+
if (types.isPromise(ret)) {
|
|
96
|
+
ret = await ret
|
|
97
|
+
}
|
|
98
|
+
if (ret) {
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (cs[func_name]) {
|
|
104
|
+
ret = cs[func_name](...args);
|
|
105
|
+
if (types.isPromise(ret)) {
|
|
106
|
+
ret = await ret
|
|
107
|
+
}
|
|
108
|
+
if (ret) {
|
|
109
|
+
key = func_name + "_after";
|
|
110
|
+
if (cs[key]) {
|
|
111
|
+
ret = cs[key](...args);
|
|
112
|
+
if (types.isPromise(ret)) {
|
|
113
|
+
ret = await ret
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return ret;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
module.exports = Ref;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用
|
|
3
|
+
* @param {Object} server 服务
|
|
4
|
+
* @param {Object} config 配置参数
|
|
5
|
+
*/
|
|
6
|
+
module.exports = function(server, config) {
|
|
7
|
+
/* 跨域限制(web防火墙) */
|
|
8
|
+
server.use(async (ctx, next) => {
|
|
9
|
+
var req = ctx.request;
|
|
10
|
+
|
|
11
|
+
// 允许来自所有域名请求
|
|
12
|
+
ctx.set('Access-Control-Allow-Origin', '*');
|
|
13
|
+
// 这样就能只允许 http://localhost:8080 这个域名的请求了
|
|
14
|
+
// ctx.set("Access-Control-Allow-Origin", "http://localhost:8080");
|
|
15
|
+
|
|
16
|
+
// 设置所允许的HTTP请求方法OPTIONS,GET,PUT,POST,DELETE
|
|
17
|
+
ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, HEAD, OPTIONS')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// 字段是必需的。它也是一个逗号分隔的字符串,表明服务器支持的所有头信息字段.
|
|
21
|
+
ctx.set('Access-Control-Allow-Headers',
|
|
22
|
+
'Content-Type, Content-Length, Authorization, Accept, X-Requested-With, x-auth-token, token, client_id, appid, apikey, user_id,x-forwarded-for,x-real-ip,user-agent,cache-control,pragma,accept-encoding,connection,host'
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// 服务器收到请求以后,检查了Origin、Access-Control-Request-Method和Access-Control-Request-Headers字段以后,确认允许跨源请求,就可以做出回应。
|
|
26
|
+
|
|
27
|
+
// Content-Type表示具体请求中的媒体类型信息
|
|
28
|
+
// ctx.set("Content-Type", "application/json;charset=utf-8");
|
|
29
|
+
|
|
30
|
+
// 该字段可选。它的值是一个布尔值,表示是否允许发送Cookie。默认情况下,Cookie不包括在CORS请求之中。
|
|
31
|
+
// 当设置成允许请求携带cookie时,需要保证"Access-Control-Allow-Origin"是服务器有的域名,而不能是"*";
|
|
32
|
+
ctx.set("Access-Control-Allow-Credentials", 'false');
|
|
33
|
+
|
|
34
|
+
// 该字段可选,用来指定本次预检请求的有效期,单位为秒。
|
|
35
|
+
// 当请求方法是PUT或DELETE等特殊方法或者Content-Type字段的类型是application/json时,服务器会提前发送一次请求进行验证
|
|
36
|
+
// 下面的的设置只本次验证的有效时间,即在该时间段内服务端可以不用进行验证
|
|
37
|
+
ctx.set("Access-Control-Max-Age", '3600');
|
|
38
|
+
/*
|
|
39
|
+
CORS请求时,XMLHttpRequest对象的getResponseHeader()方法只能拿到6个基本字段:
|
|
40
|
+
Cache-Control、
|
|
41
|
+
Content-Language、
|
|
42
|
+
Content-Type、
|
|
43
|
+
Expires、
|
|
44
|
+
Last-Modified、
|
|
45
|
+
Pragma。
|
|
46
|
+
*/
|
|
47
|
+
// 需要获取其他字段时,使用Access-Control-Expose-Headers,
|
|
48
|
+
// getResponseHeader('myData')可以返回我们所需的值
|
|
49
|
+
// ctx.set("Access-Control-Expose-Headers", "myData");
|
|
50
|
+
if (req.method === 'OPTIONS') {
|
|
51
|
+
ctx.status = 204;
|
|
52
|
+
} else {
|
|
53
|
+
await next();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return server;
|
|
57
|
+
};
|