UNPKG

ng-lib-tsx

Version:

pc端基础类库

122 lines 7.3 kB
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ConfigProvider, Spin } from 'antd'; import zhCN from 'antd/es/locale/zh_CN'; import 'dayjs/locale/zh-cn'; import { BaseColor, getGlobalConfig, initCustomThemeColor, NG, NGWaterMark, useQkState } from 'ng-base-stand'; import { useEffect, useMemo, useRef, useState } from 'react'; import { InjectModalCtx } from '../component'; import './base.less'; /** * 获取默认主题 */ function getDefaultTheme(_ref) { var inNGFrame = _ref.inNGFrame; var baseColor = getGlobalConfig().default.theme; var cw = window; if (inNGFrame) { try { while (cw !== window.top) { if (cw.NGSkin) break;else cw = cw.parent; } if (cw.NGSkin) { var _cw$NGSkin; // NG主框架设置了主题 return { primaryColor: ((_cw$NGSkin = cw.NGSkin) === null || _cw$NGSkin === void 0 ? void 0 : _cw$NGSkin.rtBgColor) || baseColor }; } } catch (e) {} } return _objectSpread({ primaryColor: baseColor }, NG.external.getDefaultTheme()); } /** * 初始化默认主题 */ function useDefaultTheme(_ref2) { var inNGFrame = _ref2.inNGFrame; var themeRef = useRef(); if (!themeRef.current) { window['__env__'] = 'pc'; themeRef.current = getDefaultTheme({ inNGFrame: inNGFrame }); if (themeRef.current) { themeRef.current.primaryColor !== BaseColor && ConfigProvider.config({ theme: themeRef.current }); initCustomThemeColor(themeRef.current.primaryColor); } } } /** * 根组件 * @param children * @param componentSize * @param loading * @param waterMark 水印 * @param ngFrame 是否NG主框架中 * @constructor */ export function NGRootContainer(_ref3) { var children = _ref3.children, componentSize = _ref3.componentSize, loading = _ref3.loading, waterMark = _ref3.waterMark, _ref3$ngFrame = _ref3.ngFrame, ngFrame = _ref3$ngFrame === void 0 ? true : _ref3$ngFrame; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), loadingState = _useState2[0], setLoadingState = _useState2[1]; var waterMarkProps = waterMark === true ? {} : _objectSpread({}, waterMark); var qkInfo = useQkState(); // useMemo 注入属性同步进行,保证子组件能够正常拿到接口数据 useMemo(function () { // qiankun 子应用子应用内 HTMLElement 对象被代理了, 导致 DOM对象 instanceof HTMLElement 返回了false。 HTMLElement = new Function('return this')().HTMLElement; NG.registerExternal({ getQianKun: function getQianKun() { return qkInfo; } }); }, [qkInfo]); useDefaultTheme({ inNGFrame: ngFrame }); useEffect(function () { NG.registerExternal({ maskLoading: function maskLoading() { var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; setLoadingState(params ? _objectSpread(_objectSpread({}, loading), params) : params); }, getWaterMark: function getWaterMark() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; return waterMark && _jsx(NGWaterMark, _objectSpread(_objectSpread({}, waterMark === true ? {} : waterMark), options)); } }); }, [waterMark]); return _jsxs(ConfigProvider, { locale: zhCN, componentSize: componentSize, children: [children, _jsx(InjectModalCtx, {}), _jsx("div", { children: loadingState && _jsx(Spin, _objectSpread(_objectSpread({}, loading), {}, { spinning: true, className: NG.classNames('ng-body-loading', loadingState.className) })) }, "loading"), waterMark && _jsx(NGWaterMark, _objectSpread({}, waterMarkProps))] }); }