Commit f26bf78e authored by liujiangnan's avatar liujiangnan

feat

parent 22295de0
......@@ -26,12 +26,16 @@ html, body {
display: flex;
flex-direction: row;
height: 100%;
margin-left: 0 !important; /* 覆盖 Element UI 的默认边距 */
margin-right: 0 !important;
}
.el-col {
display: flex;
flex-direction: column;
min-height: 0; /* 允许内容压缩 */
min-height: 0;
padding-left: 10px !important; /* 统一使用内边距 */
padding-right: 10px !important;
}
/* 卡片样式 */
......@@ -60,32 +64,36 @@ html, body {
display: flex;
flex-direction: column;
min-height: 0;
overflow: hidden;
width: 100%; /* 添加宽度限制 */
}
.image-editor .image-container {
flex: 1;
position: relative;
overflow: auto;
overflow: hidden;
border: 2px dashed #dcdfe6;
border-radius: 4px;
padding: 10px;
background-color: #fff;
display: flex;
justify-content: center;
align-items: flex-start;
align-items: center;
width: 100%; /* 添加宽度限制 */
box-sizing: border-box; /* 添加盒模型设置 */
}
.image-editor img {
max-width: 100%;
max-height: 100%;
object-fit: contain;
display: block;
position: relative;
}
/* 图片包装器,用于定位矩形 */
.image-wrapper {
position: relative;
display: inline-block;
display: flex;
justify-content: center;
align-items: center;
line-height: 0;
}
......@@ -109,6 +117,17 @@ html, body {
margin: 16px 0;
}
.text-editor .el-divider__text {
width: 100%;
padding: 0 20px;
background-color: #fff;
}
.text-editor .el-divider.el-divider--horizontal {
margin: 16px 0;
background-color: #DCDFE6;
}
.text-editor .el-table .cell {
word-break: break-all;
}
......@@ -306,3 +325,30 @@ html, body {
.add-rect-btn:hover {
opacity: 1;
}
.group-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
margin: 16px 0;
border-bottom: 1px solid #DCDFE6;
}
.group-title {
font-size: 14px;
font-weight: 500;
color: #303133;
padding: 0 8px 8px;
position: relative;
}
.group-title::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
right: 0;
height: 2px;
background-color: #409EFF;
}
\ No newline at end of file
......@@ -32,7 +32,7 @@
<el-container>
<!-- 主要内容区域 -->
<el-main>
<el-row :gutter="20">
<el-row>
<!-- 左侧图片编辑区域 -->
<el-col :span="12">
<div class="image-editor" v-if="currentPage">
......@@ -51,13 +51,12 @@
:style="getRectStyle(item.rect)"
@mousedown="startDrag($event, groupIndex, itemIndex)">
<div class="resize-handle" @mousedown.stop="startResize($event, groupIndex, itemIndex)"></div>
<div class="text-content">{{ item.text }}</div>
<el-button
class="delete-rect-btn"
type="danger"
size="mini"
circle
@click.stop="deleteRect(groupIndex, itemIndex)">
@click.stop="deleteRectFromGroup(selectedGroup, itemIndex)">
<i class="el-icon-delete"></i>
</el-button>
</div>
......@@ -100,16 +99,29 @@
</el-col>
</el-form-item>
</el-form>
<!-- 分隔线 -->
<div style="height: 10px; border-bottom: 1px solid #DCDFE6;"></div>
<!-- 选中组的编辑区域 -->
<template v-if="currentPage && selectedGroup !== null && currentGroup">
<el-divider>组编辑</el-divider>
<div class="group-header">
<span class="group-title">组编辑</span>
<el-button type="danger" size="small" @click="deleteGroup">删除整组</el-button>
</div>
<el-form label-width="100px">
<el-form-item label="英文句子">
<el-input v-model="currentGroup.sentence"></el-input>
<el-input
type="textarea"
:rows="3"
v-model="currentGroup.sentence">
</el-input>
</el-form-item>
<el-form-item label="中文翻译">
<el-input v-model="currentGroup.sentence_cn"></el-input>
<el-input
type="textarea"
:rows="3"
v-model="currentGroup.sentence_cn">
</el-input>
</el-form-item>
<el-form-item label="时间范围">
<el-col :span="11">
......@@ -137,7 +149,15 @@
border
highlight-current-row
@current-change="handleRectRowClick">
<el-table-column prop="text" label="文本内容"></el-table-column>
<el-table-column label="文本内容">
<template slot-scope="scope">
<el-input
v-model="scope.row.text"
size="mini"
@change="handleRectTextChange(scope.row.text, scope.$index)">
</el-input>
</template>
</el-table-column>
<el-table-column label="操作" width="80">
<template slot-scope="scope">
<el-button
......@@ -151,9 +171,6 @@
</el-table-column>
</el-table>
</el-form-item>
<el-form-item>
<el-button type="danger" @click="deleteGroup">删除整组</el-button>
</el-form-item>
</el-form>
</template>
</div>
......
......@@ -326,18 +326,53 @@ new Vue({
// 图片加载完成后的处理
handleImageLoad() {
const img = this.$refs.pageImage;
if (!img) return;
const container = this.$refs.imageContainer;
if (!img || !container) return;
// 获取图片在页面上的实际渲染尺寸和位置
// 获取容器的实际尺寸(减去内边距)
const containerWidth = container.clientWidth - 20;
const containerHeight = container.clientHeight - 20;
// 获取图片的原始尺寸
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.imageWidth = finalWidth;
this.imageHeight = finalHeight;
this.imageRect = img.getBoundingClientRect();
this.imageWidth = this.imageRect.width;
this.imageHeight = this.imageRect.height;
this.imageLoaded = true;
console.log('Image loaded:', {
width: this.imageWidth,
height: this.imageHeight,
rect: this.imageRect
container: { width: containerWidth, height: containerHeight, ratio: containerRatio },
image: { width: finalWidth, height: finalHeight, ratio: imageRatio }
});
},
......@@ -642,6 +677,62 @@ new Vue({
}
}
});
},
// 处理矩形文本变化
handleRectTextChange(newText, index) {
if (!this.currentGroup) return;
// 获取所有矩形框的文本
const texts = this.currentGroup.group.map(item => item.text);
// 更新英文句子
let sentence = this.currentGroup.sentence;
// 获取所有旧文本在句子中的位置
const positions = [];
let startPos = 0;
// 先找出所有文本在句子中的位置
texts.forEach((text, i) => {
if (i === index) return; // 跳过当前修改的文本
const pos = sentence.indexOf(text, startPos);
if (pos !== -1) {
positions.push({ text, pos, index: i });
startPos = pos + text.length;
}
});
// 按位置排序
positions.sort((a, b) => a.pos - b.pos);
// 找到当前修改文本在句子中的位置
const oldText = texts[index];
let replacePos = -1;
if (positions.length === 0) {
// 如果没有其他文本,直接查找
replacePos = sentence.indexOf(oldText);
} else {
// 在相邻位置之间查找
for (let i = 0; i <= positions.length; i++) {
const start = i === 0 ? 0 : positions[i-1].pos + positions[i-1].text.length;
const end = i === positions.length ? sentence.length : positions[i].pos;
const pos = sentence.slice(start, end).indexOf(oldText);
if (pos !== -1) {
replacePos = start + pos;
break;
}
}
}
// 如果找到位置,替换文本
if (replacePos !== -1) {
sentence = sentence.slice(0, replacePos) + newText + sentence.slice(replacePos + oldText.length);
this.currentGroup.sentence = sentence;
}
}
},
......
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