@lvxiaowu/antd4
Version:
antd4-components
58 lines (49 loc) • 2.52 kB
JavaScript
var _excluded = ["children", "isLogin"];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from "react";
import { useEffect } from 'react';
import { Redirect } from 'react-router-dom';
import Fallback from './fallback';
import { AppProvider } from './context';
import { getVisitHistory, setVisitId, setLastVisitPath, getLastVisitPath, removeLastVisitPath } from '../utils';
import { DataType } from '@lvxiaowu/utils';
function Content(_ref) {
var id = _ref.id,
init = _ref.init,
fallback = _ref.fallback,
children = _ref.children,
_ref$provider = _ref.provider,
provider = _ref$provider === void 0 ? {} : _ref$provider;
useEffect(function () {
if (DataType.isFunc(init)) {
init();
}
}, []);
useEffect(function () {
setVisitId(id);
}, [id]);
return /*#__PURE__*/React.createElement(AppProvider, {
value: provider
}, DataType.isUNN(id) ? fallback !== null && fallback !== void 0 ? fallback : null : children);
}
function App(_ref2) {
var children = _ref2.children,
_ref2$isLogin = _ref2.isLogin,
isLogin = _ref2$isLogin === void 0 ? function () {
return true;
} : _ref2$isLogin,
rest = _objectWithoutProperties(_ref2, _excluded);
if (DataType.isFunc(isLogin) && isLogin() === false) {
return /*#__PURE__*/React.createElement(Redirect, {
to: "/login"
});
}
return /*#__PURE__*/React.createElement(Content, rest, children);
} // 虽然访问历史是Layout组件中做的,但从Layout导出不符合语义,所以挂载在App上
App.getVisitHistory = getVisitHistory;
App.setLastVisitPath = setLastVisitPath;
App.getLastVisitPath = getLastVisitPath;
App.removeLastVisitPath = removeLastVisitPath;
App.Fallback = Fallback;
export default App;