Merge branch 'xuebaoxin' of pplokijuhyg/blog-server into master

This commit is contained in:
pplokijuhyg 2019-12-02 16:37:04 +08:00
commit 0206f7d3a5
4 changed files with 44 additions and 66 deletions

View File

@ -1,28 +1,37 @@
// title 文章标题 contern 文章内容
// 获取文章列表
var articlefind = async (ctx, next) => { var articlefind = async (ctx, next) => {
let articlelist; let articlelist;
await dbs.find("articlelists").then((res) => { await dbs.find("articlelists").then((res) => {
articlelist = res.data articlelist = res.data
ctx.body=articlelist ctx.body=articlelist
}) })
next()
} }
// 添加文章
var articleadd = async (ctx, next) => { var articleadd = async (ctx, next) => {
let month=parseInt(new Date(Date.now()).getMonth())+1 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}) 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) console.log(ctx.query)
ctx.body = "添加成功" ctx.body = "添加成功"
next()
} }
// 删除文章
var articledel=async(ctx,next)=>{ var articledel=async(ctx,next)=>{
await dbs.remove("articlelists",{num_key:parseInt(ctx.query.key)}).then((res)=>{ await dbs.remove("articlelists",{num_key:parseInt(ctx.query.key)}).then((res)=>{
console.log(res) console.log(res)
console.log(ctx.query) console.log(ctx.query)
}) })
ctx.body="删除成功" ctx.body="删除成功"
next()
} }
// 修改文章
var articleupdate=async (ctx,next)=>{ var articleupdate=async (ctx,next)=>{
let month=parseInt(new Date(Date.now()).getMonth())+1 let month=parseInt(new Date(Date.now()).getMonth())+1
await dbs.update("articlelists",{num_key:parseInt(ctx.query.key)},{articletitle:ctx.query.title, udate: 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()}) await dbs.update("articlelists",{num_key:parseInt(ctx.query.key)},{articletitle:ctx.query.title, udate: 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()})
ctx.body="修改成功" ctx.body="修改成功"
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()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes())
// console.log(new Date(Date.now()).getDate()) // console.log(new Date(Date.now()).getDate())
} }

View File

@ -1,80 +1,43 @@
//添加分组
var groupadd = async (ctx, next) => { var groupadd = async (ctx, next) => {
await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid }) await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid == null ? '0' : ctx.query.fuid })
ctx.body = "添加成功" ctx.body = "添加成功"
} }
// 删除分组
var groupdel = async (ctx, next) => { var groupdel = async (ctx, next) => {
await dbs.remove("group", { num_key: parseInt(ctx.query.key) }) await dbs.remove("group", { num_key: parseInt(ctx.query.key) })
ctx.body = "删除成功" ctx.body = "删除成功"
} }
// 获取分组
var groupfind = async (ctx, next) => { var groupfind = async (ctx, next) => {
let group = []
await dbs.find("group").then((res) => { await dbs.find("group").then((res) => {
// console.log(res) let tree = function (data) {
// for (let i in res.data) { let map = {};
// if (parseInt(res.data[i].fuid) == 0) { let val = [];
// // console.log(res.data[i]) //生成数据对象集合
// group.push({ name: res.data[i].groupname, num_key: res.data[i].num_key, child: [] }) data.forEach(it => {
// } map[it.num_key] = it;
// // console.log(res.data[i].num_key,res.data[i].fuid) })
//生成结果集
// } data.forEach(it => {
// for (let m in res.data) { const parent = map[it.fuid];
// console.log(res.data[m].num_key, parseInt(res.data[m].fuid)) if (parent) {
// // console.log(1111) if (!Array.isArray(parent.children)) parent.children = [];
// if (res.data[m].num_key == parseInt(res.data[m].fuid)){ parent.children.push(it);
// for (let n in group) { } else {
// if (group[n].num_key == parseInt(res.data[m].fuid)) { val.push(it);
// group[n].child.push({ name: res.data[m].groupname, num_key: res.data[m].num_key, child: [] })
// }
// }
// }
// for (let n in group) {
// if (group[n].num_key == parseInt(res.data[m].fuid)) {
// group[n].child.push({ name: res.data[m].groupname, num_key: res.data[m].num_key, child: [] })
// }
// }
// }
for(let i in res.data){
if (parseInt(res.data[i].fuid) == 0) {
// console.log(res.data[i])
group.push({ name: res.data[i].groupname, num_key: res.data[i].num_key, child: [] })
} }
for(let m in res.data){ console.log(parent)
// console.log(parseInt(res.data[i].fuid),res.data[m].num_key) })
if(parseInt(res.data[i].fuid)==res.data[m].num_key){ return val;
// console.log(res.data[i]) }
for(let n in group){ if(res.data.length == 0 ){
console.log(group[n].num_key) ctx.body="{code:0,data:[]}"
if(group[n].num_key==parseInt(res.data[i].fuid)){
group[n].child.push({name:res.data[i].groupname,num_key:res.data[i].num_key,child:[]})
}else{ }else{
// group[n].child[n].push({name:res.data[i].groupname,num_key:res.data[i].num_key,child:[]}) ctx.body = JSON.stringify(tree(res.data))
for(k in group[n].child){
if(group[n].child[k].num_key==parseInt(res.data[i].fuid)){
group[n].child[k].child.push({name:res.data[i].groupname,num_key:res.data[i].num_key,child:[]})
}
console.log(group[n].child[k])
}
// console.log(group[n].child.push({name:res.data[i].groupname,num_key:res.data[i].num_key,child:[]}))
} }
next()
}
}
}
// console.log("aaaaaa")
// if (parseInt(res.data[i].fuid) == 0) {
// // console.log(res.data[i])
// group.push({ name: res.data[i].groupname, num_key: res.data[i].num_key, child: [] })
// }
}
console.log(JSON.stringify(group))
ctx.body = group
}) })
} }
module.exports = { module.exports = {

View File

@ -0,0 +1,6 @@
// 获取标签
var getlabel = async (ctx,next)=>{
await IDBOpenDBRequest.find('label').then((res)=>{
})
}

View File

@ -22,7 +22,7 @@ var loginup = async (ctx,next) => {
}, 'my_token', { expiresIn: '2h' }); }, 'my_token', { expiresIn: '2h' });
ctx.body={code:0,token} ctx.body={code:0,token}
}else{ }else{
ctx.body={code:1} ctx.body={code:1,msg:"密码错误"}
} }
next() next()
} }