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);
}
return years;
}
};
/**
*
*/
const getDate = () => {
return new Date();
}
};
/**
*
*/
const getYear = () => {
return getDate().getFullYear();
}
};
/**
*
@ -33,4 +33,4 @@ const getDayLength = (year: number, month: number): number => {
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">
<span @click="showYearPanel">{{ currentYear }} </span
><span @click="showPanel = 'month'">{{ currentMonth + 1 }} </span>
><span @click="showPanel = 'month'"
>{{ currentMonth + 1 }} </span
>
</div>
<i
class="layui-icon laydate-icon laydate-next-m"
@ -137,7 +139,9 @@
>
<div class="laydate-set-ym">
<span @click="showYearPanel">{{ currentYear }} </span
><span @click="showPanel = 'month'">{{ currentMonth + 1 }} </span>
><span @click="showPanel = 'month'"
>{{ currentMonth + 1 }} </span
>
</div>
<i
class="layui-icon laydate-icon laydate-next-y"
@ -188,11 +192,7 @@
</div>
<div class="layui-laydate-content" style="height: 210px">
<ul class="layui-laydate-list laydate-time-list">
<li
class="num-list"
v-for="item in els"
:key="item.type"
>
<li class="num-list" v-for="item in els" :key="item.type">
<ol class="scroll" @click="choseTime">
<li
v-for="(it, index) in item.count"
@ -231,7 +231,15 @@
</template>
<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 LayDropdown from "../dropdown/index.vue";
import { getDayLength, getYears } from "./day";
@ -239,12 +247,25 @@ import { getDayLength, getYears } from "./day";
const $emits = defineEmits(["update:modelValue"]);
const WEEK_NAME = ["日", "一", "二", "三", "四", "五", "六"];
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 MONTH_NAME = [
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月",
];
const hms = ref({ hh: "00", mm: "00", ss: "00" });
const els = [
{count: 24, type: "hh"},
{count: 60, type: "mm"},
{count: 60, type: "ss"},
{ count: 24, type: "hh" },
{ count: 60, type: "mm" },
{ count: 60, type: "ss" },
];
export interface LayDatePickerProps {
@ -310,7 +331,7 @@ const setDateList = (year: number, month: number) => {
for (let i = 1; i <= nextDays; i++) {
list.push({
day: i,
value: + new Date(year, month + 1, i),
value: +new Date(year, month + 1, i),
isRange: false,
isSelected: false,
type: "next",
@ -333,7 +354,8 @@ watch(
const handleDayClick = (item: any) => {
selectedDay.value = item.value;
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 = () => {
showPanel.value = "year";
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

@ -41,14 +41,21 @@ const slot = useSlots();
const slots = slot.default && slot.default();
const isDragEnter = ref(false);
interface localUploadOption{
url:string,
file?:unknown,
otherRequestData?:any
interface localUploadOption {
url: string;
file?: unknown;
otherRequestData?: any;
}
const localUpload = (option:any) => {
let file, formData, xhr: XMLHttpRequest, loadedevt, total, per: number, url, uploading;
const localUpload = (option: any) => {
let file,
formData,
xhr: XMLHttpRequest,
loadedevt,
total,
per: number,
url,
uploading;
formData = new FormData();
xhr = new XMLHttpRequest();
url = option.url;
@ -102,12 +109,11 @@ const getUploadChange = (e: any) => {
if (props.url) {
//
localUpload({
url:props.url,
file:file
url: props.url,
file: file,
});
} else {
//
}
};
const uploadDragOver = (e: any) => {