App.vue
10 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!-- * WanlShop - App全局模板配置
* @author 深圳前海万联科技有限公司 <wanlshop@i36k.com>
* @link http://www.wanlshop.com
*
* @本程序受法律保护,著作权©软著登记号2020SR0255711 < 未经版权所有权人书面许可,不能用于商业用途!>
*
* @获取许可
* 后台下载:https://www.fastadmin.net/store/wanlshop.html
* 帮助文档:https://doc.fastadmin.net/wanlshop
*
* @stress 本程序仅用作FastAdmin付费插件(WanlShop B2B2C商城)API使用,未经版权所有权人书面许可,不能自行用于商业用途
* @creationtime 2019年9月10日12:52:20
* @lasttime 2020年6月9日09:26:07
* @version 1.0.0
-->
<script>
import Vue from 'vue';
/*#ifdef APP-PLUS*/
import Aegis from 'aegis-weex-sdk';
/*#endif*/
import config from '@/common/config/config.js'
import service from '@/service/service.js'
import API from '@/apis/index.js'
export default {
onLaunch() {
// 检测客户端更新
this.$store.dispatch('update/update');
// 仅首次打开一次性加载数据
this.$store.dispatch('common/init');
// 同步购物车 本地 & 网络
this.$store.dispatch('cart/get');
// 同步 动态数据
this.$store.dispatch('statistics/get');
const projectName = 'uniappApiExampleExt';
uni.$aegis = new Aegis({
id: 'iHWefAYqWuCkDjhucc',
spa: true,
reportApiSpeed: true,
reportAssetSpeed: true,
pagePerformance: true,
hostUrl: 'https://tamaegis.com',
});
uni.$uploadToTAM = (eventString, sdkAppId) => {
uni.$aegis.reportEvent({
name: eventString.split('#')[0] || '',
ext1: eventString,
ext2: projectName,
ext3: sdkAppId,
});
};
uni.$createTrtcCloudUpload = sdkAppId => uni.$uploadToTAM('createTrtcCloud', sdkAppId);
uni.$enterRoomSuccessUpload = sdkAppId => uni.$uploadToTAM('enterRoom-success', sdkAppId);
uni.$enterRoomFailedUpload = (sdkAppId, errorMsg) => uni.$uploadToTAM(`enterRoom-failed#error: ${errorMsg}`,
sdkAppId);
uni.$onErrorUpload = (sdkAppId, errorMsg) => uni.$uploadToTAM(`onError-failed#error: ${errorMsg}`, sdkAppId);
uni.$startLocalPreviewUpload = sdkAppId => uni.$uploadToTAM('startLocalPreview', sdkAppId);
uni.$startRemoteViewSuccessUpload = sdkAppId => uni.$uploadToTAM('startRemoteView-success', sdkAppId);
uni.$startRemoteViewFailedUpload = (sdkAppId, errorMsg) => uni.$uploadToTAM(
`startRemoteView-failed#error: ${errorMsg}`, sdkAppId);
this.initSocket();
},
onShow() {
// 启动或重启即时通讯
// this.$store.dispatch('chat/start');
},
onHide() {
// 断开即时通讯
// this.$store.dispatch('chat/close');
},
methods: {
handleOnMessage(msg) {
let user = this.$store.state.user;
if(msg.method == 'initMessage'){
// this.setTabBarBadge(msg.unreadMessageCount);
}
if(msg.messageType == 'messageRead' || msg.messageType == 'text' || msg.messageType == 'voice'){
getApp().globalData.updateUnReadMessageCount();
}
if (msg.messageType == 'joinRoom' && msg.intToUserId == user.id && user.user_type.length) {
console.log('joinRoom', msg);
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入房间',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/meeting?roomId=${msg.roomNo}&joinType=seller&customerid=${msg.intUserId}`
})
}
}
})
}
if (msg.messageType == 'joinMultiplayerVideo' && msg.intToUserId == user.id) {
console.log('joinMultiplayerVideo', msg);
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入房间',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/meeting?roomId=${msg.roomNo}&joinType=service&customerid=${msg.intUserId}`
})
}
}
})
}
if (msg.messageType == 'joinVideo' && msg.intToUserId == user.id) {
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/serviceMeeting?roomId=${msg.roomNo}&userid=${msg.intUserId}`
})
}
}
})
}
},
initSocket() {
let socketTask = uni.connectSocket({
url: config.socketurl,
protocols: ['protocol1'],
fail(err){
console.log('connectSocket fail',err);
},
complete() {},
});
uni.onSocketOpen((res) => {
console.log('WebSocket连接已打开!', res);
});
uni.onSocketError((res) => {
// console.log('WebSocket连接打开失败,请检查!', res);
this.initSocket();
});
this.globalData.socketTask = socketTask;
socketTask.onOpen((data) => {
let json = {
method: 'OnConnection',
token: service.getTokenChaoge(),
mobileDevice: true
};
console.log('send json', json);
socketTask.send({
data: JSON.stringify(json),
success(res){
console.log('socketTask.send success',res);
},
fail(err) {
console.log('socketTask.send fail',err);
this.initSocket();
}
})
});
socketTask.onClose((res)=>{
console.log('socketTask.onClose', res)
// this.initSocket();
})
socketTask.onError((error) => {
// console.log('socketTask.onError', error)
// this.initSocket();
});
socketTask.onMessage((msg) => {
console.log('socketTask.onMessage', msg);
msg = JSON.parse(msg.data);
this.handleOnMessage(msg);
uni.$emit('socketMessage', msg)
});
uni.$on('closeSocket', () => {
console.log('uni.$on closeSocket',)
this.globalData.socketTask.close();
});
uni.$on('openSocket', () => {
this.globalData.socketTask.onMessage((msg) => {
console.log('openSocket.onMessage', msg);
});
});
this.globalData.updateUnReadMessageCount();
},
},
globalData: {
typeNum: 1,
socketTask: {},
handleOnMessage(msg) {
let user = this.$store.state.user;
if(msg.method == 'initMessage'){
// this.setTabBarBadge(msg.unreadMessageCount);
}
if(msg.messageType == 'messageRead' || msg.messageType == 'text' || msg.messageType == 'voice'){
getApp().globalData.updateUnReadMessageCount();
}
if (msg.messageType == 'joinRoom' && msg.intToUserId == user.id && user.user_type.length) {
console.log('joinRoom', msg);
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入房间',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/meeting?roomId=${msg.roomNo}&joinType=seller&customerid=${msg.intUserId}`
})
}
}
})
}
if (msg.messageType == 'joinMultiplayerVideo' && msg.intToUserId == user.id) {
console.log('joinMultiplayerVideo', msg);
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入房间',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/meeting?roomId=${msg.roomNo}&joinType=service&customerid=${msg.intUserId}`
})
}
}
})
}
if (msg.messageType == 'joinVideo' && msg.intToUserId == user.id) {
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/serviceMeeting?roomId=${msg.roomNo}&userid=${msg.intUserId}`
})
}
}
})
}
},
initSocket(){
let socketTask = uni.connectSocket({
url: config.socketurl,
protocols: ['protocol1'],
complete() {},
});
uni.onSocketOpen((res) => {
console.log('WebSocket连接已打开!', res);
});
uni.onSocketError((res) => {
console.log('WebSocket连接打开失败,请检查!', res);
this.initSocket();
});
this.socketTask = socketTask;
socketTask.onOpen((data) => {
let json = {
method: 'OnConnection',
token: service.getTokenChaoge(),
mobileDevice: true
};
console.log('send json', json);
socketTask.send({
data: JSON.stringify(json)
})
});
socketTask.onError((error) => {
console.log('socketTask.onError', error)
this.initSocket();
});
socketTask.onMessage((msg) => {
console.log('socketTask.onMessage', msg);
msg = JSON.parse(msg.data);
this.handleOnMessage(msg);
uni.$emit('socketMessage', msg)
});
uni.$on('closeSocket', () => {
this.socketTask.close();
});
uni.$on('openSocket', () => {
this.socketTask.onMessage((msg) => {
console.log('openSocket.onMessage', msg);
});
});
this.updateUnReadMessageCount();
return socketTask;
},
updateUnReadMessageCount(){
API.message.getUserUnReadMessageCount().then(res=>{
console.log('getUserUnReadMessageCount',res);
let badgeNum = res.data;
if(badgeNum>0){
uni.setTabBarBadge({
index: 1,
text: badgeNum > 99 ? '99+' : badgeNum.toString()
});
}else{
uni.removeTabBarBadge({
index: 1,
});
}
})
}
}
};
</script>
<style>
/* #ifndef APP-NVUE */
@import 'static/style/colorui.css';
@import 'static/style/wanlshop.css';
@import 'static/style/iconfont.css';
@import url("./styles/index.scss");
/* #endif */
</style>