WIP Сделала индикатор, таймер

This commit is contained in:
Daria Golova
2022-10-14 19:20:31 +03:00
parent 00ddeff84d
commit 2ccb622243
2 changed files with 42 additions and 10 deletions

View File

@@ -7,7 +7,7 @@
img.icon-wrapper.cursor-pointer(src="@/assets/icons/lock.svg") img.icon-wrapper.cursor-pointer(src="@/assets/icons/lock.svg")
base-doc-ok-button base-doc-ok-button
.flex.flex-col .flex.flex-col
span.block.time-indicator(:style="indicatorLocation") span.block.time-indicator(v-if="isShownIndicator" :style="indicatorLocation")
.line.flex.items-center(v-for="hour in hoursArray" :key="hour") .line.flex.items-center(v-for="hour in hoursArray" :key="hour")
.middle-line .middle-line
</template> </template>
@@ -27,6 +27,11 @@ export default {
hoursArray: Array, hoursArray: Array,
currentTime: String, currentTime: String,
}, },
data() {
return {
isShownIndicator: true,
};
},
computed: { computed: {
indicatorLocation() { indicatorLocation() {
return { return {
@@ -39,7 +44,12 @@ export default {
let newTime = this.currentTime let newTime = this.currentTime
.split(":") .split(":")
.map((elem) => parseInt(elem, 10)); .map((elem) => parseInt(elem, 10));
return (newTime[0] - 7) * 60 + newTime[1]; let result = (newTime[0] - 7) * 60.5 + newTime[1];
if (result > 666) {
this.isShownIndicator = false;
return 0;
}
return result;
}, },
}, },
}; };

View File

@@ -7,7 +7,7 @@
@selected-layout="selectedLayout") @selected-layout="selectedLayout")
.schedule-body.flex .schedule-body.flex
calendar-clock-column(:hoursArray="hoursArray") calendar-clock-column(:hoursArray="hoursArray")
calendar-column(:info="columnInfo" :hoursArray="hoursArray" :currentTime="currtentTime") calendar-column(:info="columnInfo" :hoursArray="hoursArray" :currentTime="currentTime")
</template> </template>
<script> <script>
@@ -33,8 +33,9 @@ export default {
name: "Захарова А.О.", name: "Захарова А.О.",
avatar: teamMemberAvatar, avatar: teamMemberAvatar,
}, },
currtentTime: "", currentTime: moment().format("HH:mm:ss"),
hoursArray: [], hoursArray: [],
timer: null,
}; };
}, },
methods: { methods: {
@@ -48,20 +49,41 @@ export default {
this.$emit("selected-layout", option); this.$emit("selected-layout", option);
}, },
updateTime() { updateTime() {
setInterval(this.changeCurrentTime, 5000); let currentHour = parseInt(this.currentTime.slice(0, -6), 10);
if (currentHour < 20 && currentHour > 8) {
this.timer = setInterval(() => {
this.changeCurrentTime();
this.changeHoursArray();
}, 5000);
}
}, },
changeCurrentTime() { changeCurrentTime() {
this.currtentTime = moment().format("HH:mm:ss"); this.currentTime = moment().format("HH:mm:ss");
console.log(this.currtentTime);
}, },
calculateHoursCount() { hoursArrayInitialization() {
for (let i = 8; i <= 18; i++) { for (let i = 8; i <= 18; i++) {
this.hoursArray.push(`${i}:00`); let startTime = this.currentTime.slice(0, -3);
let currentHour = parseInt(startTime.slice(0, -3), 10);
if (i === currentHour) {
this.hoursArray.push(startTime);
} else this.hoursArray.push(`${i}:00`);
} }
}, },
changeHoursArray() {
let newCurrentTime = this.currentTime.slice(0, -3);
let currentHour = parseInt(newCurrentTime.slice(0, -3), 10);
let newHoursArray = this.hoursArray.map((elem) => {
if (parseInt(elem.slice(0, -3), 10) === currentHour) {
return this.currentTime.slice(0, -3);
}
return elem;
});
this.hoursArray = newHoursArray;
},
}, },
mounted() { mounted() {
this.calculateHoursCount(); this.changeCurrentTime();
this.hoursArrayInitialization();
this.updateTime(); this.updateTime();
}, },
}; };