From da73d73fe398795855a5b6acdb2202a1d32089b8 Mon Sep 17 00:00:00 2001 From: Guyi Date: Mon, 6 Sep 2021 00:39:41 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-8279=20refactor=EF=BC=9A=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/app.js | 23 ++++++++++++++++++----- dist/router.js | 21 +++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/demo/app.js b/demo/app.js index acbc2cd77..a86510ed7 100644 --- a/demo/app.js +++ b/demo/app.js @@ -36,17 +36,30 @@ BI.$(function () { height: 50 }, { type: "bi.router_view", + deps: 1, + height: 100, + }, { + type: "bi.router_view", + name: 'home', deps: 1 }] }); }, children: [{ path: '', - component: function () { - return Promise.resolve({ - type: "bi.label", - text: 'home' - }) + components: { + default: function () { + return Promise.resolve({ + type: "bi.label", + text: 'default' + }) + }, + home: function () { + return Promise.resolve({ + type: "bi.label", + text: 'home' + }) + }, } }, { name: 'dashboard', diff --git a/dist/router.js b/dist/router.js index 7f2a93478..36af78750 100644 --- a/dist/router.js +++ b/dist/router.js @@ -3147,7 +3147,8 @@ BI.RouterView = BI.inherit(BI.Widget, { props: { - deps: 0 + deps: 0, + name: 'default', }, created: function () { var self = this, o = this.options; @@ -3155,13 +3156,17 @@ var current = $router.history.current; // 匹配的路径名(/component/:id) var matchedPath = current.matched[o.deps] && current.matched[o.deps].path; - if (matchedPath) { - BI.each(current.params, function (key, value) { - // 把 :id 替换成具体的值(/component/demo.td) - matchedPath = matchedPath.replace(`:${key}`, value); - }); + var component = current.matched[o.deps] && current.matched[o.deps].components[o.name]; + + if (BI.isNotNull(component)) { + if (matchedPath) { + BI.each(current.params, function (key, value) { + // 把 :id 替换成具体的值(/component/demo.td) + matchedPath = matchedPath.replace(`:${key}`, value); + }); + } + self.tab.setSelect(matchedPath || "/"); } - self.tab.setSelect(matchedPath || "/"); }); }, render: function () { @@ -3177,7 +3182,7 @@ }, showIndex: false, cardCreator: function (v) { - return $router.history.current.matched[o.deps].components.default; + return $router.history.current.matched[o.deps].components[o.name]; } }; },