From 38c15ae91e4af231e45ff13b3e5086d512067674 Mon Sep 17 00:00:00 2001 From: zhanzhenping <128675240+Zzhenping@users.noreply.github.com> Date: Wed, 3 Jul 2024 09:31:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=8B=96=E6=8B=BD=E6=8E=92=E5=BA=8F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8F=AA=E8=83=BD=E7=AE=A1=E7=90=86=E5=91=98=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C,=20=E6=8E=92=E5=BA=8F=E5=A4=B1=E8=B4=A5=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E5=9B=9E=E5=88=B0=E5=8E=9F=E6=9C=AC=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/BookController.go | 4 ++++ static/js/sort.js | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/BookController.go b/controllers/BookController.go index 06ec4465..095e82fb 100644 --- a/controllers/BookController.go +++ b/controllers/BookController.go @@ -775,6 +775,10 @@ func (c *BookController) Release() { // 更新项目排序 func (c *BookController) UpdateBookOrder() { + if !c.Member.IsAdministrator() { + c.JsonResult(403, "权限不足") + return + } type Params struct { Ids string `form:"ids"` } diff --git a/static/js/sort.js b/static/js/sort.js index bb843766..8fc617ea 100644 --- a/static/js/sort.js +++ b/static/js/sort.js @@ -1,8 +1,12 @@ let draggedItem = null; +let draggedItemIndex = null; document.querySelectorAll('.list-item').forEach(item => { item.addEventListener('mousedown', function() { draggedItem = item; + // 获取当前item在list-item中的索引 + const parentNode = item.parentNode; + draggedItemIndex = Array.from(parentNode.children).indexOf(draggedItem); item.setAttribute('draggable', true); }); @@ -45,15 +49,25 @@ document.querySelectorAll('.list-item').forEach(item => { success: function (res) { if (res.errcode === 0) { layer.msg("排序成功", {icon: 1}); + draggedItem = null; } else { - layer.msg("排序失败", {icon: 2}); + layer.msg(res.message, {icon: 2}); + const parentNode = item.parentNode; + // 在parentNode中找到当前拖拽的item + const draggedIndex = Array.from(parentNode.children).indexOf(draggedItem); + console.log('draggedIndex:', draggedIndex); + // 移除当前拖拽的item + parentNode.removeChild(draggedItem); + // 将draggedItem放到原来的位置 + parentNode.insertBefore(draggedItem, parentNode.children[draggedItemIndex]); + draggedItem = null; } }, error: function (err) { console.log('error:', err) + draggedItem = null; } }) - draggedItem = null; } }); }); \ No newline at end of file