[ADD]文章删除
This commit is contained in:
parent
7e5f9a4561
commit
4f636c9f4a
|
@ -79,6 +79,18 @@ func (c *NoteController) EditPage() {
|
||||||
c.TplName = "note_new.html"
|
c.TplName = "note_new.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 删除文章
|
||||||
|
// @router /del/:key [post]
|
||||||
|
func (c *NoteController) Del() {
|
||||||
|
key := c.Ctx.Input.Param(":key")
|
||||||
|
|
||||||
|
if err := models.DeleteNoteByUserIdAndKey(key, int(c.User.ID)); err != nil {
|
||||||
|
c.Abort500(syserrors.NewError("删除失败", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSONOk("删除成功", "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *NoteController) NestPrepare() {
|
func (c *NoteController) NestPrepare() {
|
||||||
c.MustLogin()
|
c.MustLogin()
|
||||||
|
|
|
@ -39,4 +39,9 @@ func QueryNoteByKey(key string) (note Note, err error) {
|
||||||
|
|
||||||
func SaveNote(n *Note) error {
|
func SaveNote(n *Note) error {
|
||||||
return db.Save(n).Error
|
return db.Save(n).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeleteNoteByUserIdAndKey(key string, userId int) (err error) {
|
||||||
|
err = db.Delete(&Note{}, "`key` = ? AND `user_id` = ?", key, userId).Error
|
||||||
|
return err
|
||||||
}
|
}
|
|
@ -66,6 +66,20 @@
|
||||||
}
|
}
|
||||||
if(type === 'bar2'){
|
if(type === 'bar2'){
|
||||||
//删除的逻辑,等待实现。
|
//删除的逻辑,等待实现。
|
||||||
|
$.post("/note/del/"+note.key,function (data) {
|
||||||
|
if (data.code === 0) {
|
||||||
|
layer.msg("删除成功");
|
||||||
|
if (data.action) {
|
||||||
|
setTimeout(function () {
|
||||||
|
window.location.href = data.action;
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
layer.msg("删除失败:" + data.msg);
|
||||||
|
}
|
||||||
|
}, "json").error(function () {
|
||||||
|
layer.msg("网络异常")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue