perf(date-picker): 代码优化

This commit is contained in:
就眠儀式 2022-03-27 06:04:53 +08:00
parent c7c4e69930
commit 8169e54846
3 changed files with 111 additions and 81 deletions

View File

@ -7,21 +7,21 @@ const getYears = () => {
years.push(i); years.push(i);
} }
return years; return years;
} };
/** /**
* *
*/ */
const getDate = () => { const getDate = () => {
return new Date(); return new Date();
} };
/** /**
* *
*/ */
const getYear = () => { const getYear = () => {
return getDate().getFullYear(); return getDate().getFullYear();
} };
/** /**
* *
@ -33,4 +33,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 } export { getDayLength, getYears };

View File

@ -18,7 +18,9 @@
> >
<div class="laydate-set-ym"> <div class="laydate-set-ym">
<span @click="showYearPanel">{{ currentYear }} </span <span @click="showYearPanel">{{ currentYear }} </span
><span @click="showPanel = 'month'">{{ currentMonth + 1 }} </span> ><span @click="showPanel = 'month'"
>{{ currentMonth + 1 }} </span
>
</div> </div>
<i <i
class="layui-icon laydate-icon laydate-next-m" class="layui-icon laydate-icon laydate-next-m"
@ -137,7 +139,9 @@
> >
<div class="laydate-set-ym"> <div class="laydate-set-ym">
<span @click="showYearPanel">{{ currentYear }} </span <span @click="showYearPanel">{{ currentYear }} </span
><span @click="showPanel = 'month'">{{ currentMonth + 1 }} </span> ><span @click="showPanel = 'month'"
>{{ currentMonth + 1 }} </span
>
</div> </div>
<i <i
class="layui-icon laydate-icon laydate-next-y" class="layui-icon laydate-icon laydate-next-y"
@ -188,11 +192,7 @@
</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"> <ul class="layui-laydate-list laydate-time-list">
<li <li class="num-list" v-for="item in els" :key="item.type">
class="num-list"
v-for="item in els"
:key="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"
@ -231,7 +231,15 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, nextTick, ref, watch, defineProps, defineEmits, onMounted } from "vue"; import {
computed,
nextTick,
ref,
watch,
defineProps,
defineEmits,
onMounted,
} from "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 } from "./day"; import { getDayLength, getYears } from "./day";
@ -239,7 +247,20 @@ import { getDayLength, getYears } from "./day";
const $emits = defineEmits(["update:modelValue"]); const $emits = defineEmits(["update:modelValue"]);
const WEEK_NAME = ["日", "一", "二", "三", "四", "五", "六"]; const WEEK_NAME = ["日", "一", "二", "三", "四", "五", "六"];
const MONTH_NAME = ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]; const MONTH_NAME = [
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月",
];
const hms = ref({ hh: "00", mm: "00", ss: "00" }); const hms = ref({ hh: "00", mm: "00", ss: "00" });
const els = [ const els = [
{ count: 24, type: "hh" }, { count: 24, type: "hh" },
@ -333,7 +354,8 @@ watch(
const handleDayClick = (item: any) => { const handleDayClick = (item: any) => {
selectedDay.value = item.value; selectedDay.value = item.value;
if (item.type !== "current") { if (item.type !== "current") {
currentMonth.value = item.type === "prev" ? currentMonth.value - 1 : currentMonth.value + 1; currentMonth.value =
item.type === "prev" ? currentMonth.value - 1 : currentMonth.value + 1;
} }
}; };
@ -361,7 +383,9 @@ const changeYearOrMonth = (type: "year" | "month", num: number) => {
const showYearPanel = () => { const showYearPanel = () => {
showPanel.value = "year"; showPanel.value = "year";
nextTick(() => { nextTick(() => {
(document.querySelector(".year-panel-item.active") as HTMLElement).scrollIntoView({ block: "center" }); (
document.querySelector(".year-panel-item.active") as HTMLElement
).scrollIntoView({ block: "center" });
}); });
}; };

View File

@ -42,13 +42,20 @@ const slots = slot.default && slot.default();
const isDragEnter = ref(false); const isDragEnter = ref(false);
interface localUploadOption { interface localUploadOption {
url:string, url: string;
file?:unknown, file?: unknown;
otherRequestData?:any otherRequestData?: any;
} }
const localUpload = (option: any) => { const localUpload = (option: any) => {
let file, formData, xhr: XMLHttpRequest, loadedevt, total, per: number, url, uploading; let file,
formData,
xhr: XMLHttpRequest,
loadedevt,
total,
per: number,
url,
uploading;
formData = new FormData(); formData = new FormData();
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
url = option.url; url = option.url;
@ -103,11 +110,10 @@ const getUploadChange = (e: any) => {
// //
localUpload({ localUpload({
url: props.url, url: props.url,
file:file file: file,
}); });
} else { } else {
// //
} }
}; };
const uploadDragOver = (e: any) => { const uploadDragOver = (e: any) => {