xuebaoxin #25

Manually merged
theluyuan merged 2 commits from xuebaoxin into master 2019-12-02 16:37:04 +08:00
4 changed files with 42 additions and 64 deletions
Showing only changes of commit 2f5bae670d - Show all commits

View File

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

View File

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