@ant-design/pro-layout
Version:
114 lines (92 loc) • 2.91 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.matchParamsPath = exports.getPageTitleInfo = exports.default = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _pathToRegexp = _interopRequireDefault(require("path-to-regexp"));
var matchParamsPath = function matchParamsPath(pathname, breadcrumb, breadcrumbMap) {
// Internal logic use breadcrumbMap to ensure the order
// 内部逻辑使用 breadcrumbMap 来确保查询顺序
if (breadcrumbMap) {
var pathKey = (0, _toConsumableArray2.default)(breadcrumbMap.keys()).find(function (key) {
return (0, _pathToRegexp.default)(key).test(pathname);
});
if (pathKey) {
return breadcrumbMap.get(pathKey);
}
} // External uses use breadcrumb
// 外部用户使用 breadcrumb 参数
if (breadcrumb) {
var _pathKey = Object.keys(breadcrumb).find(function (key) {
return (0, _pathToRegexp.default)(key).test(pathname);
});
if (_pathKey) {
return breadcrumb[_pathKey];
}
}
return {
path: ''
};
};
/**
* 获取关于 pageTitle 的所有信息方便包装
*
* @param props
* @param ignoreTitle
*/
exports.matchParamsPath = matchParamsPath;
var getPageTitleInfo = function getPageTitleInfo(props, ignoreTitle) {
var _props$pathname = props.pathname,
pathname = _props$pathname === void 0 ? '/' : _props$pathname,
breadcrumb = props.breadcrumb,
breadcrumbMap = props.breadcrumbMap,
formatMessage = props.formatMessage,
title = props.title,
_props$menu = props.menu,
menu = _props$menu === void 0 ? {
locale: false
} : _props$menu;
var pageTitle = ignoreTitle ? '' : title || '';
var currRouterData = matchParamsPath(pathname, breadcrumb, breadcrumbMap);
if (!currRouterData) {
return {
title: pageTitle,
id: '',
pageName: pageTitle
};
}
var pageName = currRouterData.name;
if (menu.locale !== false && currRouterData.locale && formatMessage) {
pageName = formatMessage({
id: currRouterData.locale || '',
defaultMessage: currRouterData.name
});
}
if (!pageName) {
return {
title: pageTitle,
id: currRouterData.locale || '',
pageName: pageTitle
};
}
if (ignoreTitle || !title) {
return {
title: pageName,
id: currRouterData.locale || '',
pageName: pageName
};
}
return {
title: "".concat(pageName, " - ").concat(title),
id: currRouterData.locale || '',
pageName: pageName
};
};
exports.getPageTitleInfo = getPageTitleInfo;
var getPageTitle = function getPageTitle(props, ignoreTitle) {
return getPageTitleInfo(props, ignoreTitle).title;
};
var _default = getPageTitle;
exports.default = _default;