-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathindex.js
147 lines (144 loc) · 3.42 KB
/
index.js
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
// TUIKitWChat/Chat/index.js
import constant from './utils/constant';
import TUICore, {
TUIConstants,
} from '@tencentcloud/tui-core';
import TUICustomerServer from '@tencentcloud/tui-customer-service-plugin-wechat/server';
const app = getApp();
Component({
/**
* 组件的属性列表
*/
properties: {
conversationID: {
type: String,
value: '',
observer(conversationID) {
this.setData({
outsideConversation: true,
currentConversationID: conversationID,
});
},
},
},
/**
* 组件的初始数据
*/
data: {
isShowConversation: false,
isShowConversationList: false,
currentConversationID: '',
unreadCount: 0,
hasCallKit: false,
config: {
userID: '',
userSig: '',
type: 1,
tim: null,
SDKAppID: 0,
},
outsideConversation: false,
},
/**
* 组件的方法列表
*/
methods: {
init() {
const {
config,
} = this.data;
config.userID = wx.$chat_userID;
config.userSig = wx.$chat_userSig;
config.tim = wx.$TUIKit;
config.SDKAppID = wx.$chat_SDKAppID;
if (this.data.outsideConversation) {
this.createConversation({
detail: {
currentConversationID: this.data.currentConversationID,
unreadCount: 0,
},
});
} else {
this.showConversationList();
}
this.setData(
{
config,
},
() => {
this.initCallKit();
},
);
TUICustomerServer.getInstance();
},
initCallKit() {
if (TUICore.getService(TUIConstants.TUICalling.SERVICE.NAME)) {
this.setData({
hasCallKit: true,
});
}
},
createConversation(event) {
this.setData(
{
isShowConversation: true,
currentConversationID: event.detail.currentConversationID,
unreadCount: event.detail.unreadCount,
},
() => {
const TUIChat = this.selectComponent('#TUIChat');
TUIChat.init();
const timer = setTimeout(() => {
const TUIConversation = this.selectComponent('#TUIConversation');
TUIConversation.destroy();
clearTimeout(timer);
}, 300);
},
);
},
showConversationList() {
if (this.data.outsideConversation) {
this.handleBack();
} else {
const TUIConversation = this.selectComponent('#TUIConversation');
TUIConversation.init();
this.setData({
isShowConversation: false,
});
}
},
async handleCall(event) {
let { userIDList = [] } = event.detail;
const { groupID = '', userID = '', type } = event.detail;
if (userID) {
userIDList = [userID];
}
TUICore.callService({
serviceName: TUIConstants.TUICalling.SERVICE.NAME,
method: TUIConstants.TUICalling.SERVICE.METHOD.START_CALL,
params: {
groupID,
userIDList,
type,
},
});
},
handleBack() {
if (
app.globalData
&& app.globalData.reportType !== constant.OPERATING_ENVIRONMENT
) {
wx.navigateBack({
delta: 1,
});
} else {
wx.switchTab({
url: '/pages/TUI-Index/index',
});
}
},
sendMessage(event) {
this.selectComponent('#TUIChat').sendMessage(event);
},
},
});