Skip to content

Commit

Permalink
feat:add a time component to the login page
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghang committed Oct 23, 2023
1 parent 0a596aa commit 8cfc1dd
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/app/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ export {}

declare module 'vue' {
export interface GlobalComponents {
NAlert: typeof import('naive-ui')['NAlert']
NAutoComplete: typeof import('naive-ui')['NAutoComplete']
NBadge: typeof import('naive-ui')['NBadge']
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
NButton: typeof import('naive-ui')['NButton']
NButtonGroup: typeof import('naive-ui')['NButtonGroup']
NCalendar: typeof import('naive-ui')['NCalendar']
NCard: typeof import('naive-ui')['NCard']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDataTable: typeof import('naive-ui')['NDataTable']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NDescriptions: typeof import('naive-ui')['NDescriptions']
NDescriptionsItem: typeof import('naive-ui')['NDescriptionsItem']
NDivider: typeof import('naive-ui')['NDivider']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
Expand All @@ -22,33 +32,54 @@ declare module 'vue' {
NEmpty: typeof import('naive-ui')['NEmpty']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NGradientText: typeof import('naive-ui')['NGradientText']
NGrid: typeof import('naive-ui')['NGrid']
NGridItem: typeof import('naive-ui')['NGridItem']
NH1: typeof import('naive-ui')['NH1']
NH2: typeof import('naive-ui')['NH2']
NIcon: typeof import('naive-ui')['NIcon']
NImage: typeof import('naive-ui')['NImage']
NImageGroup: typeof import('naive-ui')['NImageGroup']
NInput: typeof import('naive-ui')['NInput']
NInputGroup: typeof import('naive-ui')['NInputGroup']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutHeader: typeof import('naive-ui')['NLayoutHeader']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NList: typeof import('naive-ui')['NList']
NListItem: typeof import('naive-ui')['NListItem']
NMenu: typeof import('naive-ui')['NMenu']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
NModal: typeof import('naive-ui')['NModal']
NNotificationProvider: typeof import('naive-ui')['NNotificationProvider']
NNumberAnimation: typeof import('naive-ui')['NNumberAnimation']
NP: typeof import('naive-ui')['NP']
NPagination: typeof import('naive-ui')['NPagination']
NPopover: typeof import('naive-ui')['NPopover']
NPopselect: typeof import('naive-ui')['NPopselect']
NProgress: typeof import('naive-ui')['NProgress']
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NResult: typeof import('naive-ui')['NResult']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NStatistic: typeof import('naive-ui')['NStatistic']
NSwitch: typeof import('naive-ui')['NSwitch']
NTab: typeof import('naive-ui')['NTab']
NTable: typeof import('naive-ui')['NTable']
NTabPane: typeof import('naive-ui')['NTabPane']
NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag']
NText: typeof import('naive-ui')['NText']
NThing: typeof import('naive-ui')['NThing']
NTimeline: typeof import('naive-ui')['NTimeline']
NTimelineItem: typeof import('naive-ui')['NTimelineItem']
NTree: typeof import('naive-ui')['NTree']
NUpload: typeof import('naive-ui')['NUpload']
NUploadDragger: typeof import('naive-ui')['NUploadDragger']
NWatermark: typeof import('naive-ui')['NWatermark']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
Expand Down
169 changes: 169 additions & 0 deletions src/packages/components/digitalClock/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<template>
<div class="clock">
<div class="digit hours">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
<div class="digit hours">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
<div class="separator"></div>
<div class="digit minutes">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
<div class="digit minutes">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
<div class="separator"></div>
<div class="digit seconds">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
<div class="digit seconds">
<div class="segment" v-for="item in 7" :key="item"></div>
</div>
</div>
</template>
<script lang="ts">
import {defineComponent,onMounted,onBeforeUnmount} from "vue"
export default defineComponent({
setup(){
const digitSegments = [[1,2,3,4,5,6],[2,3],[1,2,7,5,4],[1,2,7,3,4],[6,7,2,3],[1,6,7,3,4],[1,6,5,4,3,7],[1,2,3],[1,2,3,4,5,6,7],[1,2,7,3,6]]
let timer = null
onBeforeUnmount(()=>{
timer && clearInterval(timer)
})
onMounted(()=>{
const setNumber = function(digit, number, on) {
const segments = digit.querySelectorAll(".segment")
const current = parseInt(digit.getAttribute("data-value"))
if (!isNaN(current) && current != number) {
digitSegments[current].forEach(function(digitSegment, index) {
setTimeout(function() {
segments[digitSegment-1].classList.remove("on")
}, index*45)
})
}
if (isNaN(current) || current != number) {
setTimeout(function() {
digitSegments[number].forEach(function(digitSegment, index) {
setTimeout(function() {
segments[digitSegment-1].classList.add("on")
}, index*45)
})
}, 250)
digit.setAttribute("data-value", number)
}
}
const _hours = document.querySelectorAll(".hours")
const _minutes = document.querySelectorAll(".minutes")
const _seconds = document.querySelectorAll(".seconds")
const setDom = function (){
let date = new Date()
let hours = date.getHours(), minutes = date.getMinutes(), seconds = date.getSeconds()
setNumber(_hours[0], Math.floor(hours/10), 1)
setNumber(_hours[1], hours%10, 1)
setNumber(_minutes[0], Math.floor(minutes/10), 1)
setNumber(_minutes[1], minutes%10, 1)
setNumber(_seconds[0], Math.floor(seconds/10), 1)
setNumber(_seconds[1], seconds%10, 1)
}
setDom()
timer = setInterval(setDom, 1000)
})
}
})
</script>
<style lang="less">
.clock {
position:fixed;
bottom: 10px;
left: 10px;
}
.digit {
width:15px;
height:25px;
margin:0 3px;
position:relative;
display:inline-block;
}
.digit .segment {
background:#c00;
border-radius:5px;
position:absolute;
opacity:0.15;
transition:opacity 0.2s;
}
.digit .segment.on, .separator {
opacity:1;
box-shadow:0 0 12px rgba(255,0,0,0.7);
transition:opacity 0s;
}
.separator {
width:2.5px;
height:2.5px;
background:#c00;
border-radius:50%;
display:inline-block;
position:relative;
top:-11.25px;
}
.digit .segment:nth-child(1) {
top:1.25px;
left:2.5px;
right:2.5px;
height:1.25px;
}
.digit .segment:nth-child(2) {
top:2.5px;
right:1.25px;
width:1.25px;
height:calc(50% - 3.25px);
}
.digit .segment:nth-child(3) {
bottom:2.5px;
right:1.25px;
width:1.25px;
height:calc(50% - 3.25px);
}
.digit .segment:nth-child(4) {
bottom:1.25px;
right:2.5px;
height:1.25px;
left:2.5px;
}
.digit .segment:nth-child(5) {
bottom:2.5px;
left:1.25px;
width:1.25px;
height:calc(50% - 3.25px);
}
.digit .segment:nth-child(6) {
top:2.5px;
left:1.25px;
width:1.25px;
height: calc(50% - 3.25px);
}
.digit .segment:nth-child(7) {
bottom:calc(50% - 0.625px);
right:2.5px;
left:2.5px;
height:1.25px;
}
</style>
2 changes: 2 additions & 0 deletions src/packages/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Authority from "@/packages/components/auth/Authority.vue"
import DigitalClock from "@/packages/components/digitalClock/index.vue"
import type {App} from "vue"
const setupComponents = (app:App)=>{
app.component("Authority",Authority)
app.component("DigitalClock",DigitalClock)
}

export default setupComponents
1 change: 1 addition & 0 deletions src/packages/view/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
</div>
</div>
</n-card>
<DigitalClock></DigitalClock>
</template>
<script lang="ts">
import {defineComponent, ref,reactive,CSSProperties,computed} from "vue"
Expand Down

0 comments on commit 8cfc1dd

Please sign in to comment.