mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 17:46:28 +08:00
使用url()来构建url
This commit is contained in:
1 parent
0efac48bde
commit
86f67a0ec3
61 files changed
+262
-275
No files matched your search
+18
-3
@@ -130,6 +130,7 @@ class Handler {
|
||||
this.hasPerm = (perm) => this.user.hasPerm(perm);
|
||||
const res = await template.render(name, Object.assign(context, {
|
||||
handler: this,
|
||||
url: (...args) => this.url(...args),
|
||||
_: (str) => (str ? str.toString().translate(this.user.viewLang || this.session.viewLang) : ''),
|
||||
user: this.user,
|
||||
}));
|
||||
@@ -183,6 +184,20 @@ class Handler {
|
||||
this.response.disposition = `attachment; filename="${name}"`;
|
||||
}
|
||||
|
||||
url(name, kwargs = {}) { // eslint-disable-line class-methods-use-this
|
||||
delete kwargs.__keywords;
|
||||
let res;
|
||||
const { anchor } = kwargs;
|
||||
if (kwargs.query) {
|
||||
const { query } = kwargs;
|
||||
delete kwargs.query;
|
||||
res = router.url(name, kwargs, { query });
|
||||
}
|
||||
res = router.url(name, kwargs);
|
||||
if (anchor) return `${res}#${anchor}`;
|
||||
return res;
|
||||
}
|
||||
|
||||
async ___prepare({ domainId }) {
|
||||
this.response.body = {};
|
||||
this.now = new Date();
|
||||
@@ -296,8 +311,8 @@ class Handler {
|
||||
}
|
||||
}
|
||||
|
||||
function Route(route, RouteHandler, permission = null) {
|
||||
router.all(route, async (ctx) => {
|
||||
function Route(name, route, RouteHandler, permission = null) {
|
||||
router.all(name, route, async (ctx) => {
|
||||
const h = new RouteHandler(ctx);
|
||||
try {
|
||||
const method = ctx.method.toLowerCase();
|
||||
@@ -399,7 +414,7 @@ class ConnectionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
function Connection(prefix, RouteConnHandler) {
|
||||
function Connection(name, prefix, RouteConnHandler) {
|
||||
const sock = sockjs.createServer({ prefix });
|
||||
sock.on('connection', async (conn) => {
|
||||
const h = new RouteConnHandler(conn);
|
||||
|
||||
Reference in new issue
Block a user