|
1 | 1 | import { Action, IGroup, Util } from '@antv/g2';
|
2 |
| -import { get, last, isNil } from '@antv/util'; |
| 2 | +import { get, last, isNil, size } from '@antv/util'; |
3 | 3 | import { Data } from '../../types';
|
4 | 4 | import { DrillDownCfg } from '../../types/drill-down';
|
5 | 5 | import { deepAssign } from '../../utils/deep-assign';
|
@@ -112,12 +112,21 @@ export class DrillDownAction extends Action {
|
112 | 112 | breadCrumbGroup.setMatrix(matrix);
|
113 | 113 | }
|
114 | 114 |
|
| 115 | + /** |
| 116 | + * 返回上一层 |
| 117 | + */ |
| 118 | + public back(): void { |
| 119 | + if (size(this.historyCache)) { |
| 120 | + this.backTo(this.historyCache.slice(0, -1)); |
| 121 | + } |
| 122 | + } |
| 123 | + |
115 | 124 | /**
|
116 | 125 | * 重置
|
117 | 126 | */
|
118 | 127 | public reset(): void {
|
119 | 128 | if (this.historyCache[0]) {
|
120 |
| - this.back(this.historyCache.slice(0, 1)); |
| 129 | + this.backTo(this.historyCache.slice(0, 1)); |
121 | 130 | }
|
122 | 131 | // 清空
|
123 | 132 | this.historyCache = [];
|
@@ -158,7 +167,7 @@ export class DrillDownAction extends Action {
|
158 | 167 | * 回退事件,点击面包屑时触发
|
159 | 168 | * @param historyCache 当前要回退到的历史
|
160 | 169 | */
|
161 |
| - protected back(historyCache: HistoryCache) { |
| 170 | + protected backTo(historyCache: HistoryCache) { |
162 | 171 | if (!historyCache || historyCache.length <= 0) {
|
163 | 172 | return;
|
164 | 173 | }
|
@@ -236,7 +245,7 @@ export class DrillDownAction extends Action {
|
236 | 245 | const targetId = event.target.get('id');
|
237 | 246 | if (targetId !== last(cache)?.id) {
|
238 | 247 | const newHistoryCache = cache.slice(0, cache.findIndex((d) => d.id === targetId) + 1);
|
239 |
| - this.back(newHistoryCache); |
| 248 | + this.backTo(newHistoryCache); |
240 | 249 | }
|
241 | 250 | });
|
242 | 251 | // active 效果内置
|
|
0 commit comments