@flatbiz/pro-layout 5.2.1 → 5.2.3

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.d.ts CHANGED
@@ -568,6 +568,8 @@ export type BootstrapOptions = {
568
568
  };
569
569
  /** 浏览器title */
570
570
  browserTitle?: string;
571
+ /** 获取全局数据,默认值使用window.GLOBAL */
572
+ getGlobalData?: () => TGlobalData;
571
573
  };
572
574
  export type LayoutCtxProps = {
573
575
  menus: TMenuItem[];
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { App as App$1, Breadcrumb, FloatButton, Result, Button, Dropdown, Space,
6
6
  import { classNames } from '@dimjs/utils/class-names/class-names';
7
7
  import { useEffect, useMemo, Fragment, Children, cloneElement, forwardRef, useState, useImperativeHandle, isValidElement, Suspense, useRef, memo, Component } from 'react';
8
8
  import { useParams, useLocation, useSearchParams, matchPath, Link, useNavigate, Routes, Route, Navigate, BrowserRouter } from 'react-router-dom';
9
- import { getGlobalData, sessionStorageCache, ensureSlash as ensureSlash$1, removeSlash, toLinkPath, isHttpUri, toArray, urlJoinMulti, urlJoin, isWindowsEnv, valueIsEqual, toLinkPathWithQuery, openNewWindow, treeToArray, cloneObject, getUuid, EventEmitter, treeFilter, arrayFindByLoosely, arrayFindIndexByLoosely, isUndefinedOrNull, localStorageCache } from '@flatbiz/utils';
9
+ import { getRunningEnv, sessionStorageCache, 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
10
  import { fbaHooks } from '@flatbiz/antd/fba-hooks';
11
11
  import { parse } from '@dimjs/utils/json/parse';
12
12
  import { useMemoizedFn, useUpdateEffect, useDebounceFn } from 'ahooks';
@@ -294,7 +294,6 @@ var IframeEventEmitter = /*#__PURE__*/function () {
294
294
  }]);
295
295
  }();
296
296
 
297
- var globalData = getGlobalData();
298
297
  var iframeOpenNewTabItemOperateLinkKey = 'iframe-open-new-tab-item-operate-link';
299
298
 
300
299
  /**
@@ -338,7 +337,7 @@ var getIframeOpenNewTabItemOperateLinkList = function getIframeOpenNewTabItemOpe
338
337
  return isArray(operateLinkData === null || operateLinkData === void 0 ? void 0 : operateLinkData.dataList) ? operateLinkData === null || operateLinkData === void 0 ? void 0 : operateLinkData.dataList : [];
339
338
  };
340
339
  var getDefaultHeaderThemeConfig = function getDefaultHeaderThemeConfig() {
341
- var host = location.host;
340
+ var env = getRunningEnv();
342
341
  var headerThemeConfig = {
343
342
  inte: {
344
343
  bgColor: '#38B990'
@@ -350,16 +349,7 @@ var getDefaultHeaderThemeConfig = function getDefaultHeaderThemeConfig() {
350
349
  bgColor: '#0c1e3e'
351
350
  }
352
351
  };
353
- if (host.includes('.qa.')) {
354
- return headerThemeConfig.inte;
355
- }
356
- if (host.includes('.t.')) {
357
- return headerThemeConfig.rc;
358
- }
359
- if (host.includes('dev.flatjs.com')) {
360
- return headerThemeConfig.me;
361
- }
362
- return undefined;
352
+ return headerThemeConfig[env];
363
353
  };
364
354
 
365
355
  var getAllIframeElements = function getAllIframeElements() {
@@ -1335,11 +1325,11 @@ var Loader = function Loader(_ref) {
1335
1325
  */
1336
1326
  var Page = function Page(props) {
1337
1327
  var loading = props.loading;
1338
- var isWindows = isWindowsEnv();
1328
+ var isWin = isWindows();
1339
1329
  var className = classNames('page', {
1340
1330
  'page-loading': loading,
1341
1331
  'page-flex': !isUndefined(props.fullIndex),
1342
- 'page-windows': isWindows
1332
+ 'page-windows': isWin
1343
1333
  }, props.className);
1344
1334
  var backTopTarget = useMemoizedFn(function () {
1345
1335
  if (!isUndefined(props.fullIndex)) {
@@ -1888,10 +1878,10 @@ var DevFloatHelp = function DevFloatHelp(props) {
1888
1878
 
1889
1879
  var LayoutPage = function LayoutPage(props) {
1890
1880
  // const LeaveMenuCompt = layoutCtx.LeaveMenu || LeaveMenuDefault;
1891
- var isWindows = isWindowsEnv();
1881
+ var isWin = isWindows();
1892
1882
  var className = classNames('layout-page-wrapper', {
1893
1883
  'layout-page-noheader': props.hideHeader,
1894
- 'layout-page-windows': isWindows
1884
+ 'layout-page-windows': isWin
1895
1885
  }, props.className);
1896
1886
  return /*#__PURE__*/jsx(Fragment, {
1897
1887
  children: /*#__PURE__*/jsxs("div", {
@@ -1931,7 +1921,10 @@ var AppNoLayout = function AppNoLayout(props) {
1931
1921
  });
1932
1922
  };
1933
1923
 
1934
- var appName = globalData.appName || 'flatbiz-layout';
1924
+ var getAppName = function getAppName() {
1925
+ var defaultGlobalData = getGlobalData();
1926
+ return defaultGlobalData.appName || 'flatbiz-layout';
1927
+ };
1935
1928
  function removeNodesAtDepth(tree, depth, maxDepth) {
1936
1929
  for (var i = tree.length - 1; i >= 0; i--) {
1937
1930
  var node = tree[i];
@@ -1950,8 +1943,12 @@ function removeNodesAtDepth(tree, depth, maxDepth) {
1950
1943
  * @param isIframeType
1951
1944
  * @returns
1952
1945
  */
1953
- var getMenus = function getMenus(isIframeType, siderBarMaxMenuLevel, disableTopbarMenu) {
1954
- var menus = globalData.menus || [];
1946
+ var getMenus = function getMenus(isIframeType, siderBarMaxMenuLevel, disableTopbarMenu, customGlobalData) {
1947
+ var defaultGlobalData = getGlobalData();
1948
+ var menus = customGlobalData ? customGlobalData.menus : defaultGlobalData.menus || [];
1949
+ if (customGlobalData) {
1950
+ window['GLOBAL'] = customGlobalData;
1951
+ }
1955
1952
  treeToArray(menus, 'children').forEach(function (item) {
1956
1953
  var _item$children;
1957
1954
  if (isPlainObject(item.link)) {
@@ -1959,7 +1956,7 @@ var getMenus = function getMenus(isIframeType, siderBarMaxMenuLevel, disableTopb
1959
1956
  item.link = ((_item$link = item.link) === null || _item$link === void 0 ? void 0 : _item$link[getEnvName()]) || ((_item$link2 = item.link) === null || _item$link2 === void 0 ? void 0 : _item$link2['prod']);
1960
1957
  }
1961
1958
  var path = "/".concat(removeSlash(item.path, 'before-after'));
1962
- var routeBaseName = removeSlash(globalData.routeBaseName, 'before-after');
1959
+ var routeBaseName = removeSlash(defaultGlobalData.routeBaseName, 'before-after');
1963
1960
  /**
1964
1961
  * path 处理
1965
1962
  */
@@ -2090,6 +2087,7 @@ var getTargetMenuParentChain = function getTargetMenuParentChain(menuId, siderBa
2090
2087
  return chainMenuIdList;
2091
2088
  };
2092
2089
  var saveIframeTabToCache = function saveIframeTabToCache(menuList) {
2090
+ var appName = getAppName();
2093
2091
  var newList = isArray(menuList) ? menuList : [];
2094
2092
  window[appName] = newList;
2095
2093
  sessionStorageCache.set(appName, {
@@ -2097,6 +2095,7 @@ var saveIframeTabToCache = function saveIframeTabToCache(menuList) {
2097
2095
  });
2098
2096
  };
2099
2097
  var getIframeTabCacheList = function getIframeTabCacheList() {
2098
+ var appName = getAppName();
2100
2099
  try {
2101
2100
  if (window[appName]) return _toConsumableArray(window[appName]);
2102
2101
  var _ref = sessionStorageCache.get(appName) || {},
@@ -2109,10 +2108,12 @@ var getIframeTabCacheList = function getIframeTabCacheList() {
2109
2108
  }
2110
2109
  };
2111
2110
  var saveCacheIframeActiveItem = function saveCacheIframeActiveItem(item) {
2111
+ var appName = getAppName();
2112
2112
  window["".concat(appName, "-iframeActiveItem")] = item;
2113
2113
  sessionStorageCache.set("".concat(appName, "-iframeActiveItem"), _objectSpread2({}, item));
2114
2114
  };
2115
2115
  var getCacheIframeActiveItem = function getCacheIframeActiveItem() {
2116
+ var appName = getAppName();
2116
2117
  if (getIframeTabCacheList().length === 0) return undefined;
2117
2118
  try {
2118
2119
  if (window["".concat(appName, "-iframeActiveItem")]) return window["".concat(appName, "-iframeActiveItem")];
@@ -2176,6 +2177,7 @@ var addIframeTabListByMenuItem = function addIframeTabListByMenuItem(iframeTabLi
2176
2177
  };
2177
2178
  };
2178
2179
  var clearStorage = function clearStorage() {
2180
+ var appName = getAppName();
2179
2181
  sessionStorageCache.remove(appName);
2180
2182
  // sessionStorageCache.remove(`${appName}-iframeActiveItem`);
2181
2183
  };
@@ -3654,12 +3656,12 @@ var App = function App() {
3654
3656
  var isIframeMain = layoutCtx.layoutMode === 'iframe-main';
3655
3657
  useAntdApp();
3656
3658
  var LayoutContent = layoutCtx.LayoutComponent || LayoutPage;
3657
- var isWindows = isWindowsEnv();
3659
+ var isWin = isWindows();
3658
3660
  return /*#__PURE__*/jsxs(Fragment, {
3659
3661
  children: [/*#__PURE__*/jsx(EventHandling, {}), /*#__PURE__*/jsxs(Layout, {
3660
3662
  hasSider: true,
3661
3663
  className: classNames('flatbiz-layout', {
3662
- 'flatbiz-layout-windows': isWindows
3664
+ 'flatbiz-layout-windows': isWin
3663
3665
  }),
3664
3666
  children: [layoutCtx.hideSidebarMenu ? null : /*#__PURE__*/jsx(SiderBar, {}), /*#__PURE__*/jsxs(Layout, {
3665
3667
  className: "flatbiz-layout-main",
@@ -4500,7 +4502,7 @@ var layoutPubSub = {
4500
4502
  };
4501
4503
 
4502
4504
  var Bootstrap = function Bootstrap(options) {
4503
- var _options$headerThemeC, _options$headerThemeC2, _options$headerThemeC3, _options$sidebarTheme, _options$sidebarTheme2, _options$sidebarTheme3;
4505
+ var _options$headerThemeC, _options$headerThemeC2, _options$headerThemeC3, _options$sidebarTheme, _options$sidebarTheme2, _options$sidebarTheme3, _options$getGlobalDat;
4504
4506
  var _useState = useState(options.initDark),
4505
4507
  _useState2 = _slicedToArray(_useState, 2),
4506
4508
  isDark = _useState2[0],
@@ -4546,6 +4548,7 @@ var Bootstrap = function Bootstrap(options) {
4546
4548
  var sidebarThemeConfigNew = extend({}, sidebarThemeConfig, customSidebarThemeConfig);
4547
4549
  var iframeTabClickRefresh = isUndefinedOrNull(options.iframeTabClickRefresh) ? true : options.iframeTabClickRefresh;
4548
4550
  var _useMemo = useMemo(function () {
4551
+ var globalData = getGlobalData();
4549
4552
  var routeList = function () {
4550
4553
  if (!globalData.moduleName) {
4551
4554
  console.error('请在window.GLOBAL中添加属性moduleName(模块名称,例如:moduleName="system/admin")');
@@ -4627,7 +4630,7 @@ var Bootstrap = function Bootstrap(options) {
4627
4630
  }, [options.routeList]),
4628
4631
  routeList = _useMemo.routeList,
4629
4632
  breadList = _useMemo.breadList;
4630
- var _getMenus = getMenus(isIframeMain || isIframeTabItem, options.siderBarMaxMenuLevel, options.disableTopbarMenu),
4633
+ var _getMenus = getMenus(isIframeMain || isIframeTabItem, options.siderBarMaxMenuLevel, options.disableTopbarMenu, (_options$getGlobalDat = options.getGlobalData) === null || _options$getGlobalDat === void 0 ? void 0 : _options$getGlobalDat.call(options)),
4631
4634
  menus = _getMenus.menus,
4632
4635
  completeMenus = _getMenus.completeMenus;
4633
4636
  var appProviderValue = _objectSpread2(_objectSpread2({}, options), {}, {
@@ -4653,6 +4656,7 @@ var Bootstrap = function Bootstrap(options) {
4653
4656
  var configProviderProps = useMemo(function () {
4654
4657
  var _options$configProvid, _options$configProvid2, _options$configProvid3;
4655
4658
  var algorithm = (_options$configProvid = options.configProviderProps) === null || _options$configProvid === void 0 || (_options$configProvid = _options$configProvid.theme) === null || _options$configProvid === void 0 ? void 0 : _options$configProvid.algorithm;
4659
+ var globalData = getGlobalData();
4656
4660
  var algorithmArray = toArray(algorithm);
4657
4661
  algorithmArray = [].concat(_toConsumableArray(algorithmArray), [isDark ? theme.darkAlgorithm : null, options.compact ? theme.compactAlgorithm : null]).filter(Boolean);
4658
4662
  var configTheme = (_options$configProvid2 = options.configProviderProps) === null || _options$configProvid2 === void 0 ? void 0 : _options$configProvid2.theme;