fix: 修改右键判定区域,新增历史记录store

This commit is contained in:
MTrun
2022-01-31 23:37:43 +08:00
parent 0a223afab2
commit c6a7be352b
9 changed files with 128 additions and 46 deletions
+2
View File
@@ -55,6 +55,7 @@ export type TargetChartType = {
export enum ChartEditStoreEnum {
EDIT_RANGE = 'editRange',
EDIT_CANVAS = 'editCanvas',
RIGHT_MENU_SHOW = 'rightMenuShow',
MOUSE_POSITION = 'mousePosition',
TARGET_CHART = 'targetChart',
COMPONENT_LIST = 'componentList'
@@ -63,6 +64,7 @@ export enum ChartEditStoreEnum {
// Store 类型
export interface chartEditStoreType {
[ChartEditStoreEnum.EDIT_CANVAS]: EditCanvasType
[ChartEditStoreEnum.RIGHT_MENU_SHOW]: boolean
[ChartEditStoreEnum.MOUSE_POSITION]: MousePositionType
[ChartEditStoreEnum.TARGET_CHART]: TargetChartType
[ChartEditStoreEnum.COMPONENT_LIST]: any[]
@@ -32,6 +32,8 @@ export const useChartEditStoreStore = defineStore({
// 默认背景色
background: undefined
},
// 右键菜单
rightMenuShow: false,
// 鼠标定位
mousePosition: {
x: 0,
@@ -49,6 +51,9 @@ export const useChartEditStoreStore = defineStore({
getMousePosition(): MousePositionType {
return this.mousePosition
},
getRightMenuShow(): boolean {
return this.rightMenuShow
},
getEditCanvas(): EditCanvasType {
return this.editCanvas
},
@@ -64,6 +69,10 @@ export const useChartEditStoreStore = defineStore({
setEditCanvasItem< T extends keyof EditCanvasType, K extends EditCanvasType[T] >(key: T, value: K) {
this.editCanvas[key] = value
},
// * 设置右键菜单
setRightMenuShow(value: boolean) {
this.rightMenuShow = value
},
// * 设置目标数据 hover
setTargetHoverChart(hoverIndex?:TargetChartType["hoverIndex"]) {
this.targetChart.hoverIndex = hoverIndex
+23 -5
View File
@@ -1,10 +1,28 @@
export interface HistoryStackType {
import { CreateComponentType } from '@/packages/index.d'
// 操作类型枚举
export enum HistoryTypeEnum {
ADD = 'add',
DELETE = 'delete',
MOVE = 'move',
SELECT_HISTORY = 'selectHistory'
}
export interface chartHistoryStoreType {
// 历史栈
export enum HistoryStackEnum {
BACK_STACK= 'backStack',
FORWARD_STACK= 'forwardStack',
}
// 历史记录项类型
export interface HistoryItemType extends CreateComponentType {
historyType: HistoryTypeEnum
}
// 历史 Store 类型
export interface ChartHistoryStoreType {
// 后退栈
backStack: [],
[HistoryStackEnum.BACK_STACK]: Array<HistoryItemType>,
// 前进栈
forwardStack: []
[HistoryStackEnum.FORWARD_STACK]: Array<HistoryItemType>,
}
@@ -1,11 +1,62 @@
import { defineStore } from 'pinia'
import { chartHistoryStoreType } from './chartHistoryStore.d'
import {
HistoryStackEnum,
HistoryItemType,
ChartHistoryStoreType
} from './chartHistoryStore.d'
import { setLocalStorage, getLocalStorage } from '@/utils'
import { StorageEnum } from '@/enums/storageEnum'
export const useChartHistoryStoreStore = defineStore({
id: 'useChartHistoryStore',
state: (): chartHistoryStoreType => ({}),
getters: {},
actions: {}
})
state: (): ChartHistoryStoreType => ({
// 后退栈(记录栈)
backStack: [],
// 前进栈
forwardStack: []
}),
getters: {
getBackStack(): Array<HistoryItemType> {
return this.backStack
},
getForwardStack(): Array<HistoryItemType> {
return this.forwardStack
}
},
actions: {
// * 推入记录栈
addBackStackItem(item: HistoryItemType | Array<HistoryItemType>): void {
if(item instanceof Array) this.backStack = [...this.backStack, ...item]
else this.backStack.push(item)
},
// * 推入前进栈
addForwardStack(item: HistoryItemType | Array<HistoryItemType>): void {
if(item instanceof Array) this.forwardStack = [...this.forwardStack, ...item]
else this.forwardStack.push(item)
},
// * 移出记录栈
popBackStackItem(
index?: number
): HistoryItemType[] | HistoryItemType | undefined {
const length = this.backStack.length
if (index && length >= index) {
return this.backStack.splice(-index)
}
if (this.backStack.length > 0) {
return this.backStack.pop()
}
},
// * 移出前进栈
popForwardStack(
index?: number
): HistoryItemType[] | HistoryItemType | undefined {
const length = this.forwardStack.length
if (index && length >= index) {
return this.forwardStack.splice(-index)
}
if (this.forwardStack.length > 0) {
return this.forwardStack.pop()
}
}
}
})