tableForm.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import unique from '@form-create/utils/lib/unique';
  2. import {localeProps} from '../../utils';
  3. const label = '表格表单';
  4. const name = 'tableForm';
  5. export default {
  6. menu: 'subform',
  7. icon: 'icon-table-form',
  8. label,
  9. name,
  10. mask: false,
  11. input: true,
  12. subForm: 'array',
  13. event: ['change', 'add', 'delete'],
  14. languageKey: ['add', 'operation', 'dataEmpty'],
  15. children: 'tableFormColumn',
  16. loadRule(rule) {
  17. if (!rule.props) rule.props = {};
  18. const columns = rule.props.columns || [];
  19. rule.children = columns.map(column => {
  20. return {
  21. type: 'tableFormColumn',
  22. _fc_drag_tag: 'tableFormColumn',
  23. props: {
  24. label: column.label,
  25. required: column.required || false,
  26. width: column.style.width || '',
  27. color: column.style.color || '',
  28. },
  29. children: column.rule || []
  30. }
  31. });
  32. delete rule.props.columns;
  33. },
  34. parseRule(rule) {
  35. const children = rule.children || [];
  36. rule.props.columns = children.map(column => {
  37. return {
  38. label: column.props.label,
  39. required: column.props.required,
  40. style: {
  41. width: column.props.width,
  42. color: column.props.color,
  43. },
  44. rule: column.children || []
  45. };
  46. })
  47. rule.children = [];
  48. },
  49. rule({t}) {
  50. return {
  51. type: name,
  52. field: unique(),
  53. title: t('com.tableForm.name'),
  54. info: '',
  55. props: {},
  56. children: []
  57. };
  58. },
  59. props(_, {t}) {
  60. return localeProps(t, name + '.props', [
  61. {
  62. type: 'switch',
  63. field: 'disabled'
  64. },
  65. {
  66. type: 'switch',
  67. field: 'filterEmptyColumn',
  68. value: true,
  69. },
  70. {
  71. type: 'inputNumber',
  72. field: 'max',
  73. props: {min: 0}
  74. },
  75. ]);
  76. }
  77. };