Showing
3 changed files
with
54 additions
and
5 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-31 11:45:30 | 2 | * @Date: 2022-08-31 11:45:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-12-29 11:45:54 | 4 | + * @LastEditTime: 2023-02-07 14:06:11 |
| 5 | * @FilePath: /data-table/src/components/DatePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/DatePickerField/index.vue |
| 6 | * @Description: 日期选择组件 | 6 | * @Description: 日期选择组件 |
| 7 | --> | 7 | --> |
| ... | @@ -60,14 +60,28 @@ const onConfirm = ({ selectedValues, selectedOptions }) => { | ... | @@ -60,14 +60,28 @@ const onConfirm = ({ selectedValues, selectedOptions }) => { |
| 60 | 60 | ||
| 61 | const columns_type = ref([]); | 61 | const columns_type = ref([]); |
| 62 | const date_format = props.item.component_props.data_dateformat; // YYYY-MM=年月,YYYY-MM-DD=年月日 | 62 | const date_format = props.item.component_props.data_dateformat; // YYYY-MM=年月,YYYY-MM-DD=年月日 |
| 63 | +// 数字前面补位 | ||
| 64 | +const formatZero = (num, len) => { | ||
| 65 | + if (String(num).length > len) { | ||
| 66 | + return num; | ||
| 67 | + } | ||
| 68 | + return (Array(len).join(0) + num).slice(-len) | ||
| 69 | +} | ||
| 63 | onMounted(() => { | 70 | onMounted(() => { |
| 64 | currentDate.value = props.item.value.split("-"); | 71 | currentDate.value = props.item.value.split("-"); |
| 72 | + const Year = String(dayjs().year()); | ||
| 73 | + const Month = formatZero(dayjs().month(), 2); | ||
| 74 | + const Day = formatZero(dayjs().date(), 2); | ||
| 65 | switch (date_format) { | 75 | switch (date_format) { |
| 66 | case "YYYY-MM": | 76 | case "YYYY-MM": |
| 67 | columns_type.value = ['year', 'month'] | 77 | columns_type.value = ['year', 'month'] |
| 78 | + // 设置默认值 | ||
| 79 | + currentDate.value = [Year, Month]; | ||
| 68 | break; | 80 | break; |
| 69 | case "YYYY-MM-DD": | 81 | case "YYYY-MM-DD": |
| 70 | columns_type.value = ['year', 'month', 'day'] | 82 | columns_type.value = ['year', 'month', 'day'] |
| 83 | + // 设置默认值 | ||
| 84 | + currentDate.value = [Year, Month, Day]; | ||
| 71 | break; | 85 | break; |
| 72 | } | 86 | } |
| 73 | }); | 87 | }); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-08 15:02:45 | 2 | * @Date: 2022-09-08 15:02:45 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-12-29 11:44:54 | 4 | + * @LastEditTime: 2023-02-07 14:07:51 |
| 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue |
| 6 | * @Description: 日期时间选择器 | 6 | * @Description: 日期时间选择器 |
| 7 | --> | 7 | --> |
| ... | @@ -69,33 +69,61 @@ const onCancel = () => { | ... | @@ -69,33 +69,61 @@ const onCancel = () => { |
| 69 | const columns_date_type = ref([]); | 69 | const columns_date_type = ref([]); |
| 70 | const columns_time_type = ref([]); | 70 | const columns_time_type = ref([]); |
| 71 | const date_format = props.item.component_props.data_dateformat; | 71 | const date_format = props.item.component_props.data_dateformat; |
| 72 | +// 数字前面补位 | ||
| 73 | +const formatZero = (num, len) => { | ||
| 74 | + if (String(num).length > len) { | ||
| 75 | + return num; | ||
| 76 | + } | ||
| 77 | + return (Array(len).join(0) + num).slice(-len) | ||
| 78 | +} | ||
| 72 | onMounted(() => { | 79 | onMounted(() => { |
| 73 | // 获取值定位显示 | 80 | // 获取值定位显示 |
| 74 | const datetime = props.item.value.split(" "); | 81 | const datetime = props.item.value.split(" "); |
| 75 | currentDate.value = datetime[0]?.split("-"); | 82 | currentDate.value = datetime[0]?.split("-"); |
| 76 | currentTime.value = datetime[1]?.split(":"); | 83 | currentTime.value = datetime[1]?.split(":"); |
| 77 | // YYYY=年,YYYY-MM=年月,YYYY-MM-DD=年月日,YYYY-MM-DD HH=年月日时,YYYY-MM-DD HH:mm=年月日时分,YYYY-MM-DD HH:mm:ss=年月日时分秒 | 84 | // YYYY=年,YYYY-MM=年月,YYYY-MM-DD=年月日,YYYY-MM-DD HH=年月日时,YYYY-MM-DD HH:mm=年月日时分,YYYY-MM-DD HH:mm:ss=年月日时分秒 |
| 85 | + const Hour = String(dayjs().hour()); | ||
| 86 | + const Minute = String(dayjs().minute()); | ||
| 87 | + const Second = String(dayjs().second()); | ||
| 88 | + const Year = String(dayjs().year()); | ||
| 89 | + const Month = formatZero(dayjs().month(), 2); | ||
| 90 | + const Day = formatZero(dayjs().date(), 2); | ||
| 78 | switch (date_format) { | 91 | switch (date_format) { |
| 79 | case "YYYY": | 92 | case "YYYY": |
| 80 | columns_date_type.value = ['year'] | 93 | columns_date_type.value = ['year'] |
| 94 | + // 设置默认值 | ||
| 95 | + currentDate.value = [Year]; | ||
| 81 | break; | 96 | break; |
| 82 | case "YYYY-MM": | 97 | case "YYYY-MM": |
| 83 | columns_date_type.value = ['year', 'month'] | 98 | columns_date_type.value = ['year', 'month'] |
| 99 | + // 设置默认值 | ||
| 100 | + currentDate.value = [Year, Month]; | ||
| 84 | break; | 101 | break; |
| 85 | case "YYYY-MM-DD": | 102 | case "YYYY-MM-DD": |
| 86 | columns_date_type.value = ['year', 'month', 'day'] | 103 | columns_date_type.value = ['year', 'month', 'day'] |
| 104 | + // 设置默认值 | ||
| 105 | + currentDate.value = [Year, Month, Day]; | ||
| 87 | break; | 106 | break; |
| 88 | case "YYYY-MM-DD HH": | 107 | case "YYYY-MM-DD HH": |
| 89 | columns_date_type.value = ['year', 'month', 'day'] | 108 | columns_date_type.value = ['year', 'month', 'day'] |
| 90 | columns_time_type.value = ['hour'] | 109 | columns_time_type.value = ['hour'] |
| 110 | + // 设置默认值 | ||
| 111 | + currentDate.value = [Year, Month, Day]; | ||
| 112 | + currentTime.value = [Hour]; | ||
| 91 | break; | 113 | break; |
| 92 | case "YYYY-MM-DD HH:mm": | 114 | case "YYYY-MM-DD HH:mm": |
| 93 | columns_date_type.value = ['year', 'month', 'day'] | 115 | columns_date_type.value = ['year', 'month', 'day'] |
| 94 | columns_time_type.value = ['hour', 'minute'] | 116 | columns_time_type.value = ['hour', 'minute'] |
| 117 | + // 设置默认值 | ||
| 118 | + currentDate.value = [Year, Month, Day]; | ||
| 119 | + currentTime.value = [Hour, Minute]; | ||
| 95 | break; | 120 | break; |
| 96 | case "YYYY-MM-DD HH:mm:ss": | 121 | case "YYYY-MM-DD HH:mm:ss": |
| 97 | columns_date_type.value = ['year', 'month', 'day'] | 122 | columns_date_type.value = ['year', 'month', 'day'] |
| 98 | columns_time_type.value = ['hour', 'minute', 'second'] | 123 | columns_time_type.value = ['hour', 'minute', 'second'] |
| 124 | + // 设置默认值 | ||
| 125 | + currentDate.value = [Year, Month, Day]; | ||
| 126 | + currentTime.value = [Hour, Minute, Second]; | ||
| 99 | break; | 127 | break; |
| 100 | } | 128 | } |
| 101 | }); | 129 | }); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-31 11:45:30 | 2 | * @Date: 2022-08-31 11:45:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-12-29 11:46:19 | 4 | + * @LastEditTime: 2023-02-07 14:06:51 |
| 5 | * @FilePath: /data-table/src/components/TimePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/TimePickerField/index.vue |
| 6 | * @Description: 时间选择组件 | 6 | * @Description: 时间选择组件 |
| 7 | --> | 7 | --> |
| ... | @@ -63,12 +63,19 @@ const columns_type = ref([]); | ... | @@ -63,12 +63,19 @@ const columns_type = ref([]); |
| 63 | const date_format = props.item.component_props.data_dateformat; // HH:mm=时分,HH:mm:ss=时分秒 | 63 | const date_format = props.item.component_props.data_dateformat; // HH:mm=时分,HH:mm:ss=时分秒 |
| 64 | onMounted(() => { | 64 | onMounted(() => { |
| 65 | currentTime.value = props.item.value.split(":"); | 65 | currentTime.value = props.item.value.split(":"); |
| 66 | + const Hour = String(dayjs().hour()); | ||
| 67 | + const Minute = String(dayjs().minute()); | ||
| 68 | + const Second = String(dayjs().second()); | ||
| 66 | switch (date_format) { | 69 | switch (date_format) { |
| 67 | case "HH:mm": | 70 | case "HH:mm": |
| 68 | - columns_type.value = ['hour', 'minute'] | 71 | + columns_type.value = ['hour', 'minute']; |
| 72 | + // 设置默认值 | ||
| 73 | + currentTime.value = [Hour, Minute]; | ||
| 69 | break; | 74 | break; |
| 70 | case "HH:mm:ss": | 75 | case "HH:mm:ss": |
| 71 | - columns_type.value = ['hour', 'minute', 'second'] | 76 | + columns_type.value = ['hour', 'minute', 'second']; |
| 77 | + // 设置默认值 | ||
| 78 | + currentTime.value = [Hour, Minute, Second]; | ||
| 72 | break; | 79 | break; |
| 73 | } | 80 | } |
| 74 | }); | 81 | }); | ... | ... |
-
Please register or login to post a comment