From 83d7da520a88e8d2138a116a1454bf8b45f04863 Mon Sep 17 00:00:00 2001 From: asd Date: Tue, 3 Dec 2019 14:50:37 +0800 Subject: [PATCH] articlejs --- controllers/article.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 615e7a3..dd5da8e 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -11,8 +11,21 @@ var articlefind = async (ctx, next) => { // 添加文章 var articleadd = async (ctx, next) => { let month=parseInt(new Date(Date.now()).getMonth())+1 - await dbs.add("articlelists", { articletitle:ctx.query.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(),content:ctx.query.content,uid:1}) - console.log(ctx.query) + // await dbs.add("articletag",{articleid:ctx.query.articleid,tagid:ctx.query.tagid}) + // await dbs.add("articlelists", { articletitle:ctx.request.body.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(),content:ctx.request.body.content,uid:1}) + await dbs.find("idadd").then((res)=>{ + console.log(res.data[res.data.length-1].num_key) + let tags=ctx.request.body.tags.split(",") + console.log(ctx.request.body.tags.split(",")) + for(let i in ctx.request.body.tags.split(",")){ + // console.log(ctx.request.body.tags.split(",")[i]) + await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.request.body.tags.split(",")[i]}) + console.log("") + + } + // await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.query.tagid}) + }) + console.log(ctx.request.body) ctx.body = "添加成功" next() } -- 2.39.5