press-next
Version:
Vue3 组件库,支持 Composition API
217 lines (179 loc) • 5.26 kB
text/typescript
import { timeStampFormat } from 't-comm/es/time/time';
import {
CARD_STATUS_MAP,
// 淘汰赛
COMPONENT_STATUS_TEXT_MAP,
COMPONENT_STATUS_CLASS_MAP,
COMPONENT_STATUS_MAP,
SPECIAL_TEAM_AVATAR,
} from '../utils';
import { getKnockoutCardStatusCode } from './knockout-status';
import { getCardTeams } from './knockout-team';
/**
* 解析和平赛事淘汰赛赛程卡片
*/
export function parseKnockoutScheCard({
card = {},
childInfo = {},
}: {
card?: Record<string, any>;
childInfo?: Record<string, any>;
}) {
const {
userJoinStatus = 0,
gameDispStatus: gameDisplayStatus = 0,
teamInfo = {},
childInfo: { act_start_time: actStartTIme = 0, match_rule_cfg: matchRuleCfg = {} } = {},
} = childInfo;
const {
sign_team_min_mem: minSignNum = 1,
} = matchRuleCfg;
const isManualStart = matchRuleCfg.start_battle_type == 2;
const {
team_a: iTeamA = {},
team_b: iTeamB = {},
card_state: cardState = {},
stime,
countdown,
child_id: childId,
battle_id: battleId,
} = card;
const { teamA, teamB } = getCardTeams(card);
const boNum = card.bo_type || 1;
const curBo = card.cur_bo || 1;
const statusCode = getKnockoutCardStatusCode(cardState);
const statusText = COMPONENT_STATUS_TEXT_MAP[statusCode];
const statusClass = COMPONENT_STATUS_CLASS_MAP[statusCode];
const statusDesc = getStatusDesc({
isManualStart,
statusCode,
boNum,
curBo,
stime,
});
let myTeam: Partial<typeof teamA> = {};
let opponentTeam: Partial<typeof teamA> = {};
const isMyTeamInTeamA = iTeamA.my_team == 1;
const isMyTeamInTeamB = iTeamB.my_team == 1;
if (isMyTeamInTeamA) {
myTeam = teamA;
opponentTeam = teamB;
} else if (isMyTeamInTeamB) {
myTeam = teamB;
opponentTeam = teamA;
}
if (!Object.keys(card).length) {
opponentTeam = teamB;
}
const gameRank = myTeam.rank || '-';
let battleList = Array.from({
length: card.bo_type || matchRuleCfg?.pubg_rule_cfg?.module_cfg?.length || 1,
})
.map((item: any, index: number) => {
const res = {
title: `第${index + 1}场`,
timeDesc: '',
};
return res;
});
if (!isManualStart) {
battleList = (matchRuleCfg?.pubg_rule_cfg?.round_time_cfg || [])?.map((item: any) => ({
title: `第${item.round_id}场`,
timeDesc: `${timeStampFormat(item.stime, 'M.d hh:mm')}`,
time: item.stime * 1000,
}));
}
return {
teamA,
teamB,
minSignNum,
myTeam,
// memberList: myTeam.memberList,
// teamName: myTeam.name,
// teamAvatar: myTeam.avatar,
memberList: teamInfo.members?.map((item: any) => ({
avatar: item.head ? item.head.replace('http://thirdqq', 'https://thirdqq') : SPECIAL_TEAM_AVATAR,
name: item.nick,
})),
teamName: teamInfo.teamname,
teamAvatar: teamInfo.teamavatar,
gameStartCountdown: Math.max(0, actStartTIme * 1000 - Date.now()),
opponentInfo: {
... opponentTeam,
boNum,
curBo,
statusCode,
statusText,
statusClass,
statusDesc,
isMyTeamInTeamA,
isMyTeamInTeamB,
isTeamASpecial: teamA.isSpecial,
isTeamBSpecial: teamB.isSpecial,
showScore: statusCode !== COMPONENT_STATUS_MAP.NOT_START,
teamAScore: teamA.score,
teamBScore: teamB.score,
teamAId: teamA.teamId,
teamBId: teamB.teamId,
teamAName: teamA.name,
teamBName: teamB.name,
teamAAvatar: teamA.avatar,
teamBAvatar: teamB.avatar,
// 是否显示进房按钮
showLaunchGameButton: statusCode === COMPONENT_STATUS_MAP.ING && countdown,
// 是否显示比赛进行中按钮
showGamePlayingButton: statusCode === COMPONENT_STATUS_MAP.ING && !countdown,
},
cardState: getKnockoutCardState({
gameDisplayStatus,
userJoinStatus,
}),
gameRank,
battleList,
curBattleInfo: {
room_id: cardState.room_id,
room_pwd: cardState.room_pwd,
battle_id: battleId,
},
enterGameCountdown: countdown + Math.round(Date.now() / 1000),
curGoingBattleIndex: curBo - 1,
childId,
isSolo: matchRuleCfg?.pubg_rule_cfg?.join_func == 2,
};
}
function getKnockoutCardState({
gameDisplayStatus = 0, // 1报名中 2待比赛 3比赛中 4已结束
userJoinStatus = 0, // 1、用户已报名
}: {
curJoinStatus?: number;
cardState?: Record<string, any>;
gameDisplayStatus?: number;
userJoinStatus?: number;
}) {
if (userJoinStatus != 1) {
return CARD_STATUS_MAP.NOT_SIGN_UP;
}
if (gameDisplayStatus == 4) {
return CARD_STATUS_MAP.KNOCK_OUT_RESULT;
}
if (gameDisplayStatus == 1 && userJoinStatus == 1) {
return CARD_STATUS_MAP.KNOCK_OUT_SIGNED_UP;
}
return CARD_STATUS_MAP.KNOCK_OUT_OPPONENT;
}
function getStatusDesc({
statusCode, isManualStart, stime, curBo, boNum,
}: Record<string, any>) {
if (statusCode === COMPONENT_STATUS_MAP.END) {
return ' ';
}
if (statusCode === COMPONENT_STATUS_MAP.ING) {
return `当前${curBo}/${boNum}局`;
}
if (statusCode === COMPONENT_STATUS_MAP.NOT_START) {
if (isManualStart) {
return '等待管理员开赛';
}
return `${timeStampFormat(stime, 'M/d hh:mm')}开赛`;
}
}