-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathApp.vue
More file actions
executable file
·79 lines (77 loc) · 1.97 KB
/
Copy pathApp.vue
File metadata and controls
executable file
·79 lines (77 loc) · 1.97 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
<script>
export default {
onLaunch: async function() {
uni.onPushMessage(async (res) => {
console.log('收到推送消息==>:', res);
if (res.type == 'receive') {
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
payload: res.data.payload,
})
} else if (res.type == 'click') {
const { alarm_id } = res.data.payload;
const headers = {
'Authorization': `Bearer ${uni.getStorageSync("access_token")}`
};
const apiUrl = `/api/v1/alarm/info/history/${alarm_id}`;
try {
const { code, data } = await this.fetchAlarmInfo(apiUrl, headers);
if (code === 200) {
this.navigateToDetail(data);
} else {
console.error('API request failed with code:', code);
}
} catch (error) {
console.error('API request failed:', error);
}
}
});
uni.getPushClientId({
success: (res) => {
const push_clientid = res.cid;
console.log('客户端推送标识==>:', push_clientid);
},
fail(err) {
console.log("获取客户端标识错误:", err);
}
});
},
onShow: function() {
// console.log('App Show')
},
methods: {
async fetchAlarmInfo(url, headers) {
const response = await this.API.apiRequest(url, null, 'get', headers);
return response && typeof response.then === 'function'
? await response
: response;
},
navigateToDetail(data) {
uni.navigateTo({
url: '/pages/notify/detail',
success: (navRes) => {
if (navRes.eventChannel) {
navRes.eventChannel.emit('acceptData', { item: data });
}
}
});
}
},
onHide: function() {
// console.log('App Hide')
}
}
</script>
<style>
/* 引入公共样式 */
@import './common/uni.css';
/* 引入字体库样式 */
@import './common/icon.css';
/* 引入动画库 */
@import './common/animate.css';
/* 引入公共库样式 */
@import './common/util.css';
/* */
@import './common/common.css';
</style>