import { IPublicTypeSnippet } from '@alilc/lowcode-types' const getColumns = () => { return [ { title: '姓名', dataIndex: 'name', valueType: 'text' }, { title: '年龄', dataIndex: 'age', valueType: 'digit' }, { title: '头像', dataIndex: 'avatar', valueType: 'avatar' }, { title: '状态', dataIndex: 'status', renderTag: true, valueEnum: { all: { text: '全部', status: 'Default' }, close: { text: '关闭', status: 'Default' }, running: { text: '运行中', status: 'Processing' }, online: { text: '已上线', status: 'Success' }, error: { text: '异常', status: 'Error' } } }, // { // title: '贷款金额', // dataIndex: 'loan', // valueType: 'money' // }, // { // title: '交易进度', // dataIndex: 'trade_progress', // valueType: 'progress' // }, // { // title: '个人简介', // dataIndex: 'link', // valueType: 'link', // copyable: true // }, { title: '地址', dataIndex: 'address', valueType: 'tag' }, { title: '创建时间', dataIndex: 'create_time', valueType: 'dateTime' } ] } const generateMockData = (count: number) => { // 预设一些随机数据池 const firstNames = ['张', '王', '李', '赵', '刘', '陈', '杨', '黄', '周', '吴']; const lastNames = ['伟', '芳', '娜', '秀英', '敏', '静', '丽', '强', '磊', '洋']; const avatarUrls = [ 'https://randomuser.me/api/portraits/men/', 'https://randomuser.me/api/portraits/women/' ]; const cities = ['杭州', '北京', '上海', '广州', '深圳', '成都', '武汉']; const districts = ['西湖区', '滨江区', '上城区', '下城区', '江干区', '拱墅区']; const streets = ['网商路', '学院路', '文一路', '文二路', '文三路', '莫干山路']; const statusList = ['close', 'running', 'online', 'error']; return Array.from({ length: count }, (_, index) => { const randomId = (index + 1).toString(); const randomFirstName = firstNames[Math.floor(Math.random() * firstNames.length)]; const randomLastName = lastNames[Math.floor(Math.random() * lastNames.length)]; const gender = Math.random() > 0.5 ? 'men' : 'women'; const avatarNumber = Math.floor(Math.random() * 70) + 1; return { id: randomId, name: randomFirstName + randomLastName, age: Math.floor(Math.random() * 40) + 20, // 20-60岁 avatar: `${avatarUrls[gender === 'men' ? 0 : 1]}${avatarNumber}.jpg`, status: statusList[Math.floor(Math.random() * statusList.length)], // loan: Math.floor(Math.random() * 900000) + 100000, // 10-100万 // trade_progress: Math.floor(Math.random() * 100), // 0-100 // link: `https://example.com/profile/${randomId}`, address: `${cities[Math.floor(Math.random() * cities.length)]}${ districts[Math.floor(Math.random() * districts.length)] }${streets[Math.floor(Math.random() * streets.length)]}${ Math.floor(Math.random() * 1000) + 1 }号`, create_time: (() => { const date = new Date(); date.setDate(date.getDate() - Math.floor(Math.random() * 365)); // 最近一年内 date.setHours(Math.floor(Math.random() * 24)); date.setMinutes(Math.floor(Math.random() * 60)); return date.toISOString().replace('T', ' ').substring(0, 16); })() }; }); }; export const snippets: IPublicTypeSnippet[] = [ { title: '高级表格', screenshot: 'https://img.alicdn.com/imgextra/i1/O1CN01R1OdLV1GgCXW0rjop_!!6000000000651-2-tps-112-112.png', schema: { componentName: 'ProTable', props: { // dataSource: generateMockData(50), // columns: getColumns(), dataSource: [], columns: [], rowKey: 'id', pagination: { showSizeChanger: true, showQuickJumper: true, }, }, }, }, ];