import { FormProps, FormSchema, BasicColumn } from '/@/index'; export function getBasicColumns(): BasicColumn[] { return [ { title: 'ID', dataIndex: 'id', fixed: 'left', width: 200, }, { title: '姓名', dataIndex: 'name', width: 150, filters: [ { text: 'Male', value: 'male' }, { text: 'Female', value: 'female' }, ], }, { title: '地址', dataIndex: 'address', }, { title: '编号', dataIndex: 'no', width: 150, sorter: true, defaultHidden: true, }, { title: '开始时间', width: 150, sorter: true, dataIndex: 'beginTime', }, { title: '结束时间', width: 150, sorter: true, dataIndex: 'endTime', }, ]; } export function getBasicShortColumns(): BasicColumn[] { return [ { title: 'ID', width: 150, dataIndex: 'id', sorter: true, sortOrder: 'ascend', }, { title: '姓名', dataIndex: 'name', width: 120, }, { title: '地址', dataIndex: 'address', }, { title: '编号', dataIndex: 'no', width: 80, }, ]; } export function getMultipleHeaderColumns(): BasicColumn[] { return [ { title: 'ID', dataIndex: 'id', width: 200, }, { title: '姓名', dataIndex: 'name', width: 120, }, { title: '地址', dataIndex: 'address', sorter: true, children: [ { title: '编号', dataIndex: 'no', width: 120, filters: [ { text: 'Male', value: 'male', children: [] }, { text: 'Female', value: 'female', children: [] }, ], }, { title: '开始时间', dataIndex: 'beginTime', width: 120, }, { title: '结束时间', dataIndex: 'endTime', width: 120, }, ], }, ]; } export function getCustomHeaderColumns(): BasicColumn[] { return [ { title: 'ID', dataIndex: 'id', width: 200, }, { // title: '姓名', dataIndex: 'name', width: 120, // slots: { title: 'customTitle' }, }, { // title: '地址', dataIndex: 'address', width: 120, // slots: { title: 'customAddress' }, sorter: true, }, { title: '编号', dataIndex: 'no', width: 120, filters: [ { text: 'Male', value: 'male', children: [] }, { text: 'Female', value: 'female', children: [] }, ], }, { title: '开始时间', dataIndex: 'beginTime', width: 120, }, { title: '结束时间', dataIndex: 'endTime', width: 120, }, ]; } const renderContent = ({ text, index }: { text: any; index: number }) => { const obj: any = { children: text, attrs: {}, }; if (index === 9) { obj.attrs.colSpan = 0; } return obj; }; export function getMergeHeaderColumns(): BasicColumn[] { return [ { title: 'ID', dataIndex: 'id', width: 300, customRender: renderContent, }, { title: '姓名', dataIndex: 'name', width: 300, customRender: renderContent, }, { title: '地址', dataIndex: 'address', colSpan: 2, width: 120, sorter: true, customRender: ({ text, index }: { text: any; index: number }) => { const obj: any = { children: text, attrs: {}, }; if (index === 2) { obj.attrs.rowSpan = 2; } if (index === 3) { obj.attrs.colSpan = 0; } return obj; }, }, { title: '编号', dataIndex: 'no', colSpan: 0, filters: [ { text: 'Male', value: 'male', children: [] }, { text: 'Female', value: 'female', children: [] }, ], customRender: renderContent, }, { title: '开始时间', dataIndex: 'beginTime', width: 200, customRender: renderContent, }, { title: '结束时间', dataIndex: 'endTime', width: 200, customRender: renderContent, }, ]; } export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => { const arr: any = []; for (let index = 0; index < itemNumber; index++) { arr.push({ field: `field${index}`, label: `字段${index}`, component: 'Input', colProps: { xl: 12, xxl: 8, }, }); } return arr; }; export function getFormConfig(): Partial { return { labelWidth: 100, schemas: [ ...getAdvanceSchema(5), // { // field: `field11`, // label: `Slot示例`, // component: 'Select', // slot: 'custom', // colProps: { // xl: 12, // xxl: 8, // }, // }, ], }; } export function getBasicData() { const data: any = (() => { const arr: any = []; for (let index = 0; index < 40; index++) { arr.push({ id: `${index}`, name: 'John Brown', age: `1${index}`, no: `${index + 10}`, address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park', beginTime: new Date().toLocaleString(), endTime: new Date().toLocaleString(), }); } return arr; })(); return data; } export function getTreeTableData() { const data: any = (() => { const arr: any = []; for (let index = 0; index < 40; index++) { arr.push({ id: `${index}`, name: 'John Brown', age: `1${index}`, no: `${index + 10}`, address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park', beginTime: new Date().toLocaleString(), endTime: new Date().toLocaleString(), children: [ { id: `l2-${index}`, name: 'John Brown', age: `1${index}`, no: `${index + 10}`, address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park', beginTime: new Date().toLocaleString(), endTime: new Date().toLocaleString(), }, ], }); } return arr; })(); return data; } const demoList = () => { const data: any = (() => { const arr: any = []; for (let index = 0; index < 200; index++) { arr.push({ id: `${index}`, name: 'John Brown' + index, name1: 'name01--' + index, name2: 'name02--' + index, name3: 'name03--' + index, name4: 'name04--' + index, name5: 'name05--' + index, name6: 'name06--' + index, name7: 'name07--' + index, name8: 'name08--' + index, radio1: `选项${index + 1}`, radio2: `选项${index + 1}`, radio3: `选项${index + 1}`, age: `1${index}`, no: `${index + 10}`, avatar: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', imgArr: getRandomPics(Math.ceil(Math.random() * 3) + 1), imgs: getRandomPics(Math.ceil(Math.random() * 3) + 1), address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park', beginTime: new Date().toLocaleString(), endTime: new Date().toLocaleString(), date: `2022-05-06`, time: `12:07`, status: 1, }); } return arr; })(); return data; }; function getRandomPics(count = 10): string[] { const arr: string[] = []; const imgs = [ 'https://aliyuncdn.antdv.com/vue.png', 'https://aliyuncdn.antdv.com/logo.png', 'https://gw.alipayobjects.com/zos/antfincdn/LlvErxo8H9/photo-1503185912284-5271ff81b9a8.webp', 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', ]; for (let i = 0; i < count; i++) { arr.push(imgs[i % 4]); } return arr; } export function pagination(pageNo: number, pageSize: number, array: T[]): T[] { const offset = (pageNo - 1) * Number(pageSize); const ret = offset + Number(pageSize) >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + Number(pageSize)); return ret; } export const demoListApi = (params: any) => { return new Promise((res) => { setTimeout(() => { const { page = 1, pageSize = 20 } = params; const list: any[] = demoList(); const pageData = pagination(page, pageSize, list); res({ current: page, size: pageSize, records: pageData, total: list.length, }); }, 500); }); }; const demoTwoList = (count = 20) => { const result = { list: [] as any[], }; for (let index = 0; index < count; index++) { result.list.push({ name: `选项${index}`, id: `${index}`, }); } return result; }; const demoTreeList = () => { const result = { list: [] as Recordable[], }; for (let index = 0; index < 5; index++) { const children: Recordable[] = []; for (let j = 0; j < 3; j++) { children.push({ title: `选项${index}-${j}`, value: `${index}-${j}`, key: `${index}-${j}`, }); } result.list.push({ title: `选项${index}`, value: `${index}`, key: `${index}`, children, }); } return result; }; export const optionsListApi = (params: any) => { return new Promise((res) => { setTimeout(() => { res(demoTwoList(params.count)); }, 500); }); }; export const treeOptionsListApi = () => { return new Promise((res) => { setTimeout(() => { res(demoTreeList()); }, 500); }); };