cuilei
2025-06-13 1e653db94c24389cc7615fd4a7ef1d63b00af534
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
<template>
  <div class="full-screen-container">
    <router-view class="router-view">
      <template v-slot:function>
        <a-space class="common-button-container">
          <a-button type="primary" @click="handleLogout" size="large">切换用户</a-button>
          <a-button @click="backToIndex" size="large">返回主页</a-button>
          <!--<button class="button">设置</button>-->
        </a-space>
      </template>
    </router-view>
 
    <div class="footer" v-if="$route.path!=='/terminal/login'">
      <!--<div>姓名:{{nickname()}}</div>-->
      <div>{{currentDateAndTime}}</div>
    </div>
  </div>
</template>
 
<script>
  import { mapActions, mapGetters } from 'vuex'
 
  import moment from 'moment'
 
  export default {
    name: 'TerminalLayout',
    data() {
      return {
        currentDateAndTime: moment().format('YYYY-MM-DD HH:mm:ss'),
        getDateAndTimeInterval: null
      }
    },
    watch: {
      '$route.path': {
        handler(val) {
          if (val === '/terminal/index' || val === '/terminal/login') document.title = 'MDC智慧车间'
        }
      }
    },
    created() {
      this.getCurrentDateAndTime()
 
    },
    beforeDestroy() {
      if (this.getDateAndTimeInterval) {
        clearInterval(this.getDateAndTimeInterval)
        this.getDateAndTimeInterval = null
      }
    },
    methods: {
      ...mapActions(['Logout']),
 
      ...mapGetters(['nickname']),
 
      handleLogout() {
        const that = this
 
        this.$confirm({
          title: '提示',
          content: '确定要切换用户吗 ?',
          onOk() {
            return that.Logout({}).then(() => {
              window.location.reload()
            }).catch(err => {
              that.$message.error({
                title: '错误',
                description: err.message
              })
            })
          },
          onCancel() {
          }
        })
      },
 
      backToIndex() {
        if (this.$route.path !== '/terminal/index') this.$router.push('/terminal/index')
      },
 
      // 获取当前日期和时间(1秒更新1次)
      getCurrentDateAndTime() {
        this.getDateAndTimeInterval = setInterval(() => this.currentDateAndTime = moment().format('YYYY-MM-DD HH:mm:ss'), 1000)
      }
    }
  }
</script>
 
<style scoped lang="less">
  .full-screen-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #fff;
 
    .router-view {
      flex: 1;
      padding: 1.25vw;
      display: flex;
      flex-direction: column;
    }
  }
 
  .common-button-container {
    margin-bottom: 1vw;
  }
 
  .footer {
    font-size: 0.8vw;
    padding: 0.5vw 0;
    color: #000;
    /*font-weight: bold;*/
    text-align: center;
  }
</style>