import CategoryTab from '@/utils/CategoryTab' import request from '@/utils/request' import { computed, defineComponent, inject, ref, watch } from 'vue' import clsx from 'clsx' import useLayoutStore from '../useLayoutStore' import { AddToToken } from './AdderPage' import { v4 as uuid } from 'uuid' import { frontAddress, ossBase } from '@/config' import dayjs from 'dayjs' import { generateRandomString } from '@/utils/tool' import MD5 from 'crypto-js/md5' export const SECRET = 'A1Cv12olxT12dOE3xA1vPA==' export const URL_ADDRESS = 'http://newfatfox.oss-cn-beijing.aliyuncs.com' export interface GameType { id: string name: string rom: string playstation: string hot: number category: string despt: string icon: string } export interface OtherGame { id: number // 游戏ID category_ids: number[] // 分类ID数组 rank: number // 排名 name: string // 游戏名称 short_description: string // 简短描述 description: string // 详细描述 url: string // 游戏详情链接 icon: string // 图标URL cover_url: string // 封面URL corner_mark: number // 角标标识 } export const DefautGameTypeList = [ { id: 'fc', type: '经典红白机', attr: 0, oridinal: 0 }, { id: 'md', type: '经典世嘉', attr: 1, oridinal: 1 }, { id: 'yiqiyoo', type: '休闲游戏', attr: 1, oridinal: 2 }, { id: 'gba', type: '经典GBA', attr: 3, oridinal: 3 } ] export const GameItem = defineComponent({ props: { content: { type: Object as () => GameType, required: true } }, setup(props) { const layout = useLayoutStore() const isGame = computed(() => layout.state.current === 0) const addTo = inject(AddToToken) return () => (
{props.content.name}
{props.content.despt}
) } }) export default defineComponent(() => { const layout = useLayoutStore() const loading = ref(false) const isGame = computed(() => layout.state.current === 0) const appList = ref([]) const selectType = ref('fc') const fetchGame = async (page: number) => { const parems = `nonce=${generateRandomString(8)}&pid=PIDc8uT24mpo×tamp=${dayjs().unix()}` const sign = MD5(parems + SECRET).toString() const response = await fetch( `https://ge.yiqiyoo.com/game/v2/third-part/games?${parems}&sign=${sign}&paginate.limit=99&paginate.page=${page}` ) const res = await response.json() return res.data.items } watch( selectType, (val) => { loading.value = true if (val !== 'yiqiyoo') { request('GET', `/api/games?type=${val}`) .then((res) => { appList.value = res }) .finally(() => { setTimeout(() => { loading.value = false }, 200) }) } else { try { Promise.all([fetchGame(1), fetchGame(2), fetchGame(3)]).then((res) => { const resData = res.flat() as OtherGame[] appList.value = resData.map((el) => ({ id: el.id.toString(), name: el.name, despt: el.short_description, icon: el.icon, rom: el.url, playstation: el.url, hot: el.rank, category: el.category_ids[0].toString() })) }) } catch (err) { console.error(err) } finally { setTimeout(() => { loading.value = false }, 200) } } }, { immediate: true } ) return () => (
{ selectType.value = e }} v-slots={{ select: (text: string) => ( ), unSelect: (text: string) => ( ) }} >
{!loading.value ? (
{appList.value.map((el) => ( ))}
) : (
{Array(12) .fill(0) .map((el, idx) => (
))}
)}
) })