element-plus el-time-picker 时间段选择(可多选)

ops/2024/9/25 8:30:37/

实现一个如图的时间段选择器

在这里插入图片描述

  1. 处理好时间回显逻辑,组件内[‘’,‘’],后端数据[{startTime:‘’,endTime:‘’}]
  2. 处理好加和减的显示逻辑
<template><div><div v-for="(item, index) in currentChoose" :key="index" class="flex justify-center items-center" :class="index ? 'mt-2': ''"><el-time-pickerv-model="currentChoose[index]"v-bind="_options":disabled="_options.disabled"@change="handleChange(item, index)"/><div class="flex ml-2 w-2" v-if="!_options.disabled"><el-icon @click="plusTime(item, index)"><Plus /></el-icon><el-icon class="ml-2" v-if="index" @click="minusTime(item, index)"><Minus /></el-icon></div></div></div>
</template><script>
export default {name: "multipletimepicker",
};
</script><script setup>
import { ref, computed, watch } from "vue";
import _ from "lodash";const emits = defineEmits(["update:modelValue"
]);const props = defineProps({disabled: {//禁用type: Boolean,default: false,},options: {type: Object,default: () => {},},modelValue: {type: [Array, Object],default: () => ([]),},
});// 设置option默认值,如果传入自定义的配置则合并option配置项
const _options = computed(() => {const option = {'value-format': 'HH:mm','format':"HH:mm",'is-range': true};option.disabled = props.disabled;return Object.assign(option, props.options);
});const currentChoose = ref([]);const created = () => {if (!props.modelValue) {return []}if (props.modelValue instanceof Array) {if (props.modelValue.length) {currentChoose.value = props.modelValue.map(item => {return [item.startTime, item.endTime]})} else {currentChoose.value = [['', '']]}} else {console.log('时间选择插件,非数组格式')}
}const handleChange = () => {handleDataEmits()  
}const minusTime = (item, index) => {if (index === 0) {return;}currentChoose.value.splice(index, 1);handleDataEmits()
}const plusTime = (item, index) => {currentChoose.value.splice(index + 1, 0, [])handleDataEmits()
}// 统一处理数据回显
const handleDataEmits = () => {if (currentChoose.value && currentChoose.value.length) {// 将数组处理成后端数据格式,并触发父组件的model更新const arrFilter = currentChoose.value.filter(item => item)if (!arrFilter.length) {emits('update:modelValue', [{startTime: "", endTime: ""}])return}const arr = arrFilter.map(i => {return {startTime: i[0],endTime: i[1]}})emits('update:modelValue', arr)return arr}emits('update:modelValue', [{startTime: "", endTime: ""}])
}// 数据第一次进入,返显数据
watch(()=>props.modelValue, (val) => {created();
}, { immediate: true })
</script>

http://www.ppmy.cn/ops/36256.html

相关文章

ubuntu20部署3d高斯

3d高斯的链接&#xff1a;https://github.com/graphdeco-inria/gaussian-splatting 系统环境 ubuntu20的系统环境&#xff0c;打算只运行训练的代码&#xff0c;而不去进行麻烦的可视化&#xff0c;可视化直接在windows上用他们预编译好的exe去可视化。&#xff08;因为看的很…

JAVA每日面试题(二)

Java高级面试问题及答案 问题1: 请解释Java内存模型(JMM)及其重要性 答案&#xff1a; Java内存模型&#xff08;JMM&#xff09;是一个抽象的概念&#xff0c;它定义了Java程序中各种变量&#xff08;线程共享变量&#xff09;的访问规则&#xff0c;以及在并发环境下如何保…

30万买智驾车,选特斯拉还是华为?

文 | AUTO芯球 作者 | 雷歌 我真是佩服马斯克&#xff0c; 一趟24小时的北京出差&#xff0c;就解除了Model车系进入机关单位禁令的问题&#xff0c; 也打开了特斯拉FSD完全自动驾驶进入中国市场的大门&#xff0c; 给我我一天时间&#xff0c;估计一部剧都追不完&#xf…

深度学习实战76-基于目标检测YOLOv5模型的迁移学习使用方法,YOLOv5的原理与结构

大家好,我是微学AI,今天给大家介绍一下深度学习实战76-基于目标检测YOLOv5模型的迁移学习使用方法,YOLOv5的原理与结构。YOLOv5(You Only Look Once version 5)是一种先进的目标检测算法,基于深度学习的单阶段目标检测模型。它的主要原理是通过一次前向传播就同时预测图像…

力扣每日一题114:二叉树展开为链表

题目 中等 提示 给你二叉树的根结点 root &#xff0c;请你将它展开为一个单链表&#xff1a; 展开后的单链表应该同样使用 TreeNode &#xff0c;其中 right 子指针指向链表中下一个结点&#xff0c;而左子指针始终为 null 。展开后的单链表应该与二叉树 先序遍历 顺序相同…

如何创建git并上传

Git的配置和上传主要涉及以下步骤&#xff1a; 一、Git的配置 安装Git&#xff1a;首先&#xff0c;你需要在你的计算机上安装Git。这通常可以通过访问Git的官方网站并按照其提供的安装指南来完成。 注册GitHub账户&#xff08;如果你还没有的话&#xff09;&#xff1a;在Gi…

【QEMU系统分析之实例篇(二十)】

系列文章目录 第二十章 QEMU系统仿真的机器创建分析实例 文章目录 系列文章目录第二十章 QEMU系统仿真的机器创建分析实例 前言一、QEMU是什么&#xff1f;二、QEMU系统仿真的机器创建分析实例1.系统仿真的命令行参数2. CPU 配置项解析parse_cpu_option()cpu_class_by_name()p…

甲小姐对话柳钢:CEO对股东最大的责任,是对成功的概率负责|甲子光年

只有看见最微小的事物&#xff0c;才能洞悉伟大的定律。 来源&#xff5c;甲子光年 作者&#xff5c;甲小姐 刘杨楠 编辑&#xff5c;栗子 商业史上&#xff0c;职业经理人成为“空降CEO”的故事往往胜少败多。 “究其原因有三条——容易自嗨、喊口号&#xff1b;不顾公司历…