亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue如何實現(xiàn)簡單的時間軸與時間進度條

 更新時間:2022年09月20日 10:34:57   作者:大阿夏呀  
作為一個前端初學(xué)者,公司項目中前端需要一個進度條,所以下面這篇文章主要給大家介紹了關(guān)于Vue如何實現(xiàn)簡單的時間軸與時間進度條的相關(guān)資料,需要的朋友可以參考下

前言

項目需要按天播放地圖等值線圖功能,所以需要一個時間進度條,網(wǎng)上找了一下發(fā)現(xiàn)沒有自己需要的樣子,于是只能簡單的寫一個。

1、封裝時間尺度組件

<!-- 時間尺度 -->
<template>
	<div class="time">
		<div class="time_menu" v-show="timeList.length != 0">
			<template v-if="playState">
				<el-tooltip class="item" effect="dark" content="暫停" placement="top-end">
					<img src="../assets/timescale/zt.png" @click="playState = false,stopInterval()" />
				</el-tooltip>
			</template>
			<template v-if="!playState">
				<el-tooltip class="item" effect="dark" content="播放" placement="top-end">
					<img src="../assets/timescale/bf.png" @click="playState = true,startInterval()" />
				</el-tooltip>
			</template>
			<el-tooltip class="item" effect="dark" content="上一天" placement="top-end">
				<img src="../assets/timescale/icons_next.png" @click="upTime()" style="transform: rotate(180deg);" />
			</el-tooltip>
			<el-tooltip class="item" effect="dark" content="下一天" placement="top-end">
				<img src="../assets/timescale/icons_next.png" @click="nextTime()" />
			</el-tooltip>
		</div>
		<div style="width: 80%;height: 100%;position: relative;display: flex;align-items: flex-end;overflow: auto;">
			<div style="height: 40%;display: flex;flex-shrink: 0;flex-flow: row nowrap;align-items: flex-end;">
				<template v-for="(item,index) in timeList">
					<el-tooltip class="item" effect="dark" :content="item" placement="top-end">
						<div class="keDuXian" :style="index%5 == 0 ? 'height:100%;':'height:60%;'" :id="item"
							@click="timeClick(item)">
							<template v-if="index > 0">
							<div v-if="index%5 == 0" style="position: relative;top: -20px;left:-30px;color: #FFF;width: 70px;font-size: 0.75rem;">
								{{item}}
							</div>
							</template>
							</div>
					</el-tooltip>
				</template>
			</div>
			<div v-show="timeList.length != 0" class="progress" :style="'width:'+progresswidth+'px;'">
				<div style="width: 100%;height: 40%;background-color: rgb(20,170,255);">
				</div>
			</div>
			<img v-show="timeList.length != 0" src="../assets/timescale/xsjx.png" class="progressImg" :style="'left:'+(progresswidth == 0 ? -7 : (progresswidth-8))+'px;'" />
		</div>
	</div>
</template>
 
<script>
	import {getScopeTime} from "../utils/regular.js"
	export default {
		data() {
			return {
				timeList:[],
				thisTime: '',
				progresswidth: 0,
				playState: false,
				Interval:'',
			}
		},
		beforeDestroy(){
			clearInterval(this.Interval)
		},
		methods: {
			startInterval(){
				this.Interval = setInterval(() => {
					if(this.timeList.indexOf(this.thisTime)+1 == this.timeList.length){
						this.playState =  false
						this.stopInterval()
					}else{
						this.thisTime = this.timeList[this.timeList.indexOf(this.thisTime) + 1]
					}
					this.setProgressWidth()
				}, 4000)
			},
			stopInterval(){
				clearInterval(this.Interval)
			},
			init(time,start,end) {
				this.timeList = getScopeTime(start,end,2)
				this.thisTime = time
				this.$nextTick(()=>{
					this.setProgressWidth()
				})
			},
			timeClick(time) {
				this.thisTime = time
				this.setProgressWidth()
			},
			setProgressWidth(){
				this.progresswidth = document.getElementById(this.thisTime).offsetLeft
				this.$emit('schedule',this.thisTime)
			},
			upTime(){
				if(this.thisTime == this.timeList[0]){
					this.$message({
						message: '已經(jīng)是第一天了',
						type: 'warning'
					});
				}else{
					this.thisTime = this.timeList[this.timeList.indexOf(this.thisTime)-1]
					this.setProgressWidth()
				}
			},
			nextTime(){
				if(this.thisTime == this.timeList[this.timeList.length-1]){
					this.$message({
						message: '已經(jīng)是最后一天了',
						type: 'warning'
					});
				}else{
					this.thisTime = this.timeList[this.timeList.indexOf(this.thisTime)+1]
					this.setProgressWidth()
				}
			}
		}
	}
</script>
 
<style lang="less" scoped>
	.time {
		width: 100%;
		height: 100%;
		background: rgba(10, 34, 66, 0.65);
		box-shadow: inset 0px 1px 12px 0px rgba(75, 137, 255, 0.5);
		border-radius: 4px;
		border: 1px solid #57C8EE;
		display: flex;
		align-items: flex-end;
		position: relative;
	}
 
	.time_menu {
		width: 20%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		padding: 0 3%;
		box-sizing: border-box;
 
		img {
			width: 20px;
			height: 20px;
			cursor: pointer;
			transition-duration: 0.5s;
		}
	}
 
	.progress {
		height:100%;
		position: absolute;
		display: flex;
		align-items: flex-end;
		z-index: -1;
		transition-duration: 0.5s;
	}
 
	.triangle {
		width: 0px;
		height: 0px;
		border: 20px solid transparent;
		border-top-color: #00FFFF;
		// opacity: 1;
		position: absolute;
		left: -20px;
		top: 20px;
	}
	.keDuXian{
		width: 2px;
		background-color: #FFF;
		cursor: pointer;
		margin-right:25px;
	}
	.progressImg{
		width: 1.125rem;
		height: 1.125rem;
		position: absolute;
		z-index:9;
	}
</style>

2、在vue頁面使用時間尺度 

首先引入組件 然后給組件外部包一層div  組件的大小是根據(jù)父級來的

初始化:在methods方法里調(diào)用組件內(nèi)部的init方法初始化 傳入三個參數(shù)

schedule事件是每當(dāng)尺度變化會返回變化后的時間,可以根據(jù)時間做對應(yīng)邏輯處理

<!-- 進度條-->
<div style="width: 50%;height: 4%;position: absolute;z-index: 999;bottom: 20%;left: 25%;">
   <timescale ref="timescale" @schedule="schedule"></timescale>
</div>
 
<!-- 引入組件-->
import timescale from "../../components/timeScale.vue"
 
 
 
<!-- 調(diào)用組件內(nèi)部方法 初始化時間尺度  傳入選中時間 起時間 止時間-->
this.$refs.timescale.init(this.isOlineTime,this.selectSectionTime[0],getTomorrow(this.selectSectionTime[1]))

3、組件init方法內(nèi) 通過起止時間算出中間的所有時間尺度 

startTime:開始時間

endTime:結(jié)束時間

type:1按日返回小時 2按月返回每天 

export const getScopeTime = (startTime, endTime, type) => {
	let start = new Date(startTime).getTime()
	let end = new Date(endTime).getTime()
	let time = []
	if (type == 2) {
		for (var i = 0; i < 1; i--) {
			start += 86400000
			if (start == end) {
				time.unshift(startTime.split(' ')[0])
				break
			} else {
				time.push(unixTimeToDateTime(start).split(' ')[0])
			}
		}
	} else if (type == 1) {
		for (var i = 0; i < 1; i--) {
			start += 3600000
			if (start == end) {
				time.unshift(startTime.split(' ')[0])
				break
			} else {
				time.push(unixTimeToDateTime(start))
			}
		}
	}
 
	return time
}

附上效果圖

目前沒有實現(xiàn)拖拽功能,只能通過點擊刻度更換時間,或者自動播放。

總結(jié)

到此這篇關(guān)于Vue如何實現(xiàn)簡單的時間軸與時間進度條的文章就介紹到這了,更多相關(guān)Vue實現(xiàn)時間軸內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue+Bootstrap實現(xiàn)簡易學(xué)生管理系統(tǒng)

    Vue+Bootstrap實現(xiàn)簡易學(xué)生管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Vue+Bootstrap實現(xiàn)簡易學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-02-02
  • Element?el-date-picker?日期選擇器的使用

    Element?el-date-picker?日期選擇器的使用

    本文主要介紹了Element?el-date-picker?日期選擇器的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • elementUI+Springboot實現(xiàn)導(dǎo)出excel功能的全過程

    elementUI+Springboot實現(xiàn)導(dǎo)出excel功能的全過程

    這篇文章主要介紹了elementUI+Springboot實現(xiàn)導(dǎo)出excel功能,現(xiàn)在也對這個導(dǎo)出功能進行一個匯總整理寫出來,結(jié)合實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • Vue中進行打包與部署的方法實例

    Vue中進行打包與部署的方法實例

    這篇文章主要給大家介紹了關(guān)于Vue中進行打包與部署的相關(guān)資料, 我們常使用前后端分離項目時,會需要將前端vue打包然后部署,需要的朋友可以參考下
    2023-09-09
  • vue3中setup語法糖下父子組件間傳遞數(shù)據(jù)的方式

    vue3中setup語法糖下父子組件間傳遞數(shù)據(jù)的方式

    Vue3中父組件指的是包含一個或多個子組件的組件,它們通過props和事件等方式來傳遞數(shù)據(jù)和通信,這篇文章主要介紹了vue3中setup語法糖下父子組件間傳遞數(shù)據(jù)的方式,需要的朋友可以參考下
    2023-06-06
  • Vue3中導(dǎo)航守衛(wèi)的使用教程

    Vue3中導(dǎo)航守衛(wèi)的使用教程

    在Vue3中,導(dǎo)航守衛(wèi)(Navigation Guards)用于在路由切換前后執(zhí)行一些操作,例如驗證用戶權(quán)限、取消路由導(dǎo)航等,本文主要為大家介紹了vue3中導(dǎo)航守衛(wèi)的使用方法,需要的可以參考下
    2023-08-08
  • 淺談Vue父子組件和非父子組件傳值問題

    淺談Vue父子組件和非父子組件傳值問題

    本篇文章主要介紹了淺談Vue父子組件和非父子組件傳值問題,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2017-08-08
  • 關(guān)于ElementUI el-table 鼠標(biāo)滾動失靈的問題及解決辦法

    關(guān)于ElementUI el-table 鼠標(biāo)滾動失靈的問題及解決辦法

    這篇文章主要介紹了關(guān)于ElementUI el-table 鼠標(biāo)滾動失靈的問題及解決辦法,本文給大家分享問題所在原因及解決方案,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-08-08
  • 詳解vue computed的緩存實現(xiàn)原理

    詳解vue computed的緩存實現(xiàn)原理

    這篇文章主要介紹了vue computed的緩存實現(xiàn)原理,幫助大家更好的理解和學(xué)習(xí)使用vue,感興趣的朋友可以了解下
    2021-04-04
  • vue修改對象的屬性值后頁面不重新渲染的實例

    vue修改對象的屬性值后頁面不重新渲染的實例

    今天小編就為大家分享一篇vue修改對象的屬性值后頁面不重新渲染的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08

最新評論