press-next
Version:
Vue3 组件库,支持 Composition API
110 lines (93 loc) • 3.48 kB
text/typescript
export function getMockData() {
// 标签数据接口
interface TagItem {
text: string;
type?: 'default' | 'primary' | 'warning' | 'danger';
}
// 团队信息接口
interface TeamInfo {
id: string;
name: string;
logo: string;
avatars?: string[];
currentMembers: number;
maxMembers: number;
tagItems?: TagItem[];
}
const generateTeamList = (count: number): TeamInfo[] => {
const teamNames = [
'王者荣耀战队', '和平精英突击队', '英雄联盟战队', '休闲游戏小队',
'电竞之王', '巅峰战士', '传奇军团', '无敌战队', '钻石联盟', '星耀之光',
'最强王者', '超神战队', '职业选手', '游戏大神', '竞技高手', '冠军之队',
'胜利之师', '梦想战队', '青春无敌', '热血军团', '激情战士', '拼搏之队',
];
const tagOptions = [
{ text: '热门', type: 'primary' as const },
{ text: '新手友好', type: 'warning' as const },
{ text: '高手云集', type: 'primary' as const },
{ text: '竞技', type: 'danger' as const },
{ text: '缺人', type: 'warning' as const },
{ text: '休闲', type: 'default' as const },
{ text: '娱乐', type: 'primary' as const },
{ text: '活跃', type: 'warning' as const },
{ text: '推荐', type: 'primary' as const },
];
const teams: TeamInfo[] = [];
for (let i = 0; i < count; i += 1) {
const teamIndex = i + 1;
const avatarCount = Math.floor(Math.random() * 6) + 2; // 2-7个头像
const avatars = [];
for (let j = 0; j < avatarCount; j += 1) {
avatars.push(`https://image-1251917893.file.myqcloud.com/tip-project/pubg/pubg-match/ai-match/avatar-${(j % 11) + 1}.png`);
}
const maxMembers = Math.floor(Math.random() * 4) + 4; // 4-7人
const currentMembers = Math.floor(Math.random() * maxMembers) + 1; // 1到maxMembers人
// 随机选择1-3个标签
const tagCount = Math.floor(Math.random() * 3) + 1;
const selectedTags = [];
const shuffledTags = [...tagOptions].sort(() => Math.random() - 0.5);
for (let k = 0; k < tagCount; k += 1) {
selectedTags.push(shuffledTags[k]);
}
teams.push({
id: teamIndex.toString(),
name: `${teamNames[i % teamNames.length]}${teamIndex}`,
logo: `https://image-1251917893.file.myqcloud.com/tip-project/pubg/pubg-match/ai-match/team-logo-${((i % 4) + 1)}.png`,
avatars,
currentMembers,
maxMembers,
tagItems: selectedTags,
});
}
return teams;
};
const getMockTeamList = (): TeamInfo[] => generateTeamList(20);
// 组件属性配置
const componentProps = {
// 主要props - 与组件Props接口一一对应
teamList: getMockTeamList(),
tagItems: [
{ text: '推荐', type: 'primary' as const },
{ text: '活跃', type: 'warning' as const },
],
itemType: 'with-avatars' as const,
actionText: '申请加入',
customClass: '',
emptyText: '暂无队伍信息',
image: '',
finishText: '没有更多了',
loading: false,
finished: false,
// 额外的演示数据
teamListWithAvatars: getMockTeamList(),
teamListSimple: getMockTeamList().map(team => ({
...team,
avatars: undefined, // 简单模式不显示头像
})),
};
return componentProps;
}
const DEMO_DATA = {
...getMockData(),
};
export default DEMO_DATA;