/** * API 配置和接口函数 * 用于统一管理项目的 API 请求 */ // API 基础地址 export const API_BASE_URL = 'https://ele.ccttiot.com/prod-api' /** * Banner 数据类型定义 */ export interface BannerItem { id: string imgUrl: string status: string orderNum: string createBy?: string createTime?: string updateBy?: string updateTime?: string remark?: string | null scope?: string | null deleted?: string | null areaPermissions?: string | null createId?: string updateId?: string } /** * API 响应数据结构 */ export interface ApiResponse { msg: string code: number data: T } /** * 获取轮播图列表 * @returns Promise 返回轮播图数据数组 */ export async function getBannerList(): Promise { try { const response = await $fetch>( `${API_BASE_URL}/app/owBanner/list`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, } ) // 检查响应状态 if (response.code === 200 && Array.isArray(response.data)) { // 过滤出状态为启用的 banner,并按 orderNum 排序 return response.data .filter((item) => item.status === '1') // 只返回启用状态的 banner .sort((a, b) => { const orderA = parseInt(a.orderNum || '0', 10) const orderB = parseInt(b.orderNum || '0', 10) return orderB - orderA // 降序排列,数字越大越靠前 }) } console.warn('获取轮播图列表失败,返回空数组', response) return [] } catch (error) { console.error('获取轮播图列表时发生错误:', error) // 发生错误时返回空数组,避免页面崩溃 return [] } }