diff --git a/data/data.db b/data/data.db index 3653b20..41acff1 100644 Binary files a/data/data.db and b/data/data.db differ diff --git a/route.txt b/route.txt index 2db2a91..2c8d9ad 100644 --- a/route.txt +++ b/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*} diff --git a/source/route/views/index.ts b/source/route/views/index.ts index 1484d90..c51b211 100644 --- a/source/route/views/index.ts +++ b/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 diff --git a/template/htmx/path/color.pug b/template/htmx/path/color.pug index 6bd727e..555468b 100644 --- a/template/htmx/path/color.pug +++ b/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