Commit 0a07f8d1 authored by liujiangnan's avatar liujiangnan

feat: 图片编辑

parent f26bf78e
...@@ -352,3 +352,68 @@ html, body { ...@@ -352,3 +352,68 @@ html, body {
height: 2px; height: 2px;
background-color: #409EFF; background-color: #409EFF;
} }
/* 全屏按钮 */
.fullscreen-btn {
position: absolute;
right: 15px;
top: 15px;
z-index: 100;
opacity: 0.8;
transition: opacity 0.3s;
box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
}
.fullscreen-btn:hover {
opacity: 1;
}
/* 全屏编辑器 */
.fullscreen-editor {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.7);
z-index: 2000;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.fullscreen-content {
background-color: #fff;
border-radius: 4px;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
overflow: hidden;
}
.fullscreen-content .image-container {
flex: 1;
margin: 0;
border: none;
border-radius: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #f5f7fa;
}
.fullscreen-content .image-wrapper {
position: relative;
display: flex;
justify-content: center;
align-items: center;
line-height: 0;
}
.fullscreen-content img {
display: block;
max-width: 100%;
max-height: 100%;
}
\ No newline at end of file
...@@ -70,6 +70,63 @@ ...@@ -70,6 +70,63 @@
@click="addNewRect"> @click="addNewRect">
<i class="el-icon-plus"></i> <i class="el-icon-plus"></i>
</el-button> </el-button>
<el-button
class="fullscreen-btn"
type="primary"
circle
size="small"
@click="toggleFullscreen">
<i :class="isFullscreen ? 'el-icon-close' : 'el-icon-full-screen'"></i>
</el-button>
</div>
</div>
<!-- 全屏浮层 -->
<div class="fullscreen-editor" v-if="isFullscreen" @click.self="toggleFullscreen">
<div class="fullscreen-content">
<div class="image-container" ref="fullscreenContainer">
<div class="image-wrapper">
<img :src="currentPage.image_url" ref="fullscreenImage" @load="handleFullscreenImageLoad">
<template v-for="(group, groupIndex) in currentPage.groups">
<div
v-for="(item, itemIndex) in group.group"
:key="groupIndex + '-' + itemIndex"
class="text-rect"
:class="{
'selected': selectedGroup === groupIndex,
'highlighted': selectedGroup === groupIndex && selectedItemIndex === itemIndex
}"
:style="getFullscreenRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<el-button
class="delete-rect-btn"
type="danger"
size="mini"
circle
@click.stop="deleteRectFromGroup(selectedGroup, itemIndex)">
<i class="el-icon-delete"></i>
</el-button>
</div>
</template>
</div>
<el-button
class="add-rect-btn"
type="primary"
circle
size="small"
@click="addNewRect">
<i class="el-icon-plus"></i>
</el-button>
<el-button
class="fullscreen-btn"
type="primary"
circle
size="small"
@click="toggleFullscreen">
<i class="el-icon-close"></i>
</el-button>
</div>
</div> </div>
</div> </div>
</el-col> </el-col>
......
...@@ -30,7 +30,13 @@ new Vue({ ...@@ -30,7 +30,13 @@ new Vue({
imageWidth: 0, imageWidth: 0,
imageHeight: 0, imageHeight: 0,
imageLoaded: false, imageLoaded: false,
imageRect: null imageRect: null,
// 全屏相关
isFullscreen: false,
fullscreenImageWidth: 0,
fullscreenImageHeight: 0,
fullscreenImageRect: null
}, },
mounted() { mounted() {
...@@ -733,6 +739,101 @@ new Vue({ ...@@ -733,6 +739,101 @@ new Vue({
sentence = sentence.slice(0, replacePos) + newText + sentence.slice(replacePos + oldText.length); sentence = sentence.slice(0, replacePos) + newText + sentence.slice(replacePos + oldText.length);
this.currentGroup.sentence = sentence; this.currentGroup.sentence = sentence;
} }
},
// 切换全屏模式
toggleFullscreen() {
this.isFullscreen = !this.isFullscreen;
if (this.isFullscreen) {
// 进入全屏时,等待 DOM 更新后初始化全屏图片
this.$nextTick(() => {
const img = this.$refs.fullscreenImage;
if (img && img.complete) {
this.handleFullscreenImageLoad();
}
});
}
},
// 处理全屏图片加载
handleFullscreenImageLoad() {
const img = this.$refs.fullscreenImage;
const container = this.$refs.fullscreenContainer;
if (!img || !container) return;
// 获取容器的实际尺寸(减去padding和一些边距)
const containerWidth = container.clientWidth - 40; // 两边各留20px边距
const containerHeight = container.clientHeight - 40;
// 获取图片的原始尺寸
const imgNaturalWidth = img.naturalWidth;
const imgNaturalHeight = img.naturalHeight;
// 计算容器和图片的宽高比
const containerRatio = containerWidth / containerHeight;
const imageRatio = imgNaturalWidth / imgNaturalHeight;
let finalWidth, finalHeight;
if (imageRatio > containerRatio) {
// 图片较宽,以容器宽度为准,上下居中
finalWidth = containerWidth;
finalHeight = containerWidth / imageRatio;
} else {
// 图片较高,以容器高度为准,左右居中
finalHeight = containerHeight;
finalWidth = containerHeight * imageRatio;
}
// 设置图片尺寸
img.style.width = `${finalWidth}px`;
img.style.height = `${finalHeight}px`;
// 更新包装器尺寸
const wrapper = img.parentElement;
if (wrapper) {
wrapper.style.width = `${finalWidth}px`;
wrapper.style.height = `${finalHeight}px`;
}
// 保存全屏模式的尺寸信息
this.fullscreenImageWidth = finalWidth;
this.fullscreenImageHeight = finalHeight;
this.fullscreenImageRect = img.getBoundingClientRect();
console.log('Fullscreen image loaded:', {
container: { width: containerWidth, height: containerHeight, ratio: containerRatio },
image: {
naturalWidth: imgNaturalWidth,
naturalHeight: imgNaturalHeight,
finalWidth,
finalHeight,
ratio: imageRatio
}
});
},
// 获取全屏模式下矩形框的样式
getFullscreenRectStyle(rect) {
if (!rect || !this.isFullscreen || !this.fullscreenImageRect) return { display: 'none' };
const x = parseFloat(rect.x);
const y = parseFloat(rect.y);
const width = parseFloat(rect.width);
const height = parseFloat(rect.height);
const actualX = x * this.fullscreenImageWidth;
const actualY = y * this.fullscreenImageHeight;
const actualWidth = width * this.fullscreenImageWidth;
const actualHeight = height * this.fullscreenImageHeight;
return {
position: 'absolute',
left: actualX + 'px',
top: actualY + 'px',
width: actualWidth + 'px',
height: actualHeight + 'px'
};
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment