import { Badge, Box, Center, HStack, Icon, Text, VStack } from "@hope-ui/solid" import { Motion } from "@motionone/solid" import { useContextMenu } from "solid-contextmenu" import { batch, Show, createMemo } from "solid-js" import { CenterLoading, LinkWithPush, ImageWithError } from "~/components" import { usePath, useRouter, useUtil, useT } from "~/hooks" import { checkboxOpen, getMainColor, local, selectIndex, StoreObj, } from "~/store" import { Obj, ObjType } from "~/types" import { bus, hoverColor, normalizeStorageClass } from "~/utils" import { getIconByObj } from "~/utils/icon" import { ItemCheckbox, useSelectWithMouse } from "./helper" import { pathJoin } from "~/utils/path" export const GridItem = (props: { obj: StoreObj & Obj; index: number }) => { const { isHide } = useUtil() if (isHide(props.obj)) { return null } const { setPathAs } = usePath() const objIcon = ( ) const { show } = useContextMenu({ id: 1 }) const { pushHref, to, pathname } = useRouter() const t = useT() const { openWithDoubleClick, toggleWithClick, restoreSelectionCache } = useSelectWithMouse() const storageClassKey = createMemo(() => normalizeStorageClass(props.obj.storage_class), ) const storageClassLabel = createMemo(() => { const key = storageClassKey() return key ? t(`home.storage_class.${key}`) : undefined }) // 构建完整路径 const getFullPath = () => { return pathJoin(pathname(), props.obj.name) } return ( { if (!openWithDoubleClick()) return selectIndex(props.index, true, true) to(getFullPath()) }} on:click={(e: MouseEvent) => { e.preventDefault() if (openWithDoubleClick()) return if (e.ctrlKey || e.metaKey || e.shiftKey) return if (!restoreSelectionCache()) return if (toggleWithClick()) return selectIndex(props.index, !props.obj.selected) to(getFullPath()) }} onMouseEnter={() => { setPathAs(props.obj.name, props.obj.is_dir, true) }} onContextMenu={(e: MouseEvent) => { batch(() => { // if (!checkboxOpen()) { // toggleCheckbox(); // } selectIndex(props.index, true, true) }) show(e, { props: props.obj }) }} >
{ if (props.obj.type !== ObjType.IMAGE) return if (e.ctrlKey || e.metaKey || e.shiftKey) return if (!restoreSelectionCache()) return bus.emit("gallery", props.obj.name) e.preventDefault() e.stopPropagation() }} pos="relative" > { e.stopPropagation() }} on:click={(e: MouseEvent) => { e.stopPropagation() }} checked={props.obj.selected} onChange={(e: any) => { selectIndex(props.index, e.target.checked) }} /> } fallbackErr={objIcon} src={props.obj.thumb} loading="lazy" />
{props.obj.name} {storageClassLabel()}
) }