import { Button, Input, Modal, message } from 'ant-design-vue' import { StyleValue, ref } from 'vue' import * as Path from '@/util/path' import { FileNodeInfo, mkdirs } from '@/api/files' import { setTargetFrameAsCover } from '@/api' import { t } from '@/i18n' import { downloadFiles, globalEvents, toRawFileUrl, toStreamVideoUrl } from '@/util' import { DownloadOutlined } from '@/icon' import { isStandalone } from '@/util/env' import { addCustomTag, getDbBasicInfo, rebuildImageIndex, renameFile } from '@/api/db' import { useTagStore } from '@/store/useTagStore' import { useGlobalStore } from '@/store/useGlobalStore' import { base64ToFile, video2base64 } from '@/util/video' export const openCreateFlodersModal = (base: string) => { const floderName = ref('') return new Promise((resolve) => { Modal.confirm({ title: t('inputFolderName'), content: () => , async onOk() { if (!floderName.value) { return } const dest = Path.join(base, floderName.value) await mkdirs(dest) resolve() } }) }) } export const MultiSelectTips = () => (

Tips: {t('multiSelectTips')}

) export const openVideoModal = (file: FileNodeInfo, onTagClick?: (id: string| number) => void) => { const tagStore = useTagStore() const global = useGlobalStore() const isSelected = (id: string | number) => { return !!tagStore.tagMap.get(file.fullpath)?.some(v => v.id === id) } const videoRef = ref(null) const onSetCurrFrameAsVideoPoster = async () => { if (!videoRef.value) { return } const video = videoRef.value video.pause() const base64 = video2base64(video) await setTargetFrameAsCover({ path: file.fullpath, base64_img: base64, updated_time: file.date } ) file.cover_url = URL.createObjectURL(await base64ToFile(base64, 'cover')) message.success(t('success') + '! ' + t('clearCacheIfNotTakeEffect')) } const tagBaseStyle: StyleValue = { margin: '2px', padding: '2px 16px', 'border-radius': '4px', display: 'inline-block', cursor: 'pointer', 'font-weight': 'bold', transition: '.5s all ease', 'user-select': 'none', } Modal.confirm({ width: '80vw', title: file.name, icon: null, content: () => (
{ t('addNewCustomTag') }
{global.conf!.all_custom_tags.map((tag) =>
onTagClick?.(tag.id)} style={{ background: isSelected(tag.id) ? tagStore.getColor(tag) : 'var(--zp-primary-background)', color: !isSelected(tag.id) ? tagStore.getColor(tag) : 'white', border: `2px solid ${tagStore.getColor(tag)}`, ...tagBaseStyle }}> { tag.name }
)}
), maskClosable: true, wrapClassName: 'hidden-antd-btns-modal' }) } export const openRebuildImageIndexModal = () => { Modal.confirm({ title: t('confirmRebuildImageIndex'), onOk: async () => { await rebuildImageIndex() globalEvents.emit('searchIndexExpired') message.success(t('rebuildComplete')) } }) } export const openRenameFileModal = (path: string) => { const name = ref(path.split(/[\\/]/).pop() ?? '') return new Promise((resolve) => { Modal.confirm({ title: t('rename'), content: () => , async onOk() { if (!name.value) { return } const resp = await renameFile({ path, name: name.value }) resolve(resp.new_path) } }) }) } export const openAddNewTagModal = () => { const name = ref('') const global = useGlobalStore() return new Promise((resolve) => { Modal.confirm({ title: t('addNewCustomTag'), content: () => , async onOk() { if (!name.value) { return } const info = await getDbBasicInfo() const tag = await addCustomTag({ tag_name: name.value }) if (tag.type !== 'custom') { message.error(t('existInOtherType')) throw new Error(t('existInOtherType')) } if (info.tags.find((v) => v.id === tag.id)) { message.error(t('alreadyExists')) throw new Error(t('alreadyExists')) } else { global.conf?.all_custom_tags.push(tag) message.success(t('success')) } resolve(name.value) } }) }) }