Merge branch 'jie' into main

bak
lizijiee 1 year ago
commit 900e3a58e7

@ -30,6 +30,10 @@ export const viewOptions = [
label: '平铺', label: '平铺',
value: 'masonry', value: 'masonry',
}, },
{
label: '竖版',
value: 'verticalVersion',
},
{ {
label: '3:4', label: '3:4',
value: '3:4', value: '3:4',

@ -1,12 +1,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { GlobalThemeOverrides, UploadCustomRequestOptions } from 'naive-ui'
import { computed, ref, unref } from 'vue'
import { useElementHover } from '@vueuse/core'
import { useThemeVars } from 'naive-ui'
import { upload } from '@/api/home/main' import { upload } from '@/api/home/main'
import { getImgUrl } from '@/utils/urlUtils'
import { useConfig } from '@/store/modules/asideConfig'
import { hideDownload } from '@/utils/image' import { hideDownload } from '@/utils/image'
import { getImgUrl } from '@/utils/urlUtils'
import { useElementHover } from '@vueuse/core'
import type { GlobalThemeOverrides, UploadCustomRequestOptions } from 'naive-ui'
import { useThemeVars } from 'naive-ui'
import { computed, ref } from 'vue'
const props = defineProps<{ const props = defineProps<{
value: string value: string
@ -16,9 +15,9 @@ const emit = defineEmits<{
(e: 'update:value', value: string): void (e: 'update:value', value: string): void
}>() }>()
const configStore = useConfig()
const figureUrl = ref(props.value) const figureUrl = ref(props.value)
const uploadRef = ref(null);
async function customRequest(data: UploadCustomRequestOptions) { async function customRequest(data: UploadCustomRequestOptions) {
const result = await upload({ file: data.file.file as any }) const result = await upload({ file: data.file.file as any })
@ -39,6 +38,7 @@ function clearHandler(event: MouseEvent) {
event.stopImmediatePropagation() event.stopImmediatePropagation()
event.stopPropagation() event.stopPropagation()
figureUrl.value = '' figureUrl.value = ''
emit('update:value', '')
} }
function previewHandler(event: MouseEvent) { function previewHandler(event: MouseEvent) {
@ -60,11 +60,41 @@ const imageGroupThemeOverrides = computed(() => {
} }
return themeOverrides return themeOverrides
}) })
//
const handleDragOver = (e) => {
e.preventDefault(); //
e.dataTransfer.dropEffect = 'copy'; //
};
//
const handleDragLeave = (e) => {
e.preventDefault(); //
};
//
const handleDrop = (e) => {
e.preventDefault(); //
const files = e.dataTransfer.files;
const draggedElement = e.dataTransfer.getData('text/plain');
if (files.length === 0) {
fetch(draggedElement)
.then(res => res.blob())
.then(async blob => {
const file = new File([blob], String(new Date().getTime()) + '.jpg', { type: 'image/jpeg' });
const result = await upload({ file: file as any })
const imgUrl = getImgUrl(result.data)
figureUrl.value = imgUrl
emit('update:value', result.data)
});
}
};
</script> </script>
<template> <template>
<n-space> <n-space>
<n-upload directory-dnd :show-file-list="false" accept=".png,.jpg,.bmp" :custom-request="customRequest"> <n-upload ref="uploadRef" directory-dnd :show-file-list="false" accept=".png,.jpg,.bmp"
:custom-request="customRequest" @dragover="handleDragOver" @dragleave="handleDragLeave" @drop="handleDrop">
<n-upload-dragger class="wrapper"> <n-upload-dragger class="wrapper">
<div v-show="!showFigure" class="wrapper-dragger"> <div v-show="!showFigure" class="wrapper-dragger">
<SvgIcon size="30" name="upload" /> <SvgIcon size="30" name="upload" />
@ -72,7 +102,8 @@ const imageGroupThemeOverrides = computed(() => {
<span class="wrapper-tip2">上传格式为.png .jpg .bmp 20M以内</span> <span class="wrapper-tip2">上传格式为.png .jpg .bmp 20M以内</span>
</div> </div>
<div v-show="showFigure" ref="figureRef" class="wrapper-figure"> <div v-show="showFigure" ref="figureRef" class="wrapper-figure">
<n-image ref="imageRef" :img-props="{ onClick: hideDownload }" :theme-overrides="imageGroupThemeOverrides" width="288" height="116" :src="figureUrl" /> <n-image ref="imageRef" :img-props="{ onClick: hideDownload }" :theme-overrides="imageGroupThemeOverrides"
width="288" height="116" :src="figureUrl" />
<div v-show="figureHovered" class="wrapper-figure-tools"> <div v-show="figureHovered" class="wrapper-figure-tools">
<SvgIcon size="28" name="view" @click="previewHandler" /> <SvgIcon size="28" name="view" @click="previewHandler" />
<div class="wrapper-figure-line" /> <div class="wrapper-figure-line" />
@ -133,7 +164,7 @@ const imageGroupThemeOverrides = computed(() => {
justify-content: center; justify-content: center;
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color:rgba(102, 102, 102, 0.2) background-color: rgba(102, 102, 102, 0.2)
} }
&-line { &-line {

@ -166,6 +166,8 @@ const gridHeight = computed(() => {
height ='' height =''
}else if(viewMode.value ==='horizontalVersion'){ }else if(viewMode.value ==='horizontalVersion'){
height ='145px' height ='145px'
}else if(viewMode.value ==='verticalVersion'){
height ='320px'
}else if(viewMode.value ==='3:4'){ }else if(viewMode.value ==='3:4'){
height ='240px' height ='240px'
} }
@ -307,7 +309,7 @@ function sortHandler() {
> --> > -->
<n-image <n-image
class="img" :img-props="{ onClick: hideDownload }" class="img" :img-props="{ onClick: hideDownload }"
:class="{ 'img-fit': viewMode === 'horizontalVersion', 'img-full': viewMode === '3:4' }" :preview-src="item.imgUrl" :src="item.thumburl" :class="{ 'img-fit': viewMode === 'horizontalVersion', 'img-full': viewMode === '3:4'|| viewMode === 'verticalVersion' }" :preview-src="item.imgUrl" :src="item.thumburl"
/> />
<div class="percent"> <div class="percent">
<SvgIcon size="42" name="tag" /> <SvgIcon size="42" name="tag" />
@ -401,8 +403,9 @@ function sortHandler() {
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
::v-deep(img) { ::v-deep(img) {
height: 100%;
width: 100%; width: 100%;
height: 100%;
object-fit: cover;
} }
} }

Loading…
Cancel
Save