UNPKG

@alicloud/console-components

Version:

Alibaba Cloud React Components

195 lines (183 loc) 4.53 kB
import { DataSourceItem, TreeDataSourceItem, TreeSelectDataSourceItem } from '@alicloud/console-components'; import { IDemoDataRegion, IDemoDataAlbum } from '../types'; function convertTreeSelectDataSourceItem<T = string>(items: TreeDataSourceItem[], convertValue: (o: TreeDataSourceItem/* , index: number */) => T): TreeSelectDataSourceItem<T>[] { return items.reduce((result: TreeSelectDataSourceItem<T>[], v) => { const { key, children, ...reset } = v; const treeSelectDataSourceItem: TreeSelectDataSourceItem<T> = { ...reset, value: convertValue(v), children: children ? convertTreeSelectDataSourceItem(children, convertValue) : undefined }; result.push(treeSelectDataSourceItem); return result; }, []); } export const DATA_SOURCE_PURE_STRING: string[] = ['hello', 'world', 'yuck', 'fou']; export const DATA_SOURCE_PURE_NUMBER: number[] = [1, 22, 333, 4444, 5555]; export const DATA_SOURCE_PURE_BOOLEAN: boolean[] = [true, false]; export const DATA_SOURCE_PURE_REGION: IDemoDataRegion[] = [{ id: 'cn-hangzhou', name: '行舟' }, { id: 'cn-shanghai', name: '伤害' }, { id: 'cn-beijing', name: '背景' }, { id: 'cn-nanjing', name: '难经' }]; export const DATA_SOURCE_PURE_ALBUM: IDemoDataAlbum[] = [{ title: 'Appetite for Destruction', artist: 'Guns N\' Roses', year: 1987, tracks: [ 'Appetite for Destruction', 'It\'s so Easy', 'Night Train', 'Outta Get Me', 'Mr. Brownstone', 'Paradise City', 'My Michelle', 'Think about You', 'Sweet Child O\' Mine', 'You\'re Crazy', 'Anything Goes', 'Rocket Queen' ] }, { title: 'Keep the Faith', artist: 'Bon Jovi', year: 1992, tracks: [ 'I Believe', 'I\'ll Sleep When I\'m Dead', 'In These Arms', 'Bed of Roses', 'If I Was Your Mother', 'Dry County', 'Woman in Love', 'Fear', 'I Want You', 'Blame It on the Love of Rock & Roll', 'Little Bit of Soul' ] }, { title: 'Deep Purple in Rock', artist: 'Deep Purple', year: 1970, tracks: [ 'Speed King', 'Blood Sucker', 'Child in Time', 'Flight of the Rat', 'Into the Fire', 'Living Wreck', 'Hard Lovin\' Woman' ] }, { title: 'Echos', artist: 'Lacrimosa', year: 2003, tracks: [ 'Durch Nacht und Flut', 'Sacrifice', 'Apart', 'Ein Hauch von Menschichkeit', 'Malina', 'Die Schreie sind Verstummt' ] }, { title: 'Brave New World', artist: 'Iron Maiden', year: 2000, tracks: [ 'The Wicker Man', 'Ghost of the Navigator', 'Brave New World', 'Blood Brothers', 'The Mercenary', 'Dream of Mirrors', 'The Fallen Angel', 'The Nomad', 'Out of the Silent Planet', 'The Thin Line Between Love and Hate' ] }]; export const DATA_SOURCE_REGION_WRAPPED: DataSourceItem<IDemoDataRegion>[] = DATA_SOURCE_PURE_REGION.map(v => ({ key: v.id, label: `${v.name} - ${v.id}`, value: v })); export const DATA_SOURCE_ALBUM_WRAPPED: DataSourceItem<IDemoDataAlbum>[] = DATA_SOURCE_PURE_ALBUM.map(v => ({ key: `${v.title} - ${v.artist}`, id: v.title, label: `${v.title} - ${v.artist}`, value: v })); export const DATA_SOURCE_TREE: TreeDataSourceItem[] = [{ key: '1', label: '数据接口', children: [{ key: '1-1', label: '文档 console-base-data-help' }, { key: '1-2', label: '教程 console-base-data-tutor' }, { key: '1-3', label: '语言 console-base-data-locale' }] }, { key: '2', label: 'Plugins', children: [{ key: '2-1', label: '侧边栏 SidePanel', children: [{ key: '2-1-1', label: 'API Inspector' }, { key: '2-1-2', label: '联系我们 Contact' }, { key: '2-1-3', label: '回到顶部 ToTop' }] }, { key: '2-2', label: '微浏览器 MicroBrowser', children: [{ key: '2-2-1', label: '微文档 MicroHelp' }, { key: '2-2-2', label: '微教程 MicroTutor' }, { key: '2-2-3', label: '微实验 MicroLab' }, { key: '2-2-4', label: '微协议 MicroTerm', disabled: true, selectable: false }] }] }]; export const DATA_SOURCE_TREE_SELECT: TreeSelectDataSourceItem[] = convertTreeSelectDataSourceItem(DATA_SOURCE_TREE, o => o.key); export const DATA_SOURCE_TREE_SELECT_NUMBER: TreeSelectDataSourceItem<number>[] = (() => { let i = 1; return convertTreeSelectDataSourceItem(DATA_SOURCE_TREE, () => i++); })();