zhangzengfei
2020-07-20 6efd5fd74bdaa5497968a2938a1dba984c8a4068
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
<template>
  <transition name="tip-slide">
    <div class="notice-tip" v-show="count > 0">
      <div class="notice-tip-icon">
        <img :src="icon"/>
      </div>
      <div class="notice-tip-content">
        <div class="notice-tip-content-title">{{title}}</div>
        <div class="notice-tip-content-body" v-html="body"></div>
      </div>
    </div>
  </transition>
</template>
 
<script>
  export default {
    name: "NoticeTip",
    data() {
      return {
        icon: '',
        title: '',
        body: '',
        count: 0
      }
    },
    created() {
      let _that = this;
      if (window.noticeTipIntervalArr) {
        window.noticeTipIntervalArr.forEach(item => clearInterval(item));
      }
      window.noticeTipIntervalArr = [setInterval(function () {
        _that.count -= 1;
      }, 1000)];
    },
    methods: {
      showTip: function (notice) {
        this.icon = notice.icon;
        this.title = notice.title;
        this.body = notice.body;
        this.count = 3;
      }
    }
  }
</script>
 
<style scoped>
  .notice-tip {
    position: absolute;
    right: 10px;
    top: 40px;
    height: 60px;
    width: 250px;
    background-color: rgba(200, 200, 200, 0.7);
    z-index: 140;
    border-radius: 5px;
  }
 
  .notice-tip-icon {
    display: inline-block;
    float: left;
  }
 
  .notice-tip-icon img {
    width: 40px;
    height: 40px;
    margin: 8px;
  }
 
  .notice-tip-content {
    display: inline-block;
    padding: 8px;
    width: 170px;
  }
 
  .notice-tip-content-title {
    color: #333333;
  }
 
  .notice-tip-content-body {
    color: #333333;
    overflow: hidden;
    height: 20px;
    text-overflow: ellipsis;
    white-space: nowrap
  }
 
  .tip-slide-enter-active {
    transition: all 0.5s;
  }
 
  .tip-slide-leave-active {
    transition: all 0.5s;
  }
 
  .tip-slide-enter, .tip-slide-leave-to {
    transform: translateX(260px);
  }
</style>