彩票游戏列表页 - 实时开奖结果查询
import GameListCom from '../components/GameListCom.vue'; import TabNavCom from '../components/TabNavCom.vue'; const { proxy } = getCurrentInstance(); const $TOOL = proxy.$TOOL; const $API = proxy.$API; const route = useRoute(); const gid = ref();
const resdata = reactive({ shijian: 0, miaoshu: '', stoptime: 0, opentime: 0, status: false, info: null, lastLotto: null, record: null, nextGame: null, indexList: [], });
const timer = ref(null);
// 切换游戏 const get_gid = async (val) => { gid.value = val; await getHaed(gid.value); await getList(gid.value); };
onBeforeUnmount(() => { clearInterval(timer.value); // 清除定时器 console.log('清除定时器'); });
// 获取下一期游戏的状态标签 const nextGameLabel = () => { const nextGame = resdata.nextGame; if (!nextGame) { return ''; } else if (nextGame.now > nextGame.startTime) { return '开奖中'; } else { return '马上参与'; } };
// 获取按钮样式 const buttonClass = (index) => { const state = index.state; if (state === 0) { if (resdata.nextGame.now > index.stopTime) { return 'btn-border-warning'; } else { return 'btn-danger'; } } else { return 'btn-border-default'; } };
const buttonLabel = (index) => { const state = index.state; if (state === 1) { return '已开奖'; } else if (state === 0 && resdata.nextGame.now > index.stopTime) { return '开奖中'; } else { return nextGameLabel(); } };
const daojishi = () => { if (resdata.stoptime > 0) { resdata.miaoshu = '距离停止投注还有'; resdata.shijian = resdata.stoptime; } else if (resdata.opentime > 0) { resdata.miaoshu = '停止参与,等待开奖'; resdata.shijian = resdata.opentime; } else { resdata.status = true; resdata.miaoshu = resdata.opentime % 3 == 0 ? '正在开奖..' : '开奖中,请稍后'; getState(resdata.info.id, resdata.nextGame.nextIssue); }
resdata.status = resdata.opentime > 0 ? false : true;
resdata.stoptime--; resdata.opentime--; };
// 获取头部数据 const getHaed = async (val) => { const data = { g: val, }; var res = await $API.game.index.head.get(data); if (res.code === 0) { const { info, lastLotto, record, nextGame } = res.data; resdata.info = info; resdata.lastLotto = lastLotto; resdata.record = record; resdata.nextGame = nextGame;
const timeA = new Date(nextGame.now).getTime();
const timeB = new Date(nextGame.stoptime).getTime();
const timeC = new Date(nextGame.opentime).getTime();
resdata.stoptime = (timeB - timeA) / 1000;
resdata.opentime = (timeC - timeA) / 1000;
daojishi();
clearInterval(timer.value);
timer.value = setInterval(daojishi, 1000);
} };
const getState = async (gid, did) => { console.log(gid); console.log(did); if (did === 0 || gid < 1 || gid > 100) { return; } const data = { g: gid, did: did, }; var res = await $API.game.index.getState.get(data);
if (res.code === 0) { if (res.data.state == 1) { await getHaed(gid); } else { console.log('未开奖'); } } };
const getList = async (gid) => { const data = { g: gid, p: 1, }; var res = await $API.game.index.IndexList.get(data);
resdata.indexList = res.data.listData; console.log(res); };
原文地址: https://www.cveoy.top/t/topic/lDsc 著作权归作者所有。请勿转载和采集!