update:拖拽优化

This commit is contained in:
2025-11-25 20:03:55 +08:00
parent 4c885b741e
commit f7d0df58ed
2 changed files with 74 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="comp-upload-list"> <div class="comp-upload-list">
<div class="btn" @click="listVisible = true"><el-icon :size="22"><Upload /></el-icon></div> <div ref="dragRef" class="btn" @click="openFun" @mousedown="startDragFun"><el-icon :size="22"><Upload /></el-icon></div>
<el-drawer <el-drawer
title="上传列表" title="上传列表"
v-model="listVisible" v-model="listVisible"
@@ -63,6 +63,12 @@ const UPLOAD_FILE_STATUS: any = { // TODO
'2': '上传完成', '2': '上传完成',
}; };
const dragRef = ref<any>();
let isDragging = false;
let isDragged = false;
let offsetX = 0;
let offsetY = 0;
emitter.on('ADD_UPLOAD_FILE', (addData: any) => { emitter.on('ADD_UPLOAD_FILE', (addData: any) => {
const data = addData.data; const data = addData.data;
data.status = '0'; // 默认状态 data.status = '0'; // 默认状态
@@ -159,9 +165,66 @@ const uploadFun = async(params: any) => {
return data; return data;
}; };
const openFun = () => {
if (isDragged) {
isDragged = false;
return;
}
listVisible.value = true;
};
const removeFun = (index: any) => { const removeFun = (index: any) => {
listData.value.splice(index, 1); listData.value.splice(index, 1);
}; };
const startDragFun = (e: any) => {
isDragging = true;
const rect = dragRef.value.getBoundingClientRect();
offsetX = e.clientX - rect.left;
offsetY = e.clientY - rect.top;
document.addEventListener('mousemove', onDragFun);
document.addEventListener('mouseup', stopDragFun);
};
const onDragFun = (e: any) => {
if (!isDragging) {
return;
}
const el = dragRef.value;
const width = el.offsetWidth;
const height = el.offsetHeight;
let x = e.clientX - offsetX;
let y = e.clientY - offsetY;
isDragged = true;
const maxX = window.innerWidth - width;
const maxY = window.innerHeight - height;
x = Math.max(0, Math.min(x, maxX));
y = Math.max(0, Math.min(y, maxY));
if (x <= 0) {
x = 0;
isDragging = false;
}
if (x >= maxX) {
x = maxX;
isDragging = false;
}
if (y <= 0) {
y = 0;
isDragging = false;
}
if (y >= maxY) {
y = maxY;
isDragging = false;
}
el.style.left = x + 'px';
el.style.top = y + 'px';
};
const stopDragFun = () => {
setTimeout(() => {
isDragging = false;
}, 200);
document.removeEventListener('mousemove', onDragFun);
document.removeEventListener('mouseup', stopDragFun);
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@@ -178,9 +241,10 @@ const removeFun = (index: any) => {
background-color: var(--el-color-primary); background-color: var(--el-color-primary);
box-shadow: 0 0 10px var(--el-text-color-primary); box-shadow: 0 0 10px var(--el-text-color-primary);
border-radius: 50%; border-radius: 50%;
z-index: 999; z-index: 9999;
color: var(--el-bg-color); color: var(--el-bg-color);
cursor: pointer; cursor: pointer;
user-select: none;
} }
.content { .content {
height: 100%; height: 100%;

View File

@@ -11,16 +11,20 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue'; import { ref, onMounted, watch } from 'vue';
import { getAllDictDataFun } from '@/utils/common'; import { getAllDictDataFun } from '@/utils/common';
import UploadList from '@/components/common/uploadList/index.vue'; import UploadList from '@/components/common/uploadList/index.vue';
import { useRoute } from 'vue-router';
const w: any = window; const route = useRoute();
const $wujie: any = w.$wujie; const previewMode = ref<any>(false);
const previewMode = $wujie?.props?.VIEW_MODE || '';
const loading = ref(true); const loading = ref(true);
watch(() => route.path, () => {
previewMode.value = route.path.indexOf('/approvalPreview') > -1;
}, { deep: true, immediate: true });
onMounted(async() => { onMounted(async() => {
await getAllDictDataFun(); await getAllDictDataFun();
loading.value = false; loading.value = false;