@flatbiz/pro-layout 5.2.7 → 5.2.9

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/index.js CHANGED
@@ -2,32 +2,29 @@
2
2
  import './index.css';
3
3
  /*! @flatjs/forge MIT @flatbiz/pro-layout */
4
4
 
5
- import { App as App$1, Breadcrumb, FloatButton, Result, Button, Dropdown, Space, Menu, Badge, Layout, message as message$1, Tabs, Typography, theme } from 'antd';
6
- import { classNames } from '@dimjs/utils/class-names/class-names';
7
- import { useEffect, useMemo, Fragment, Children, cloneElement, forwardRef, useState, useImperativeHandle, isValidElement, Suspense, useRef, memo, Component } from 'react';
8
- import { useParams, useLocation, useSearchParams, matchPath, Link, useNavigate, Routes, Route, Navigate, BrowserRouter } from 'react-router-dom';
9
- import { sessionStorageCache, getRunningEnv, ensureSlash as ensureSlash$1, removeSlash, getGlobalData, toLinkPath, isHttpUri, toArray, urlJoinMulti, urlJoin, isWindows, valueIsEqual, toLinkPathWithQuery, openNewWindow, treeToArray, cloneObject, getUuid, EventEmitter, treeFilter, arrayFindByLoosely, arrayFindIndexByLoosely, isUndefinedOrNull, localStorageCache } from '@flatbiz/utils';
10
- import { fbaHooks } from '@flatbiz/antd/fba-hooks';
11
- import { parse } from '@dimjs/utils/json/parse';
5
+ import { useEffect, useMemo, Fragment, isValidElement, Suspense, useState, useRef, memo, Component, Children, cloneElement, forwardRef, useImperativeHandle } from 'react';
12
6
  import { useMemoizedFn, useUpdateEffect, useDebounceFn, useAsyncEffect } from 'ahooks';
13
- import { isArray } from '@dimjs/lang/is-array';
14
- import { pick } from '@dimjs/utils/pick/pick';
15
- import { paramStrToJson } from '@dimjs/utils/uri/param-str-to-json';
16
- import { jsx, jsxs } from 'react/jsx-runtime';
17
- import { ButtonWrapper } from '@flatbiz/antd/button-wrapper';
18
- import { isPromise } from '@dimjs/lang/is-promise';
19
- import { modifyQueryString } from '@dimjs/utils/uri/modify-query-string';
20
- import { uriParse } from '@dimjs/utils/uri/uri-parse';
21
- import { isUndefined } from '@dimjs/lang/is-undefined';
22
- import { isFragment } from 'react-is';
23
- import { createRoot } from 'react-dom/client';
7
+ import { App as App$1, Result, Breadcrumb, FloatButton, Dropdown, Space, Button, Menu, Badge, Layout, message as message$1, Tabs, Typography, theme } from 'antd';
24
8
  import { ConfigProviderWrapper } from '@flatbiz/antd/config-provider-wrapper';
25
9
  import { FbaApp } from '@flatbiz/antd/fba-app';
26
10
  import { getQueryString } from '@dimjs/utils/uri/get-query-string';
11
+ import { isArray } from '@dimjs/lang/is-array';
27
12
  import { extend } from '@dimjs/utils/extend/extend';
13
+ import { useParams, useLocation, useSearchParams, matchPath, Link, Routes, Route, Navigate, useNavigate, BrowserRouter } from 'react-router-dom';
14
+ import { getRunningEnv, sessionStorageCache, ensureSlash as ensureSlash$1, removeSlash, getGlobalData, toLinkPath, isHttpUri, toArray, urlJoinMulti, urlJoin, valueIsEqual, toLinkPathWithQuery, openNewWindow, isWindows, treeToArray, cloneObject, getUuid, EventEmitter, treeFilter, arrayFindByLoosely, arrayFindIndexByLoosely, isUndefinedOrNull, localStorageCache } from '@flatbiz/utils';
28
15
  import { get } from '@dimjs/utils/get/get';
16
+ import { fbaHooks } from '@flatbiz/antd/fba-hooks';
17
+ import { jsx, jsxs } from 'react/jsx-runtime';
29
18
  import { isString } from '@dimjs/lang/is-string';
19
+ import { classNames } from '@dimjs/utils/class-names/class-names';
20
+ import { parse } from '@dimjs/utils/json/parse';
21
+ import { pick } from '@dimjs/utils/pick/pick';
22
+ import { paramStrToJson } from '@dimjs/utils/uri/param-str-to-json';
23
+ import { isHttpUrl } from '@dimjs/utils/uri/is-http-url';
24
+ import { modifyQueryString } from '@dimjs/utils/uri/modify-query-string';
25
+ import { uriParse } from '@dimjs/utils/uri/uri-parse';
30
26
  import _CloseOutlined from '@ant-design/icons/es/icons/CloseOutlined.js';
27
+ import { isUndefined } from '@dimjs/lang/is-undefined';
31
28
  import { useMediaQuery } from 'react-responsive';
32
29
  import { SvgHttpView } from '@flatbiz/antd/svg-http-view';
33
30
  import { findAncestors } from '@dimjs/utils/tree/find-ancestors';
@@ -44,17 +41,10 @@ import _CaretDownOutlined from '@ant-design/icons/es/icons/CaretDownOutlined.js'
44
41
  import _LoadingOutlined from '@ant-design/icons/es/icons/LoadingOutlined.js';
45
42
  import _RedoOutlined from '@ant-design/icons/es/icons/RedoOutlined.js';
46
43
  import { arrayRemove } from '@dimjs/utils/array/array-remove';
47
-
48
- var message;
49
- var notification;
50
- var modal;
51
- var useAntdApp = (function () {
52
- var staticFunction = App$1.useApp();
53
- message = staticFunction.message;
54
- modal = staticFunction.modal;
55
- notification = staticFunction.notification;
56
- return null;
57
- });
44
+ import { ButtonWrapper } from '@flatbiz/antd/button-wrapper';
45
+ import { isPromise } from '@dimjs/lang/is-promise';
46
+ import { isFragment } from 'react-is';
47
+ import { createRoot } from 'react-dom/client';
58
48
 
59
49
  function _arrayLikeToArray(r, a) {
60
50
  (null == a || a > r.length) && (a = r.length);
@@ -236,6 +226,91 @@ function _unsupportedIterableToArray(r, a) {
236
226
  }
237
227
  }
238
228
 
229
+ var AntdAppWrapper = function AntdAppWrapper(props) {
230
+ var theme = fbaHooks.useThemeToken();
231
+ var appProviderValue = props.appProviderValue;
232
+ var headerThemeConfig = appProviderValue.headerThemeConfig;
233
+ var sidebarThemeConfig = appProviderValue.sidebarThemeConfig;
234
+ var varStyleList = [{
235
+ '--header-bgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.bgColor
236
+ }, {
237
+ '--header-textColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.textColor
238
+ }, {
239
+ '--header-menuColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuColor
240
+ }, {
241
+ '--header-menuActiveTextColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuActiveTextColor
242
+ }, {
243
+ '--header-menuActiveBgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuActiveBgColor
244
+ }, {
245
+ '--header-menuSelectedBgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuSelectedBgColor
246
+ }, {
247
+ '--header-menuSelectedTextColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuSelectedTextColor
248
+ }, {
249
+ '--sidebar-bgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.bgColor
250
+ }, {
251
+ '--sidebar-menuActiveBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuActiveBgColor
252
+ }, {
253
+ '--sidebar-menuActiveTextColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuActiveTextColor
254
+ }, {
255
+ '--sidebar-menuSelectedBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSelectedBgColor
256
+ }, {
257
+ '--sidebar-menuSelectedTextColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSelectedTextColor
258
+ }, {
259
+ '--sidebar-menuSubMenuBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSubMenuBgColor
260
+ }, {
261
+ '--sidebar-menuColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuColor
262
+ }, {
263
+ '--color-primary': theme.colorPrimary
264
+ }];
265
+ if (appProviderValue.dark) {
266
+ varStyleList.push({
267
+ '--block-bg-color': get(appProviderValue, 'bgColorConfig.dark.blockBgColor', '#000')
268
+ });
269
+ varStyleList.push({
270
+ '--bg-color': get(appProviderValue, 'bgColorConfig.dark.bgColor', '#1b1a1a')
271
+ });
272
+ } else {
273
+ varStyleList.push({
274
+ '--block-bg-color': get(appProviderValue, 'bgColorConfig.light.blockBgColor', '#FFF')
275
+ });
276
+ varStyleList.push({
277
+ '--bg-color': get(appProviderValue, 'bgColorConfig.light.bgColor', '#F2F2F2')
278
+ });
279
+ }
280
+ var varStyleText = '';
281
+ varStyleList.forEach(function (item) {
282
+ var key = Object.keys(item)[0];
283
+ if (item[key]) {
284
+ varStyleText = varStyleText + "".concat(key, ":").concat(item[key], ";");
285
+ }
286
+ });
287
+ document.body.style.cssText = "".concat(document.body.style.cssText, ";").concat(varStyleText);
288
+ if (appProviderValue.dark) {
289
+ document.body.classList.remove('light-theme');
290
+ document.body.classList.add('dark-theme');
291
+ } else {
292
+ document.body.classList.remove('dark-theme');
293
+ document.body.classList.add('light-theme');
294
+ }
295
+ if (appProviderValue.compact) {
296
+ document.body.classList.add('compact-theme');
297
+ } else {
298
+ document.body.classList.remove('compact-theme');
299
+ }
300
+ return /*#__PURE__*/jsx(App$1, {
301
+ className: appProviderValue.className,
302
+ children: props.children
303
+ });
304
+ };
305
+
306
+ var NotFound = function NotFound() {
307
+ return /*#__PURE__*/jsx(Result, {
308
+ status: "404",
309
+ title: "404",
310
+ subTitle: "Sorry, \u60A8\u8BBF\u95EE\u7684\u5730\u5740\u4E0D\u5B58\u5728"
311
+ });
312
+ };
313
+
239
314
  var _fbaHooks$createCtx$1 = fbaHooks.createCtx(),
240
315
  _fbaHooks$createCtx2$1 = _slicedToArray(_fbaHooks$createCtx$1, 2),
241
316
  useLayoutCtx = _fbaHooks$createCtx2$1[0],
@@ -838,6 +913,31 @@ var Bread = function Bread(props) {
838
913
  });
839
914
  };
840
915
 
916
+ var Loader = function Loader(_ref) {
917
+ var _ref$spinning = _ref.spinning,
918
+ spinning = _ref$spinning === void 0 ? false : _ref$spinning,
919
+ _ref$fullScreen = _ref.fullScreen,
920
+ fullScreen = _ref$fullScreen === void 0 ? false : _ref$fullScreen,
921
+ _ref$style = _ref.style,
922
+ style = _ref$style === void 0 ? {} : _ref$style;
923
+ return /*#__PURE__*/jsx("div", {
924
+ style: style,
925
+ className: classNames('loader', {
926
+ hidden: !spinning,
927
+ fullScreen: fullScreen
928
+ }),
929
+ children: /*#__PURE__*/jsxs("div", {
930
+ className: "loader-wrapper",
931
+ children: [/*#__PURE__*/jsx("div", {
932
+ className: "loader-inner"
933
+ }), /*#__PURE__*/jsx("div", {
934
+ className: "loader-text",
935
+ children: "LOADING"
936
+ })]
937
+ })
938
+ });
939
+ };
940
+
841
941
  // export const urlJoin = (first: string, second: string) => {
842
942
  // return (first || '').replace(/\/$/, '') + '/' + (second || '').replace(/^\//, '');
843
943
  // };
@@ -1204,422 +1304,29 @@ var getHostUrlAndRouteBaseName = function getHostUrlAndRouteBaseName(pathOrUrl)
1204
1304
  };
1205
1305
  };
1206
1306
 
1207
- var _excluded$3 = ["level"];
1208
1307
  /**
1209
- * 通过面包屑路径返回
1210
- * @param props
1211
- * @returns
1212
- * ```
1213
- * 1. breads 模块面包屑配置
1214
- * 2. level回退级别,如果传递数据未获取到路由配置,则取上一级
1215
- * 例如:-1,-2,-3
1216
- * 3. 为什么不能使用useNavigate(-1)
1217
- * 因为内部iframe和外部浏览器共用history历史记录,导致里外浏览器栈混乱
1218
- * 4. 什么场景使用
1219
- * 使用iframe tab的项目,在执行路由回退时使用
1220
- * 5. onClick返回 promise reject,则不会进行回退处理(V4.2.4)
1221
- * ```
1308
+ * 写一个函数,入参数一个http链接,根据当前浏览器访问页面的协议,把入参改成相同协议在返回
1309
+ * 例如:当前访问地址为 https,则传入的参数改成 https 协议在返回
1222
1310
  */
1223
- var HistoryBackButton = function HistoryBackButton(props) {
1224
- var ctx = bootstrapCtx();
1225
- var level = props.level,
1226
- otherProps = _objectWithoutProperties(props, _excluded$3);
1227
- var _getHostUrlAndRouteBa = getHostUrlAndRouteBaseName(location.href),
1228
- routeBaseName = _getHostUrlAndRouteBa.routeBaseName;
1229
- var routerList = useBread(ctx.breads, routeBaseName);
1230
- var navigate = useNavigate();
1231
- var path = useMemo(function () {
1232
- var newLevel = level || -1;
1233
- if (routerList.length >= 2) {
1234
- var routerItem = routerList[routerList.length - 1 - Math.abs(newLevel)] || routerList[routerList.length - 2];
1235
- if (routerItem) {
1236
- return toLinkPath(routerItem.path, routerItem.query);
1237
- } else {
1238
- console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
1239
- return '';
1240
- }
1241
- }
1242
- console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
1243
- return '';
1244
- }, []);
1245
- var onBack = function onBack() {
1246
- if (path) {
1247
- navigate(toLinkPath(path));
1248
- } else {
1249
- console.warn("\u672A\u83B7\u53D6\u5230\u9762\u5305\u5C51\u6570\u636E\uFF0C\u65E0\u8FD4\u56DE\u94FE\u63A5");
1250
- }
1251
- };
1252
- var onClick = useMemoizedFn(function (event) {
1253
- var _props$onClick;
1254
- var result = props === null || props === void 0 || (_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props, event);
1255
- if (result && isPromise(result)) {
1256
- return result.then(function () {
1257
- onBack();
1258
- });
1259
- }
1260
- onBack();
1261
- return;
1262
- });
1263
- return /*#__PURE__*/jsx(ButtonWrapper, _objectSpread2(_objectSpread2({}, otherProps), {}, {
1264
- onClick: onClick,
1265
- children: props.children || '返回'
1266
- }));
1311
+ var getSameProtocolUrl = function getSameProtocolUrl(url) {
1312
+ if (!isHttpUrl(url)) return url;
1313
+ var protocol = window.location.protocol;
1314
+ var newUrl = url.replace('http://', '');
1315
+ newUrl = newUrl.replace('https://', '');
1316
+ return "".concat(protocol, "//").concat(newUrl);
1267
1317
  };
1268
- var useHistoryBack = function useHistoryBack(props) {
1269
- var ctx = bootstrapCtx();
1270
- var level = (props === null || props === void 0 ? void 0 : props.level) || -1;
1271
- var _getHostUrlAndRouteBa2 = getHostUrlAndRouteBaseName(location.href),
1272
- routeBaseName = _getHostUrlAndRouteBa2.routeBaseName;
1273
- var routerList = useBread(ctx.breads, routeBaseName);
1274
- var path = useMemo(function () {
1275
- var newLevel = level;
1276
- if (routerList.length >= 2) {
1277
- var routerItem = routerList[routerList.length - 1 - Math.abs(newLevel)] || routerList[routerList.length - 2];
1278
- if (routerItem) {
1279
- return toLinkPath(routerItem.path, routerItem.query);
1280
- } else {
1281
- console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
1282
- return '';
1318
+
1319
+ var AppRoutes = function AppRoutes(props) {
1320
+ var getHideBreadsFlag = function getHideBreadsFlag() {
1321
+ var _props$hideBreadsPath;
1322
+ var target = (_props$hideBreadsPath = props.hideBreadsPathList) === null || _props$hideBreadsPath === void 0 ? void 0 : _props$hideBreadsPath.find(function (item) {
1323
+ if (props.layoutMode === 'iframe-tab') {
1324
+ return getIframeMainPurePath(item) == getIframeMainPurePath(location.pathname);
1283
1325
  }
1284
- }
1285
- console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
1286
- return '';
1287
- }, []);
1288
- return {
1289
- path: path
1290
- };
1291
- };
1292
-
1293
- var Loader = function Loader(_ref) {
1294
- var _ref$spinning = _ref.spinning,
1295
- spinning = _ref$spinning === void 0 ? false : _ref$spinning,
1296
- _ref$fullScreen = _ref.fullScreen,
1297
- fullScreen = _ref$fullScreen === void 0 ? false : _ref$fullScreen,
1298
- _ref$style = _ref.style,
1299
- style = _ref$style === void 0 ? {} : _ref$style;
1300
- return /*#__PURE__*/jsx("div", {
1301
- style: style,
1302
- className: classNames('loader', {
1303
- hidden: !spinning,
1304
- fullScreen: fullScreen
1305
- }),
1306
- children: /*#__PURE__*/jsxs("div", {
1307
- className: "loader-wrapper",
1308
- children: [/*#__PURE__*/jsx("div", {
1309
- className: "loader-inner"
1310
- }), /*#__PURE__*/jsx("div", {
1311
- className: "loader-text",
1312
- children: "LOADING"
1313
- })]
1314
- })
1315
- });
1316
- };
1317
-
1318
- /**
1319
- * 页面包装组件
1320
- * ```
1321
- * 1. 如果初始化面包屑被隐藏,在特殊页面级可以独立设置显示面包屑
1322
- * <Page bread={<Bread />}/>
1323
- * 2. 如果需要在 面包屑上添加按钮,初始化设置 bootstrap.hideDefaultBread = true,在需要按钮的页面上配置
1324
- * <Page bread={<Bread><Button>我是按钮</Button></Bread>}/>
1325
- * ```
1326
- * @param props
1327
- * @returns
1328
- */
1329
- var Page = function Page(props) {
1330
- var loading = props.loading;
1331
- var isWin = isWindows();
1332
- var className = classNames('page', {
1333
- 'page-loading': loading,
1334
- 'page-flex': !isUndefined(props.fullIndex),
1335
- 'page-windows': isWin
1336
- }, props.className);
1337
- var backTopTarget = useMemoizedFn(function () {
1338
- if (!isUndefined(props.fullIndex)) {
1339
- return document.querySelector('.page-full');
1340
- }
1341
- return document.querySelector('.page');
1342
- });
1343
- return /*#__PURE__*/jsxs(Fragment, {
1344
- children: [props.bread, /*#__PURE__*/jsxs("div", {
1345
- style: props.style,
1346
- className: className,
1347
- id: props.elementId,
1348
- children: [Children.map(props.children, function (item, index) {
1349
- if (index === props.fullIndex) {
1350
- var _item$props;
1351
- return /*#__PURE__*/jsx(Fragment, {
1352
- children: /*#__PURE__*/cloneElement(item, {
1353
- className: classNames('page-full', item === null || item === void 0 || (_item$props = item['props']) === null || _item$props === void 0 ? void 0 : _item$props.className)
1354
- })
1355
- }, index);
1356
- }
1357
- return /*#__PURE__*/jsx(Fragment, {
1358
- children: item
1359
- }, index);
1360
- }), /*#__PURE__*/jsx(FloatButton.BackTop, {
1361
- target: backTopTarget
1362
- }), loading && /*#__PURE__*/jsx(Loader, {
1363
- spinning: true
1364
- })]
1365
- })]
1366
- });
1367
- };
1368
-
1369
- var _fbaHooks$createCtx = fbaHooks.createCtx(),
1370
- _fbaHooks$createCtx2 = _slicedToArray(_fbaHooks$createCtx, 2),
1371
- usePageWrapperCtx = _fbaHooks$createCtx2[0],
1372
- PageWrapperCtxProvider = _fbaHooks$createCtx2[1];
1373
-
1374
- var _excluded$2 = ["respData"],
1375
- _excluded2 = ["serviceConfig", "isAsync", "errorRender"];
1376
- var PageContent$1 = function PageContent(props) {
1377
- var _props$children;
1378
- var respData = props.respData,
1379
- otherProps = _objectWithoutProperties(props, _excluded$2);
1380
- var children = typeof props.children === 'function' ? (_props$children = props.children) === null || _props$children === void 0 ? void 0 : _props$children.call(props, respData) : props.children;
1381
- if (isFragment(children)) {
1382
- var childrenList = Children.toArray(children.props.children);
1383
- return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({}, otherProps), {}, {
1384
- children: childrenList
1385
- }));
1386
- }
1387
- return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({}, otherProps), {}, {
1388
- children: children
1389
- }));
1390
- };
1391
-
1392
- /**
1393
- * 为Page内置接口处理流程组件,如果无全局初始化接口请求场景,请使用Page组件
1394
- * ```
1395
- * 包括
1396
- * 1. loading显示效果
1397
- * 2. error显示效果
1398
- * 3. 正常接口数据渲染
1399
- * ```
1400
- * @param props
1401
- * @returns
1402
- */
1403
- var PageWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
1404
- var serviceConfig = props.serviceConfig,
1405
- isAsync = props.isAsync,
1406
- errorRender = props.errorRender,
1407
- otherProps = _objectWithoutProperties(props, _excluded2);
1408
- var _useState = useState({
1409
- status: 'loading'
1410
- }),
1411
- _useState2 = _slicedToArray(_useState, 2),
1412
- result = _useState2[0],
1413
- setResult = _useState2[1];
1414
- var _useState3 = useState(false),
1415
- _useState4 = _slicedToArray(_useState3, 2),
1416
- againRefresh = _useState4[0],
1417
- setAgainRefresh = _useState4[1];
1418
- var onRequest = function onRequest() {
1419
- return new Promise(function ($return, $error) {
1420
- var params, _result;
1421
- var $Try_1_Post = function () {
1422
- try {
1423
- return $return(Promise.resolve());
1424
- } catch ($boundEx) {
1425
- return $error($boundEx);
1426
- }
1427
- };
1428
- var $Try_1_Catch = function (error) {
1429
- try {
1430
- setResult({
1431
- status: 'error',
1432
- respData: error
1433
- });
1434
- return $Try_1_Post();
1435
- } catch ($boundEx) {
1436
- return $error($boundEx);
1437
- }
1438
- };
1439
- try {
1440
- params = typeof serviceConfig.params === 'function' ? serviceConfig.params() : serviceConfig.params;
1441
- return Promise.resolve(serviceConfig.onRequest(params)).then(function ($await_2) {
1442
- try {
1443
- _result = $await_2;
1444
- setResult({
1445
- status: 'success',
1446
- respData: _result
1447
- });
1448
- return $Try_1_Post();
1449
- } catch ($boundEx) {
1450
- return $Try_1_Catch($boundEx);
1451
- }
1452
- }, $Try_1_Catch);
1453
- } catch (error) {
1454
- $Try_1_Catch(error);
1455
- }
1456
- });
1457
- };
1458
- fbaHooks.useEffectCustomAsync(onRequest, []);
1459
- var onReload = useMemoizedFn(function () {
1460
- setResult({
1461
- status: 'loading'
1462
- });
1463
- void onRequest();
1464
- });
1465
- var onRefresh = useMemoizedFn(function () {
1466
- setAgainRefresh(true);
1467
- onRequest().finally(function () {
1468
- setAgainRefresh(false);
1469
- });
1470
- });
1471
- useImperativeHandle(ref, function () {
1472
- return {
1473
- onRefresh: onRefresh,
1474
- onReload: onReload
1475
- };
1476
- });
1477
- if (result.status === 'error') {
1478
- var _result$respData;
1479
- if (errorRender) {
1480
- return errorRender(result.respData);
1481
- }
1482
- return /*#__PURE__*/jsx(Page, {
1483
- fullIndex: 0,
1484
- style: {
1485
- backgroundColor: '#fff'
1486
- },
1487
- children: /*#__PURE__*/jsx(Result, {
1488
- status: "error",
1489
- title: '数据获取异常',
1490
- subTitle: ((_result$respData = result.respData) === null || _result$respData === void 0 ? void 0 : _result$respData.message) || '数据请求异常',
1491
- extra: [/*#__PURE__*/jsx(Button, {
1492
- type: "primary",
1493
- onClick: onReload,
1494
- children: "\u91CD\u65B0\u83B7\u53D6"
1495
- }, "console")]
1496
- })
1497
- });
1498
- }
1499
- if (result.status === 'loading' && !isAsync) {
1500
- return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({
1501
- loading: true
1502
- }, otherProps), {}, {
1503
- children: /*#__PURE__*/jsx(Fragment, {})
1504
- }));
1505
- }
1506
- return /*#__PURE__*/jsxs(PageWrapperCtxProvider, {
1507
- value: {
1508
- onReload: onReload,
1509
- onRefresh: onRefresh
1510
- },
1511
- children: [againRefresh ? /*#__PURE__*/jsx(Loader, {
1512
- spinning: true,
1513
- style: {
1514
- backgroundColor: 'transparent'
1515
- }
1516
- }) : null, /*#__PURE__*/jsx(PageContent$1, _objectSpread2({
1517
- loading: result.status === 'loading',
1518
- respData: result.respData
1519
- }, otherProps))]
1520
- });
1521
- });
1522
- var usePageWrapper = function usePageWrapper() {
1523
- var ctx = usePageWrapperCtx();
1524
- return ctx;
1525
- };
1526
-
1527
- var AntdAppWrapper = function AntdAppWrapper(props) {
1528
- var theme = fbaHooks.useThemeToken();
1529
- var appProviderValue = props.appProviderValue;
1530
- var headerThemeConfig = appProviderValue.headerThemeConfig;
1531
- var sidebarThemeConfig = appProviderValue.sidebarThemeConfig;
1532
- var varStyleList = [{
1533
- '--header-bgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.bgColor
1534
- }, {
1535
- '--header-textColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.textColor
1536
- }, {
1537
- '--header-menuColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuColor
1538
- }, {
1539
- '--header-menuActiveTextColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuActiveTextColor
1540
- }, {
1541
- '--header-menuActiveBgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuActiveBgColor
1542
- }, {
1543
- '--header-menuSelectedBgColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuSelectedBgColor
1544
- }, {
1545
- '--header-menuSelectedTextColor': headerThemeConfig === null || headerThemeConfig === void 0 ? void 0 : headerThemeConfig.menuSelectedTextColor
1546
- }, {
1547
- '--sidebar-bgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.bgColor
1548
- }, {
1549
- '--sidebar-menuActiveBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuActiveBgColor
1550
- }, {
1551
- '--sidebar-menuActiveTextColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuActiveTextColor
1552
- }, {
1553
- '--sidebar-menuSelectedBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSelectedBgColor
1554
- }, {
1555
- '--sidebar-menuSelectedTextColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSelectedTextColor
1556
- }, {
1557
- '--sidebar-menuSubMenuBgColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuSubMenuBgColor
1558
- }, {
1559
- '--sidebar-menuColor': sidebarThemeConfig === null || sidebarThemeConfig === void 0 ? void 0 : sidebarThemeConfig.menuColor
1560
- }, {
1561
- '--color-primary': theme.colorPrimary
1562
- }];
1563
- if (appProviderValue.dark) {
1564
- varStyleList.push({
1565
- '--block-bg-color': get(appProviderValue, 'bgColorConfig.dark.blockBgColor', '#000')
1566
- });
1567
- varStyleList.push({
1568
- '--bg-color': get(appProviderValue, 'bgColorConfig.dark.bgColor', '#1b1a1a')
1569
- });
1570
- } else {
1571
- varStyleList.push({
1572
- '--block-bg-color': get(appProviderValue, 'bgColorConfig.light.blockBgColor', '#FFF')
1573
- });
1574
- varStyleList.push({
1575
- '--bg-color': get(appProviderValue, 'bgColorConfig.light.bgColor', '#F2F2F2')
1576
- });
1577
- }
1578
- var varStyleText = '';
1579
- varStyleList.forEach(function (item) {
1580
- var key = Object.keys(item)[0];
1581
- if (item[key]) {
1582
- varStyleText = varStyleText + "".concat(key, ":").concat(item[key], ";");
1583
- }
1584
- });
1585
- document.body.style.cssText = "".concat(document.body.style.cssText, ";").concat(varStyleText);
1586
- if (appProviderValue.dark) {
1587
- document.body.classList.remove('light-theme');
1588
- document.body.classList.add('dark-theme');
1589
- } else {
1590
- document.body.classList.remove('dark-theme');
1591
- document.body.classList.add('light-theme');
1592
- }
1593
- if (appProviderValue.compact) {
1594
- document.body.classList.add('compact-theme');
1595
- } else {
1596
- document.body.classList.remove('compact-theme');
1597
- }
1598
- return /*#__PURE__*/jsx(App$1, {
1599
- className: appProviderValue.className,
1600
- children: props.children
1601
- });
1602
- };
1603
-
1604
- var NotFound = function NotFound() {
1605
- return /*#__PURE__*/jsx(Result, {
1606
- status: "404",
1607
- title: "404",
1608
- subTitle: "Sorry, \u60A8\u8BBF\u95EE\u7684\u5730\u5740\u4E0D\u5B58\u5728"
1609
- });
1610
- };
1611
-
1612
- var AppRoutes = function AppRoutes(props) {
1613
- var getHideBreadsFlag = function getHideBreadsFlag() {
1614
- var _props$hideBreadsPath;
1615
- var target = (_props$hideBreadsPath = props.hideBreadsPathList) === null || _props$hideBreadsPath === void 0 ? void 0 : _props$hideBreadsPath.find(function (item) {
1616
- if (props.layoutMode === 'iframe-tab') {
1617
- return getIframeMainPurePath(item) == getIframeMainPurePath(location.pathname);
1618
- }
1619
- return getPurePath(item) == getPurePath(location.pathname);
1620
- });
1621
- if (target) return true;
1622
- return !!getQueryString('hideBreads');
1326
+ return getPurePath(item) == getPurePath(location.pathname);
1327
+ });
1328
+ if (target) return true;
1329
+ return !!getQueryString('hideBreads');
1623
1330
  };
1624
1331
  var hideBreads = getHideBreadsFlag();
1625
1332
  var routeList = props.routeList;
@@ -1675,6 +1382,17 @@ var AppRoutes = function AppRoutes(props) {
1675
1382
  });
1676
1383
  };
1677
1384
 
1385
+ var message;
1386
+ var notification;
1387
+ var modal;
1388
+ var useAntdApp = (function () {
1389
+ var staticFunction = App$1.useApp();
1390
+ message = staticFunction.message;
1391
+ modal = staticFunction.modal;
1392
+ notification = staticFunction.notification;
1393
+ return null;
1394
+ });
1395
+
1678
1396
  var currentIsIframe = function currentIsIframe() {
1679
1397
  return self != top;
1680
1398
  };
@@ -1949,6 +1667,19 @@ function removeNodesAtDepth(tree, depth, maxDepth) {
1949
1667
  var getMenus = function getMenus(isIframeType, siderBarMaxMenuLevel, disableTopbarMenu) {
1950
1668
  var globalData = getGlobalData();
1951
1669
  var menus = globalData.menus || [];
1670
+ if (!disableTopbarMenu) {
1671
+ for (var i = 0; i < menus.length; i++) {
1672
+ var item = menus[i];
1673
+ if (!item.link || !isHttpUri(item.link)) {
1674
+ var target = findFirstLeafNode(item);
1675
+ if (isIframeType) {
1676
+ item.link = guessIframeMainLink(target.path);
1677
+ } else {
1678
+ item.link = guessNormalItemLink(target.path);
1679
+ }
1680
+ }
1681
+ }
1682
+ }
1952
1683
  treeToArray(menus, 'children').forEach(function (item) {
1953
1684
  var _item$children;
1954
1685
  if (isPlainObject(item.link)) {
@@ -1976,8 +1707,7 @@ var getMenus = function getMenus(isIframeType, siderBarMaxMenuLevel, disableTopb
1976
1707
  if (!item.link) {
1977
1708
  item.link = guessIframeTabItemLink(item.path);
1978
1709
  } else if (!isHttpUri(item.link)) {
1979
- // 解决link不完整,以及link中包含/main
1980
- item.link = guessIframeTabItemLink(item.link);
1710
+ item.link = urlJoin(location.origin, item.link);
1981
1711
  }
1982
1712
  } else {
1983
1713
  if (item.link && !isHttpUri(item.link)) {
@@ -3101,7 +2831,7 @@ var getIframeTabUid = function getIframeTabUid(prefix) {
3101
2831
  return "".concat(prefix, "_").concat(iframeId);
3102
2832
  };
3103
2833
 
3104
- var _excluded$1 = ["_isClosed"];
2834
+ var _excluded$3 = ["_isClosed"];
3105
2835
  var EventHandling = function EventHandling() {
3106
2836
  var navigate = useNavigate();
3107
2837
  var layoutCtx = useLayoutCtx();
@@ -3112,7 +2842,7 @@ var EventHandling = function EventHandling() {
3112
2842
  if (result.type === 'redirect_to_frame_layout_menu_item') {
3113
2843
  var _ref = result.data,
3114
2844
  _isClosed = _ref._isClosed,
3115
- iframeTabItem = _objectWithoutProperties(_ref, _excluded$1);
2845
+ iframeTabItem = _objectWithoutProperties(_ref, _excluded$3);
3116
2846
  var targetIndex = layoutCtx.iframeTabList.findIndex(function (item) {
3117
2847
  var _layoutCtx$iframeTabA;
3118
2848
  return valueIsEqual(item.id, (_layoutCtx$iframeTabA = layoutCtx.iframeTabActiveItem) === null || _layoutCtx$iframeTabA === void 0 ? void 0 : _layoutCtx$iframeTabA.id);
@@ -3247,7 +2977,7 @@ var IframePage = /*#__PURE__*/memo(IframePageInner, function (prevProps, nextPro
3247
2977
  return prevProps.iframeKey === nextProps.iframeKey;
3248
2978
  });
3249
2979
 
3250
- var PageContent = function PageContent() {
2980
+ var PageContent$1 = function PageContent() {
3251
2981
  var _useLayoutCtx = useLayoutCtx(),
3252
2982
  iframeTabList = _useLayoutCtx.iframeTabList,
3253
2983
  iframeTabBarExtra = _useLayoutCtx.iframeTabBarExtra,
@@ -3644,7 +3374,7 @@ var LayoutIFrame = function LayoutIFrame() {
3644
3374
  });
3645
3375
  }
3646
3376
  if (layoutCtx.multiFrameTabs) {
3647
- return /*#__PURE__*/jsx(PageContent, {});
3377
+ return /*#__PURE__*/jsx(PageContent$1, {});
3648
3378
  }
3649
3379
  if (layoutCtx.siderBarMaxMenuLevel) {
3650
3380
  return /*#__PURE__*/jsx(PageLevelContent, {});
@@ -3703,7 +3433,7 @@ var NormalRoutesTiming = function NormalRoutesTiming() {
3703
3433
  return /*#__PURE__*/jsx(Fragment, {});
3704
3434
  };
3705
3435
 
3706
- var _excluded = ["sidebarWidth", "componentSize", "locale", "logoPath", "headerThemeConfig", "sidebarThemeConfig", "completeMenus", "onIframeTabActiveEvent"];
3436
+ var _excluded$2 = ["sidebarWidth", "componentSize", "locale", "logoPath", "headerThemeConfig", "sidebarThemeConfig", "completeMenus", "onIframeTabActiveEvent"];
3707
3437
  var AppProvider = function AppProvider(props) {
3708
3438
  var navigate = useNavigate();
3709
3439
  var sidebarWidth = props.sidebarWidth,
@@ -3714,7 +3444,7 @@ var AppProvider = function AppProvider(props) {
3714
3444
  sidebarThemeConfig = props.sidebarThemeConfig,
3715
3445
  completeMenus = props.completeMenus,
3716
3446
  onIframeTabActiveEvent = props.onIframeTabActiveEvent,
3717
- options = _objectWithoutProperties(props, _excluded);
3447
+ options = _objectWithoutProperties(props, _excluded$2);
3718
3448
  var isIframeMain = options.layoutMode === 'iframe-main';
3719
3449
  var unMatchHiddenSiderBar = useMemo(function () {
3720
3450
  if (options.disableTopbarMenu) {
@@ -4691,121 +4421,424 @@ var BootstrapContent = function BootstrapContent(options) {
4691
4421
  space: {
4692
4422
  size: componentSize
4693
4423
  }
4694
- }, configProviderProps), {}, {
4695
- children: /*#__PURE__*/jsx(ContainerWrapper, {
4696
- children: /*#__PURE__*/jsx(BrowserRouter, {
4697
- basename: globalValue.routeBaseName,
4698
- children: /*#__PURE__*/jsx(BootstrapCtx, {
4699
- value: {
4700
- breads: breadList,
4701
- breadTitle: appProviderValue.breadTitle,
4702
- breadcrumbProps: appProviderValue.breadcrumbProps,
4703
- layoutMode: appProviderValue.layoutMode
4704
- },
4705
- children: /*#__PURE__*/jsx(AntdAppWrapper, {
4706
- appProviderValue: appProviderValue,
4707
- children: /*#__PURE__*/jsx(FbaApp, {
4708
- children: /*#__PURE__*/jsxs(ErrorBoundary, {
4709
- onError: options.onError,
4710
- onReset: options.onErrorReset,
4711
- FallbackComponent: options.ErrorFallback || ErrorFallback,
4712
- children: [layoutMode === 'iframe-main' ? /*#__PURE__*/jsx(IframeMainRegister, {}) : null, /*#__PURE__*/jsx(Container, {
4713
- layoutMode: appProviderValue.layoutMode,
4714
- MenuEmptyRender: appProviderValue.MenuEmptyRender,
4715
- menus: menus,
4716
- ignoreMenuEmptyJudge: appProviderValue.ignoreMenuEmptyJudge,
4717
- children: isNoLayout ? /*#__PURE__*/jsx(AppNoLayout, {
4718
- routeList: routeList,
4719
- layoutMode: layoutMode,
4720
- LayoutComponent: appProviderValue.LayoutComponent,
4721
- breadExtendRender: appProviderValue.breadExtendRender,
4722
- breads: appProviderValue.breads,
4723
- hideDefaultBread: appProviderValue.hideDefaultBread,
4724
- hideHeader: appProviderValue.hideHeader,
4725
- breadTitle: appProviderValue.breadTitle,
4726
- iframeTabAloneView: appProviderValue.iframeTabAloneView,
4727
- layoutPageClassName: appProviderValue.layoutPageClassName,
4728
- hideBreadsPathList: appProviderValue.hideBreadsPathList,
4729
- developmentEnvGuideConfigs: appProviderValue.developmentEnvGuideConfigs,
4730
- showProdEnvGuide: appProviderValue.showProdEnvGuide,
4731
- hidenEnvGuide: appProviderValue.hidenEnvGuide
4732
- }) : /*#__PURE__*/jsx(AppProvider, _objectSpread2({}, appProviderValue))
4733
- })]
4734
- })
4424
+ }, configProviderProps), {}, {
4425
+ children: /*#__PURE__*/jsx(ContainerWrapper, {
4426
+ children: /*#__PURE__*/jsx(BrowserRouter, {
4427
+ basename: globalValue.routeBaseName,
4428
+ children: /*#__PURE__*/jsx(BootstrapCtx, {
4429
+ value: {
4430
+ breads: breadList,
4431
+ breadTitle: appProviderValue.breadTitle,
4432
+ breadcrumbProps: appProviderValue.breadcrumbProps,
4433
+ layoutMode: appProviderValue.layoutMode
4434
+ },
4435
+ children: /*#__PURE__*/jsx(AntdAppWrapper, {
4436
+ appProviderValue: appProviderValue,
4437
+ children: /*#__PURE__*/jsx(FbaApp, {
4438
+ children: /*#__PURE__*/jsxs(ErrorBoundary, {
4439
+ onError: options.onError,
4440
+ onReset: options.onErrorReset,
4441
+ FallbackComponent: options.ErrorFallback || ErrorFallback,
4442
+ children: [layoutMode === 'iframe-main' ? /*#__PURE__*/jsx(IframeMainRegister, {}) : null, /*#__PURE__*/jsx(Container, {
4443
+ layoutMode: appProviderValue.layoutMode,
4444
+ MenuEmptyRender: appProviderValue.MenuEmptyRender,
4445
+ menus: menus,
4446
+ ignoreMenuEmptyJudge: appProviderValue.ignoreMenuEmptyJudge,
4447
+ children: isNoLayout ? /*#__PURE__*/jsx(AppNoLayout, {
4448
+ routeList: routeList,
4449
+ layoutMode: layoutMode,
4450
+ LayoutComponent: appProviderValue.LayoutComponent,
4451
+ breadExtendRender: appProviderValue.breadExtendRender,
4452
+ breads: appProviderValue.breads,
4453
+ hideDefaultBread: appProviderValue.hideDefaultBread,
4454
+ hideHeader: appProviderValue.hideHeader,
4455
+ breadTitle: appProviderValue.breadTitle,
4456
+ iframeTabAloneView: appProviderValue.iframeTabAloneView,
4457
+ layoutPageClassName: appProviderValue.layoutPageClassName,
4458
+ hideBreadsPathList: appProviderValue.hideBreadsPathList,
4459
+ developmentEnvGuideConfigs: appProviderValue.developmentEnvGuideConfigs,
4460
+ showProdEnvGuide: appProviderValue.showProdEnvGuide,
4461
+ hidenEnvGuide: appProviderValue.hidenEnvGuide
4462
+ }) : /*#__PURE__*/jsx(AppProvider, _objectSpread2({}, appProviderValue))
4463
+ })]
4464
+ })
4465
+ })
4466
+ })
4467
+ })
4468
+ })
4469
+ })
4470
+ }));
4471
+ };
4472
+
4473
+ var Bootstrap = function Bootstrap(options) {
4474
+ var _useState = useState(false),
4475
+ _useState2 = _slicedToArray(_useState, 2),
4476
+ renderFlag = _useState2[0],
4477
+ setRenderFlag = _useState2[1];
4478
+ var _useState3 = useState(''),
4479
+ _useState4 = _slicedToArray(_useState3, 2),
4480
+ errorMessage = _useState4[0],
4481
+ setErrorMessage = _useState4[1];
4482
+ useAsyncEffect(function () {
4483
+ return new Promise(function ($return, $error) {
4484
+ var globalData, apiBase, hostUrl;
4485
+ var $Try_1_Post = function () {
4486
+ try {
4487
+ return $return();
4488
+ } catch ($boundEx) {
4489
+ return $error($boundEx);
4490
+ }
4491
+ };
4492
+ var $Try_1_Catch = function (error) {
4493
+ try {
4494
+ setErrorMessage((error === null || error === void 0 ? void 0 : error['message']) || '获取初始加载数据失败');
4495
+ return $Try_1_Post();
4496
+ } catch ($boundEx) {
4497
+ return $error($boundEx);
4498
+ }
4499
+ };
4500
+ try {
4501
+ if (options.layoutMode === 'iframe-main') {
4502
+ window['__flat_iframe_parent_window'] = true;
4503
+ }
4504
+ if (options.getGlobalData) {
4505
+ return Promise.resolve(options.getGlobalData()).then(function ($await_3) {
4506
+ try {
4507
+ globalData = $await_3;
4508
+ if (globalData) {
4509
+ window['GLOBAL'] = globalData;
4510
+ }
4511
+ return $If_2.call(this);
4512
+ } catch ($boundEx) {
4513
+ return $Try_1_Catch($boundEx);
4514
+ }
4515
+ }.bind(this), $Try_1_Catch);
4516
+ }
4517
+ function $If_2() {
4518
+ apiBase = window['GLOBAL'].apiBase;
4519
+ if (apiBase) {
4520
+ window['GLOBAL'].apiBase = getSameProtocolUrl(apiBase);
4521
+ }
4522
+ hostUrl = window['GLOBAL'].hostUrl;
4523
+ if (hostUrl) {
4524
+ window['GLOBAL'].hostUrl = getSameProtocolUrl(hostUrl);
4525
+ }
4526
+ setRenderFlag(true);
4527
+ return $Try_1_Post();
4528
+ }
4529
+ return $If_2.call(this);
4530
+ } catch (error) {
4531
+ $Try_1_Catch(error);
4532
+ }
4533
+ });
4534
+ }, []);
4535
+ if (errorMessage) {
4536
+ return /*#__PURE__*/jsx(Result, {
4537
+ status: "error",
4538
+ title: errorMessage
4539
+ });
4540
+ }
4541
+ if (!renderFlag) {
4542
+ return /*#__PURE__*/jsx(Loader, {
4543
+ spinning: true
4544
+ });
4545
+ }
4546
+ return /*#__PURE__*/jsx(BootstrapContent, _objectSpread2({}, options));
4547
+ };
4548
+
4549
+ var _excluded$1 = ["level"];
4550
+ /**
4551
+ * 通过面包屑路径返回
4552
+ * @param props
4553
+ * @returns
4554
+ * ```
4555
+ * 1. breads 模块面包屑配置
4556
+ * 2. level回退级别,如果传递数据未获取到路由配置,则取上一级
4557
+ * 例如:-1,-2,-3
4558
+ * 3. 为什么不能使用useNavigate(-1)
4559
+ * 因为内部iframe和外部浏览器共用history历史记录,导致里外浏览器栈混乱
4560
+ * 4. 什么场景使用
4561
+ * 使用iframe tab的项目,在执行路由回退时使用
4562
+ * 5. onClick返回 promise reject,则不会进行回退处理(V4.2.4)
4563
+ * ```
4564
+ */
4565
+ var HistoryBackButton = function HistoryBackButton(props) {
4566
+ var ctx = bootstrapCtx();
4567
+ var level = props.level,
4568
+ otherProps = _objectWithoutProperties(props, _excluded$1);
4569
+ var _getHostUrlAndRouteBa = getHostUrlAndRouteBaseName(location.href),
4570
+ routeBaseName = _getHostUrlAndRouteBa.routeBaseName;
4571
+ var routerList = useBread(ctx.breads, routeBaseName);
4572
+ var navigate = useNavigate();
4573
+ var path = useMemo(function () {
4574
+ var newLevel = level || -1;
4575
+ if (routerList.length >= 2) {
4576
+ var routerItem = routerList[routerList.length - 1 - Math.abs(newLevel)] || routerList[routerList.length - 2];
4577
+ if (routerItem) {
4578
+ return toLinkPath(routerItem.path, routerItem.query);
4579
+ } else {
4580
+ console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
4581
+ return '';
4582
+ }
4583
+ }
4584
+ console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
4585
+ return '';
4586
+ }, []);
4587
+ var onBack = function onBack() {
4588
+ if (path) {
4589
+ navigate(toLinkPath(path));
4590
+ } else {
4591
+ console.warn("\u672A\u83B7\u53D6\u5230\u9762\u5305\u5C51\u6570\u636E\uFF0C\u65E0\u8FD4\u56DE\u94FE\u63A5");
4592
+ }
4593
+ };
4594
+ var onClick = useMemoizedFn(function (event) {
4595
+ var _props$onClick;
4596
+ var result = props === null || props === void 0 || (_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props, event);
4597
+ if (result && isPromise(result)) {
4598
+ return result.then(function () {
4599
+ onBack();
4600
+ });
4601
+ }
4602
+ onBack();
4603
+ return;
4604
+ });
4605
+ return /*#__PURE__*/jsx(ButtonWrapper, _objectSpread2(_objectSpread2({}, otherProps), {}, {
4606
+ onClick: onClick,
4607
+ children: props.children || '返回'
4608
+ }));
4609
+ };
4610
+ var useHistoryBack = function useHistoryBack(props) {
4611
+ var ctx = bootstrapCtx();
4612
+ var level = (props === null || props === void 0 ? void 0 : props.level) || -1;
4613
+ var _getHostUrlAndRouteBa2 = getHostUrlAndRouteBaseName(location.href),
4614
+ routeBaseName = _getHostUrlAndRouteBa2.routeBaseName;
4615
+ var routerList = useBread(ctx.breads, routeBaseName);
4616
+ var path = useMemo(function () {
4617
+ var newLevel = level;
4618
+ if (routerList.length >= 2) {
4619
+ var routerItem = routerList[routerList.length - 1 - Math.abs(newLevel)] || routerList[routerList.length - 2];
4620
+ if (routerItem) {
4621
+ return toLinkPath(routerItem.path, routerItem.query);
4622
+ } else {
4623
+ console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
4624
+ return '';
4625
+ }
4626
+ }
4627
+ console.warn("\u672A\u83B7\u53D6\u5230\u3010level\uFF1A".concat(newLevel, "\u3011\u9762\u5305\u5C51\u6570\u636E"));
4628
+ return '';
4629
+ }, []);
4630
+ return {
4631
+ path: path
4632
+ };
4633
+ };
4634
+
4635
+ /**
4636
+ * 页面包装组件
4637
+ * ```
4638
+ * 1. 如果初始化面包屑被隐藏,在特殊页面级可以独立设置显示面包屑
4639
+ * <Page bread={<Bread />}/>
4640
+ * 2. 如果需要在 面包屑上添加按钮,初始化设置 bootstrap.hideDefaultBread = true,在需要按钮的页面上配置
4641
+ * <Page bread={<Bread><Button>我是按钮</Button></Bread>}/>
4642
+ * ```
4643
+ * @param props
4644
+ * @returns
4645
+ */
4646
+ var Page = function Page(props) {
4647
+ var loading = props.loading;
4648
+ var isWin = isWindows();
4649
+ var className = classNames('page', {
4650
+ 'page-loading': loading,
4651
+ 'page-flex': !isUndefined(props.fullIndex),
4652
+ 'page-windows': isWin
4653
+ }, props.className);
4654
+ var backTopTarget = useMemoizedFn(function () {
4655
+ if (!isUndefined(props.fullIndex)) {
4656
+ return document.querySelector('.page-full');
4657
+ }
4658
+ return document.querySelector('.page');
4659
+ });
4660
+ return /*#__PURE__*/jsxs(Fragment, {
4661
+ children: [props.bread, /*#__PURE__*/jsxs("div", {
4662
+ style: props.style,
4663
+ className: className,
4664
+ id: props.elementId,
4665
+ children: [Children.map(props.children, function (item, index) {
4666
+ if (index === props.fullIndex) {
4667
+ var _item$props;
4668
+ return /*#__PURE__*/jsx(Fragment, {
4669
+ children: /*#__PURE__*/cloneElement(item, {
4670
+ className: classNames('page-full', item === null || item === void 0 || (_item$props = item['props']) === null || _item$props === void 0 ? void 0 : _item$props.className)
4735
4671
  })
4736
- })
4737
- })
4738
- })
4739
- })
4672
+ }, index);
4673
+ }
4674
+ return /*#__PURE__*/jsx(Fragment, {
4675
+ children: item
4676
+ }, index);
4677
+ }), /*#__PURE__*/jsx(FloatButton.BackTop, {
4678
+ target: backTopTarget
4679
+ }), loading && /*#__PURE__*/jsx(Loader, {
4680
+ spinning: true
4681
+ })]
4682
+ })]
4683
+ });
4684
+ };
4685
+
4686
+ var _fbaHooks$createCtx = fbaHooks.createCtx(),
4687
+ _fbaHooks$createCtx2 = _slicedToArray(_fbaHooks$createCtx, 2),
4688
+ usePageWrapperCtx = _fbaHooks$createCtx2[0],
4689
+ PageWrapperCtxProvider = _fbaHooks$createCtx2[1];
4690
+
4691
+ var _excluded = ["respData"],
4692
+ _excluded2 = ["serviceConfig", "isAsync", "errorRender"];
4693
+ var PageContent = function PageContent(props) {
4694
+ var _props$children;
4695
+ var respData = props.respData,
4696
+ otherProps = _objectWithoutProperties(props, _excluded);
4697
+ var children = typeof props.children === 'function' ? (_props$children = props.children) === null || _props$children === void 0 ? void 0 : _props$children.call(props, respData) : props.children;
4698
+ if (isFragment(children)) {
4699
+ var childrenList = Children.toArray(children.props.children);
4700
+ return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({}, otherProps), {}, {
4701
+ children: childrenList
4702
+ }));
4703
+ }
4704
+ return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({}, otherProps), {}, {
4705
+ children: children
4740
4706
  }));
4741
4707
  };
4742
4708
 
4743
- var Bootstrap = function Bootstrap(options) {
4744
- var _useState = useState(false),
4709
+ /**
4710
+ * 为Page内置接口处理流程组件,如果无全局初始化接口请求场景,请使用Page组件
4711
+ * ```
4712
+ * 包括
4713
+ * 1. loading显示效果
4714
+ * 2. error显示效果
4715
+ * 3. 正常接口数据渲染
4716
+ * ```
4717
+ * @param props
4718
+ * @returns
4719
+ */
4720
+ var PageWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
4721
+ var serviceConfig = props.serviceConfig,
4722
+ isAsync = props.isAsync,
4723
+ errorRender = props.errorRender,
4724
+ otherProps = _objectWithoutProperties(props, _excluded2);
4725
+ var _useState = useState({
4726
+ status: 'loading'
4727
+ }),
4745
4728
  _useState2 = _slicedToArray(_useState, 2),
4746
- renderFlag = _useState2[0],
4747
- setRenderFlag = _useState2[1];
4748
- var _useState3 = useState(''),
4729
+ result = _useState2[0],
4730
+ setResult = _useState2[1];
4731
+ var _useState3 = useState(false),
4749
4732
  _useState4 = _slicedToArray(_useState3, 2),
4750
- errorMessage = _useState4[0],
4751
- setErrorMessage = _useState4[1];
4752
- useAsyncEffect(function () {
4733
+ againRefresh = _useState4[0],
4734
+ setAgainRefresh = _useState4[1];
4735
+ var onRequest = function onRequest() {
4753
4736
  return new Promise(function ($return, $error) {
4754
- var globalData;
4737
+ var params, _result;
4755
4738
  var $Try_1_Post = function () {
4756
4739
  try {
4757
- return $return();
4740
+ return $return(Promise.resolve());
4758
4741
  } catch ($boundEx) {
4759
4742
  return $error($boundEx);
4760
4743
  }
4761
4744
  };
4762
4745
  var $Try_1_Catch = function (error) {
4763
4746
  try {
4764
- setErrorMessage((error === null || error === void 0 ? void 0 : error['message']) || '获取初始加载数据失败');
4747
+ setResult({
4748
+ status: 'error',
4749
+ respData: error
4750
+ });
4765
4751
  return $Try_1_Post();
4766
4752
  } catch ($boundEx) {
4767
4753
  return $error($boundEx);
4768
4754
  }
4769
4755
  };
4770
4756
  try {
4771
- if (options.layoutMode === 'iframe-main') {
4772
- window['__flat_iframe_parent_window'] = true;
4773
- }
4774
- if (options.getGlobalData) {
4775
- return Promise.resolve(options.getGlobalData()).then(function ($await_3) {
4776
- try {
4777
- globalData = $await_3;
4778
- if (globalData) {
4779
- window['GLOBAL'] = globalData;
4780
- }
4781
- return $If_2.call(this);
4782
- } catch ($boundEx) {
4783
- return $Try_1_Catch($boundEx);
4784
- }
4785
- }.bind(this), $Try_1_Catch);
4786
- }
4787
- function $If_2() {
4788
- setRenderFlag(true);
4789
- return $Try_1_Post();
4790
- }
4791
- return $If_2.call(this);
4757
+ params = typeof serviceConfig.params === 'function' ? serviceConfig.params() : serviceConfig.params;
4758
+ return Promise.resolve(serviceConfig.onRequest(params)).then(function ($await_2) {
4759
+ try {
4760
+ _result = $await_2;
4761
+ setResult({
4762
+ status: 'success',
4763
+ respData: _result
4764
+ });
4765
+ return $Try_1_Post();
4766
+ } catch ($boundEx) {
4767
+ return $Try_1_Catch($boundEx);
4768
+ }
4769
+ }, $Try_1_Catch);
4792
4770
  } catch (error) {
4793
4771
  $Try_1_Catch(error);
4794
4772
  }
4795
4773
  });
4796
- }, []);
4797
- if (errorMessage) {
4798
- return /*#__PURE__*/jsx(Result, {
4799
- status: "error",
4800
- title: errorMessage
4774
+ };
4775
+ fbaHooks.useEffectCustomAsync(onRequest, []);
4776
+ var onReload = useMemoizedFn(function () {
4777
+ setResult({
4778
+ status: 'loading'
4801
4779
  });
4802
- }
4803
- if (!renderFlag) {
4804
- return /*#__PURE__*/jsx(Loader, {
4805
- spinning: true
4780
+ void onRequest();
4781
+ });
4782
+ var onRefresh = useMemoizedFn(function () {
4783
+ setAgainRefresh(true);
4784
+ onRequest().finally(function () {
4785
+ setAgainRefresh(false);
4786
+ });
4787
+ });
4788
+ useImperativeHandle(ref, function () {
4789
+ return {
4790
+ onRefresh: onRefresh,
4791
+ onReload: onReload
4792
+ };
4793
+ });
4794
+ if (result.status === 'error') {
4795
+ var _result$respData;
4796
+ if (errorRender) {
4797
+ return errorRender(result.respData);
4798
+ }
4799
+ return /*#__PURE__*/jsx(Page, {
4800
+ fullIndex: 0,
4801
+ style: {
4802
+ backgroundColor: '#fff'
4803
+ },
4804
+ children: /*#__PURE__*/jsx(Result, {
4805
+ status: "error",
4806
+ title: '数据获取异常',
4807
+ subTitle: ((_result$respData = result.respData) === null || _result$respData === void 0 ? void 0 : _result$respData.message) || '数据请求异常',
4808
+ extra: [/*#__PURE__*/jsx(Button, {
4809
+ type: "primary",
4810
+ onClick: onReload,
4811
+ children: "\u91CD\u65B0\u83B7\u53D6"
4812
+ }, "console")]
4813
+ })
4806
4814
  });
4807
4815
  }
4808
- return /*#__PURE__*/jsx(BootstrapContent, _objectSpread2({}, options));
4816
+ if (result.status === 'loading' && !isAsync) {
4817
+ return /*#__PURE__*/jsx(Page, _objectSpread2(_objectSpread2({
4818
+ loading: true
4819
+ }, otherProps), {}, {
4820
+ children: /*#__PURE__*/jsx(Fragment, {})
4821
+ }));
4822
+ }
4823
+ return /*#__PURE__*/jsxs(PageWrapperCtxProvider, {
4824
+ value: {
4825
+ onReload: onReload,
4826
+ onRefresh: onRefresh
4827
+ },
4828
+ children: [againRefresh ? /*#__PURE__*/jsx(Loader, {
4829
+ spinning: true,
4830
+ style: {
4831
+ backgroundColor: 'transparent'
4832
+ }
4833
+ }) : null, /*#__PURE__*/jsx(PageContent, _objectSpread2({
4834
+ loading: result.status === 'loading',
4835
+ respData: result.respData
4836
+ }, otherProps))]
4837
+ });
4838
+ });
4839
+ var usePageWrapper = function usePageWrapper() {
4840
+ var ctx = usePageWrapperCtx();
4841
+ return ctx;
4809
4842
  };
4810
4843
 
4811
4844
  /**
@@ -4829,5 +4862,5 @@ var onUpdateTheme = function onUpdateTheme(theme) {
4829
4862
  });
4830
4863
  };
4831
4864
 
4832
- export { Bread, HistoryBackButton, LayoutPage, Page, PageWrapper, bootstrap, getIframeTabUid, menuPubSub, message, modal, notification, onUpdateTheme, useHistoryBack, useIframe, useIframeTabActive, usePageWrapper, useRefreshRegisterIframeTab, useRegisterRefreshCurrentIframeTab };
4865
+ export { Bootstrap, Bread, HistoryBackButton, LayoutPage, Page, PageWrapper, bootstrap, getIframeTabUid, menuPubSub, message, modal, notification, onUpdateTheme, useHistoryBack, useIframe, useIframeTabActive, usePageWrapper, useRefreshRegisterIframeTab, useRegisterRefreshCurrentIframeTab };
4833
4866
  //# sourceMappingURL=index.js.map