helper.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import type { ComponentMap } from './types/form';
  2. /**
  3. * @description: 生成placeholder
  4. */
  5. export function createPlaceholderMessage(component: keyof ComponentMap, label: string) {
  6. if (component === 'NInput') return `请输入${label}`;
  7. if (
  8. [
  9. 'NPicker',
  10. 'NSelect',
  11. 'NCheckbox',
  12. 'NRadio',
  13. 'NSwitch',
  14. 'NDatePicker',
  15. 'NTimePicker',
  16. 'NCheckboxGroup',
  17. 'ApiSelect',
  18. 'ApiTreeSelect',
  19. 'dictSelect'
  20. ].includes(component)
  21. )
  22. return `请选择${label}`;
  23. return '';
  24. }
  25. const DATE_TYPE = ['NDatePicker', 'NMonthPicker', 'NWeekPicker', 'NTimePicker'];
  26. function genType() {
  27. return [...DATE_TYPE, 'NRangePicker'];
  28. }
  29. /**
  30. * 时间字段
  31. */
  32. export const dateItemType = genType();
  33. export function defaultType(component: keyof ComponentMap) {
  34. if (component === 'NInput') return '';
  35. if (component === 'NInputNumber') return null;
  36. return [
  37. 'NPicker',
  38. 'NSelect',
  39. 'NCheckbox',
  40. 'NRadio',
  41. 'NSwitch',
  42. 'NDatePicker',
  43. 'NTimePicker',
  44. 'NCheckboxGroup'
  45. ].includes(component)
  46. ? ''
  47. : undefined;
  48. }