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
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
<template>
  <div>
    <div class="message-header" v-if="showHeader">
      <div class="message-header-time">{{dayAgo}}</div>
      <div class="message-header-close">
        <i class="fa fa-times-circle" aria-hidden="true"
           @click="messageHeaderCloseClick(dateStr)"></i>
      </div>
    </div>
    <notice class="message-notice">
      <template slot="notice-header-icon">
        <img class="notice-header-icon-img" :src="icon"/>
      </template>
      <template slot="notice-header-title">
        <span class="message-tip">{{tip}}</span>
        <span class="message-time">
          <span class="message-time-text">{{timeAgo}}</span>
          <i class="fa fa-times-circle message-time-close" aria-hidden="true"
             @click="messageTimeCloseClick(id)"></i>
        </span>
      </template>
      <template slot="notice-body">
        <div class="message-item">
          <div class="message-title" v-html="title"></div>
          <div class="message-body" v-html="body"></div>
        </div>
      </template>
    </notice>
  </div>
</template>
 
<script>
  import Notice from './Notice';
  import Calendar from './Calendar';
 
  export default {
    name: "MessageNotice",
    components: {
      Notice
    },
    props: {
      id: String,
      showHeader: Boolean,
      icon: String,
      tip: String,
      title: String,
      body: String,
      time: Date
    },
    computed: {
      timeAgo: function () {
        return Calendar.timeAgo(this.time);
      },
      dayAgo: function () {
        return Calendar.dayAgo(this.time);
      },
      dateStr: function () {
        return Calendar.dateOfYear(new Date(this.time));
      }
    },
    methods: {
      messageHeaderCloseClick: function (dateStr) {
        this.$store.dispatch('desktop/removeMessageByDate', dateStr);
      },
      messageTimeCloseClick: function (id) {
        this.$store.dispatch('desktop/removeMessageById', id);
      }
    }
  }
</script>
 
<style scoped>
 
  .message-header, .message-tip {
    color: #4e4e4e;
  }
 
  .message-header-time {
    font-size: 20px;
    display: inline-block;
    padding: 5px 20px 0 20px;
  }
 
  .message-header-close {
    display: inline-block;
    text-align: right;
    float:right;
    padding-right: 9px;
    line-height: 35px;
  }
 
  .message-header-close i {
    margin-right: 8px;
    font-size: 15px;
  }
 
  .message-item {
    padding: 10px 20px;
  }
 
  .message-item .message-title {
    font-weight: 600;
    font-size: 15px;
  }
 
  .message-item .message-body {
    font-size: 10px;
    color: #4e4e4e;
  }
 
  .message-time {
    float: right;
    margin-right: 10px;
    color: #4e4e4e;
  }
 
  .message-notice:hover .message-time-text, .message-notice .message-time-close {
    display: none;
  }
 
  .message-notice:hover .message-time-close, .message-notice .message-time-text {
    display: unset;
  }
 
  .message-time-close {
    font-size: 15px;
  }
 
</style>