Merge branch 'main' into shen

bak
Dragon 1 year ago
commit 2140d48712

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

@ -1,12 +1,11 @@
<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 { getImgUrl } from '@/utils/urlUtils'
import { useConfig } from '@/store/modules/asideConfig'
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<{
value: string
@ -16,9 +15,9 @@ const emit = defineEmits<{
(e: 'update:value', value: string): void
}>()
const configStore = useConfig()
const figureUrl = ref(props.value)
const uploadRef = ref(null);
async function customRequest(data: UploadCustomRequestOptions) {
const result = await upload({ file: data.file.file as any })
@ -39,6 +38,7 @@ function clearHandler(event: MouseEvent) {
event.stopImmediatePropagation()
event.stopPropagation()
figureUrl.value = ''
emit('update:value', '')
}
function previewHandler(event: MouseEvent) {
@ -60,11 +60,35 @@ const imageGroupThemeOverrides = computed(() => {
}
return themeOverrides
})
//
const handleDragOver = (e) => {
e.preventDefault(); //
e.dataTransfer.dropEffect = 'copy'; //
};
//
const handleDragLeave = (e) => {
e.preventDefault(); //
};
//
const handleDrop = async (e) => {
e.preventDefault(); //
const files = e.dataTransfer.files;
if( files[0] ){
const result = await upload({ file: files[0] as any })
const imgUrl = getImgUrl(result.data)
figureUrl.value = imgUrl
emit('update:value', result.data)
}
};
</script>
<template>
<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">
<div v-show="!showFigure" class="wrapper-dragger">
<SvgIcon size="30" name="upload" />
@ -72,7 +96,8 @@ const imageGroupThemeOverrides = computed(() => {
<span class="wrapper-tip2">上传格式为.png .jpg .bmp 20M以内</span>
</div>
<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">
<SvgIcon size="28" name="view" @click="previewHandler" />
<div class="wrapper-figure-line" />
@ -133,7 +158,7 @@ const imageGroupThemeOverrides = computed(() => {
justify-content: center;
width: 100%;
height: 100%;
background-color:rgba(102, 102, 102, 0.2)
background-color: rgba(102, 102, 102, 0.2)
}
&-line {

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

Loading…
Cancel
Save