@teamias/pro-layout 0.0.16 → 0.0.18

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.
@@ -166,38 +166,72 @@ export var KeepAliveClass = /*#__PURE__*/function () {
166
166
  * 如需修改为独立组件,需要通过 props 显式传入这些依赖,这里为了简化内部实现,
167
167
  * 保留为类属性组件的实现方式是有意为之。
168
168
  */
169
- _defineProperty(this, "AutoRefreshKeepAliveItem", function () {
169
+ _defineProperty(this, "AutoRefreshKeepAliveItem", function (_ref) {
170
+ var children = _ref.children;
170
171
  var _useAccessRouter2 = useAccessRouter(),
171
172
  location = _useAccessRouter2.location;
172
- var ref = useRef(location);
173
- var count = useRef(0);
173
+ var _useState3 = useState({}),
174
+ _useState4 = _slicedToArray(_useState3, 2),
175
+ update = _useState4[1];
176
+ var _useRef2 = useRef({
177
+ divId: "auto-refresh-keep-alive-item-".concat(Date.now(), "-").concat(Math.random().toString(36).substring(2)),
178
+ div: document.createElement('div'),
179
+ portal: null,
180
+ show: true,
181
+ count: 0,
182
+ location: location
183
+ }),
184
+ cache = _useRef2.current;
174
185
  // 计数器大于该阈值才生效,避免初次加载时触发自动刷新
175
186
  var ACTIVATION_COUNT_THRESHOLD = 2;
176
- ref.current = location;
187
+ cache.location = location;
177
188
  _this.useLifeCycle(function (type) {
178
189
  // 计数器大于2次才生效,避免初次加载时候触发
179
- if (type === ELifeCycleType.ACTIVATED && count.current > ACTIVATION_COUNT_THRESHOLD) {
180
- var _ref$current$state;
190
+ if (type === ELifeCycleType.ACTIVATED && cache.count > ACTIVATION_COUNT_THRESHOLD) {
191
+ var _cache$location$state;
181
192
  // console.log('ACTIVATED', ref.current);
182
- if (!((_ref$current$state = ref.current.state) !== null && _ref$current$state !== void 0 && _ref$current$state.disabledReload)) {
193
+ if (!((_cache$location$state = cache.location.state) !== null && _cache$location$state !== void 0 && _cache$location$state.disabledReload)) {
183
194
  // debugger;
184
- _this.refreshPage(ref.current.pathname);
195
+ _this.refreshPage(cache.location.pathname);
196
+ } else {
197
+ cache.show = true;
198
+ update({});
185
199
  }
200
+ } else if (type === ELifeCycleType.DEACTIVATED) {
201
+ // console.log('DEACTIVATED', location);
202
+ cache.show = false;
203
+ update({});
186
204
  }
187
- count.current += 1;
205
+ cache.count += 1;
206
+ });
207
+ useEffect(function () {
208
+ cache.portal = cache.portal || /*#__PURE__*/createPortal(children, cache.div);
209
+ // update({});
210
+ if (cache.show) {
211
+ var _document$getElementB;
212
+ // debugger;
213
+ (_document$getElementB = document.getElementById(cache.divId)) === null || _document$getElementB === void 0 || (_document$getElementB = _document$getElementB.parentElement) === null || _document$getElementB === void 0 || _document$getElementB.appendChild(cache.div);
214
+ } else {
215
+ cache.div.remove();
216
+ }
217
+ update({});
218
+ }, [cache.show]);
219
+ return /*#__PURE__*/_jsxs(_Fragment, {
220
+ children: [/*#__PURE__*/_jsx("div", {
221
+ id: cache.divId
222
+ }), cache.portal]
188
223
  });
189
- return /*#__PURE__*/_jsx(_Fragment, {});
190
224
  });
191
225
  /** 页面挂载组件 */
192
- _defineProperty(this, "KeepAliveItem", function (_ref) {
193
- var activate = _ref.activate,
194
- idKey = _ref.idKey;
226
+ _defineProperty(this, "KeepAliveItem", function (_ref2) {
227
+ var activate = _ref2.activate,
228
+ idKey = _ref2.idKey;
195
229
  var _useAccessRouter3 = useAccessRouter(),
196
230
  page = _useAccessRouter3.page;
197
- var _useState3 = useState({}),
198
- _useState4 = _slicedToArray(_useState3, 2),
199
- update = _useState4[1];
200
- var _useRef2 = useRef({
231
+ var _useState5 = useState({}),
232
+ _useState6 = _slicedToArray(_useState5, 2),
233
+ update = _useState6[1];
234
+ var _useRef3 = useRef({
201
235
  div: document.createElement('div'),
202
236
  portal: null,
203
237
  /** 是否挂载 */
@@ -207,7 +241,7 @@ export var KeepAliveClass = /*#__PURE__*/function () {
207
241
  /** 开启生命周期回调 */
208
242
  useLifeCycle: false
209
243
  }),
210
- cache = _useRef2.current;
244
+ cache = _useRef3.current;
211
245
  var lifeCycle = _this.keepAliveData.pageLifeCycle[idKey] = _this.keepAliveData.pageLifeCycle[idKey] || {
212
246
  callbacks: [],
213
247
  notification: function notification() {
@@ -227,9 +261,9 @@ export var KeepAliveClass = /*#__PURE__*/function () {
227
261
 
228
262
  useEffect(function () {
229
263
  if (activate && _this.contentDom) {
230
- cache.portal = cache.portal || /*#__PURE__*/createPortal( /*#__PURE__*/_jsxs(ErrorBoundary, {
231
- fallbackRender: function fallbackRender(_ref2) {
232
- var error = _ref2.error;
264
+ cache.portal = cache.portal || /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(ErrorBoundary, {
265
+ fallbackRender: function fallbackRender(_ref3) {
266
+ var error = _ref3.error;
233
267
  return /*#__PURE__*/_jsx(_Fragment, {
234
268
  children: /*#__PURE__*/_jsx(Result, {
235
269
  status: "error",
@@ -245,7 +279,9 @@ export var KeepAliveClass = /*#__PURE__*/function () {
245
279
  })
246
280
  });
247
281
  },
248
- children: [(page === null || page === void 0 ? void 0 : page.element) || /*#__PURE__*/_jsx(NoFoundPage, {}), /*#__PURE__*/_jsx(_this.AutoRefreshKeepAliveItem, {})]
282
+ children: /*#__PURE__*/_jsx(_this.AutoRefreshKeepAliveItem, {
283
+ children: (page === null || page === void 0 ? void 0 : page.element) || /*#__PURE__*/_jsx(NoFoundPage, {})
284
+ })
249
285
  }), cache.div);
250
286
  _this.contentDom.appendChild(cache.div);
251
287
  cache.mount = true;
@@ -413,7 +449,7 @@ export var KeepAliveClass = /*#__PURE__*/function () {
413
449
  setTimeout(function () {
414
450
  _this3.updateCurrentPage(index);
415
451
  rel();
416
- }, 0);
452
+ }, 160);
417
453
  });
418
454
  }
419
455
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamias/pro-layout",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",