tongji.ts 1.9 KB


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};