tongji.ts
1.9 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
import * as user_api from '@/api/user_api';
import { default as moment } from 'moment';
// 投票方法
const gntj = async(number:any) => {
// 构建GraphQL查询
await user_api.toupiao_vote({
lottery_id:999,
play_type:'live2_game',
issue_name: moment().format("YY/MM/DD"),
number:number,
vote_type:1
}).then((res: any) => {
console.info(res)
})
}
// 处理点击事件
const handleClick = (event:any) => {
const target = event.target;
const nogntj = target.getAttribute('nogntj');
if (nogntj === '' || nogntj) return;
const gntjText = target.getAttribute('gntj');
let number = '';
if (!gntjText || gntjText.split('_').length < 2) {
number = gntjText && gntjText !== '' && gntjText !== '2' ? gntjText : target.textContent.trim();
if (gntjText === '2' && hasClass(target, ['select', 'check', 'sel', 'choice'])) {
number += '_选中';
} else if (gntjText === '2' && !hasClass(target, ['select', 'check', 'sel', 'choice'])) {
number += '_取消';
}
} else {
const [type, gntjTextValue] = gntjText.split('_');
number = gntjTextValue && gntjTextValue !== '' ? gntjTextValue : target.textContent.trim();
if (type === '2' && hasClass(target, ['select', 'check', 'sel', 'choice'])) {
number += '_选中';
} else if (type === '2' && !hasClass(target, ['select', 'check', 'sel', 'choice'])) {
number += '_取消';
}
}
// 调用gntj方法
gntj(number);
};
// 辅助函数,检查元素是否具有某个或多个类
const hasClass = (element:any, classes:any) => {
return classes.every((o: any) => element.classList.contains(o));
};
export { gntj, handleClick};