|
@@ -0,0 +1,87 @@
|
|
|
+import { $BRIDGE } from './bridge'
|
|
|
+import { interceptorNotFindPage } from '../router/router-interceptor'
|
|
|
+import RouterUtils from '../router/utils'
|
|
|
+
|
|
|
+class WorkBenchFrame {
|
|
|
+ /**
|
|
|
+ * 初始化配置
|
|
|
+ * @param options
|
|
|
+ */
|
|
|
+ constructor (options) {
|
|
|
+ const {
|
|
|
+ debug = false,
|
|
|
+ title = '工作台',
|
|
|
+ route = {}
|
|
|
+ } = options
|
|
|
+
|
|
|
+ // 初始化基础配置
|
|
|
+ this.debug = debug
|
|
|
+ this.title = title
|
|
|
+
|
|
|
+ // 初始化路由配置
|
|
|
+ this.route = Object.assign({
|
|
|
+ base: '/work-bench',
|
|
|
+ 404: '/404'
|
|
|
+ }, route)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注入对应钩子
|
|
|
+ * @param Vue
|
|
|
+ * @param router
|
|
|
+ * @param subApps
|
|
|
+ */
|
|
|
+ inject ({ Vue, router, subApps } = options) {
|
|
|
+ this.injectBridge(options)
|
|
|
+ this.injectRouter(router)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注入工具函数到原型 及 window
|
|
|
+ */
|
|
|
+ injectBridge ({ Vue, router, subApps }) {
|
|
|
+ const routerUtils = new RouterUtils({
|
|
|
+ router,
|
|
|
+ subApps
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ const $BRACE = {
|
|
|
+ methods: {
|
|
|
+ open: routerUtils.open,
|
|
|
+ reload: routerUtils.reload,
|
|
|
+ currentRoute: routerUtils.currentRoute
|
|
|
+ },
|
|
|
+ $on: $BRIDGE.on,
|
|
|
+ $off: $BRIDGE.off,
|
|
|
+ $emit: $BRIDGE.emit,
|
|
|
+ $promise: $BRIDGE.promise
|
|
|
+ }
|
|
|
+ $BRIDGE.on('routerUtils', () => {
|
|
|
+ return routerUtils
|
|
|
+ })
|
|
|
+
|
|
|
+ window.$BRACE = $BRACE
|
|
|
+ Vue.prototype.$BRACE = $BRACE
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注入路由钩子
|
|
|
+ * @param router
|
|
|
+ */
|
|
|
+ injectRouter (router) {
|
|
|
+ interceptorNotFindPage.call(this, router)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * debug log
|
|
|
+ * @param args
|
|
|
+ */
|
|
|
+ log (...args) {
|
|
|
+ if (this.debug) {
|
|
|
+ console.info.apply(void 0,['%c [work-bench-frame]:', 'color: #24C0D7', args])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export default WorkBenchFrame
|