perf(date-picker): 代码优化
This commit is contained in:
parent
c7c4e69930
commit
8169e54846
@ -2,26 +2,26 @@
|
|||||||
* 获取年份列表
|
* 获取年份列表
|
||||||
*/
|
*/
|
||||||
const getYears = () => {
|
const getYears = () => {
|
||||||
let years = [];
|
let years = [];
|
||||||
for (let i = 1970; i < getYear() + 100; i++) {
|
for (let i = 1970; i < getYear() + 100; i++) {
|
||||||
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();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取月份天数
|
* 获取月份天数
|
||||||
@ -30,7 +30,7 @@ const getYear = () => {
|
|||||||
* @param month
|
* @param month
|
||||||
*/
|
*/
|
||||||
const getDayLength = (year: number, month: number): number => {
|
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 };
|
||||||
|
@ -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,12 +247,25 @@ 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 = [
|
||||||
const hms = ref({hh: "00",mm: "00",ss: "00"});
|
"1月",
|
||||||
|
"2月",
|
||||||
|
"3月",
|
||||||
|
"4月",
|
||||||
|
"5月",
|
||||||
|
"6月",
|
||||||
|
"7月",
|
||||||
|
"8月",
|
||||||
|
"9月",
|
||||||
|
"10月",
|
||||||
|
"11月",
|
||||||
|
"12月",
|
||||||
|
];
|
||||||
|
const hms = ref({ hh: "00", mm: "00", ss: "00" });
|
||||||
const els = [
|
const els = [
|
||||||
{count: 24, type: "hh"},
|
{ count: 24, type: "hh" },
|
||||||
{count: 60, type: "mm"},
|
{ count: 60, type: "mm" },
|
||||||
{count: 60, type: "ss"},
|
{ count: 60, type: "ss" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export interface LayDatePickerProps {
|
export interface LayDatePickerProps {
|
||||||
@ -310,7 +331,7 @@ const setDateList = (year: number, month: number) => {
|
|||||||
for (let i = 1; i <= nextDays; i++) {
|
for (let i = 1; i <= nextDays; i++) {
|
||||||
list.push({
|
list.push({
|
||||||
day: i,
|
day: i,
|
||||||
value: + new Date(year, month + 1, i),
|
value: +new Date(year, month + 1, i),
|
||||||
isRange: false,
|
isRange: false,
|
||||||
isSelected: false,
|
isSelected: false,
|
||||||
type: "next",
|
type: "next",
|
||||||
@ -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" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,58 +41,65 @@ const slot = useSlots();
|
|||||||
const slots = slot.default && slot.default();
|
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 = new FormData();
|
formData,
|
||||||
xhr = new XMLHttpRequest();
|
xhr: XMLHttpRequest,
|
||||||
url = option.url;
|
loadedevt,
|
||||||
file = option.file;
|
total,
|
||||||
formData.append("files", file);
|
per: number,
|
||||||
//append 其他数据
|
url,
|
||||||
if (option.otherRequestData instanceof Object) {
|
uploading;
|
||||||
var _requestDate = option.otherRequestData;
|
formData = new FormData();
|
||||||
for (var key in _requestDate) {
|
xhr = new XMLHttpRequest();
|
||||||
formData.append(key, _requestDate[key]);
|
url = option.url;
|
||||||
}
|
file = option.file;
|
||||||
|
formData.append("files", file);
|
||||||
|
//append 其他数据
|
||||||
|
if (option.otherRequestData instanceof Object) {
|
||||||
|
var _requestDate = option.otherRequestData;
|
||||||
|
for (var key in _requestDate) {
|
||||||
|
formData.append(key, _requestDate[key]);
|
||||||
}
|
}
|
||||||
//事件回调
|
}
|
||||||
// event callbacks
|
//事件回调
|
||||||
xhr.onreadystatechange = function () {
|
// event callbacks
|
||||||
if (xhr.readyState === 4) {
|
xhr.onreadystatechange = function () {
|
||||||
if ((xhr.status >= 200 && xhr.status <= 300) || xhr.status === 304) {
|
if (xhr.readyState === 4) {
|
||||||
option.successF instanceof Function &&
|
if ((xhr.status >= 200 && xhr.status <= 300) || xhr.status === 304) {
|
||||||
option.successF(xhr.responseText);
|
option.successF instanceof Function &&
|
||||||
} else {
|
option.successF(xhr.responseText);
|
||||||
option.errorF instanceof Function && option.errorF(xhr.responseText);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
option.errorF instanceof Function && option.errorF();
|
option.errorF instanceof Function && option.errorF(xhr.responseText);
|
||||||
}
|
}
|
||||||
};
|
} else {
|
||||||
//侦查当前附件上传情况
|
option.errorF instanceof Function && option.errorF();
|
||||||
/**
|
}
|
||||||
* 附件的上传进度条方法在xhr.upload.onprogeress上,
|
};
|
||||||
* 还有一个xhr.onprogress,是下载时候的进度条,***
|
//侦查当前附件上传情况
|
||||||
* */
|
/**
|
||||||
xhr.upload.onprogress = function (event) {
|
* 附件的上传进度条方法在xhr.upload.onprogeress上,
|
||||||
// event.total是需要传输的总字节,event.loaded是已经传输的字节。如果event.lengthComputable不为真,则event.total等于0
|
* 还有一个xhr.onprogress,是下载时候的进度条,***
|
||||||
if (event.lengthComputable) {
|
* */
|
||||||
loadedevt = event.loaded;
|
xhr.upload.onprogress = function (event) {
|
||||||
total = event.total;
|
// event.total是需要传输的总字节,event.loaded是已经传输的字节。如果event.lengthComputable不为真,则event.total等于0
|
||||||
per = Math.floor((100 * loadedevt) / total);
|
if (event.lengthComputable) {
|
||||||
}
|
loadedevt = event.loaded;
|
||||||
//执行回调
|
total = event.total;
|
||||||
option.uploadProgress instanceof Function && option.uploadProgress(per);
|
per = Math.floor((100 * loadedevt) / total);
|
||||||
};
|
}
|
||||||
xhr.open("post", url, true); //不能是GET, get请求数据发送只能拼接在URL后面
|
//执行回调
|
||||||
xhr.setRequestHeader("Accept", "application/json, text/javascript");
|
option.uploadProgress instanceof Function && option.uploadProgress(per);
|
||||||
xhr.send(formData);
|
};
|
||||||
|
xhr.open("post", url, true); //不能是GET, get请求数据发送只能拼接在URL后面
|
||||||
|
xhr.setRequestHeader("Accept", "application/json, text/javascript");
|
||||||
|
xhr.send(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUploadChange = (e: any) => {
|
const getUploadChange = (e: any) => {
|
||||||
@ -102,12 +109,11 @@ const getUploadChange = (e: any) => {
|
|||||||
if (props.url) {
|
if (props.url) {
|
||||||
// 表单提交
|
// 表单提交
|
||||||
localUpload({
|
localUpload({
|
||||||
url:props.url,
|
url: props.url,
|
||||||
file:file
|
file: file,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const uploadDragOver = (e: any) => {
|
const uploadDragOver = (e: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user