mirror of
https://gitee.com/dromara/go-view.git
synced 2025-02-24 16:22:57 +08:00
Merge branch 'dev' of https://gitee.com/MTrun/go-view
This commit is contained in:
commit
4eca4c607a
@ -12,6 +12,7 @@
|
|||||||
"@types/color": "^3.0.3",
|
"@types/color": "^3.0.3",
|
||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/keymaster": "^1.6.30",
|
"@types/keymaster": "^1.6.30",
|
||||||
|
"@types/lodash": "^4.14.184",
|
||||||
"animate.css": "^4.1.1",
|
"animate.css": "^4.1.1",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
|
2
src/packages/index.d.ts
vendored
2
src/packages/index.d.ts
vendored
@ -63,7 +63,7 @@ export enum FilterEnum {
|
|||||||
export interface PublicConfigType {
|
export interface PublicConfigType {
|
||||||
id: string
|
id: string
|
||||||
isGroup: boolean
|
isGroup: boolean
|
||||||
attr: { x: number; y: number; w: number; h: number; zIndex: number }
|
attr: { x: number; y: number; w: number; h: number; zIndex: number; offsetX: number; offsetY: number; }
|
||||||
styles: {
|
styles: {
|
||||||
[FilterEnum.OPACITY]: number
|
[FilterEnum.OPACITY]: number
|
||||||
[FilterEnum.SATURATE]: number
|
[FilterEnum.SATURATE]: number
|
||||||
|
@ -104,5 +104,5 @@ export class PublicGroupConfigClass extends publicConfig implements CreateCompon
|
|||||||
// 标识
|
// 标识
|
||||||
public id = getUUID()
|
public id = getUUID()
|
||||||
// 基本信息
|
// 基本信息
|
||||||
public attr = { w: 0, h: 0, x: 0, y: 0, zIndex: -1 }
|
public attr = { w: 0, h: 0, x: 0, y: 0, offsetX: 0, offsetY: 0, zIndex: -1 }
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,10 @@ export const chartInitConfig = {
|
|||||||
x: 50,
|
x: 50,
|
||||||
y: 50,
|
y: 50,
|
||||||
w: 500,
|
w: 500,
|
||||||
h: 300
|
h: 300,
|
||||||
|
// 不建议动 offset
|
||||||
|
offsetX: 0,
|
||||||
|
offsetY: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
// dialog 图标的大小
|
// dialog 图标的大小
|
||||||
|
@ -313,6 +313,28 @@ export const useChartEditStore = defineStore({
|
|||||||
loadingError()
|
loadingError()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// * 重置组件位置
|
||||||
|
resetComponentPosition(item: CreateComponentType | CreateComponentGroupType, isForward: boolean): void {
|
||||||
|
const index = this.fetchTargetIndex(item.id)
|
||||||
|
if (index > -1) {
|
||||||
|
const componentInstance = this.getComponentList[index]
|
||||||
|
if (isForward) {
|
||||||
|
componentInstance.attr = Object.assign(componentInstance.attr, {
|
||||||
|
x: item.attr.x + item.attr.offsetX,
|
||||||
|
y: item.attr.y + item.attr.offsetY
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
componentInstance.attr = Object.assign(componentInstance.attr, {
|
||||||
|
x: item.attr.x,
|
||||||
|
y: item.attr.y
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// * 移动组件
|
||||||
|
moveComponentList(item: Array<CreateComponentType | CreateComponentGroupType>) {
|
||||||
|
chartHistoryStore.createMoveHistory(item)
|
||||||
|
},
|
||||||
// * 更新组件列表某一项的值
|
// * 更新组件列表某一项的值
|
||||||
updateComponentList(index: number, newData: CreateComponentType | CreateComponentGroupType) {
|
updateComponentList(index: number, newData: CreateComponentType | CreateComponentGroupType) {
|
||||||
if (index < 1 && index > this.getComponentList.length) return
|
if (index < 1 && index > this.getComponentList.length) return
|
||||||
@ -530,6 +552,15 @@ export const useChartEditStore = defineStore({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理移动
|
||||||
|
const isMove = HistoryItem.actionType === HistoryActionTypeEnum.MOVE
|
||||||
|
if (isMove) {
|
||||||
|
historyData.forEach(item => {
|
||||||
|
this.resetComponentPosition(item, isForward)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 处理层级
|
// 处理层级
|
||||||
const isTop = HistoryItem.actionType === HistoryActionTypeEnum.TOP
|
const isTop = HistoryItem.actionType === HistoryActionTypeEnum.TOP
|
||||||
const isBottom = HistoryItem.actionType === HistoryActionTypeEnum.BOTTOM
|
const isBottom = HistoryItem.actionType === HistoryActionTypeEnum.BOTTOM
|
||||||
@ -562,12 +593,12 @@ export const useChartEditStore = defineStore({
|
|||||||
if (isGroup || isUnGroup) {
|
if (isGroup || isUnGroup) {
|
||||||
if ((isGroup && isForward) || (isUnGroup && !isForward)) {
|
if ((isGroup && isForward) || (isUnGroup && !isForward)) {
|
||||||
const ids: string[] = []
|
const ids: string[] = []
|
||||||
if(historyData.length > 1) {
|
if (historyData.length > 1) {
|
||||||
historyData.forEach(item => {
|
historyData.forEach(item => {
|
||||||
ids.push(item.id)
|
ids.push(item.id)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
(historyData[0] as CreateComponentGroupType).groupList.forEach(item => {
|
;(historyData[0] as CreateComponentGroupType).groupList.forEach(item => {
|
||||||
ids.push(item.id)
|
ids.push(item.id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -575,7 +606,7 @@ export const useChartEditStore = defineStore({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 都需使用子组件的id去解组
|
// 都需使用子组件的id去解组
|
||||||
if(historyData.length > 1) {
|
if (historyData.length > 1) {
|
||||||
this.setUnGroup([(historyData[0] as CreateComponentType).id], undefined, false)
|
this.setUnGroup([(historyData[0] as CreateComponentType).id], undefined, false)
|
||||||
} else {
|
} else {
|
||||||
this.setUnGroup([(historyData[0] as CreateComponentGroupType).groupList[0].id], undefined, false)
|
this.setUnGroup([(historyData[0] as CreateComponentGroupType).groupList[0].id], undefined, false)
|
||||||
|
@ -85,6 +85,8 @@ const canvasPositionList = computed(() => {
|
|||||||
h: cloneDeep(chartEditStore.getEditCanvasConfig.height),
|
h: cloneDeep(chartEditStore.getEditCanvasConfig.height),
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
offsetX: 0,
|
||||||
|
offsetY: 0,
|
||||||
zIndex: 0
|
zIndex: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,10 @@ watch(
|
|||||||
// 宽
|
// 宽
|
||||||
w: 0,
|
w: 0,
|
||||||
// 高
|
// 高
|
||||||
h: 0
|
h: 0,
|
||||||
|
// 偏移
|
||||||
|
offsetX: 0,
|
||||||
|
offsetY: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理位置
|
// 处理位置
|
||||||
|
@ -7,7 +7,7 @@ import { useContextMenu } from '@/views/chart/hooks/useContextMenu.hook'
|
|||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { EditCanvasTypeEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
import { loadingStart, loadingFinish, loadingError } from '@/utils'
|
||||||
import throttle from 'lodash/throttle'
|
import { throttle, cloneDeep } from 'lodash'
|
||||||
|
|
||||||
const chartEditStore = useChartEditStore()
|
const chartEditStore = useChartEditStore()
|
||||||
const { onClickOutSide } = useContextMenu()
|
const { onClickOutSide } = useContextMenu()
|
||||||
@ -111,7 +111,7 @@ export const mousedownBoxSelect = (e: MouseEvent, item?: CreateComponentType | C
|
|||||||
selectAttr.x1 = Math.round(startOffsetX - (startScreenX - moveEvent.screenX) / scale)
|
selectAttr.x1 = Math.round(startOffsetX - (startScreenX - moveEvent.screenX) / scale)
|
||||||
selectAttr.y1 = startOffsetY
|
selectAttr.y1 = startOffsetY
|
||||||
selectAttr.x2 = startOffsetX
|
selectAttr.x2 = startOffsetX
|
||||||
selectAttr.y2 = Math.round(startOffsetY + (moveEvent.screenY - startScreenY ) / scale)
|
selectAttr.y2 = Math.round(startOffsetY + (moveEvent.screenY - startScreenY) / scale)
|
||||||
// 左下方向
|
// 左下方向
|
||||||
} else {
|
} else {
|
||||||
// 左上方向
|
// 左上方向
|
||||||
@ -222,6 +222,16 @@ export const useMouseHandle = () => {
|
|||||||
const startX = e.screenX
|
const startX = e.screenX
|
||||||
const startY = e.screenY
|
const startY = e.screenY
|
||||||
|
|
||||||
|
// 记录历史位置
|
||||||
|
let prevComponentInstance: Array<CreateComponentType | CreateComponentGroupType> = []
|
||||||
|
chartEditStore.getTargetChart.selectId.forEach(id => {
|
||||||
|
if (!targetMap.has(id)) return
|
||||||
|
|
||||||
|
const index = chartEditStore.fetchTargetIndex(id)
|
||||||
|
// 拿到初始位置数据
|
||||||
|
prevComponentInstance.push(cloneDeep(chartEditStore.getComponentList[index]))
|
||||||
|
})
|
||||||
|
|
||||||
// 记录初始位置
|
// 记录初始位置
|
||||||
chartEditStore.setMousePosition(undefined, undefined, startX, startY)
|
chartEditStore.setMousePosition(undefined, undefined, startX, startY)
|
||||||
|
|
||||||
@ -267,6 +277,24 @@ export const useMouseHandle = () => {
|
|||||||
const mouseup = () => {
|
const mouseup = () => {
|
||||||
chartEditStore.setMousePosition(0, 0, 0, 0)
|
chartEditStore.setMousePosition(0, 0, 0, 0)
|
||||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_DRAG, false)
|
chartEditStore.setEditCanvas(EditCanvasTypeEnum.IS_DRAG, false)
|
||||||
|
// 加入历史栈
|
||||||
|
if (prevComponentInstance.length) {
|
||||||
|
chartEditStore.getTargetChart.selectId.forEach(id => {
|
||||||
|
if (!targetMap.has(id)) return
|
||||||
|
const index = chartEditStore.fetchTargetIndex(id)
|
||||||
|
const curComponentInstance = chartEditStore.getComponentList[index]
|
||||||
|
// 找到记录的所选组件
|
||||||
|
prevComponentInstance.forEach(preItem => {
|
||||||
|
if (preItem.id === id) {
|
||||||
|
preItem.attr = Object.assign(preItem.attr, {
|
||||||
|
offsetX: curComponentInstance.attr.x - preItem.attr.x,
|
||||||
|
offsetY: curComponentInstance.attr.y - preItem.attr.y
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
chartEditStore.moveComponentList(prevComponentInstance)
|
||||||
|
}
|
||||||
document.removeEventListener('mousemove', mousemove)
|
document.removeEventListener('mousemove', mousemove)
|
||||||
document.removeEventListener('mouseup', mouseup)
|
document.removeEventListener('mouseup', mouseup)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user