11<template lang="html">
22 <div class =" msg" >
33 <div class =" msg-header" >
4- <i @click =" showInfo " class =" icon-back" ></i>消息中心
4+ <i @click =" hideMsg " class =" icon-back" ></i>消息中心
55 </div>
6+
7+ <div class =" msg-content" >
8+ <div class =" msg-read" >
9+ <div :class =" {selected: isOnRead}" @click.stop.prevent =" changeTab(true)" class =" has-no" >
10+ 未读消息:0
11+ </div>
12+ <div :class =" {selected: !isOnRead}" @click.stop.prevent =" changeTab(false)" class =" has" >
13+ 已读消息:2
14+ </div>
15+ </div>
16+
17+
18+ </div>
19+
20+ <div class =" msg-list" >
21+
22+ <div v-for =" item of (isOnRead ? msg.hasnot_read_messages : msg.has_read_messages)" class =" msg-item" >
23+ <div class =" msg-body" >
24+ <div class =" msg-name" >
25+ {{ item.author.loginname }} 的回复:
26+ </div>
27+ <div v-html =" item.reply.content" class =" msg-msg" >
28+
29+ </div>
30+ <div @click =" view" >
31+ <router-link :to =" {name: 'article', params: {id: item.topic.id}}" " >
32+
33+ <div class=" msg-from " >
34+ 来自:{{ item.topic.title }}
35+ </div>
36+ </router-link>
37+ </div>
38+
39+ </div>
40+
41+
42+ </div>
43+
44+ </div>
45+
646 </div>
747</template>
848
949<script>
1050export default {
11- name: ' msg'
51+ name: 'msg',
52+ data() {
53+ return {
54+ msg: {},
55+ isOnRead: true
56+ }
57+ },
58+ computed: {
59+ ak() {
60+ return this.$store.state.ak;
61+ }
62+ },
63+ created() {
64+ this.axios.get(`https://cnodejs.org/api/v1/messages?accesstoken=${this.ak}`)
65+ .then(result => result.data.data)
66+ .then(msg => this.msg = msg)
67+ },
68+ methods: {
69+ hideMsg() {
70+ this.$store.commit('showMsg', false);
71+ },
72+ changeTab(flag) {
73+ this.isOnRead = flag;
74+ console.log('this.isOnRead', this.isOnRead);
75+ },
76+ view() {
77+
78+ this.$store.commit('showMsg', false);
79+ // this.$router.push('/')
80+
81+ }
82+ }
1283}
1384</script>
1485
@@ -28,6 +99,7 @@ export default {
2899 background-color: white;
29100
30101 .msg-header {
102+
31103 display: flex;
32104 justify-content: center;
33105 align-items: center;
@@ -36,6 +108,7 @@ export default {
36108 color: white;
37109 font-size: 1.4rem;
38110 background-color: #2196f3;
111+ border-bottom: 1px solid rgba(255, 255, 255, .2);
39112 i.icon-back {
40113 position: absolute;
41114 left: 10px;
@@ -46,5 +119,87 @@ export default {
46119 background-size: contain;
47120 }
48121 }
122+
123+ .msg-content {
124+ display: flex;
125+ justify-content: center;
126+ // align-items: center;
127+ width: 100%;
128+ height: 40px;
129+ .msg-read {
130+ display: flex;
131+ justify-content: center;
132+ width: 100%;
133+ height: 40px;
134+ background-color: #2196f3;
135+ color: rgba(255, 255, 255, .5);
136+ font-size: 1.2rem;
137+ .has-no {
138+ flex: 1;
139+ display: flex;
140+ justify-content: center;
141+ align-items: center;
142+ border-right: 1px solid rgba(255, 255, 255, .2);
143+
144+ }
145+ .has {
146+ flex: 1;
147+ display: flex;
148+ justify-content: center;
149+ align-items: center;
150+ }
151+ .selected {
152+ border-bottom: 2px solid #ff4081;
153+ color: white;
154+ }
155+ }
156+
157+ }
158+
159+ .msg-list {
160+ flex: 1;
161+ width: 100%;
162+ .msg-item {
163+ display: flex;
164+ align-items: center;
165+ width: 100%;
166+ padding: 10px;
167+
168+ .msg-avatar {
169+ width: 50px;
170+ height: 50px;
171+ margin-right: 10px;
172+
173+ img {
174+ width: 30px;
175+ height: 30px;
176+ vertical-align: bottom;
177+ border-radius: 4px;
178+ }
179+ }
180+
181+ .msg-body {
182+ flex: 1;
183+ .msg-name {
184+ font-size: 1.3rem;
185+ }
186+ .msg-from {
187+ color: gray;
188+ font-size: 80%;
189+ }
190+ }
191+ }
192+
193+ @media screen and (min-width: 760px) {
194+ .msg-item {
195+ width: 60%;
196+ margin: auto;
197+ }
198+ }
199+
200+ .msg-item + .msg-item {
201+ border-top: 1px solid rgba(0, 0, 0, .1);
202+ }
203+ }
49204 }
50205</style>
0 commit comments