import { IPublicTypeFieldConfig } from '@alilc/lowcode-types'; import { material } from '@alilc/lowcode-engine'; import is from '@sindresorhus/is'; export const hideProp = () => false; export const uuid = () => Math.random().toString(36).substr(-6); export const PRO_TABLE_COLUMN_MOCK_VALUES = { text: '云路科技有限公司', number: 1234561.231, money: 123213.1232, date: '2021-08-18 20:52:33', phone: '+86 13888888888', currency: 'CNY', ou: '34', percent: 0.64, progress: 0.64, link: '这是链接', tag: '成功', textTag: '进行中', files: [], bankCard: '6226123412341234', employee: { img: 'https://work.alibaba-inc.com/photo/256512.40x40.jpg', staff_id: '256512', nickname: '乔勇', realname: '石强', }, }; export const mockProTableCell = (formatType) => PRO_TABLE_COLUMN_MOCK_VALUES[formatType]; export const mockId = () => `id-${uuid()}`; export const columnMockValueKey = (formatType) => `_mock_value_${formatType}`; export const mockProTableRow = (columns: any[]) => { return columns ?.filter?.((vo) => vo.formatType && vo.dataIndex) ?.reduce?.((p, column) => { const { formatType, dataIndex } = column; const mockValue = column[columnMockValueKey(formatType)]; p[dataIndex] = is.nullOrUndefined(mockValue) ? mockProTableCell(formatType) : mockValue; return p; }, {}); }; export const getDataSourceItemSetter = (formatType) => { let setter; switch (formatType) { case 'text': case 'phone': case 'link': case 'dialog': setter = 'StringSetter'; break; case 'number': case 'money': case 'percent': case 'currency': case 'progress': setter = 'NumberSetter'; break; case 'date': setter = 'DateSetter'; break; default: setter = 'StringSetter'; } return setter; }; export function isJSExpression(data: any) { return data && data.type === 'JSExpression'; } export interface IProps extends IPublicTypeFieldConfig { showInListSetter?: boolean; initialValue?: Function | any; editable?: boolean; items?: IProps[] | IPublicTypeFieldConfig[]; } export function getInitialPropsItem(componentName, currentComponentProps) { const component = material ?.getAssets() ?.components.filter((item) => item.componentName === componentName)[0]; const defaultProps = {}; const initials = component?.advanced?.initials; if (initials && Array.isArray(initials) && initials.length) { initials.forEach((initial) => { if (initial && initial.name && initial.initial) { defaultProps[initial.name] = typeof initial.initial === 'function' ? initial.initial() : initial.initial; } }); } const props = { ...currentComponentProps }; Object.keys(defaultProps).forEach((item) => { const propValue = currentComponentProps[item]; if (!propValue && defaultProps[item]) { props[item] = defaultProps[item]; } }); return props; }