ke_junjie
2025-06-04 84620534eb627e95811b971a4b552b6a177829bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
    <div class="screen-header">
        <div class="left">
            <div class="left-str"><span class="day-str">{{dayStr}}</span><span>{{weekStr}}</span></div>
            <div class="compName">青汽智能立体库监控平台</div>
            <div class="right-str">{{timeStr}}</div>
        </div>
        <!-- <div class="right">
            <img src="@/assets/img/logo_white.png" alt="Logo" class="logo-img" />
        </div> -->
    </div>
</template>
 
<script>
import dayjs from 'dayjs'
export default {
    name:'screenHeader',
    data(){
        return {
            serverTime:'',
            timerCount:0,
            dayStr:'',
            weekStr:'',
            timeStr:'',
            interval:null,
            serverInterval:null
        }
    },
    mounted() {
        this.init()
    },
    beforeDestroy(){
        this.clearInerval()
    },
    beforeUnmount(){
        console.log("beforeUnmount------------------清除年月日的定时器")
        this.clearInerval()
    },
    methods:{
        init(){
            this.serverTime  = new Date().getTime()
            this.getTime();
            this.createInterVal()
 
            // this.getServerTime(()=>{
            //     this.getTime();
            //     this.createInterVal()
            // })
        },
        getServerTime(callback){
            this.loading = false;
            callback && callback(true)
 
            // this.loading = true;
            // this.$api.get('GetNowTime',{},{block:'screen',needToken:false}).then((d)=>{
            //     this.serverTime = d;
            //     this.timerCount = 0;
            //     this.loading = false;
            //     callback && callback(true)
            // }).catch(()=>{
            //     this.serverTime = new Date().getTime();
            //     this.timerCount = 0;
            //     this.loading = false;
            //     callback && callback(false)
            // })
        },
        getTime(){
            let now = dayjs(this.serverTime+this.timerCount*1000);
            this.dayStr = now.format('YYYY-MM-DD');
            let week = now.day(), weekStr="";
            switch (week) {
                case 1:
                    this.weekStr = '星期一';
                    break;
                case 2:
                    this.weekStr = '星期二';
                    break;
                case 3:
                    this.weekStr = '星期三';
                    break;
                case 4:
                    this.weekStr = '星期四';
                    break;
                case 5:
                    this.weekStr = '星期五';
                    break;
                case 6:
                    this.weekStr = '星期六';
                    break;
                default:
                    this.weekStr = '星期日';
                    break;
            }
            this.timeStr = now.format('HH:mm:ss');
            this.timerCount++;
        },
        createInterVal(){
            this.createServerInterVal();
            this.createTimerInterVal();
        },
        createTimerInterVal(){
            this.interval = window.setInterval(this.getTime.bind(this),1000)
        },
        createServerInterVal(){
            this.serverInterval = window.setInterval(this.getServerTime.bind(this),10*60*1000)
        },
        clearInerval(){
            this.clearTimerInerval();
            this.clearServerInerval();
        },
        clearTimerInerval(){
            window.clearInterval(this.interval)
        },
        clearServerInerval(){
            window.clearInterval(this.serverInterval)
        }
    }
}
</script>
 
<style lang="scss" scoped>
 
.screen-header{
    height: 100%;
    display: flex;
    .compName{
    color: white;
    font-size: 16px;
    display: block;
    text-align: center;
    justify-content: center;
    padding-left: 5.5%;
    letter-spacing: 4px;
    padding-top: 6px;
    font-family: initial;
    font-weight: 700;
    }
    &>.left{
        height: 100%;
        overflow: hidden;
        flex: 1;
        background-repeat: no-repeat;
        background-image: url(@/assets/img/screen/header3.png);
        background-size: 100% 100%;
        position: relative;
    }
    &>.right{
        width: 88px;
        flex-shrink: 0;
        box-sizing: border-box;
        overflow: hidden;
        display: flex;
    align-items: center;
    justify-content: center;
        .logo-img{
            height: 24px;
            width: auto;
            top: 5px;
        }
    }
    .left-str,.right-str{
        position: absolute;
        top: 9px;
        color: #fff;
        font-size: 12px;
    }
    .left-str{
        left: 10px;
    }
    .right-str{
        right: 12px;
    }
    .day-str{
        margin-right: 10px;
    }
}
</style>