EditCellTable.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="p-4">
  3. <BasicTable @register="registerTable" @edit-end="handleEditEnd" @edit-cancel="handleEditCancel">
  4. </BasicTable>
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent } from 'vue';
  9. import { BasicTable, useTable, BasicColumn, EditTableHeaderIcon } from '/@/components/Table';
  10. import { optionsListApi } from '/@/api/demo/select';
  11. import { demoListApi } from '/@/api/demo/table';
  12. const columns: BasicColumn[] = [
  13. {
  14. title: '输入框',
  15. dataIndex: 'name',
  16. edit: true,
  17. editComponentProps: {
  18. prefix: '$',
  19. },
  20. width: 200,
  21. },
  22. {
  23. title: '默认输入状态',
  24. dataIndex: 'name7',
  25. edit: true,
  26. editable: true,
  27. width: 200,
  28. },
  29. {
  30. title: '输入框校验',
  31. dataIndex: 'name1',
  32. edit: true,
  33. // 默认必填校验
  34. editRule: true,
  35. width: 200,
  36. },
  37. {
  38. title: '输入框函数校验',
  39. dataIndex: 'name2',
  40. edit: true,
  41. editRule: async (text) => {
  42. if (text === '2') {
  43. return '不能输入该值';
  44. }
  45. return '';
  46. },
  47. width: 200,
  48. },
  49. {
  50. title: '数字输入框',
  51. dataIndex: 'id',
  52. edit: true,
  53. editRule: true,
  54. editComponent: 'InputNumber',
  55. width: 200,
  56. },
  57. {
  58. title: '下拉框',
  59. dataIndex: 'name3',
  60. edit: true,
  61. editComponent: 'Select',
  62. editComponentProps: {
  63. options: [
  64. {
  65. label: 'Option1',
  66. value: '1',
  67. },
  68. {
  69. label: 'Option2',
  70. value: '2',
  71. },
  72. ],
  73. },
  74. width: 200,
  75. },
  76. {
  77. title: '远程下拉',
  78. dataIndex: 'name4',
  79. edit: true,
  80. editComponent: 'ApiSelect',
  81. editComponentProps: {
  82. api: optionsListApi,
  83. },
  84. width: 200,
  85. },
  86. {
  87. title: '勾选框',
  88. dataIndex: 'name5',
  89. edit: true,
  90. editComponent: 'Checkbox',
  91. editValueMap: (value) => {
  92. return value ? '是' : '否';
  93. },
  94. width: 200,
  95. },
  96. {
  97. title: '开关',
  98. dataIndex: 'name6',
  99. edit: true,
  100. editComponent: 'Switch',
  101. editValueMap: (value) => {
  102. return value ? '开' : '关';
  103. },
  104. width: 200,
  105. },
  106. ];
  107. export default defineComponent({
  108. components: { BasicTable, EditTableHeaderIcon },
  109. setup() {
  110. const [registerTable] = useTable({
  111. title: '可编辑单元格示例',
  112. api: demoListApi,
  113. columns: columns,
  114. showIndexColumn: false,
  115. bordered: true,
  116. });
  117. function handleEditEnd({ record, index, key, value }: Recordable) {
  118. console.log(record, index, key, value);
  119. }
  120. function handleEditCancel() {
  121. console.log('cancel');
  122. }
  123. return {
  124. registerTable,
  125. handleEditEnd,
  126. handleEditCancel,
  127. };
  128. },
  129. });
  130. </script>