Unverified 提交 93eb5931 authored 作者: 王嘉豪's avatar 王嘉豪 提交者: GitHub

Merge pull request #1157 from dataease/pr@v1.4@fix_panel-new-view

refactor:优化仪表板上移,下移,置顶,置底移动算法可以实时得到移动效果,解决置顶不准确问题
import { swap } from '@/components/canvas/utils/utils' import { swap, toBottom, toTop, moveUp, moveDown } from '@/components/canvas/utils/utils'
import toast from '@/components/canvas/utils/toast' import toast from '@/components/canvas/utils/toast'
export default { export default {
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
upComponent({ componentData, curComponentIndex }) { upComponent({ componentData, curComponentIndex }) {
// 上移图层 index,表示元素在数组中越往后 // 上移图层 index,表示元素在数组中越往后
if (curComponentIndex < componentData.length - 1) { if (curComponentIndex < componentData.length - 1) {
swap(componentData, curComponentIndex, curComponentIndex + 1) moveUp(componentData, curComponentIndex)
} else { } else {
toast('已经到顶了') toast('已经到顶了')
} }
...@@ -15,7 +15,7 @@ export default { ...@@ -15,7 +15,7 @@ export default {
downComponent({ componentData, curComponentIndex }) { downComponent({ componentData, curComponentIndex }) {
// 下移图层 index,表示元素在数组中越往前 // 下移图层 index,表示元素在数组中越往前
if (curComponentIndex > 0) { if (curComponentIndex > 0) {
swap(componentData, curComponentIndex, curComponentIndex - 1) moveDown(componentData, curComponentIndex)
} else { } else {
toast('已经到底了') toast('已经到底了')
} }
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
topComponent({ componentData, curComponentIndex }) { topComponent({ componentData, curComponentIndex }) {
// 置顶 // 置顶
if (curComponentIndex < componentData.length - 1) { if (curComponentIndex < componentData.length - 1) {
swap(componentData, curComponentIndex, componentData.length - 1) toTop(componentData, curComponentIndex)
} else { } else {
toast('已经到顶了') toast('已经到顶了')
} }
...@@ -33,7 +33,7 @@ export default { ...@@ -33,7 +33,7 @@ export default {
bottomComponent({ componentData, curComponentIndex }) { bottomComponent({ componentData, curComponentIndex }) {
// 置底 // 置底
if (curComponentIndex > 0) { if (curComponentIndex > 0) {
swap(componentData, curComponentIndex, 0) toBottom(componentData, curComponentIndex)
} else { } else {
toast('已经到底了') toast('已经到底了')
} }
......
...@@ -16,11 +16,28 @@ export function deepCopy(target) { ...@@ -16,11 +16,28 @@ export function deepCopy(target) {
} }
export function swap(arr, i, j) { export function swap(arr, i, j) {
console.log('before:' + i + '-->' + j + JSON.stringify(arr))
const temp = arr[i] const temp = arr[i]
arr[i] = arr[j] arr[i] = arr[j]
arr[j] = temp arr[j] = temp
console.log('after:' + JSON.stringify(arr))
} }
export function moveUp(arr, i) {
arr.splice(i + 1, 0, arr.splice(i, 1)[0])
}
export function moveDown(arr, i) {
arr.splice(i, 0, arr.splice(i - 1, 1)[0])
}
export function toTop(arr, i, j) {
arr.push(arr.splice(i, 1)[0])
}
export function toBottom(arr, i) {
arr.unshift(arr.splice(i, 1)[0])
}
export function $(selector) { export function $(selector) {
return document.querySelector(selector) return document.querySelector(selector)
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论