import React, { useState, useEffect } from 'react' import { View, Text, ScrollView } from '@tarojs/components' import Taro from '@tarojs/taro' import { Button, Empty, Tabs, PullToRefresh } from '@nutui/nutui-react-taro' import './index.scss' const ProjectList: React.FC = () => { const [activeTab, setActiveTab] = useState('all') const [projects, setProjects] = useState([]) const [loading, setLoading] = useState(true) const [refreshing, setRefreshing] = useState(false) // 模拟数据 const mockProjects = [ { id: 1, name: '我的企业官网', type: 'pro', description: '企业品牌展示官网', appCount: 2, memberCount: 3, apiCallCount: 12580, status: 'active', updatedAt: '2026-04-10', }, { id: 2, name: '电商小程序', type: 'enterprise', description: '多端电商解决方案', appCount: 5, memberCount: 8, apiCallCount: 98650, status: 'active', updatedAt: '2026-04-12', }, { id: 3, name: '内部管理系统', type: 'basic', description: 'OA办公系统', appCount: 1, memberCount: 5, apiCallCount: 3200, status: 'active', updatedAt: '2026-04-08', }, ] // 加载数据 const loadData = async () => { try { setLoading(true) // TODO: 替换为真实 API 调用 // const result = await pageMyProject({ type: activeTab === 'all' ? undefined : activeTab }) await new Promise((resolve) => setTimeout(resolve, 500)) setProjects(mockProjects) } catch (error) { console.error('加载失败', error) Taro.showToast({ title: '加载失败', icon: 'none' }) } finally { setLoading(false) } } // 下拉刷新 const onRefresh = async () => { setRefreshing(true) await loadData() setRefreshing(false) } useEffect(() => { loadData() }, [activeTab]) // 获取项目类型标签 const getTypeBadge = (type: string) => { const badges: Record = { basic: { text: '基础', color: '#6b7280' }, pro: { text: '专业', color: '#3b82f6' }, enterprise: { text: '企业', color: '#f59e0b' }, } return badges[type] || badges.basic } // 跳转创建页面 const handleCreate = () => { Taro.navigateTo({ url: '/developer/project/create' }) } // 跳转项目详情 const handleProjectClick = (id: number) => { Taro.navigateTo({ url: `/developer/project/${id}` }) } return ( {/* 标签页 */} setActiveTab(v as string)}> {/* 项目列表 */} {loading ? ( 加载中... ) : projects.length === 0 ? ( ) : ( {projects.map((project) => { const badge = getTypeBadge(project.type) return ( handleProjectClick(project.id)}> {project.name} {badge.text} {project.description} {project.appCount} 应用 {project.memberCount} 成员 {project.apiCallCount} API调用 更新于 {project.updatedAt} 查看详情 › ) })} )} {/* 底部安全区域 */} {/* 创建按钮 */} ) } export default ProjectList