(component): 发布 1.2.11 版本

This commit is contained in:
就眠儀式 2022-07-14 23:25:46 +08:00
parent eb09c753a5
commit 3fc0c38362
2 changed files with 64 additions and 39 deletions

View File

@ -12,10 +12,10 @@ const getYears = () => {
/** /**
* *
*/ */
const getDate = (val='') => { const getDate = (val = "") => {
if(val){ if (val) {
return new Date(val); return new Date(val);
}else{ } else {
return new Date(); return new Date();
} }
}; };
@ -23,24 +23,24 @@ const getDate = (val='') => {
/** /**
* *
*/ */
const getYear = (val='') => { const getYear = (val = "") => {
return getDate(val).getFullYear(); return getDate(val).getFullYear();
}; };
/** /**
* *
*/ */
const getMonth = (val='') => { const getMonth = (val = "") => {
return getDate(val).getMonth(); return getDate(val).getMonth();
}; };
const getDay=(val='')=>{ const getDay = (val = "") => {
if(val){ if (val) {
return new Date(getDate(val).toDateString()).getTime(); return new Date(getDate(val).toDateString()).getTime();
}else{ } else {
return -1; return -1;
} }
} };
/** /**
* *
@ -52,4 +52,4 @@ const getDayLength = (year: number, month: number): number => {
return new Date(year, month + 1, 0).getDate(); return new Date(year, month + 1, 0).getDate();
}; };
export { getDayLength, getYears, getDate, getMonth, getYear,getDay }; export { getDayLength, getYears, getDate, getMonth, getYear, getDay };

View File

@ -84,7 +84,10 @@
<div class="layui-laydate-footer"> <div class="layui-laydate-footer">
<span <span
v-if="type === 'datetime'" v-if="type === 'datetime'"
@click="showPane = 'time';scrollToCurrentTime()" @click="
showPane = 'time';
scrollToCurrentTime();
"
class="laydate-btns-time" class="laydate-btns-time"
>选择时间</span >选择时间</span
> >
@ -218,8 +221,16 @@
</div> </div>
</div> </div>
<div class="layui-laydate-content" style="height: 210px"> <div class="layui-laydate-content" style="height: 210px">
<ul class="layui-laydate-list laydate-time-list" ref="timePanelRef"> <ul
<li class="num-list" v-for="item in els" :key="item.type" :data-type="item.type"> class="layui-laydate-list laydate-time-list"
ref="timePanelRef"
>
<li
class="num-list"
v-for="item in els"
:key="item.type"
:data-type="item.type"
>
<ol class="scroll" @click="choseTime"> <ol class="scroll" @click="choseTime">
<li <li
v-for="(it, index) in item.count" v-for="(it, index) in item.count"
@ -278,8 +289,16 @@ import dayjs from "dayjs";
import { LayIcon } from "@layui/icons-vue"; import { LayIcon } from "@layui/icons-vue";
import LayInput from "../input/index.vue"; import LayInput from "../input/index.vue";
import LayDropdown from "../dropdown/index.vue"; import LayDropdown from "../dropdown/index.vue";
import { getDayLength, getYears, getMonth, getYear,getDay } from "./day"; import { getDayLength, getYears, getMonth, getYear, getDay } from "./day";
import { ref, watch, computed, defineProps, defineEmits, onMounted, nextTick } from "vue"; import {
ref,
watch,
computed,
defineProps,
defineEmits,
onMounted,
nextTick,
} from "vue";
import { anyTypeAnnotation } from "@babel/types"; import { anyTypeAnnotation } from "@babel/types";
export interface LayDatePickerProps { export interface LayDatePickerProps {
@ -339,7 +358,7 @@ const yearList = ref<number[]>(getYears());
const dateList = ref<any[]>([]); const dateList = ref<any[]>([]);
const showPane = ref("date"); const showPane = ref("date");
const yearmonthScrollRef=ref() const yearmonthScrollRef = ref();
watch( watch(
() => props.type, () => props.type,
@ -356,9 +375,10 @@ onMounted(() => {
clear(); clear();
}, 0); }, 0);
} }
let modelValue=props.modelValue; let modelValue = props.modelValue;
if(modelValue.length===8){ //dayjs if (modelValue.length === 8) {
modelValue='1970-01-01 '+modelValue; //dayjs
modelValue = "1970-01-01 " + modelValue;
} }
hms.value.hh = dayjs(modelValue).hour(); hms.value.hh = dayjs(modelValue).hour();
hms.value.mm = dayjs(modelValue).minute(); hms.value.mm = dayjs(modelValue).minute();
@ -562,45 +582,50 @@ const choseTime = (e: any) => {
} }
}; };
const openDropDown=()=>{ const openDropDown = () => {
nextTick(()=>{ nextTick(() => {
if(showPane.value=='year'||showPane.value=='yearmonth'){ if (showPane.value == "year" || showPane.value == "yearmonth") {
let scrollTop=0; let scrollTop = 0;
for (const child of yearmonthScrollRef.value.firstElementChild.childNodes) { for (const child of yearmonthScrollRef.value.firstElementChild
if(child.classList&&child.classList.contains('layui-this')){ .childNodes) {
scrollTop=child.offsetTop-(yearmonthScrollRef.value.offsetHeight-child.offsetHeight)/2; if (child.classList && child.classList.contains("layui-this")) {
scrollTop =
child.offsetTop -
(yearmonthScrollRef.value.offsetHeight - child.offsetHeight) / 2;
break; break;
} }
} }
yearmonthScrollRef.value.scrollTo(0,scrollTop) yearmonthScrollRef.value.scrollTo(0, scrollTop);
}else if(showPane.value=='time'){ } else if (showPane.value == "time") {
scrollToCurrentTime() scrollToCurrentTime();
} }
}) });
} };
// //
const timePanelRef=ref() const timePanelRef = ref();
const scrollToCurrentTime = () => { const scrollToCurrentTime = () => {
nextTick(() => { nextTick(() => {
timePanelRef.value.childNodes.forEach((element: HTMLElement) => { timePanelRef.value.childNodes.forEach((element: HTMLElement) => {
if (element.nodeName === 'LI') { if (element.nodeName === "LI") {
let scrollTop = 0; let scrollTop = 0;
let parentDom = element.firstElementChild as HTMLElement; let parentDom = element.firstElementChild as HTMLElement;
let childList = parentDom.childNodes; let childList = parentDom.childNodes;
for (let index = 0; index < childList.length; index++) { for (let index = 0; index < childList.length; index++) {
const child = childList[index] as HTMLElement; const child = childList[index] as HTMLElement;
if (child.nodeName !== 'LI') { if (child.nodeName !== "LI") {
continue; continue;
} }
if (child.classList && child.classList.contains('layui-this')) { if (child.classList && child.classList.contains("layui-this")) {
scrollTop = child.offsetTop - (parentDom.offsetHeight - child.offsetHeight) / 2; scrollTop =
parentDom.scrollTo(0, scrollTop) child.offsetTop -
(parentDom.offsetHeight - child.offsetHeight) / 2;
parentDom.scrollTo(0, scrollTop);
break; break;
} }
} }
} }
}); });
}) });
} };
</script> </script>