-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwa-js-panel-general-functions.js
49 lines (45 loc) · 1.54 KB
/
wa-js-panel-general-functions.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
// General Functions module
const GeneralFunctions = {
init: function() {
const htmlContent = `
<h4>通用功能</h4>
<button id="connect">连接</button>
<button id="isAuthenticated">检查认证</button>
<button id="logout">登出</button>
`;
WA_JS_Panel.addFunctionToPanel('general', htmlContent);
this.bindEvents();
},
bindEvents: function() {
document.getElementById('connect').addEventListener('click', this.connect);
document.getElementById('isAuthenticated').addEventListener('click', this.isAuthenticated);
document.getElementById('logout').addEventListener('click', this.logout);
},
connect: async function() {
try {
await WPP.conn.connect();
alert('连接成功');
} catch (error) {
console.error('连接失败:', error);
alert('连接失败');
}
},
isAuthenticated: async function() {
try {
const authenticated = await WPP.conn.isAuthenticated();
alert(`认证状态: ${authenticated}`);
} catch (error) {
console.error('检查认证失败:', error);
alert('检查认证失败');
}
},
logout: async function() {
try {
await WPP.conn.logout();
alert('登出成功');
} catch (error) {
console.error('登出失败:', error);
alert('登出失败');
}
}
};