import React, { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' import { Button, Empty } from '@nutui/nutui-react-taro' import { useThemeStyles } from '@/hooks/useTheme' import { pageMyApp } from '@/api/developer' import type { App } from '@/types/developer' import { APP_TYPE_NAME } from '@/types/developer' import './index.scss' const DeveloperIndex: React.FC = () => { const themeStyles = useThemeStyles() const [apps, setApps] = useState([]) const [loading, setLoading] = useState(true) const [stats, setStats] = useState({ totalApps: 0, runningApps: 0, totalCalls: 0, }) // 加载数据 const loadData = async () => { try { setLoading(true) const result = await pageMyApp({ current: 1, size: 10 }) if (result) { setApps(result.list || []) setStats({ totalApps: result.count || 0, runningApps: result.list?.filter((a) => a.status === 1).length || 0, totalCalls: 0, }) } } catch (error) { console.error('加载数据失败', error) Taro.showToast({ title: '加载失败', icon: 'none' }) } finally { setLoading(false) } } useEffect(() => { loadData() }, []) // 跳转页面 const navigateTo = (url: string) => { Taro.navigateTo({ url }) } // 获取状态颜色 const getStatusColor = (status?: number) => { const colors: Record = { 0: '#6b7280', 1: '#10b981', 2: '#f59e0b', 3: '#ef4444', 4: '#ef4444', 5: '#ef4444', } return colors[status || 0] || '#6b7280' } // 获取状态文本 const getStatusText = (status?: number) => { const texts: Record = { 0: '未开通', 1: '运行中', 2: '维护中', 3: '已关闭', 4: '已欠费', 5: '违规停机', } return texts[status || 0] || '未知' } return ( {/* 头部区域 */} 🛠️ 开发者中心 管理你的项目和应用 {/* 统计卡片 */} {stats.totalApps} 我的应用 {stats.runningApps} 运行中 {stats.totalCalls} API 调用 {/* 快捷操作 */} 快捷操作 navigateTo('/developer/project/index')}> 📁 项目管理 navigateTo('/developer/app/index')}> 📱 应用管理 navigateTo('/developer/app/api-keys')}> 🔑 API Key navigateTo('/developer/docs/index')}> 📖 开发者文档 {/* 应用列表 */} 我的应用 navigateTo('/developer/app/index')}> 查看全部 › {loading ? ( 加载中... ) : apps.length === 0 ? ( ) : ( {apps.map((app) => ( navigateTo(`/developer/app/${app.productId}`)}> {app.icon ? ( {app.productName} ) : ( 📱 )} {app.productName} {APP_TYPE_NAME[app.appType as keyof typeof APP_TYPE_NAME] || '未知'} {getStatusText(app.status)} ))} )} {/* 底部安全区域 */} ) } export default DeveloperIndex