npmrun 2 years ago
parent
commit
b731d00a83
  1. BIN
      data/data.db
  2. 3
      route.txt
  3. 22
      source/route/views/index.ts
  4. 5
      template/htmx/path/color.pug

BIN
data/data.db

Binary file not shown.

3
route.txt

@ -4,7 +4,8 @@
不需权限(提供无需验证): GET /404
不需权限(提供无需验证): GET /
不需权限(提供无需验证): GET /about
不需权限(提供无需验证): POST /color
需要权限 : POST /color/del
需要权限 : POST /color
不需权限(提供无需验证): GET /color
需要权限 : GET /docs/{path*}
不需权限(提供无需验证): GET /{path*}

22
source/route/views/index.ts

@ -40,8 +40,30 @@ export default class Index {
return h.view("views/about.pug", data)
}
@route("/color/del")
@method("POST")
@auth()
async color_del(request: Req, h: Res) {
const { id } = request.payload as any
if (!id) {
request.yar.flash("error", "未提供id")
return h.redirect("/color")
}
try {
const ColorModel = request.getModel("color")
await ColorModel.destroy({ where: { id} })
request.yar.flash("success", "删除成功")
} catch (error) {
loggerSite.error(error)
request.yar.flash("error", "删除失败")
}
return h.redirect("/color")
}
@route("/color")
@method("POST")
@auth()
async color_post(request: Req, h: Res) {
const { name, value, desctibe } = request.payload as any

5
template/htmx/path/color.pug

@ -46,7 +46,10 @@ div(class="container page")
div(class="color_item_title") #{item.name}
div(class="color_item_desc" title=item.desctibe) #{item.desctibe || "暂无描述"}
if isLogin
div 删除
form(action="/color/del" method="post")
+security
input(type="text" value=item.id name="id" hidden)
button(type="submit" style="background: transparent;border:0;color:red;cursor: pointer;float: right;") 删除
//- div(class="color_item")
//- img(src="/public/image/add.png", alt="添加" title="添加" class="color_add")
if isLogin

Loading…
Cancel
Save