From 85d395d22ad616ebf67d566fb5985908ba28b248 Mon Sep 17 00:00:00 2001 From: jeremyjone Date: Mon, 15 May 2023 00:48:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=E4=BF=AE=E6=AD=A3=20slider?= =?UTF-8?q?=20=E4=BD=8D=E7=A7=BB=E5=90=8E=E7=9A=84=E6=97=A7=E6=97=A5?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/slider/index.vue | 9 ++- src/models/data/row.ts | 100 ++++++++++++++++++-------------- src/typings/data.d.ts | 14 ++++- 3 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/components/slider/index.vue b/src/components/slider/index.vue index 465c181..319bfe7 100644 --- a/src/components/slider/index.vue +++ b/src/components/slider/index.vue @@ -98,6 +98,7 @@ import useStyle from '@/composables/useStyle'; import { formatDate } from '@/utils/date'; import { flow, isBoolean, isFunction } from 'lodash'; import useEvent from '@/composables/useEvent'; +import { MoveSliderInternalData, RowData } from '@/typings/data'; export default defineComponent({ name: Variables.name.slider @@ -170,16 +171,18 @@ onMounted(() => { // 移动过的对象数组 const { EmitMoveSlider } = useEvent(); -let movedData: MoveSliderData[] = []; +let movedData: MoveSliderInternalData[] = []; function EmitMove() { movedData.unshift({ - row: props.data!.data, + row: props.data!, old: { start: startDate!.date, end: endDate!.date } }); - EmitMoveSlider(movedData); + EmitMoveSlider( + movedData.map(item => ({ row: item.row.data, old: item.old })) + ); movedData = []; } diff --git a/src/models/data/row.ts b/src/models/data/row.ts index 711672c..4b087de 100644 --- a/src/models/data/row.ts +++ b/src/models/data/row.ts @@ -2,11 +2,12 @@ * @Author: JeremyJone * @Date: 2021-09-09 15:50:52 * @LastEditors: JeremyJone - * @LastEditTime: 2023-05-13 21:40:32 + * @LastEditTime: 2023-05-15 00:46:31 * @Description: 一条数据类 */ import { Variables } from '@/constants/vars'; +import { type MoveSliderInternalData } from '@/typings/data'; import { addIfNotExist, uuid } from '@/utils/common'; import { cloneDeep, isEqual } from 'lodash'; import { XDate } from '../param/date'; @@ -61,6 +62,9 @@ export default class RowItem { private __isExpand: boolean = false; private __isChecked: boolean = false; + private __oldStart?: XDate = undefined; + private __oldEnd?: XDate = undefined; + /** * 原始数据 */ @@ -190,8 +194,11 @@ export default class RowItem { date: XDate, unit: HeaderDateUnit, linkage = false, - modifyArr?: MoveSliderData[] + modifyArr?: MoveSliderInternalData[] ) { + this.__oldStart = new XDate(this.__data[this.options.startLabel]); + this.__oldEnd = new XDate(this.__data[this.options.endLabel]); + this.__data[this.options.startLabel] = date.date; // 首先判断起始日期不能大于结束日期 @@ -199,10 +206,11 @@ export default class RowItem { date.compareTo( this.end.getOffset(-Variables.time.millisecondOf[unit]) ) === 'r' - ) + ) { this.__data[this.options.endLabel] = date.getOffset( Variables.time.millisecondOf[unit] ).date; + } if (!linkage) return; @@ -210,20 +218,19 @@ export default class RowItem { let pNode = this.parentNode; while (pNode !== null) { if (this.start.compareTo(pNode.start) === 'l') { - const oldDate = pNode.start; // 赋值应该给data的日期数据赋值 pNode.setStart(this.start, unit); modifyArr && - addIfNotExist( + addIfNotExist( modifyArr, { - row: pNode.data, - old: { start: oldDate.date, end: pNode.end.date } + row: pNode, + old: { + start: pNode.__oldStart?.date ?? pNode.start.date, + end: pNode.__oldEnd?.date ?? pNode.end.date + } }, - item => - item.row.uuid === pNode?.uuid && - item.old.start === oldDate.date && - item.old.end === pNode?.end.date + item => item.row.uuid === pNode?.uuid ); } else { break; @@ -239,8 +246,11 @@ export default class RowItem { date: XDate, unit: HeaderDateUnit, linkage = false, - modifyArr?: MoveSliderData[] + modifyArr?: MoveSliderInternalData[] ) { + this.__oldStart = new XDate(this.__data[this.options.startLabel]); + this.__oldEnd = new XDate(this.__data[this.options.endLabel]); + this.__data[this.options.endLabel] = date.date; // 首先判断起始日期不能大于结束日期 @@ -249,29 +259,29 @@ export default class RowItem { date.compareTo( this.start.getOffset(Variables.time.millisecondOf[unit]) ) === 'l' - ) + ) { this.__data[this.options.startLabel] = date.getOffset( -Variables.time.millisecondOf[unit] ).date; + } if (!linkage) return; let pNode = this.parentNode; while (pNode !== null) { if (this.end.compareTo(pNode.end) === 'r') { - const oldDate = pNode.end; pNode.setEnd(this.end, unit); modifyArr && - addIfNotExist( + addIfNotExist( modifyArr, { - row: pNode.data, - old: { start: pNode.start.date, end: oldDate.date } + row: pNode, + old: { + start: pNode.__oldStart?.date ?? pNode.start.date, + end: pNode.__oldEnd?.date ?? pNode.end.date + } }, - item => - item.row.uuid === pNode?.uuid && - item.old.start === pNode?.start.date && - item.old.end === pNode?.end.date + item => item.row.uuid === pNode?.uuid ); } else { break; @@ -292,40 +302,42 @@ export default class RowItem { node: RowItem, key: 'start' | 'end', unit: HeaderDateUnit, - modifyArr?: MoveSliderData[] + modifyArr?: MoveSliderInternalData[] ) { - const pushTo = (item: MoveSliderData) => { - modifyArr && - addIfNotExist( - modifyArr, - item, - i => - i.row.uuid === item?.row.uuid && - i.old.start === item?.old.start && - i.old.end === item?.old.end - ); - }; - for (let i = 0; i < node.children.length; i++) { const c = node.children[i]; if (key === 'start') { if (c.start.compareTo(node.start) === 'l') { - const oldDate = c.start; c.setStart(node.start, unit); - pushTo({ - row: c.data, - old: { start: oldDate.date, end: c.end.date } - }); + modifyArr && + addIfNotExist( + modifyArr, + { + row: c, + old: { + start: c.__oldStart?.date ?? c.start.date, + end: c.__oldEnd?.date ?? c.end.date + } + }, + i => i.row.uuid === c.uuid + ); this.__setChildrenDate(c, key, unit, modifyArr); } } else if (key === 'end') { if (c.end.compareTo(node.end) === 'r') { - const oldDate = c.end; c.setEnd(node.end, unit); - pushTo({ - row: c.data, - old: { start: c.start.date, end: oldDate.date } - }); + modifyArr && + addIfNotExist( + modifyArr, + { + row: c, + old: { + start: c.__oldStart?.date ?? c.start.date, + end: c.__oldEnd?.date ?? c.end.date + } + }, + i => i.row.uuid === c.uuid + ); this.__setChildrenDate(c, key, unit, modifyArr); } } diff --git a/src/typings/data.d.ts b/src/typings/data.d.ts index 0353def..28a5262 100644 --- a/src/typings/data.d.ts +++ b/src/typings/data.d.ts @@ -1,3 +1,5 @@ +import type RowItem from '@/models/data/row'; + /** * 事件抛出的数据 */ @@ -7,10 +9,20 @@ declare interface RowData { level?: number; } +declare interface MoveSliderOldDate { + start: Date; + end: Date; +} + +declare interface MoveSliderInternalData { + row: RowItem; + old: MoveSliderOldDate; +} + /** * 滑动抛出的数据 */ declare interface MoveSliderData { row: any; - old: { start: Date; end: Date }; + old: MoveSliderOldDate; }