-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.vue
78 lines (75 loc) · 1.41 KB
/
App.vue
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
<script>
import * as QNIM from './im/qnuniapp-im.umd.js';
export default {
globalData: {
im: {},
SDK_VERSION: QNIM.version
},
onLaunch: function() {
this.initSDK();
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
/**
* 初始化 IM SDK
*/
initSDK() {
const im = QNIM.init({
appid: 'cigzypnhoyno'
});
if (im) {
this.globalData.im = im;
this.addEventListenersOfIM();
}
},
/**
* 设置 IM 事件监听
*/
addEventListenersOfIM() {
const im = this.getIM();
im.on({
loginSuccess: this.loginSuccess,
loginerror: this.loginFail
});
},
/**
* 登录成功
*/
loginSuccess() {
console.log('loginSuccess');
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage.route === 'pages/login/login') {
uni.navigateTo({
url: '/pages/home/home',
});
}
},
/**
* 登录失败提示
* @param {*} error
*/
loginFail(error) {
console.log('登录失败');
uni.showModal({
title: '登录失败提示',
content: error
});
},
/**
* 获取 IM 对象
*/
getIM() {
return this.globalData.im;
}
}
}
</script>
<style>
/*每个页面公共css */
</style>