messageList.vue
4.94 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
<view class="page">
<view class="list-box">
<view class="item" v-for="(it,index) in messageList" :key="index"
@click="toDetail(it.MessageContent,it.MessageInfo.MessageId)">
<view class="info">
<view class="title">
{{it.MessageContent.Title}}
</view>
<view class="desc">
{{it.MessageContent.BodyText}}
</view>
</view>
<view class="isRead" style="background: red;" v-if="it.MessageReceiveEntity.IsRead === 0">
未读
</view>
<view class="isRead" style="background: #009e00;" v-else>
已读
</view>
</view>
</view>
</view>
</template>
<script>
import request from '@/utils/request.js'
export default {
data() {
return {
messageList: [],
isAdmin: false,
baseUrl: 'http://deyanggaoxin.fengshiyun.com'
}
},
onShow() {
this.getUser()
this.getNoticeTell()
},
methods: {
// 获取用户信息
getUser() {
if (uni.getStorageSync('user')) {
let userCode = uni.getStorageSync("user")
console.log(userCode)
if (userCode.userInfo.userId === 'admin') {
this.isAdmin = true
}
console.log('用户已登录!')
} else {
uni.showToast({
title: '请登录',
icon: 'none',
duration: 1500
})
// setTimeout(() => {
// uni.reLaunch({
// url: '/pages/login/index'
// })
// })
}
},
// 获取消息通知
getNoticeTell() {
request({
url: '/api/extend/demo/GetMyMessage',
method: 'get',
data: {}
}).then(res => {
console.log('通知列表', res)
if (res.code == 200) {
this.messageList = res.data
}
})
},
// 获取消息通知
getAdminNoticeTell() {
request({
url: '/api/extend/demo/GetMessageList',
method: 'get',
data: {}
}).then(res => {
console.log('通知列表', res)
if (res.code == 200) {
this.messageList = res.data
}
})
},
// 跳转到消息详情
toDetail(it, id) {
let link = JSON.parse(it.bodyJson)
// let id = it.Id
console.log('link', link.link)
// uni.navigateTo({
// url:link.link + `?data=${JSON.stringify(link.reid)}`
// })
// this.API.updateInfo({MessageId:id}).then(res=>{
// console.log("修改已读",res)
// if(res.code == 200){
// console.log('成功修改')
// uni.navigateTo({
// url:link.link + `?data=${JSON.stringify(link.reid)}`
// })
// }
// })
request({
url: `/api/extend/demo/UpdateIsReadEnd?MessageId=${id}`,
method: 'put',
data: {}
}).then(res => {
console.log("修改已读", res)
if (res.code == 200) {
console.log('成功修改')
if (link.type === '公文办理通知') {
this.download(link.link)
} else {
uni.navigateTo({
url: link.link + `?data=${JSON.stringify(link.reid)}`
})
}
if (link.type === '公文办理通知') {
this.download(link.link)
} else if (link.type === '表单填报通知') {
uni.navigateTo({
url: link.link + `?id=${link.reid}`
})
} else {
uni.navigateTo({
url: link.link + `?data=${JSON.stringify(link.reid)}`
})
}
}
})
},
download(it) {
uni.downloadFile({
url: this.baseUrl + it, //下载地址接口返回
success: (data) => {
if (data.statusCode === 200) {
//文件保存到本地
uni.saveFile({
tempFilePath: data.tempFilePath, //临时路径
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
title: '文件已保存:' + res.savedFilePath, //保存路径
duration: 3000,
});
setTimeout(() => {
//打开文档查看
uni.openDocument({
filePath: res.savedFilePath,
success: function(res) {
// console.log('打开文档成功');
}
});
}, 3000)
}
});
}
},
fail: (err) => {
that.loadelshow = false
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '失败请重新下载',
});
},
});
},
}
}
</script>
<style lang="scss" scoped>
.page {
width: 100%;
height: 100vh;
background-color: #f3f3f3;
}
.list-box {
width: 96%;
margin: 0 auto;
overflow-y: scroll;
}
.item {
width: 100%;
background-color: white;
border-radius: 30rpx;
padding: 30rpx;
margin-top: 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
.info {
display: flex;
flex-direction: column;
// align-items: center;
.title {
font-size: 36rpx;
font-weight: bold;
}
.desc {
// width: 400rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-left: 20rpx;
}
}
.isRead {
color: red;
margin-right: 10rpx;
padding: 6rpx 18rpx;
border-radius: 5px;
color: #f3f3f3;
}
}
</style>