Преглед изворни кода

feat(table): add editable DatePicker & TimePicker (#654)

为表格的可编辑单元格添加日期选择框和时间选择框组件
Netfan пре 3 година
родитељ
комит
93006c7dc7

+ 2 - 0
mock/demo/table-demo.ts

@@ -18,6 +18,8 @@ const demoList = (() => {
       name6: '@cname()',
       name7: '@cname()',
       name8: '@cname()',
+      date: `@date('yyyy-MM-dd')`,
+      time: `@time('HH:mm')`,
       'no|100000-10000000': 100000,
       'status|1': ['normal', 'enable', 'disable'],
     });

+ 11 - 1
src/components/Table/src/componentMap.ts

@@ -1,6 +1,14 @@
 import type { Component } from 'vue';
 
-import { Input, Select, Checkbox, InputNumber, Switch } from 'ant-design-vue';
+import {
+  Input,
+  Select,
+  Checkbox,
+  InputNumber,
+  Switch,
+  DatePicker,
+  TimePicker,
+} from 'ant-design-vue';
 
 import type { ComponentType } from './types/componentType';
 import { ApiSelect } from '/@/components/Form';
@@ -14,6 +22,8 @@ componentMap.set('Select', Select);
 componentMap.set('ApiSelect', ApiSelect);
 componentMap.set('Switch', Switch);
 componentMap.set('Checkbox', Checkbox);
+componentMap.set('DatePicker', DatePicker);
+componentMap.set('TimePicker', TimePicker);
 
 export function add(compName: ComponentType, component: Component) {
   componentMap.set(compName, component);

+ 3 - 1
src/components/Table/src/components/editable/helper.ts

@@ -18,7 +18,9 @@ export function createPlaceholderMessage(component: ComponentType) {
     component.includes('Select') ||
     component.includes('Checkbox') ||
     component.includes('Radio') ||
-    component.includes('Switch')
+    component.includes('Switch') ||
+    component.includes('DatePicker') ||
+    component.includes('TimePicker')
   ) {
     return t('common.chooseText');
   }

+ 3 - 1
src/components/Table/src/types/componentType.ts

@@ -4,4 +4,6 @@ export type ComponentType =
   | 'Select'
   | 'ApiSelect'
   | 'Checkbox'
-  | 'Switch';
+  | 'Switch'
+  | 'DatePicker'
+  | 'TimePicker';

+ 22 - 0
src/views/demo/table/EditCellTable.vue

@@ -88,6 +88,28 @@
       width: 200,
     },
     {
+      title: '日期选择',
+      dataIndex: 'date',
+      edit: true,
+      editComponent: 'DatePicker',
+      editComponentProps: {
+        valueFormat: 'YYYY-MM-DD',
+        format: 'YYYY-MM-DD',
+      },
+      width: 200,
+    },
+    {
+      title: '时间选择',
+      dataIndex: 'time',
+      edit: true,
+      editComponent: 'TimePicker',
+      editComponentProps: {
+        valueFormat: 'HH:mm',
+        format: 'HH:mm',
+      },
+      width: 200,
+    },
+    {
       title: '勾选框',
       dataIndex: 'name5',
       edit: true,

+ 32 - 0
src/views/demo/table/EditRowTable.vue

@@ -94,6 +94,38 @@
       width: 200,
     },
     {
+      title: '日期选择',
+      dataIndex: 'date',
+      editRow: true,
+      editComponent: 'DatePicker',
+      editComponentProps: {
+        valueFormat: 'YYYY-MM-DD',
+        format: 'YYYY-MM-DD',
+      },
+      width: 200,
+    },
+    {
+      title: '时间选择',
+      dataIndex: 'time',
+      editRow: true,
+      editComponent: 'TimePicker',
+      editComponentProps: {
+        valueFormat: 'HH:mm',
+        format: 'HH:mm',
+      },
+      width: 200,
+    },
+    {
+      title: '远程下拉',
+      dataIndex: 'name4',
+      editRow: true,
+      editComponent: 'ApiSelect',
+      editComponentProps: {
+        api: optionsListApi,
+      },
+      width: 200,
+    },
+    {
       title: '勾选框',
       dataIndex: 'name5',
       editRow: true,