+
+
-
- {{ i.menuName[0] }}
- {{ i.menuName }}
+ {{ i.menuName }}
@@ -109,6 +111,8 @@ async function getNav() {
else {
res = await $http.nav.listNav()
}
+ // console.log(res.data);
+ res.data.sort((a, b) => a.menuSort - b.menuSort)
navList.value = res.data.map((item) => {
item.exp = false
item.active = false
@@ -208,7 +212,7 @@ function handdleleavemenu(id) {
}, 2000);
}
function handdlemenutext(e, i) {
- if(i.belong == 'common') return
+ if (i.belong == 'common') return
// console.log(e, i);
menuShow.value = false
@@ -234,6 +238,65 @@ function resetMenuList() {
},
])
}
+const dragIdx = ref(-1)
+function handdleDragstart(e) {
+ console.log(e.target.dataset.idx || 0);
+ dragIdx.value = parseInt(e.target.dataset.idx)
+}
+function handdleDragover(e) {
+ e.preventDefault();
+}
+function handdleDrop(e) {
+ e.preventDefault();
+ console.log(navList.value);
+}
+
+const dropIdx = ref(-1)
+const dragBox = ref(null)
+// 拖拽排序
+function haddleDragenter(e) {
+ // 拖拽
+ e.preventDefault();
+ // console.log(e.target.dataset.idx == dropIdx.value);
+
+ if (e.target == dragBox.value || e.target.dataset.idx == dropIdx.value) {
+ return
+ }
+ // console.log(e.target.dataset);
+ if (e.target.dataset.idx) {
+ dropIdx.value = parseInt(e.target.dataset.idx)
+ }
+ if (dropIdx.value == 0) dropIdx.value = 1
+ const s = dragIdx.value, d = dropIdx.value
+ let si, di
+ navList.value.forEach((i, ii) => {
+ if (i.menuSort == s) {
+ si = ii
+ }
+ if (i.menuSort == d) {
+ di = ii
+ }
+ })
+ if (s > d) {
+ let temp = navList.value[si]
+ for (let i = si; i >= di; i--) {
+ navList.value[i] = navList.value[i - 1]
+ navList.value[i].menuSort++
+ }
+ navList.value[di] = temp
+ navList.value[di].menuSort = d
+ }
+ if (s < d) {
+ let temp = navList.value[si]
+ for (let i = si; i < di; i++) {
+ navList.value[i] = navList.value[i + 1]
+ navList.value[i].menuSort--
+ }
+ navList.value[di] = temp
+ navList.value[di].menuSort = d
+ }
+
+}
//mark 周期、内置函数等
onMounted(() => {
@@ -337,4 +400,8 @@ onMounted(() => {
flex-direction: column;
background-color: #fff;
}
+
+.drag-box {
+ transition: transform 1s ease-in-out;
+}
\ No newline at end of file