hookehuyr

✨ feat(时间相关控件): 设置默认值后显示优化问题

<!--
* @Date: 2022-08-31 11:45:30
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-02-07 16:42:28
* @LastEditTime: 2023-02-08 15:01:56
* @FilePath: /data-table/src/components/DatePickerField/index.vue
* @Description: 日期选择组件
-->
......@@ -75,10 +75,20 @@ const minDate = ref()
const maxDate = ref()
onMounted(() => {
currentDate.value = props.item.value.split("-");
const Year = String(dayjs().year());
const Month = formatZero(dayjs().month(), 2);
const Day = formatZero(dayjs().date(), 2);
// 根据默认值时间调整显示
currentDate.value = props.item.component_props.default ? props.item.component_props.default.split("-") : props.item.value.split("-");
let Year = '';
let Month = '';
let Day = '';
if (!props.item.component_props.default) {
Year = String(dayjs().year());
Month = formatZero(dayjs().month(), 2);
Day = formatZero(dayjs().date(), 2);
} else {
Year = currentDate.value[0];
Month = formatZero(currentDate.value[1], 2);
Day = formatZero(currentDate.value[2], 2);
}
switch (date_format) {
case "YYYY-MM":
columns_type.value = ['year', 'month']
......
......@@ -81,17 +81,35 @@ const minDate = ref()
const maxDate = ref()
onMounted(() => {
// 获取值定位显示
const datetime = props.item.value.split(" ");
// 根据默认值时间调整显示
const datetime = props.item.component_props.default ? props.item.component_props.default.split(" ") : props.item.value.split(" ");
currentDate.value = datetime[0]?.split("-");
currentTime.value = datetime[1]?.split(":");
// YYYY=年,YYYY-MM=年月,YYYY-MM-DD=年月日,YYYY-MM-DD HH=年月日时,YYYY-MM-DD HH:mm=年月日时分,YYYY-MM-DD HH:mm:ss=年月日时分秒
const Hour = String(dayjs().hour());
const Minute = String(dayjs().minute());
const Second = String(dayjs().second());
const Year = String(dayjs().year());
const Month = formatZero(dayjs().month(), 2);
const Day = formatZero(dayjs().date(), 2);
let Year = '';
let Month = '';
let Day = '';
if (!props.item.component_props.default) {
Year = String(dayjs().year());
Month = formatZero(dayjs().month(), 2);
Day = formatZero(dayjs().date(), 2);
} else {
Year = currentDate.value[0];
Month = formatZero(currentDate.value[1], 2);
Day = formatZero(currentDate.value[2], 2);
}
let Hour = ''
let Minute = ''
let Second = ''
if (!props.item.component_props.default) {
Hour = String(dayjs().hour());
Minute = String(dayjs().minute());
Second = String(dayjs().second());
} else {
Hour = currentTime.value[0];
Minute = currentTime.value[1];
Second = currentTime.value[2];
}
switch (date_format) {
case "YYYY":
columns_date_type.value = ['year']
......
<!--
* @Date: 2022-08-31 11:45:30
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-02-07 15:14:48
* @LastEditTime: 2023-02-08 14:59:28
* @FilePath: /data-table/src/components/TimePickerField/index.vue
* @Description: 时间选择组件
-->
......@@ -62,10 +62,20 @@ const onConfirm = ({ selectedValues, selectedOptions }) => {
const columns_type = ref([]);
const date_format = props.item.component_props.data_dateformat; // HH:mm=时分,HH:mm:ss=时分秒
onMounted(() => {
currentTime.value = props.item.value.split(":");
const Hour = String(dayjs().hour());
const Minute = String(dayjs().minute());
const Second = String(dayjs().second());
// 根据默认值时间调整显示
currentTime.value = props.item.component_props.default ? props.item.component_props.default.split(":") : props.item.value.split(":");
let Hour = ''
let Minute = ''
let Second = ''
if (!props.item.component_props.default) {
Hour = String(dayjs().hour());
Minute = String(dayjs().minute());
Second = String(dayjs().second());
} else {
Hour = currentTime.value[0];
Minute = currentTime.value[1];
Second = currentTime.value[2];
}
switch (date_format) {
case "HH:mm":
columns_type.value = ['hour', 'minute'];
......