diff --git a/core/core-frontend/src/views/chart/components/editor/index.vue b/core/core-frontend/src/views/chart/components/editor/index.vue index 050312ebd4..a53b0471a2 100644 --- a/core/core-frontend/src/views/chart/components/editor/index.vue +++ b/core/core-frontend/src/views/chart/components/editor/index.vue @@ -1266,6 +1266,92 @@ const onRefreshChange = val => { return } } + +const isCtrl = ref(false) + +const isDraggingItem = ref(false) + +const activeDimension = ref([]) +const activeQuota = ref([]) + +const setActive = (ele, type = 'dimension') => { + if (isCtrl.value) { + isCtrl.value = false + } + const activeChild = type === 'dimension' ? activeDimension : activeQuota + const deactiveChild = type === 'quota' ? activeDimension : activeQuota + deactiveChild.value = [] + activeChild.value = activeChild.value.some(item => item.id === ele.id) ? [] : [ele] +} + +const setActiveCtrl = (ele, type = 'dimension') => { + isCtrl.value = true + const activeChild = type === 'dimension' ? activeDimension : activeQuota + const deactiveChild = type === 'quota' ? activeDimension : activeQuota + deactiveChild.value = [] + const index = activeChild.value.findIndex(item => item.id === ele.id) + if (index !== -1) { + activeChild.value.splice(index, 1) + return + } + activeChild.value.push(ele) +} + +const isDrag = ref(false) + +const dragStart = (e: DragEvent) => { + isDrag.value = true + setTimeout(() => { + isDraggingItem.value = true + }, 0) +} + +const singleDragStart = (e: DragEvent, ele, type) => { + const activeChild = type === 'dimension' ? activeDimension : activeQuota + const deactiveChild = type === 'quota' ? activeDimension : activeQuota + deactiveChild.value = [] + if (!activeChild.value.length) { + activeChild.value = [ele] + } + dragStart(e) +} + +const dragEnd = () => { + isDrag.value = false + isDraggingItem.value = false +} + +const singleDragEnd = () => { + activeDimension.value = [] + activeQuota.value = [] + dragEnd() +} + +const dragEnter = (ev: MouseEvent) => { + ev.preventDefault() +} + +const dragOver = (ev: MouseEvent) => { + ev.preventDefault() +} + +const drop = (ev: MouseEvent, type = 'xAxis') => { + ev.preventDefault() + const arr = activeDimension.value.length ? activeDimension.value : activeQuota.value + for (let i = 0; i < arr.length; i++) { + const obj = cloneDeep(arr[i]) + state.moveId = obj.id as unknown as number + view.value[type].push(obj) + const e = { newDraggableIndex: view.value.xAxis.length - 1 } + if ('drillFields' === type) { + addDrill(e) + } else if (type === 'customFilter') { + addCustomFilter(e) + } else { + addAxis(e, type as AxisType) + } + } +}