App.vue
4.86 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
<!-- * 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';
import Aegis from 'aegis-weex-sdk';
import config from '@/common/config/config.js'
import service from '@/service/service.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);
const handleOnMessage = (msg) => {
console.log('handleOnMessage', msg);
let user = this.$store.state.user;
msg = JSON.parse(msg.data);
if (msg.messageType == 'joinRoom') {
uni.showModal({
content: `用户【${msg.realName}】邀请你视频连线,是否加入房间?`,
confirmText: '加入房间',
cancelText: '放弃',
confirmColor: '#D669BE',
success({
confirm
}) {
if (confirm) {
uni.navigateTo({
url: `/pages/meeting/meeting?roomId=${msg.roomNo}`
})
}
}
})
}
}
let socketTask = uni.connectSocket({
url: config.socketurl,
complete() {},
});
uni.onSocketOpen(function(res) {
console.log('WebSocket连接已打开!');
});
uni.onSocketError(function(res) {
console.log('WebSocket连接打开失败,请检查!');
});
this.globalData.socketTask = socketTask;
socketTask.onOpen((data) => {
console.log('socketTask.onOpen', data);
socketTask.send({
data: JSON.stringify({
method: 'OnConnection',
token: service.getToken(),
mobileDevice: true
})
})
});
socketTask.onError((error) => {
console.log('socketTask.onError', error)
});
uni.onSocketMessage((res) => {
console.log('socketTask.onMessage', res);
})
socketTask.onMessage((msg) => {
console.log('socketTask.onMessage', msg);
handleOnMessage(msg);
uni.$emit('socketMessage', JSON.parse(msg.data))
});
uni.$on('sendSocketMessage', (data) => {
uni.send({
data: data,
success(res) {
console.log('sendSocketMessage success', res);
},
fail(e) {
console.log('sendSocketMessage fail', e);
},
complete() {}
});
});
uni.$on('closeSocket', () => {
this.globalData.socketTask.close();
})
uni.$on('openSocket', () => {
this.globalData.socketTask = uni.connectSocket({
url: config.socketurl,
complete() {},
});
this.globalData.socketTask.onMessage((msg) => {
handleOnMessage(msg);
uni.$emit('socketMessage', msg)
});
})
},
onShow() {
// 启动或重启即时通讯
// this.$store.dispatch('chat/start');
},
onHide() {
// 断开即时通讯
// this.$store.dispatch('chat/close');
},
globalData: {
typeNum: 1,
socketTask: {}
}
};
</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>