feat: 新增多选删除功能

This commit is contained in:
奔跑的面条
2022-08-15 16:50:52 +08:00
parent 8832da10c9
commit dcb7806847
3 changed files with 48 additions and 15 deletions
@@ -139,7 +139,7 @@ export const useChartEditStore = defineStore({
getEditCanvasConfig(): EditCanvasConfigType { getEditCanvasConfig(): EditCanvasConfigType {
return this.editCanvasConfig return this.editCanvasConfig
}, },
getTargetChart():TargetChartType { getTargetChart(): TargetChartType {
return this.targetChart return this.targetChart
}, },
getRecordChart(): RecordChartType | undefined { getRecordChart(): RecordChartType | undefined {
@@ -249,6 +249,14 @@ export const useChartEditStore = defineStore({
} }
return -1 return -1
}, },
// * 统一格式化处理入参 id
idPreFormat(id?: string | string[]) {
const idArr = []
if (!id) idArr.push(...this.getTargetChart.selectId)
if (isString(id)) idArr.push(id)
if (isArray(id)) idArr.push(...id)
return idArr
},
/** /**
* * 新增组件列表 * * 新增组件列表
* @param chartConfig 新图表实例 * @param chartConfig 新图表实例
@@ -266,17 +274,21 @@ export const useChartEditStore = defineStore({
} }
this.componentList.push(chartConfig) this.componentList.push(chartConfig)
}, },
// * 删除单个组件 // * 删除组件
removeComponentList(id?:string, isHistory = true): void { removeComponentList(id?:string | string[], isHistory = true): void {
try { try {
loadingStart() loadingStart()
const index = this.fetchTargetIndex(id) const idArr = this.idPreFormat(id)
if (index !== -1) { // 遍历所有对象
isHistory ? chartHistoryStore.createDeleteHistory(this.getComponentList[index]) : undefined idArr.forEach(ids => {
this.componentList.splice(index, 1) const index = this.fetchTargetIndex(ids)
loadingFinish() if (index !== -1) {
return isHistory ? chartHistoryStore.createDeleteHistory(this.getComponentList[index]) : undefined
} this.componentList.splice(index, 1)
}
})
loadingFinish()
return
} catch(value) { } catch(value) {
loadingError() loadingError()
} }
@@ -299,6 +311,9 @@ export const useChartEditStore = defineStore({
// * 移动组件列表层级位置到两端 // * 移动组件列表层级位置到两端
setBothEnds(isEnd = false, isHistory = true): void { setBothEnds(isEnd = false, isHistory = true): void {
try { try {
// 暂不支持多选
if (this.getTargetChart.selectId.length > 1) return
loadingStart() loadingStart()
const length = this.getComponentList.length const length = this.getComponentList.length
if (length < 2) { if (length < 2) {
@@ -351,6 +366,9 @@ export const useChartEditStore = defineStore({
// * 上移/下移互换图表位置 // * 上移/下移互换图表位置
wrap(isDown = false, isHistory = true) { wrap(isDown = false, isHistory = true) {
try { try {
// 暂不支持多选
if (this.getTargetChart.selectId.length > 1) return
loadingStart() loadingStart()
const length = this.getComponentList.length const length = this.getComponentList.length
if (length < 2) { if (length < 2) {
@@ -397,6 +415,9 @@ export const useChartEditStore = defineStore({
// * 复制 // * 复制
setCopy(isCut = false) { setCopy(isCut = false) {
try { try {
// 暂不支持多选
if (this.getTargetChart.selectId.length > 1) return
loadingStart() loadingStart()
const index:number = this.fetchTargetIndex() const index:number = this.fetchTargetIndex()
if (index !== -1) { if (index !== -1) {
@@ -88,6 +88,12 @@ const optionsHandle = (
allList: MenuOptionsItemType[], allList: MenuOptionsItemType[],
targetInstance: CreateComponentType targetInstance: CreateComponentType
) => { ) => {
// 多选
const moreMenuEnums = [MenuEnum.GROUP, MenuEnum.DELETE]
// 单选
const singleMenuEnums = [MenuEnum.UN_GROUP]
const filter = (menulist: MenuEnum[]) => { const filter = (menulist: MenuEnum[]) => {
const list: MenuOptionsItemType[] = [] const list: MenuOptionsItemType[] = []
allList.forEach(item => { allList.forEach(item => {
@@ -100,9 +106,9 @@ const optionsHandle = (
// 多选处理 // 多选处理
if (chartEditStore.getTargetChart.selectId.length > 1) { if (chartEditStore.getTargetChart.selectId.length > 1) {
return filter([MenuEnum.GROUP]) return filter(moreMenuEnums)
} else { } else {
return [...filter([MenuEnum.UN_GROUP]), divider(), ...targetList] return [...filter(singleMenuEnums), divider(), ...targetList]
} }
} }
+9 -3
View File
@@ -107,18 +107,24 @@ const optionsHandle = (
allList: MenuOptionsItemType[], allList: MenuOptionsItemType[],
targetInstance: CreateComponentType targetInstance: CreateComponentType
) => { ) => {
// 多选
const moreMenuEnums = [MenuEnum.GROUP, MenuEnum.DELETE]
// 单选
const singleMenuEnums = targetList
// 多选处理 // 多选处理
if (chartEditStore.getTargetChart.selectId.length > 1) { if (chartEditStore.getTargetChart.selectId.length > 1) {
const list: MenuOptionsItemType[] = [] const list: MenuOptionsItemType[] = []
targetList.forEach(item => {
allList.forEach(item => {
// 成组 // 成组
if (item.key === MenuEnum.GROUP) { if (moreMenuEnums.includes(item.key as MenuEnum)) {
list.push(item) list.push(item)
} }
}) })
return list return list
} }
return targetList return singleMenuEnums
} }
// 主题色 // 主题色