Fix:修复缩放图片工具方法有误的问题;Feat:默认主题的最大图片宽度改为200;Feat:缩放节点图片按钮大小支持配置

This commit is contained in:
街角小林 2024-10-11 09:16:50 +08:00
parent 3349df2183
commit 0055bbb39d
4 changed files with 27 additions and 23 deletions

View File

@ -207,13 +207,12 @@ class MindMap {
this.cssEl = document.createElement('style') this.cssEl = document.createElement('style')
this.cssEl.type = 'text/css' this.cssEl.type = 'text/css'
this.cssEl.innerHTML = this.joinCss() this.cssEl.innerHTML = this.joinCss()
document.head.appendChild(this.cssEl) document.head.appendChild(this.cssEl)
} }
// 移除css // 移除css
removeCss() { removeCss() {
document.head.removeChild(this.cssEl) if (this.cssEl) document.head.removeChild(this.cssEl)
} }
// 渲染,部分渲染 // 渲染,部分渲染

View File

@ -6,7 +6,6 @@ class NodeImgAdjust {
// 构造函数 // 构造函数
constructor({ mindMap }) { constructor({ mindMap }) {
this.mindMap = mindMap this.mindMap = mindMap
this.resizeBtnSize = 26 // 调整按钮的大小
this.handleEl = null // 自定义元素,用来渲染临时图片、调整按钮 this.handleEl = null // 自定义元素,用来渲染临时图片、调整按钮
this.isShowHandleEl = false // 自定义元素是否在显示中 this.isShowHandleEl = false // 自定义元素是否在显示中
this.node = null // 当前节点实例 this.node = null // 当前节点实例
@ -116,6 +115,7 @@ class NodeImgAdjust {
// 创建调整按钮元素 // 创建调整按钮元素
createResizeBtnEl() { createResizeBtnEl() {
const { imgResizeBtnSize } = this.mindMap.opt
// 容器元素 // 容器元素
this.handleEl = document.createElement('div') this.handleEl = document.createElement('div')
this.handleEl.style.cssText = ` this.handleEl.style.cssText = `
@ -134,8 +134,8 @@ class NodeImgAdjust {
bottom: 0; bottom: 0;
pointer-events: auto; pointer-events: auto;
background-color: rgba(0, 0, 0, 0.3); background-color: rgba(0, 0, 0, 0.3);
width: ${this.resizeBtnSize}px; width: ${imgResizeBtnSize}px;
height: ${this.resizeBtnSize}px; height: ${imgResizeBtnSize}px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -178,8 +178,8 @@ class NodeImgAdjust {
right: 0;top:0;color:#fff; right: 0;top:0;color:#fff;
pointer-events: auto; pointer-events: auto;
background-color: rgba(0, 0, 0, 0.3); background-color: rgba(0, 0, 0, 0.3);
width: ${this.resizeBtnSize}px; width: ${imgResizeBtnSize}px;
height: ${this.resizeBtnSize}px; height: ${imgResizeBtnSize}px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -244,16 +244,21 @@ class NodeImgAdjust {
// 隐藏自定义元素 // 隐藏自定义元素
this.hideHandleEl() this.hideHandleEl()
// 更新节点图片为新的大小 // 更新节点图片为新的大小
let { image, imageTitle } = this.node.getData() let { image, imageTitle, imageSize } = this.node.getData()
let { scaleX, scaleY } = this.mindMap.draw.transform() let { scaleX, scaleY } = this.mindMap.draw.transform()
this.mindMap.execCommand('SET_NODE_IMAGE', this.node, { const newWidth = this.currentImgWidth / scaleX
url: image, const newHeight = this.currentImgHeight / scaleY
title: imageTitle, if (newWidth !== imageSize.width || newHeight !== imageSize.height) {
width: this.currentImgWidth / scaleX, this.mindMap.execCommand('SET_NODE_IMAGE', this.node, {
height: this.currentImgHeight / scaleY, url: image,
custom: true // 代表自定义了图片大小 title: imageTitle,
}) width: newWidth,
this.isAdjusted = true height: newHeight,
custom: true // 代表自定义了图片大小
})
this.isAdjusted = true
}
this.isMousedown = false this.isMousedown = false
} }

View File

@ -4,7 +4,7 @@ export default {
paddingX: 15, paddingX: 15,
paddingY: 5, paddingY: 5,
// 图片显示的最大宽度 // 图片显示的最大宽度
imgMaxWidth: 100, imgMaxWidth: 200,
// 图片显示的最大高度 // 图片显示的最大高度
imgMaxHeight: 100, imgMaxHeight: 100,
// icon的大小 // icon的大小

View File

@ -76,11 +76,11 @@ export const resizeImgSizeByOriginRatio = (
let nRatio = width / height let nRatio = width / height
let mRatio = newWidth / newHeight let mRatio = newWidth / newHeight
if (nRatio > mRatio) { if (nRatio > mRatio) {
// 固定高度
arr = [nRatio * newHeight, newHeight]
} else {
// 固定宽度 // 固定宽度
arr = [newWidth, newWidth / nRatio] arr = [newWidth, newWidth / nRatio]
} else {
// 固定高度
arr = [nRatio * newHeight, newHeight]
} }
return arr return arr
} }
@ -95,11 +95,11 @@ export const resizeImgSize = (width, height, maxWidth, maxHeight) => {
} else { } else {
let mRatio = maxWidth / maxHeight let mRatio = maxWidth / maxHeight
if (nRatio > mRatio) { if (nRatio > mRatio) {
// 固定高度
arr = [nRatio * maxHeight, maxHeight]
} else {
// 固定宽度 // 固定宽度
arr = [maxWidth, maxWidth / nRatio] arr = [maxWidth, maxWidth / nRatio]
} else {
// 固定高度
arr = [nRatio * maxHeight, maxHeight]
} }
} }
} else if (maxWidth) { } else if (maxWidth) {