Merge branch 'master' into xuebaoxin

This commit is contained in:
pplokijuhyg 2019-12-06 11:37:45 +08:00
commit 23208b3a4e
2 changed files with 107 additions and 6 deletions

View File

@ -1,18 +1,107 @@
// title 文章标题 contern 文章内容
// 获取文章列表
// 获取所有文章列表
var articlefind = async (ctx, next) => {
let articlelist;
await dbs.find("articlelists").then((res) => {
articlelist = res.data
let articlelist=[];
let tags=[]
await dbs.find("articlelists").then(async (res) => {
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){
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)
}
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
})
next()
}
// 添加文章
// 参数: title 文章标题, content 文章内容 tags 选择的标签id 形式: 1,2
var articleadd = async (ctx, next) => {
let articleid=0
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,groupid:ctx.request.body.groupid})
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(",")
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(ctx.request.body)
ctx.body = "添加成功"
next()
}
@ -35,6 +124,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,

View File

@ -1,10 +1,13 @@
//添加分组
//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 = "添加成功"
next()
}
// 删除分组
// num_key 操作使用的id
var groupdel = async (ctx, next) => {
await dbs.remove("group", { num_key: parseInt(ctx.query.key) })
ctx.body = "删除成功"