EditCellTable.vue 3.3 KB

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