"use client"; import { deleteSearchWay, SearchTypeItem, SearchWayItemType } from "@/app/_lib/data/search"; import { mRequest } from "@/app/_lib/request"; import { useAntdTable } from "ahooks"; import { Button, Card, Drawer, Form, Input, InputNumber, message, Popconfirm, Space, Table } from "antd"; import { useState } from "react"; import '@ant-design/v5-patch-for-react-19'; import SearchSelect from "./SearchSelect"; export default function Page() { const { tableProps, refresh } = useAntdTable(async ({ current, pageSize }) => mRequest<{ total: number; list: SearchWayItemType[] }>('GET', `/api/search?page=${current}&pageSize=${pageSize}`)) const { tableProps: typeTableProps, refresh: refreshTypeList } = useAntdTable(async ({ current, pageSize }) => mRequest<{ total: number; list: SearchTypeItem[] }>('GET', `/api/searchType?page=${current}&pageSize=${pageSize}`)) const [selected, setSelected] = useState() const [selectedType, setSelectedType] = useState() const [viewMode, setViewMode] = useState(false) return <> }> {...tableProps} rowKey={'_id'} columns={[ { title: '名称', dataIndex: 'label', }, { title: '全称', dataIndex: 'fullName', }, { title: '搜索链接', dataIndex: 'value' }, { title: '操作', render: (_, row) => ( { // mRequest('DELETE', `/api/search/${row._id}`).then(res => { // refresh() // }) deleteSearchWay(row._id).then(res => { refresh() message.success('删除成功') }) }} > ) } ]} > }> {...typeTableProps} rowKey={'_id'} columns={[ { title: '名称', dataIndex: 'name', width: 400 }, { title: '优先级', dataIndex: 'priority' }, { title: '操作', render: (_, row) => ( { mRequest('DELETE', `/api/searchType/${row._id}`).then(res => { refreshTypeList() message.success('删除成功') }) }} > ) } ]} > { setSelected(undefined) }} >
{ if (selected) { await mRequest("PUT", "/api/search", { _id: selected._id, ...res }) } else { await mRequest("POST", "/api/search", { ...res, }) } refresh() setSelected(undefined) message.success("操作成功") }} >
{ setSelectedType(undefined) setViewMode(false) }} >
{ if (selectedType) { await mRequest("PUT", "/api/searchType", { _id: selectedType._id, ...res }) } else { await mRequest("POST", "/api/searchType", { ...res, }) } refreshTypeList() setSelectedType(undefined) message.success("操作成功") }} > { !viewMode && }
}