import { MaterialAPI } from '@/config/API.ts' import type { ResponseInfo } from '@/types/axios.ts' import axiosInstance from '@/utils/axios/axiosInstance.ts' import type { GameData, GameSelectItem, TagItem, TagsRes, } from '@/views/Material/types/uploadFileType.ts' import type { Reactive } from 'vue' export function useMaterial() { const getGameInfo = async () => { const res = (await axiosInstance.post( MaterialAPI.getAllGamesInfo, {}, )) as ResponseInfo if (res.code !== 0) { console.error('获取游戏信息失败') return null } return res.data as GameData } const generateGameSelect = ( gameInfoList: GameData, gameSelect: Reactive, ) => { gameSelect.splice(0, gameSelect.length) for (let [k, v] of Object.entries(gameInfoList)) { const children = v.map(item => { return { value: item.gid, label: item.gameName, } }) gameSelect.push({ value: k, label: k === '' ? '默认' : k, children, }) } } const getAllTags = async () => { const res = (await axiosInstance.post( MaterialAPI.getAllTags, {}, )) as TagsRes if (res.code !== 0) { ElMessage.error('获取标签失败') return [] } if (!res.data) return [] return res.data } /** * 构建过滤函数 * @param queryString 查询值 */ const createFilter = (queryString: string) => { return (restaurant: TagItem) => { return ( restaurant.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0 ) } } return { getGameInfo, generateGameSelect, getAllTags, createFilter, } }