feat: 实现首页项目拖拽排序功能以及部分功能优化 (#955)

* feat: 首页项目拖拽排序功能

* feat: 增加首页项目拖拽排序增加只能管理员进行, 排序失败元素回到原本位置

* perf: 新建文章以后直接进入到编辑文章页面

* perf: 优化文档打开时或刷新时样式闪动问题
This commit is contained in:
zhanzhenping
2024-07-04 09:43:33 +08:00
committed by GitHub
parent ad5e871a0f
commit 710d5bcf50
13 changed files with 337 additions and 30 deletions

View File

@@ -773,6 +773,39 @@ func (c *BookController) Release() {
c.JsonResult(0, i18n.Tr(c.Lang, "message.publish_to_queue"))
}
// 更新项目排序
func (c *BookController) UpdateBookOrder() {
if !c.Member.IsAdministrator() {
c.JsonResult(403, "权限不足")
return
}
type Params struct {
Ids string `form:"ids"`
}
var params Params
if err := c.ParseForm(&params); err != nil {
c.JsonResult(6003, "参数错误")
return
}
idArray := strings.Split(params.Ids, ",")
orderCount := len(idArray)
for _, id := range idArray {
bookId, _ := strconv.Atoi(id)
orderCount--
book, err := models.NewBook().Find(bookId)
if err != nil {
continue
}
book.BookId = bookId
book.OrderIndex = orderCount
err = book.Update()
if err != nil {
continue
}
}
c.JsonResult(0, "ok")
}
// 文档排序.
func (c *BookController) SaveSort() {
c.Prepare()