x-star-design 0.0.66 → 0.0.67
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/dist/micro-app/index.js +47 -58
- package/package.json +1 -1
package/dist/micro-app/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
1
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
2
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
5
|
import { initGlobalState, loadMicroApp } from 'qiankun';
|
|
5
|
-
import React, { useEffect, useMemo } from 'react';
|
|
6
|
-
import ReactDOM from 'react-dom/client';
|
|
6
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
7
7
|
import { randomString } from 'x-star-utils';
|
|
8
8
|
import { useLocale } from "../locales";
|
|
9
9
|
import RainbowCat from "../rainbow-cat";
|
|
@@ -17,58 +17,13 @@ var MicroApp = function MicroApp(_ref) {
|
|
|
17
17
|
var microAppId = useMemo(function () {
|
|
18
18
|
return "microapp-".concat(randomString(8));
|
|
19
19
|
}, []);
|
|
20
|
+
var _useState = useState(false),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
loading = _useState2[0],
|
|
23
|
+
setLoading = _useState2[1];
|
|
20
24
|
var _useLocale = useLocale('MicroApp'),
|
|
21
25
|
t = _useLocale.format;
|
|
22
26
|
useEffect(function () {
|
|
23
|
-
// 创建一个加载元素
|
|
24
|
-
var rainbowCatContainer = null;
|
|
25
|
-
var showLoading = /*#__PURE__*/function () {
|
|
26
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
27
|
-
var microAppContainer;
|
|
28
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
29
|
-
while (1) switch (_context.prev = _context.next) {
|
|
30
|
-
case 0:
|
|
31
|
-
// 加载子应用前,创建一个容器并挂载 RainbowCat 组件
|
|
32
|
-
rainbowCatContainer = document.createElement('div');
|
|
33
|
-
rainbowCatContainer.style.position = 'absolute';
|
|
34
|
-
rainbowCatContainer.style.top = '0';
|
|
35
|
-
rainbowCatContainer.style.left = '0';
|
|
36
|
-
rainbowCatContainer.style.width = '100%';
|
|
37
|
-
microAppContainer = document.getElementById(microAppId);
|
|
38
|
-
microAppContainer.append(rainbowCatContainer);
|
|
39
|
-
ReactDOM.createRoot(rainbowCatContainer).render( /*#__PURE__*/React.createElement(RainbowCat, {
|
|
40
|
-
text: t('Loading')
|
|
41
|
-
}));
|
|
42
|
-
case 8:
|
|
43
|
-
case "end":
|
|
44
|
-
return _context.stop();
|
|
45
|
-
}
|
|
46
|
-
}, _callee);
|
|
47
|
-
}));
|
|
48
|
-
return function showLoading() {
|
|
49
|
-
return _ref2.apply(this, arguments);
|
|
50
|
-
};
|
|
51
|
-
}();
|
|
52
|
-
var hideLoading = /*#__PURE__*/function () {
|
|
53
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
54
|
-
var _rainbowCatContainer;
|
|
55
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
56
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
57
|
-
case 0:
|
|
58
|
-
// 挂载子应用前,卸载 RainbowCat 组件
|
|
59
|
-
(_rainbowCatContainer = rainbowCatContainer) === null || _rainbowCatContainer === void 0 ? void 0 : _rainbowCatContainer.remove();
|
|
60
|
-
rainbowCatContainer = null;
|
|
61
|
-
case 2:
|
|
62
|
-
case "end":
|
|
63
|
-
return _context2.stop();
|
|
64
|
-
}
|
|
65
|
-
}, _callee2);
|
|
66
|
-
}));
|
|
67
|
-
return function hideLoading() {
|
|
68
|
-
return _ref3.apply(this, arguments);
|
|
69
|
-
};
|
|
70
|
-
}();
|
|
71
|
-
|
|
72
27
|
// 启动 qiankun
|
|
73
28
|
var microApp = loadMicroApp({
|
|
74
29
|
name: name,
|
|
@@ -78,8 +33,40 @@ var MicroApp = function MicroApp(_ref) {
|
|
|
78
33
|
pathname: pathname
|
|
79
34
|
}, microProps)
|
|
80
35
|
}, undefined, {
|
|
81
|
-
beforeLoad:
|
|
82
|
-
|
|
36
|
+
beforeLoad: function () {
|
|
37
|
+
var _beforeLoad = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
38
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
|
+
while (1) switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
setLoading(true);
|
|
42
|
+
case 1:
|
|
43
|
+
case "end":
|
|
44
|
+
return _context.stop();
|
|
45
|
+
}
|
|
46
|
+
}, _callee);
|
|
47
|
+
}));
|
|
48
|
+
function beforeLoad() {
|
|
49
|
+
return _beforeLoad.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
return beforeLoad;
|
|
52
|
+
}(),
|
|
53
|
+
beforeMount: function () {
|
|
54
|
+
var _beforeMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
55
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
56
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
57
|
+
case 0:
|
|
58
|
+
setLoading(false);
|
|
59
|
+
case 1:
|
|
60
|
+
case "end":
|
|
61
|
+
return _context2.stop();
|
|
62
|
+
}
|
|
63
|
+
}, _callee2);
|
|
64
|
+
}));
|
|
65
|
+
function beforeMount() {
|
|
66
|
+
return _beforeMount.apply(this, arguments);
|
|
67
|
+
}
|
|
68
|
+
return beforeMount;
|
|
69
|
+
}()
|
|
83
70
|
});
|
|
84
71
|
return function () {
|
|
85
72
|
microApp.unmount();
|
|
@@ -92,11 +79,13 @@ var MicroApp = function MicroApp(_ref) {
|
|
|
92
79
|
position: 'relative',
|
|
93
80
|
minHeight: 600
|
|
94
81
|
}, style)
|
|
95
|
-
}
|
|
82
|
+
}, loading && /*#__PURE__*/React.createElement(RainbowCat, {
|
|
83
|
+
text: t('Loading')
|
|
84
|
+
}));
|
|
96
85
|
};
|
|
97
|
-
MicroApp.useGlobalState = function (
|
|
98
|
-
var lang =
|
|
99
|
-
setLang =
|
|
86
|
+
MicroApp.useGlobalState = function (_ref2) {
|
|
87
|
+
var lang = _ref2.lang,
|
|
88
|
+
setLang = _ref2.setLang;
|
|
100
89
|
var actions = useMemo(function () {
|
|
101
90
|
return initGlobalState({
|
|
102
91
|
lang: lang
|