您的位置:首页 > 房产 > 家装 > 筑龙网官网首页_建设网站建设投标网1249中官网词_整站营销系统_网站在线优化检测

筑龙网官网首页_建设网站建设投标网1249中官网词_整站营销系统_网站在线优化检测

2025/1/14 1:05:22 来源:https://blog.csdn.net/weixin_42112342/article/details/142942249  浏览:    关键词:筑龙网官网首页_建设网站建设投标网1249中官网词_整站营销系统_网站在线优化检测
筑龙网官网首页_建设网站建设投标网1249中官网词_整站营销系统_网站在线优化检测

基于 

"vant": "^4.8.3",

效果图

<template><!-- 弹出层 --><van-popupv-model:show="isPicker"position="bottom"><van-pickerref="picker":title="title"v-model="selectedValues":columns="columns"@change="onChange"@cancel="cancelOn"@confirm="onConfirm"/></van-popup>
</template>

js

<script setup lang="ts">
import { ref ,watch } from 'vue';
import {formatTimeArray} from "@/utils/formate/date_formate";const props = defineProps({showPicker: {type: Boolean,default: false,},title: {type: String,default: "请选择时间",},timeFormat: {type: String,default: "yyyy-MM-dd HH:mm:ss",},
})const  isPicker = ref<any>(false) //是否显示弹出层
const  columns = ref<any>([])
const picker = ref()
const getCountDays = (year: any, month: any) => {//获取某年某月多少天const day = new Date(year, month, 0);return day.getDate();
}const selectedValues = ref<any>(formatTimeArray(new Date()));const getColumns = () => {const Y: any = selectedValues.value[0];const M: any = selectedValues.value[1];let year: any = []; // 默认范围 前后十年for (let i = Y - 10; i <= Y + 10; i++) {year.push({text: i,value: i});}let month: any ;//月month = getColumn(13,true)let days: any = getCountDays(Y, M); //天,和当年月有关let day: any;day = getColumn(days + 1,true)let hour: any ; //小时hour = getColumn(24)let minute: any ; //分钟minute = getColumn(60)let seconds: any ; //秒seconds = getColumn(60)if (props.timeFormat?.includes("yyyy")) {columns.value.push(year);}if (props.timeFormat?.includes("MM")) {columns.value.push(month); //获取当月的天数}if (props.timeFormat?.includes("dd")) {columns.value.push(day);}if (props.timeFormat?.includes("HH")) {columns.value.push(hour);}if (props.timeFormat?.includes("mm")) {columns.value.push(minute);}if (props.timeFormat?.includes("ss")) {columns.value.push(seconds);}
}const getColumn = (length: any,isSplice: Boolean = false) => {if ( isSplice ) {const data = Array.from({ length }, (_, index) => ({ text: index, value: index }));return data.splice(1)} else {return Array.from({ length }, (_, index) => ({ text: index, value: index }));}
}const onChange = (values: any) => {let days: any = getCountDays(values.selectedValues[0], values.selectedValues[1]);let newDayColumn: any ;newDayColumn = getColumn(days + 1,true);columns.value[2] = newDayColumn
}const emits = defineEmits(["changeValue",'confirm']);const cancelOn = () => {emits("changeValue");
};const onConfirm = (val: any) => {let endVal: any = "";for (let i = 0; i < columns.value.length; i++) {endVal += val[i];if ( i === 2 ) {endVal += " ";} else if (i >= 3 && i <= 5) {endVal += ":";} else if (i < columns.value.length - 1) {endVal += "-";}}// 判断最后一个字符是否是分隔符if (endVal.endsWith("-") || endVal.endsWith(":")) {endVal = endVal.slice(0, -1); // 删除最后一个字符}emits("changeValue", endVal);emits("confirm", val.selectedValues);}// 监听 isPicker 的变化
watch(isPicker, (val: any) => {if (!val) {emits("changeValue");}columns.value = [];getColumns();
});// 监听 showPicker 的变化
watch(() => props.showPicker, (val) => {isPicker.value = val;
});</script>

引用组件

 <DateTimePicker@changeValue="showEndPicker = false"ref="popup":showPicker="showEndPicker"@confirm="onEndConfirm"/>

结合 输入框一起使用

      <van-fieldclass="form-wrapper"v-model="formData.pzzy_enddate"is-linkrequiredlabel-width="130"name="datePicker"label="批准作业结束时间"placeholder="点击选择时间"@click="showEndPicker = true"/><DateTimePicker@changeValue="showEndPicker = false"ref="popup":showPicker="showEndPicker"@confirm="onEndConfirm"/>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com