diff --git a/app/admin/page.tsx b/app/admin/page.tsx
index 99f007a..ebdda2a 100644
--- a/app/admin/page.tsx
+++ b/app/admin/page.tsx
@@ -40,6 +40,14 @@ import IpDisplay from "@/components/ip-display"
import RadarChart from "@/components/radar-chart"
import { categories, categorizeWishMultiple, type Wish } from "@/lib/categorization"
+// 擴展 Wish 接口以包含額外屬性
+interface ExtendedWish extends Wish {
+ isPublic?: boolean
+ email?: string
+ images?: any[]
+ like_count?: number
+}
+
interface WishData {
id: number
title: string
@@ -116,13 +124,12 @@ export default function AdminPage() {
categories.forEach((cat) => {
categoryStats[cat.name] = 0
})
- categoryStats["其他問題"] = 0
// 分析每個許願(多標籤統計)- 包含所有數據
wishList.forEach((wish) => {
// 轉換數據格式以匹配 categorization.ts 的 Wish 接口
- const convertedWish: Wish = {
- id: wish.id.toString(),
+ const convertedWish: ExtendedWish = {
+ id: wish.id,
title: wish.title,
currentPain: wish.current_pain,
expectedSolution: wish.expected_solution,
@@ -152,7 +159,7 @@ export default function AdminPage() {
})
})
- // 計算百分比和準備數據
+ // 計算百分比和準備數據,保留"其他問題"分類
const categoryDetails: CategoryData[] = categories.map((cat) => ({
name: cat.name,
count: categoryStats[cat.name] || 0,
@@ -530,7 +537,7 @@ export default function AdminPage() {
- {Object.keys(stats.categories).length}
+ {stats.categoryDetails?.filter((c) => c.count > 0).length || 0}
不同類別
@@ -752,70 +759,6 @@ export default function AdminPage() {
- {/* 統計概覽 */}
-
-
-
-
-
-
- {stats?.totalWishes || 0}
- 總案例數
-
- 公開 {stats?.publicWishes || 0} + 私密 {stats?.privateWishes || 0}
-
-
-
-
-
-
-
-
-
- {stats?.recentTrends?.thisWeek || 0}
- 本週新增
-
-
-
-
-
-
-
-
-
- {stats?.categoryDetails?.filter((c) => c.count > 0).length || 0}
-
- 問題領域
-
-
-
-
-
-
- {stats?.recentTrends?.growthIcon === "up" ? (
-
- ) : stats?.recentTrends?.growthIcon === "down" ? (
-
- ) : (
-
- )}
-
-
- {stats?.recentTrends?.growth && stats.recentTrends.growth > 0 ? "+" : ""}
- {stats?.recentTrends?.growth || 0}%
-
-
- {stats?.recentTrends?.growthLabel || "持平"}
-
- 上週: {stats?.recentTrends?.lastWeek || 0} 個
-
-
-
{/* 分類指南 */}
diff --git a/scripts/test-admin-export.js b/scripts/test-admin-export.js
deleted file mode 100644
index ee8b958..0000000
--- a/scripts/test-admin-export.js
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * 測試後台管理匯出功能
- */
-
-async function testAdminExport() {
- try {
- console.log('🔍 測試後台管理匯出功能...')
- console.log('')
-
- // 1. 測試獲取數據
- console.log('1️⃣ 測試獲取困擾案例數據...')
- const wishesResponse = await fetch('http://localhost:3000/api/admin/wishes')
- const wishesResult = await wishesResponse.json()
-
- if (wishesResult.success) {
- console.log(`✅ 成功獲取 ${wishesResult.data.length} 筆困擾案例數據`)
- } else {
- console.log(`❌ 獲取失敗: ${wishesResult.error}`)
- return
- }
- console.log('')
-
- // 2. 測試獲取統計數據
- console.log('2️⃣ 測試獲取統計數據...')
- const statsResponse = await fetch('http://localhost:3000/api/admin/stats')
- const statsResult = await statsResponse.json()
-
- if (statsResult.success) {
- console.log(`✅ 成功獲取統計數據:`)
- console.log(` 總案例數: ${statsResult.data.totalWishes}`)
- console.log(` 公開案例: ${statsResult.data.publicWishes}`)
- console.log(` 私密案例: ${statsResult.data.privateWishes}`)
- console.log(` 總點讚數: ${statsResult.data.totalLikes}`)
- console.log(` 本週新增: ${statsResult.data.recentWishes}`)
- } else {
- console.log(`❌ 獲取統計失敗: ${statsResult.error}`)
- }
- console.log('')
-
- // 3. 測試 CSV 匯出
- console.log('3️⃣ 測試 CSV 匯出...')
- const exportResponse = await fetch('http://localhost:3000/api/admin/export-csv', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- data: wishesResult.data.slice(0, 5), // 只匯出前5筆測試
- filename: 'test_export.csv'
- })
- })
-
- if (exportResponse.ok) {
- const csvContent = await exportResponse.text()
- console.log(`✅ CSV 匯出成功,內容長度: ${csvContent.length} 字元`)
- console.log(` 前100字元: ${csvContent.substring(0, 100)}...`)
- } else {
- console.log(`❌ CSV 匯出失敗: ${exportResponse.status}`)
- }
- console.log('')
-
- console.log('🎉 後台管理功能測試完成!')
-
- } catch (error) {
- console.error('❌ 測試失敗:', error.message)
- }
-}
-
-// 執行測試
-if (require.main === module) {
- testAdminExport()
-}
-
-module.exports = { testAdminExport }