st-comp 0.0.134 → 0.0.135

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.134",
4
+ "version": "0.0.135",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -473,7 +473,7 @@ const draw = (keepDataZoom = false) => {
473
473
  if (showSubChart) {
474
474
  klineSubRef.value.draw({ startValue, endValue, maxValueSpan: maxShowCounts }, { gridLeft, gridRight });
475
475
  }
476
- drawBrush()
476
+ drawBrush();
477
477
  };
478
478
 
479
479
  // 绘制线
@@ -492,57 +492,60 @@ const drawLine = () => {
492
492
  },
493
493
  true
494
494
  );
495
- drawBrush()
495
+ drawBrush();
496
496
  };
497
497
 
498
498
  // 区域框选
499
499
  const drawBrush = () => {
500
+ const { time } = chartData.value;
500
501
  // 如果传入了刷选时间段
501
- if (props.brushRange) {
502
- const { time } = chartData.value;
502
+ if (props.brushRange && time?.length) {
503
+ // 传入时段的始末时间
504
+ let startTime = dayjs(props.brushRange[0]).format("YYYY-MM-DD 00:00:00");
505
+ let endTime = dayjs(props.brushRange[1]).format("YYYY-MM-DD 23:59:59");
506
+ // 匹配到对应K线的时间段始末时间
503
507
  let brushStartTime = null;
504
508
  let brushEndTime = null;
505
509
  switch (props.cycle) {
506
510
  // 日
507
511
  case "6": {
508
- brushStartTime = time.find((item) => {
509
- return new Date(item).getTime() >= new Date(props.brushRange[0]).getTime() || dayjs(item).format("YYYY-MM-DD") === dayjs(props.brushRange[0]).format("YYYY-MM-DD");
510
- });
511
- brushEndTime = time.findLast((item) => {
512
- return new Date(item).getTime() <= new Date(props.brushRange[1]).getTime() || dayjs(item).format("YYYY-MM-DD") === dayjs(props.brushRange[1]).format("YYYY-MM-DD");
513
- });
512
+ brushStartTime = time.find((item) => dayjs(item).format("YYYY-MM-DD") === dayjs(startTime).format("YYYY-MM-DD"));
513
+ brushEndTime = brushStartTime;
514
514
  break;
515
515
  }
516
516
  // 周
517
517
  case "7": {
518
518
  brushStartTime = time.find((item) => {
519
- return dayjs(item).day(5).format("YYYY-MM-DD") === dayjs(props.brushRange[0]).day(5).format("YYYY-MM-DD");
519
+ return dayjs(item).day(5).format("YYYY-MM-DD") === dayjs(startTime).day(5).format("YYYY-MM-DD");
520
520
  });
521
521
  brushEndTime = time.findLast((item) => {
522
- return dayjs(item).day(5).format("YYYY-MM-DD") === dayjs(props.brushRange[1]).day(5).format("YYYY-MM-DD");
522
+ return dayjs(item).day(5).format("YYYY-MM-DD") === dayjs(endTime).day(5).format("YYYY-MM-DD");
523
523
  });
524
524
  break;
525
525
  }
526
526
  // 月
527
527
  case "8": {
528
528
  brushStartTime = time.find((item) => {
529
- return dayjs(item).endOf("month").format("YYYY-MM-DD") === dayjs(props.brushRange[0]).endOf("month").format("YYYY-MM-DD");
529
+ return dayjs(item).endOf("month").format("YYYY-MM-DD") === dayjs(startTime).endOf("month").format("YYYY-MM-DD");
530
530
  });
531
531
  brushEndTime = time.findLast((item) => {
532
- return dayjs(item).endOf("month").format("YYYY-MM-DD") === dayjs(props.brushRange[1]).endOf("month").format("YYYY-MM-DD");
532
+ return dayjs(item).endOf("month").format("YYYY-MM-DD") === dayjs(endTime).endOf("month").format("YYYY-MM-DD");
533
533
  });
534
534
  break;
535
535
  }
536
536
  default: {
537
537
  brushStartTime = time.find((item) => {
538
- return new Date(item).getTime() >= new Date(props.brushRange[0]).getTime();
538
+ const condition1 = dayjs(item).format("YYYY-MM-DD") === dayjs(startTime).format("YYYY-MM-DD");
539
+ const condition2 = new Date(item).getTime() >= new Date(startTime).getTime();
540
+ return condition1 && condition2;
539
541
  });
540
542
  brushEndTime = time.findLast((item) => {
541
- return new Date(item).getTime() <= new Date(props.brushRange[1]).getTime();
543
+ const condition1 = dayjs(item).format("YYYY-MM-DD") === dayjs(endTime).format("YYYY-MM-DD");
544
+ const condition2 = new Date(item).getTime() <= new Date(endTime).getTime();
545
+ return condition1 && condition2;
542
546
  });
543
547
  }
544
548
  }
545
- console.log(brushStartTime, brushEndTime);
546
549
  mainChartIns.dispatchAction({
547
550
  type: "brush",
548
551
  areas: [