waibu 1.1.12 → 1.1.14
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/lib/build-locals.js +28 -8
- package/package.json +1 -1
- package/plugin/factory.js +8 -10
package/lib/build-locals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function buildHomesMenu () {
|
|
1
|
+
function buildHomesMenu (req) {
|
|
2
2
|
const { get, find, orderBy } = this.lib._
|
|
3
3
|
const routes = []
|
|
4
4
|
for (const ns of this.app.bajo.pluginNames) {
|
|
@@ -10,13 +10,33 @@ function buildHomesMenu () {
|
|
|
10
10
|
return orderBy(routes, ['title'])
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function buildPagesMenu () {
|
|
14
|
-
const {
|
|
15
|
-
const all = [{ icon: 'house', href: '/',
|
|
13
|
+
function buildPagesMenu (req) {
|
|
14
|
+
const { orderBy } = this.lib._
|
|
15
|
+
const all = [{ icon: 'house', href: '/', level: 1 }]
|
|
16
16
|
for (const ns of this.app.bajo.pluginNames) {
|
|
17
|
-
const
|
|
17
|
+
const items = []
|
|
18
|
+
const pages = this.app[ns].getConfig('waibuMpa.pages', { defValue: [] })
|
|
18
19
|
if (pages.length === 0) continue
|
|
19
|
-
|
|
20
|
+
for (const page of pages) {
|
|
21
|
+
page.level = page.level ?? 1000
|
|
22
|
+
if (page.visible === 'auth' && !req.user) continue
|
|
23
|
+
if (page.visible === 'anon' && req.user) continue
|
|
24
|
+
if (!page.children) {
|
|
25
|
+
items.push(page)
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
const children = []
|
|
29
|
+
for (const child of page.children) {
|
|
30
|
+
if (child.visible === 'auth' && !req.user) continue
|
|
31
|
+
if (child.visible === 'anon' && req.user) continue
|
|
32
|
+
children.push(child)
|
|
33
|
+
}
|
|
34
|
+
if (children.length > 0) {
|
|
35
|
+
page.children = children
|
|
36
|
+
items.push(page)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
all.push(...items)
|
|
20
40
|
}
|
|
21
41
|
return orderBy(all, ['level', 'title'])
|
|
22
42
|
}
|
|
@@ -54,8 +74,8 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
|
|
|
54
74
|
if (this.app.bajo.config.env === 'dev') console.log(params.error)
|
|
55
75
|
}
|
|
56
76
|
if (reply && req.session && req.flash && !opts.partial) _meta.flash = reply.flash()
|
|
57
|
-
set(params, 'menu.homes', buildHomesMenu.call(this))
|
|
58
|
-
set(params, 'menu.pages', buildPagesMenu.call(this))
|
|
77
|
+
set(params, 'menu.homes', buildHomesMenu.call(this, req))
|
|
78
|
+
set(params, 'menu.pages', buildPagesMenu.call(this, req))
|
|
59
79
|
const merged = merge({}, params, { _meta })
|
|
60
80
|
await runHook(`${this.name}:afterBuildLocals`, merged, req)
|
|
61
81
|
if (!isEmpty(routeOpts.ns)) await runHook(`${this.name}.${routeOpts.ns}:afterBuildLocals`, merged, req)
|
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -142,7 +142,8 @@ async function factory (pkgName) {
|
|
|
142
142
|
})
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
escape = (text) => {
|
|
145
|
+
escape = (text = '') => {
|
|
146
|
+
if (typeof text !== 'string') return text
|
|
146
147
|
const { forOwn } = this.lib._
|
|
147
148
|
forOwn(this.escapeChars, (v, k) => {
|
|
148
149
|
text = text.replaceAll(k, v)
|
|
@@ -173,15 +174,12 @@ async function factory (pkgName) {
|
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
getPluginByPrefix = (prefix) => {
|
|
176
|
-
const { get } = this.lib._
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return plugin
|
|
177
|
+
const { get, find } = this.lib._
|
|
178
|
+
const item = find(this.app.waibu.routes, r => {
|
|
179
|
+
return get(r, 'config.prefix') === prefix
|
|
180
|
+
})
|
|
181
|
+
const ns = get(item, 'config.ns')
|
|
182
|
+
if (ns) return this.app[ns]
|
|
185
183
|
}
|
|
186
184
|
|
|
187
185
|
getPluginPrefix = (base, webApp = 'waibuMpa') => {
|