Browse Source

Pull request #2159: KERNEL-8279 refactor:路由-命名视图

Merge in VISUAL/fineui from ~GUYI/fineui:master to master

* commit 'ac68cf89b61cb9044a452b500b68a7af5ccfa769':
  KERNEL-8279 refactor:格式
  KERNEL-8279 refactor:命名视图
es6
Guyi 3 years ago
parent
commit
1049a89d98
  1. 27
      demo/app.js
  2. 21
      dist/router.js

27
demo/app.js

@ -36,17 +36,30 @@ BI.$(function () {
height: 50 height: 50
}, { }, {
type: "bi.router_view", type: "bi.router_view",
deps: 1,
height: 100
}, {
type: "bi.router_view",
name: 'home',
deps: 1 deps: 1
}] }]
}); });
}, },
children: [{ children: [{
path: '', path: '',
component: function () { components: {
return Promise.resolve({ default: function () {
type: "bi.label", return Promise.resolve({
text: 'home' type: "bi.label",
}) text: 'default'
});
},
home: function () {
return Promise.resolve({
type: "bi.label",
text: 'home'
});
},
} }
}, { }, {
name: 'dashboard', name: 'dashboard',
@ -55,7 +68,7 @@ BI.$(function () {
return Promise.resolve({ return Promise.resolve({
type: "bi.label", type: "bi.label",
text: 'dashboard' text: 'dashboard'
}) });
} }
}, { }, {
name: 'tables', name: 'tables',
@ -64,7 +77,7 @@ BI.$(function () {
return Promise.resolve({ return Promise.resolve({
type: "bi.label", type: "bi.label",
text: 'tables' text: 'tables'
}) });
} }
}] }]
}]; }];

21
dist/router.js vendored

@ -3147,7 +3147,8 @@
BI.RouterView = BI.inherit(BI.Widget, { BI.RouterView = BI.inherit(BI.Widget, {
props: { props: {
deps: 0 deps: 0,
name: 'default'
}, },
created: function () { created: function () {
var self = this, o = this.options; var self = this, o = this.options;
@ -3155,13 +3156,17 @@
var current = $router.history.current; var current = $router.history.current;
// 匹配的路径名(/component/:id) // 匹配的路径名(/component/:id)
var matchedPath = current.matched[o.deps] && current.matched[o.deps].path; var matchedPath = current.matched[o.deps] && current.matched[o.deps].path;
if (matchedPath) { var component = current.matched[o.deps] && current.matched[o.deps].components[o.name];
BI.each(current.params, function (key, value) {
// 把 :id 替换成具体的值(/component/demo.td) if (BI.isNotNull(component)) {
matchedPath = matchedPath.replace(`:${key}`, value); 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 () { render: function () {
@ -3177,7 +3182,7 @@
}, },
showIndex: false, showIndex: false,
cardCreator: function (v) { cardCreator: function (v) {
return $router.history.current.matched[o.deps].components.default; return $router.history.current.matched[o.deps].components[o.name];
} }
}; };
}, },

Loading…
Cancel
Save