diff --git a/src/app/api/fix-database/route.ts b/src/app/api/fix-database/route.ts deleted file mode 100644 index c478c3b..0000000 --- a/src/app/api/fix-database/route.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { getPayload } from 'payload' -import config from '@payload-config' -import { NextResponse } from 'next/server' - -/** - * 修复数据库字段类型 - * GET /api/fix-database - */ -export async function GET(request: Request) { - try { - const payload = await getPayload({ config }) - const db = payload.db - - console.log('🔧 开始修复数据库字段类型...') - - // 修复 products 表的 thumbnail 字段 - await db.execute({ - raw: ` - ALTER TABLE "products" - ALTER COLUMN "thumbnail" TYPE varchar - USING CASE - WHEN "thumbnail" IS NULL THEN NULL - ELSE "thumbnail"::varchar - END; - `, - }) - - console.log('✅ Products.thumbnail 字段已修复为 varchar 类型') - - return NextResponse.json({ - success: true, - message: '数据库字段类型修复成功!', - fixes: ['products.thumbnail: integer → varchar'], - }) - } catch (error) { - console.error('❌ 修复数据库出错:', error) - return NextResponse.json( - { - success: false, - error: error instanceof Error ? error.message : 'Unknown error', - message: '数据库修复失败,请查看控制台日志', - }, - { status: 500 }, - ) - } -} diff --git a/src/components/fields/HiddenField.tsx b/src/components/fields/HiddenField.tsx deleted file mode 100644 index acb12bc..0000000 --- a/src/components/fields/HiddenField.tsx +++ /dev/null @@ -1,7 +0,0 @@ -'use client' -import type { SelectFieldClientComponent } from 'payload' - -// 隐藏字段(因为在ThumbnailAndStatusField中已经显示和编辑) -export const HiddenField: SelectFieldClientComponent = () => { - return null -} diff --git a/src/components/fields/ThumbnailAndStatusField.tsx b/src/components/fields/ThumbnailAndStatusField.tsx deleted file mode 100644 index 4e030a1..0000000 --- a/src/components/fields/ThumbnailAndStatusField.tsx +++ /dev/null @@ -1,60 +0,0 @@ -'use client' -import { useFormFields, useField } from '@payloadcms/ui' -import type { TextFieldClientComponent } from 'payload' - -// 并排显示缩略图和状态(带状态选择器) -export const ThumbnailAndStatusField: TextFieldClientComponent = ({ path }) => { - // 获取thumbnail值 - const fields = useFormFields(([fields]) => fields) - const thumbnail = fields.thumbnail?.value - - // 获取status字段的值和setter - const { value: status, setValue: setStatus } = useField({ path: 'status' }) - - const isImage = typeof thumbnail === 'string' && thumbnail.match(/^https?:\/\/.+/) - - return ( -
- -
-
- {isImage ? ( - 商品缩略图 - ) : ( - 无图片 - )} -
-
- - -
-
-
- ) -} diff --git a/src/components/nav/AdminPanelNavLink.tsx b/src/components/nav/AdminPanelNavLink.tsx deleted file mode 100644 index b9e22b1..0000000 --- a/src/components/nav/AdminPanelNavLink.tsx +++ /dev/null @@ -1,45 +0,0 @@ -'use client' - -import React from 'react' -import Link from 'next/link' -import { usePathname } from 'next/navigation' - -/** - * 管理员面板导航链接 - */ -export function AdminPanelNavLink() { - const pathname = usePathname() - const isActive = pathname === '/admin/admin-panel' - - return ( - { - if (!isActive) { - e.currentTarget.style.backgroundColor = 'var(--theme-elevation-50)' - } - }} - onMouseLeave={(e) => { - if (!isActive) { - e.currentTarget.style.backgroundColor = 'transparent' - } - }} - > -
- 🛠️ - - 管理员面板 - -
- - ) -} diff --git a/src/components/sync/ClearDataButton.tsx b/src/components/sync/ClearDataButton.tsx deleted file mode 100644 index 3495c9f..0000000 --- a/src/components/sync/ClearDataButton.tsx +++ /dev/null @@ -1,107 +0,0 @@ -'use client' -import { useState } from 'react' -import { Button } from '@payloadcms/ui' - -/** - * 清理数据库按钮 - * 用于清除 Products, Announcements, Articles 的所有数据 - */ -export function ClearDataButton() { - const [loading, setLoading] = useState(false) - const [message, setMessage] = useState('') - const [showConfirm, setShowConfirm] = useState(false) - - const handleClearData = () => { - setShowConfirm(true) - setMessage('') - } - - const handleConfirm = async () => { - setLoading(true) - setMessage('') - setShowConfirm(false) - - try { - const response = await fetch('/api/clear-data?confirm=true', { - method: 'GET', - }) - - const data = await response.json() - - if (data.success) { - setMessage(data.message || '数据清理成功!') - setTimeout(() => window.location.reload(), 2000) - } else { - setMessage(`清理失败: ${data.error}`) - } - } catch (error) { - setMessage(`清理出错: ${error instanceof Error ? error.message : '未知错误'}`) - } finally { - setLoading(false) - } - } - - const handleCancel = () => { - setShowConfirm(false) - setMessage('') - } - - return ( -
-

🗑️ 清理数据库

-

- 清除所有商品、公告、文章数据(保留用户和媒体文件) -

- - {showConfirm ? ( -
-
-

- ⚠️ 确认清理所有数据? -

-

- 此操作不可撤销!将删除所有商品、公告和文章。 -

-
- -
- - -
-
- ) : ( - - )} - - {message && ( -
- {message} -
- )} -
- ) -} diff --git a/src/components/views/AdminPanel.tsx b/src/components/views/AdminPanel.tsx index daa276c..49756a6 100644 --- a/src/components/views/AdminPanel.tsx +++ b/src/components/views/AdminPanel.tsx @@ -12,9 +12,6 @@ export default function AdminPanel() { const [clearMessage, setClearMessage] = useState('') const [showClearConfirm, setShowClearConfirm] = useState(false) - const [fixLoading, setFixLoading] = useState(false) - const [fixMessage, setFixMessage] = useState('') - const handleClearData = () => { setShowClearConfirm(true) setClearMessage('') @@ -49,33 +46,6 @@ export default function AdminPanel() { setClearMessage('') } - const handleFixDatabase = async () => { - if (!confirm('确定要修复数据库字段类型吗?这会修改 products 表的 thumbnail 字段。')) { - return - } - - setFixLoading(true) - setFixMessage('') - - try { - const response = await fetch('/api/fix-database', { - method: 'GET', - }) - - const data = await response.json() - - if (data.success) { - setFixMessage(data.message || '数据库修复成功!') - } else { - setFixMessage(`修复失败: ${data.error}`) - } - } catch (error) { - setFixMessage(`修复出错: ${error instanceof Error ? error.message : '未知错误'}`) - } finally { - setFixLoading(false) - } - } - return (

@@ -179,56 +149,6 @@ export default function AdminPanel() {

)} - - {/* 修复数据库区域 */} -
-

- 🔧 修复数据库 -

-

- 修复数据库字段类型(将 products.thumbnail 从 integer 改为 varchar) -

- - - - {fixMessage && ( -
- {fixMessage} -
- )} -
{/* 系统信息区域 */} diff --git a/src/migrations/index.ts b/src/migrations/index.ts index de493e1..935e859 100644 --- a/src/migrations/index.ts +++ b/src/migrations/index.ts @@ -1,6 +1,4 @@ import * as migration_20260208_171142 from './20260208_171142' -import * as migration_20260211_180407 from './20260211_180407' -import * as migration_20260211_180500_fix_thumbnail from './20260211_180500_fix_thumbnail' export const migrations = [ { @@ -8,14 +6,4 @@ export const migrations = [ down: migration_20260208_171142.down, name: '20260208_171142', }, - { - up: migration_20260211_180407.up, - down: migration_20260211_180407.down, - name: '20260211_180407', - }, - { - up: migration_20260211_180500_fix_thumbnail.up, - down: migration_20260211_180500_fix_thumbnail.down, - name: '20260211_180500_fix_thumbnail', - }, ]