Skip to content

Commit

Permalink
fix: 🐛修正 slider 位移后的旧日期
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 14, 2023
1 parent 529b71a commit 85d395d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 48 deletions.
9 changes: 6 additions & 3 deletions src/components/slider/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [];
}
Expand Down
100 changes: 56 additions & 44 deletions src/models/data/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,6 +62,9 @@ export default class RowItem {
private __isExpand: boolean = false;
private __isChecked: boolean = false;

private __oldStart?: XDate = undefined;
private __oldEnd?: XDate = undefined;

/**
* 原始数据
*/
Expand Down Expand Up @@ -190,40 +194,43 @@ 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;

// 首先判断起始日期不能大于结束日期
if (
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;

// 查看父节点
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<MoveSliderData>(
addIfNotExist<MoveSliderInternalData>(
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;
Expand All @@ -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;

// 首先判断起始日期不能大于结束日期
Expand All @@ -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<MoveSliderData>(
addIfNotExist<MoveSliderInternalData>(
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;
Expand All @@ -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<MoveSliderData>(
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<MoveSliderInternalData>(
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<MoveSliderInternalData>(
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);
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/typings/data.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type RowItem from '@/models/data/row';

/**
* 事件抛出的数据
*/
Expand All @@ -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;
}

0 comments on commit 85d395d

Please sign in to comment.