mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 06:09:34 +08:00
ff31a5b555
This reverts commit 7a07b128d1
.
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
export function getMenuItems(data, locale) {
|
|
const menuMeta = Object.keys(data)
|
|
.map((key) => data[key])
|
|
.map((item) => {
|
|
const file = item.index || item;
|
|
if (file.meta) {
|
|
return file.meta;
|
|
}
|
|
return file[locale].meta;
|
|
});
|
|
|
|
const menuItems = {};
|
|
menuMeta.sort((a, b) => {
|
|
return parseInt(a.order, 10) - parseInt(b.order, 10);
|
|
}).forEach((meta) => {
|
|
const category = meta.category || 'topLevel';
|
|
if (!menuItems[category]) {
|
|
menuItems[category] = {};
|
|
}
|
|
|
|
const type = meta.type || 'topLevel';
|
|
if (!menuItems[category][type]) {
|
|
menuItems[category][type] = [];
|
|
}
|
|
|
|
menuItems[category][type].push(meta);
|
|
});
|
|
|
|
return menuItems;
|
|
}
|
|
|
|
export function ping(url, callback) {
|
|
const img = new Image();
|
|
let done;
|
|
const finish = (status) => {
|
|
if (!done) {
|
|
done = true;
|
|
img.src = '';
|
|
callback(status);
|
|
}
|
|
};
|
|
img.onload = () => finish('responded');
|
|
img.onerror = () => finish('error');
|
|
img.src = url;
|
|
setTimeout(() => finish('timeout'), 1500);
|
|
}
|