-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
318 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'server-only' | ||
import { deleteBatchImage } from '~/server/lib/operate' | ||
import { NextRequest } from 'next/server' | ||
|
||
export async function DELETE(req: NextRequest) { | ||
try { | ||
const data = await req.json() | ||
await deleteBatchImage(data); | ||
return Response.json({ code: 200, message: '删除成功!' }) | ||
} catch (e) { | ||
console.log(e) | ||
return Response.json({ code: 500, message: '删除失败!' }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
'use client' | ||
|
||
import { DataProps, ImageServerHandleProps, ImageType } from '~/types' | ||
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '~/components/ui/Sheet' | ||
import React, { useState } from 'react' | ||
import { useButtonStore } from '~/app/providers/button-store-Providers' | ||
import { Select, Space } from 'antd' | ||
import { toast } from 'sonner' | ||
import { Button, Modal, ModalBody, ModalContent, ModalFooter, ModalHeader } from '@nextui-org/react' | ||
import { useSWRInfiniteServerHook } from '~/hooks/useSWRInfiniteServerHook' | ||
import ListImage from '~/components/admin/list/ListImage' | ||
|
||
export default function ImageBatchDeleteSheet(props : Readonly<ImageServerHandleProps & { dataProps: DataProps } & { pageNum: number } & { tag: string }>) { | ||
const { dataProps, pageNum, tag, ...restProps } = props | ||
const { mutate } = useSWRInfiniteServerHook(restProps, pageNum, tag) | ||
const { imageBatchDelete, setImageBatchDelete } = useButtonStore( | ||
(state) => state, | ||
) | ||
const [isOpen, setIsOpen] = useState(false) | ||
const [loading, setLoading] = useState(false) | ||
const [data, setData] = useState([] as any[]) | ||
|
||
const fieldNames = { label: 'name', value: 'id' } | ||
|
||
async function submit() { | ||
if (data.length === 0) { | ||
toast.warning('请选择要删除的图片') | ||
return | ||
} | ||
try { | ||
setLoading(true) | ||
await fetch('/api/v1/image-batch-delete', { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
method: 'DELETE', | ||
}).then(response => response.json()) | ||
toast.success('删除成功!') | ||
setImageBatchDelete(false) | ||
setData([]) | ||
await mutate() | ||
} catch (e) { | ||
toast.error('删除失败!') | ||
} finally { | ||
setLoading(false) | ||
setIsOpen(false) | ||
} | ||
} | ||
|
||
return ( | ||
<Sheet | ||
defaultOpen={false} | ||
open={imageBatchDelete} | ||
onOpenChange={(open: boolean) => { | ||
if (!open) { | ||
setImageBatchDelete(false) | ||
setData([]) | ||
} | ||
}} | ||
modal={false} | ||
> | ||
<SheetContent side="left" onInteractOutside={(event: any) => event.preventDefault()}> | ||
<SheetHeader> | ||
<SheetTitle>批量删除</SheetTitle> | ||
<SheetDescription className="space-y-2"> | ||
{ | ||
Array.isArray(data) && data.length > 0 && | ||
<div className="grid grid-cols-3"> | ||
{dataProps.data.filter((item: ImageType) => data.includes(item.id)).map((image: ImageType) => ( | ||
<ListImage key={image.id} image={image} /> | ||
))} | ||
</div> | ||
} | ||
<Select | ||
mode="multiple" | ||
style={{ width: '100%' }} | ||
placeholder="选择您要删除的图片" | ||
onChange={(value: any) => setData(value)} | ||
options={dataProps.data} | ||
fieldNames={fieldNames} | ||
optionRender={(option) => ( | ||
<Space> | ||
<span role="img" aria-label={option.data.id}> | ||
id: {option.data.id} | ||
</span> | ||
name: {option.data.name} | ||
</Space> | ||
)} | ||
/> | ||
<Button | ||
color="primary" | ||
variant="shadow" | ||
onClick={() => setIsOpen(true)} | ||
aria-label="更新" | ||
> | ||
更新 | ||
</Button> | ||
</SheetDescription> | ||
</SheetHeader> | ||
</SheetContent> | ||
<Modal | ||
isOpen={isOpen} | ||
hideCloseButton | ||
placement="center" | ||
> | ||
<ModalContent> | ||
<ModalHeader className="flex flex-col gap-1">确定要删掉?</ModalHeader> | ||
<ModalBody> | ||
<p>图片 ID:{JSON.stringify(data)}</p> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button | ||
color="danger" | ||
variant="flat" | ||
onClick={() => { | ||
setIsOpen(false) | ||
}} | ||
aria-label="不删除" | ||
> | ||
算了 | ||
</Button> | ||
<Button | ||
color="primary" | ||
isLoading={loading} | ||
onClick={() => submit()} | ||
aria-label="确认删除" | ||
> | ||
是的 | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</Sheet> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react' | ||
import { Slot } from '@radix-ui/react-slot' | ||
import { cva, type VariantProps } from 'class-variance-authority' | ||
|
||
import { cn } from '~/utils' | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: | ||
"bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: | ||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground", | ||
secondary: | ||
"bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 rounded-md px-3", | ||
lg: "h-11 rounded-md px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
} | ||
) | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button" | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
} | ||
) | ||
Button.displayName = "Button" | ||
|
||
export { Button, buttonVariants } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import * as CheckboxPrimitive from '@radix-ui/react-checkbox' | ||
import { Check } from 'lucide-react' | ||
|
||
import { cn } from '~/utils' | ||
|
||
const Checkbox = React.forwardRef< | ||
React.ElementRef<typeof CheckboxPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<CheckboxPrimitive.Indicator | ||
className={cn("flex items-center justify-center text-current")} | ||
> | ||
<Check className="h-4 w-4" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
Checkbox.displayName = CheckboxPrimitive.Root.displayName | ||
|
||
export { Checkbox } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.