From b2cf5898cfb2fb6257c6a9aaf95c563f6c1bdd5d Mon Sep 17 00:00:00 2001 From: npmrun Date: Sat, 13 May 2023 01:27:19 +0800 Subject: [PATCH] add pages --- readme.md | 4 +++- route.txt | 4 ++-- source/route/views/user.ts | 4 ++++ template/htmx/path/about.pug | 2 +- template/htmx/path/user.pug | 7 +++++++ template/ui/header.pug | 2 +- template/views/user.pug | 4 ++++ 7 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 template/htmx/path/user.pug create mode 100644 template/views/user.pug diff --git a/readme.md b/readme.md index b149687..37a1033 100644 --- a/readme.md +++ b/readme.md @@ -39,4 +39,6 @@ docker stop 容器ID docker container prune docker image rm 镜像名 docker image ls -a -docker container ls -a \ No newline at end of file +docker container ls -a + +https://blog.csdn.net/LIFENG0402/article/details/117930091 \ No newline at end of file diff --git a/route.txt b/route.txt index 31b9f77..9d5ff58 100644 --- a/route.txt +++ b/route.txt @@ -1,6 +1,6 @@ -D:\1XYX\pro\hapi-demo\source\route\htmx对应路径: +/home/topuser/Code/@project/hapi-demo/source/route/htmx对应路径: 不需权限 : GET /htmx/path/{path*} -D:\1XYX\pro\hapi-demo\source\route\views对应路径: +/home/topuser/Code/@project/hapi-demo/source/route/views对应路径: 不需权限(提供无需验证): GET /404 不需权限(提供无需验证): GET / 不需权限(提供无需验证): GET /about diff --git a/source/route/views/user.ts b/source/route/views/user.ts index 866feae..dddd4d4 100644 --- a/source/route/views/user.ts +++ b/source/route/views/user.ts @@ -10,6 +10,7 @@ export default class { @method("GET") @auth() async index(request: Req, h: Res): ReturnValue { + const isRenderHtmx = Reflect.has(request.query, "htmx") const { id } = request.auth.credentials const User = request.getModel("User") let result = await User.findOne({ where: { id: id } }) @@ -18,6 +19,9 @@ export default class { } const userinfo = result.toJSON() delete userinfo.password + if (isRenderHtmx) { + return h.view("htmx/path/user.pug", { userinfo }) + } return h.view("views/user.pug", { userinfo }) } diff --git a/template/htmx/path/about.pug b/template/htmx/path/about.pug index 7d67d69..cb8d9fc 100644 --- a/template/htmx/path/about.pug +++ b/template/htmx/path/about.pug @@ -5,7 +5,7 @@ block var -title="关于" // 网页标题 title 关于 -div about +div aboutasdad section.section .container if user diff --git a/template/htmx/path/user.pug b/template/htmx/path/user.pug new file mode 100644 index 0000000..3540890 --- /dev/null +++ b/template/htmx/path/user.pug @@ -0,0 +1,7 @@ +include @/helper/helper.pug + +block var + -title=user.nickname || "Welcome" // 网页标题 +title #{user.nickname || "Welcome"} + +div user \ No newline at end of file diff --git a/template/ui/header.pug b/template/ui/header.pug index 9667eb3..5ac78f2 100644 --- a/template/ui/header.pug +++ b/template/ui/header.pug @@ -36,7 +36,7 @@ nav.is-fixed-top.navbar(role='navigation', aria-label='main navigation', style=" a.navbar-link div #{user.nickname} .navbar-dropdown.is-right - a.navbar-item + a.navbar-item(hx-get="/user?htmx" hx-push-url="/user" hx-trigger="click" hx-target="#single-page" hx-swap="innerHTML") | 用户资料 hr.navbar-divider a.navbar-item(href="/user/logout") diff --git a/template/views/user.pug b/template/views/user.pug new file mode 100644 index 0000000..89360c6 --- /dev/null +++ b/template/views/user.pug @@ -0,0 +1,4 @@ +extends @/layout/single-page + +block page + include @hxpath/user.pug