From 8ae7334be303f4659c3d73cc6e5a5c76d95d4fee Mon Sep 17 00:00:00 2001 From: asd Date: Mon, 2 Dec 2019 17:38:42 +0800 Subject: [PATCH 1/7] biaoqian --- controllers/grouping.js | 3 +++ controllers/label.js | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/controllers/grouping.js b/controllers/grouping.js index 28019b4..1b0b1e7 100644 --- a/controllers/grouping.js +++ b/controllers/grouping.js @@ -1,9 +1,12 @@ //添加分组 +//groupname:分组名 fuid :父分组 +// 父分组=0时是一级分组 var groupadd = async (ctx, next) => { await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid == null ? '0' : ctx.query.fuid }) ctx.body = "添加成功" } // 删除分组 +// num_key 操作使用的id var groupdel = async (ctx, next) => { await dbs.remove("group", { num_key: parseInt(ctx.query.key) }) ctx.body = "删除成功" diff --git a/controllers/label.js b/controllers/label.js index 59ae797..3771281 100644 --- a/controllers/label.js +++ b/controllers/label.js @@ -1,6 +1,17 @@ // 获取标签 var getlabel = async (ctx,next)=>{ - await IDBOpenDBRequest.find('label').then((res)=>{ - + await dbs.find("label").then((res) => { + console.log(res) }) -} \ No newline at end of file + +} + +//添加标签 +var addlabel=async(ctx,next)=>{ + await dbs.add("label", {labelname:ctx.query.labelname}) + ctx.body = "添加成功" +} +module.exports = { + 'GET /addlabel': addlabel, + 'GET /getlabel': getlabel, +}; \ No newline at end of file From 83d7da520a88e8d2138a116a1454bf8b45f04863 Mon Sep 17 00:00:00 2001 From: asd Date: Tue, 3 Dec 2019 14:50:37 +0800 Subject: [PATCH 2/7] 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() } From 2730de72cbab63a002a0a27d0df31c19538c1ddd Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Thu, 5 Dec 2019 10:42:58 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 53 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index dd5da8e..1376c66 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -10,19 +10,45 @@ var articlefind = async (ctx, next) => { } // 添加文章 var articleadd = async (ctx, next) => { + let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 // 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) + 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("label").then(async (res)=>{ + // console.log(res.data) + await dbs.find("idadd").then((res)=>{ + // console.log(res) + for(let i in res.data){ + // console.log(res.data[i].set) + if(res.data[i].set=='articlelists'){ + console.log(res.data[i].num_key-1,"article") + articleid=res.data[i].num_key-1 + } + } + }) 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("") - + for(let i in tags){ + // console.log(tags[i]) + for(let m in res.data){ + // console.log(res.data[m].num_key,parseInt(tags[i])) + + if(res.data[m].num_key==parseInt(tags[i])){ + console.log(res.data[m].lablename,77774) + await dbs.add("articletag",{articleid:articleid,tagid:parseInt(tags[i])}) + } + } } + + // console.log(res.data.length) + // 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("success") + + // } // await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.query.tagid}) }) console.log(ctx.request.body) @@ -48,6 +74,15 @@ var articleupdate=async (ctx,next)=>{ // console.log(new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes()) // console.log(new Date(Date.now()).getDate()) } + +function text(s) { + var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]"); + var rs = ""; + for (var i = 0; i < s.length; i++) { + rs = rs+s.substr(i, 1).replace(pattern, ''); + } + return rs; +} module.exports = { 'POST /articleadd': articleadd, 'GET /articlefind': articlefind, From 178bb9fc711d9bdd688a20d5c9c8b288e38949b1 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Thu, 5 Dec 2019 10:59:48 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B8=A6=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 1376c66..30fa713 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -9,6 +9,7 @@ var articlefind = async (ctx, next) => { next() } // 添加文章 +// 参数: title 文章标题, content 文章内容 tag 选择的标签id 形式: 1,2 var articleadd = async (ctx, next) => { let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 @@ -38,18 +39,6 @@ var articleadd = async (ctx, next) => { } } } - - // console.log(res.data.length) - // 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("success") - - // } - // await dbs.add("articletag",{articleid:res.data[res.data.length-1].num_key,tagid:ctx.query.tagid}) }) console.log(ctx.request.body) ctx.body = "添加成功" From 998b86f8e31af56b3c15c6f425e6b3b26f262263 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Fri, 6 Dec 2019 08:59:26 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 30fa713..5a4c4bc 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -2,14 +2,40 @@ // 获取文章列表 var articlefind = async (ctx, next) => { let articlelist; - await dbs.find("articlelists").then((res) => { + let tags=[] + await dbs.find("articlelists").then(async (res) => { + let num=0 articlelist = res.data + await dbs.find("articletag").then((res)=>{ + for(let i in articlelist){ + + for(let m in res.data){ + // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + if(res.data[m].articleid==articlelist[i].num_key){ + console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + // console.log(res.data[m].articleid) + // console.log(res.data[m].articleid,res.data[m].tagid) + // tags.push([res.data[m].articleid]) + tags.push(res.data[m].tagid) + articlelist[i].tag=tags + + }else{ + tags=[] + } + } + + console.log(tags) + + + } + }) + ctx.body=articlelist }) next() } // 添加文章 -// 参数: title 文章标题, content 文章内容 tag 选择的标签id 形式: 1,2 +// 参数: title 文章标题, content 文章内容 tags 选择的标签id 形式: 1,2 var articleadd = async (ctx, next) => { let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 From ea74c739f68696a74107bfbadc70d39e6ac1db44 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Fri, 6 Dec 2019 09:10:12 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=87=E7=AB=A0=E6=A0=87=E7=AD=BE111?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 5a4c4bc..9b6b235 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -6,13 +6,14 @@ var articlefind = async (ctx, next) => { await dbs.find("articlelists").then(async (res) => { let num=0 articlelist = res.data - await dbs.find("articletag").then((res)=>{ + await dbs.find("articletag").then( async (res)=>{ + for(let i in articlelist){ for(let m in res.data){ // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) if(res.data[m].articleid==articlelist[i].num_key){ - console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) + // console.log(res.data[m].articleid,articlelist[i].num_key,res.data[m].tagid) // console.log(res.data[m].articleid) // console.log(res.data[m].articleid,res.data[m].tagid) // tags.push([res.data[m].articleid]) @@ -24,10 +25,22 @@ var articlefind = async (ctx, next) => { } } - console.log(tags) + // console.log(tags) } + await dbs.find("label").then((res)=>{ + for(let i in articlelist){ + for(let m in articlelist[i].tag){ + console.log(articlelist[i].tag[m]) + for(let n in res.data){ + if(res.data[n].num_key==articlelist[i].tag[m]){ + articlelist[i].tag[m]=res.data[n].lablename + } + } + } + } + }) }) ctx.body=articlelist From a292148a79df3d2e7cbfe86de8f0a7e99697e4e1 Mon Sep 17 00:00:00 2001 From: asd <374367073@qq.com> Date: Fri, 6 Dec 2019 10:56:53 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=96=87=E7=AB=A0=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/article.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/controllers/article.js b/controllers/article.js index 9b6b235..407095c 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -1,11 +1,33 @@ // title 文章标题 contern 文章内容 -// 获取文章列表 +// 获取所有文章列表 var articlefind = async (ctx, next) => { - let articlelist; + let articlelist=[]; let tags=[] + await dbs.find("articlelists").then(async (res) => { - let num=0 - articlelist = res.data + let articlelists=res.data + await dbs.find("group").then((res)=>{ + let groups=res.data + for(let i in groups){ + if(parseInt(ctx.query.groupid)==groups[i].num_key){ + // console.log(groups[i]) + if(groups[i].fuid!=0){ + for(let m in articlelists){ + if(articlelists[m].groupid==parseInt(ctx.query.groupid)){ + articlelist.push(articlelists[m]) + } + // articlelist.push() + } + } + + } + } + if(articlelist.length==0){ + articlelist=articlelists + } + }) + + // articlelist = res.data await dbs.find("articletag").then( async (res)=>{ for(let i in articlelist){ @@ -53,7 +75,7 @@ var articleadd = async (ctx, next) => { let articleid=0 let month=parseInt(new Date(Date.now()).getMonth())+1 // 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.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,groupid:ctx.request.body.groupid}) await dbs.find("label").then(async (res)=>{ // console.log(res.data) await dbs.find("idadd").then((res)=>{