From 2ceeee0bbc4b02500b762493f2e12d22eb01f665 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Oct 2024 17:16:59 +0800 Subject: [PATCH] Optimize upload component (70%) --- .../edit/Upload/components/Audio.less | 25 +++ .../edit/Upload/components/Audio.tsx | 81 ++++++++- .../edit/Upload/components/Image.less | 7 + .../edit/Upload/components/Image.tsx | 55 ++++-- .../edit/Upload/components/UploadBtn.tsx | 13 +- .../xgen/components/edit/Upload/filemap.tsx | 26 +-- .../xgen/components/edit/Upload/index.less | 157 ++++++++++++------ .../xgen/components/edit/Upload/index.tsx | 47 +++++- packages/xgen/components/edit/Upload/types.ts | 12 +- packages/xgen/package.json | 1 + pnpm-lock.yaml | 38 +++++ 11 files changed, 356 insertions(+), 106 deletions(-) create mode 100644 packages/xgen/components/edit/Upload/components/Audio.less create mode 100644 packages/xgen/components/edit/Upload/components/Image.less diff --git a/packages/xgen/components/edit/Upload/components/Audio.less b/packages/xgen/components/edit/Upload/components/Audio.less new file mode 100644 index 00000000..f979d9f4 --- /dev/null +++ b/packages/xgen/components/edit/Upload/components/Audio.less @@ -0,0 +1,25 @@ +._local { + :global { + .vds-menu-button, + .vds-seek-button { + display: none; + } + + .vds-button { + color: var(--color_text); + } + .vds-play-button { + color: var(--color_bg); + background-color: var(--color_text); + } + + .vds-title-text { + animation: none; + } + + .layout { + background: var(--color_bg_nav); + padding: 11px; + } + } +} diff --git a/packages/xgen/components/edit/Upload/components/Audio.tsx b/packages/xgen/components/edit/Upload/components/Audio.tsx index f70c0fa9..451a31c5 100644 --- a/packages/xgen/components/edit/Upload/components/Audio.tsx +++ b/packages/xgen/components/edit/Upload/components/Audio.tsx @@ -2,16 +2,87 @@ import { getFileSrc } from '@/knife' import { DeleteOutlined } from '@ant-design/icons' import type { IPropsCustomRender } from '../types' +import { useEffect, useRef, useState } from 'react' +import { Skeleton } from 'antd' +import { Icon } from '@/widgets' +import { MediaPlayer, MediaProvider } from '@vidstack/react' +import { DefaultAudioLayout, DefaultLayoutIcons, defaultLayoutIcons } from '@vidstack/react/player/layouts/default' + +import { useGlobal } from '@/context/app' +import '@vidstack/react/player/styles/default/theme.css' +import '@vidstack/react/player/styles/default/layouts/audio.css' +import styles from './Audio.less' +import clsx from 'clsx' const Index = (props: IPropsCustomRender) => { - const { file, remove } = props + const { file, preivewSize, remove } = props + const [loading, setLoading] = useState(true) + const [url, setUrl] = useState(file.response || '') + const [title, setTitle] = useState(file.name) + const [showOpration, setShowOpration] = useState(false) + + const src = getFileSrc(url, props.appRoot) + useEffect(() => { + if (file.response) { + const url = getFileSrc(file.response, props.appRoot) + const title = url.split('name=/')[1]?.split('&')[0] || file.name + console.log('title', title) + setUrl(url) + setTitle(title) + setLoading(false) + } + }, [file.response]) + + const preview = () => { + window.open(src) + } + + const global = useGlobal() + const theme = global.theme + const isDark = theme === 'dark' + const icons: DefaultLayoutIcons = { + ...defaultLayoutIcons + } return ( -
-
- +
setShowOpration(true)} + onMouseLeave={() => setShowOpration(false)} + > +
+
+ +
+
+ +
- + + + + + + +
) } diff --git a/packages/xgen/components/edit/Upload/components/Image.less b/packages/xgen/components/edit/Upload/components/Image.less new file mode 100644 index 00000000..bf43d240 --- /dev/null +++ b/packages/xgen/components/edit/Upload/components/Image.less @@ -0,0 +1,7 @@ +._local { + :global { + .image_wrap { + filter: 'var(--audio-filter,drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06)))'; + } + } +} diff --git a/packages/xgen/components/edit/Upload/components/Image.tsx b/packages/xgen/components/edit/Upload/components/Image.tsx index ba8b3aad..1459a205 100644 --- a/packages/xgen/components/edit/Upload/components/Image.tsx +++ b/packages/xgen/components/edit/Upload/components/Image.tsx @@ -1,14 +1,20 @@ import { getFileSrc } from '@/knife' import { DeleteOutlined } from '@ant-design/icons' -import type { IPropsCustomImage } from '../types' +import type { IPropsCustomRender } from '../types' import { useEffect, useState } from 'react' import { Skeleton } from 'antd' +import { Icon } from '@/widgets' -const Index = (props: IPropsCustomImage) => { - const { file, imageSize, remove } = props +import styles from './Image.less' +import clsx from 'clsx' + +const Index = (props: IPropsCustomRender) => { + const { file, preivewSize, remove } = props const [loading, setLoading] = useState(true) const [url, setUrl] = useState(file.response || '') + const [showOpration, setShowOpration] = useState(false) + const src = getFileSrc(url, props.appRoot) useEffect(() => { if (file.response) { @@ -17,23 +23,48 @@ const Index = (props: IPropsCustomImage) => { } }, [file.response]) + const preview = () => { + window.open(src) + } + return ( -
-
- +
setShowOpration(true)} + onMouseLeave={() => setShowOpration(false)} + > +
+
+ +
+
+ +
+ - +
+ +
) diff --git a/packages/xgen/components/edit/Upload/components/UploadBtn.tsx b/packages/xgen/components/edit/Upload/components/UploadBtn.tsx index 7df0fd4c..7e3771e8 100644 --- a/packages/xgen/components/edit/Upload/components/UploadBtn.tsx +++ b/packages/xgen/components/edit/Upload/components/UploadBtn.tsx @@ -3,13 +3,22 @@ import type { IPropsUploadBtn } from '../types' import { Icon } from '@/widgets' const Index = (props: IPropsUploadBtn) => { - const { filetype, placeholder, placeholderIcon } = props + const { filetype, placeholder, placeholderIcon, size } = props const iconProps = { name: typeof placeholderIcon === 'string' ? placeholderIcon : placeholderIcon?.name || 'cloud-upload', size: typeof placeholderIcon === 'string' ? 14 : placeholderIcon?.size || 14 } + return ( -
+
{placeholder}
diff --git a/packages/xgen/components/edit/Upload/filemap.tsx b/packages/xgen/components/edit/Upload/filemap.tsx index 11185f9d..cb7077b5 100644 --- a/packages/xgen/components/edit/Upload/filemap.tsx +++ b/packages/xgen/components/edit/Upload/filemap.tsx @@ -15,7 +15,7 @@ export default { }, placeholderIcon: 'icon-upload', preview: (props: PreviewProps, file: UploadFile, remove: () => void) => { - return + return } }, @@ -28,7 +28,7 @@ export default { }, placeholderIcon: 'icon-upload', preview: (props: PreviewProps, file: UploadFile, remove: () => void) => { - return
Image
+ return