import { defineComponent } from 'vue' import { OhVueIcon, addIcons } from 'oh-vue-icons' import { MdUpload, FaEye } from 'oh-vue-icons/icons' import upload from './upload' import 'viewerjs/dist/viewer.css' import { api as showViewer } from 'v-viewer' import { globalToast } from '@/main' import useUserStore from '@/user/useUserStore' import useRouterStore from '@/useRouterStore' addIcons(MdUpload, FaEye) // !清 asyncLoader 加载使用 export default defineComponent({ props: { ratio: { type: Number, default: 1 }, width: { type: Number, default: 64 }, value: { type: String, default: '' }, size: { type: Number, default: 4 } }, emits: { 'update:value': (() => true) as (val: string) => boolean }, setup(props, ctx) { let input: HTMLInputElement | null = null return () => (
(input = el as any)} onChange={(e) => { const el = e.target as any const file: File | undefined = el.files?.[0] el.value = '' if (!file) return if (file.size > props.size * 1000 * 1000) { globalToast.warning(`大小不得超过${props.size}mb`) return } upload(file, 'test').then((res) => { ctx.emit('update:value', res) }) }} />
{ if (useUserStore().isLogin) { input?.click() } else { globalToast.warning('请先登录') useRouterStore().go('global-login') } }} > {props.value ? (
{ e.stopPropagation() showViewer({ images: [props.value], options: { navbar: false, toolbar: false } }) }} >
) : ( )}
{/*
支持上传 .png, .jpeg, .jpg, .svg
{' '} */}
) } })