Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复model在resize时选中文本和拖拽时右键出现菜单出现异常问题 #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions packages/modal/src/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ export default defineComponent({
boxElem.style.height
] as (string | number)[]).concat(revertLocat
? [
revertLocat.left,
revertLocat.top,
revertLocat.width,
revertLocat.height
]
revertLocat.left,
revertLocat.top,
revertLocat.width,
revertLocat.height
]
: []).map(val => val ? XEUtils.toNumber(val) : '').join(',')
localStorage.setItem(storageKey, XEUtils.toJSONString(posStorageMap))
}
Expand Down Expand Up @@ -899,8 +899,16 @@ export default defineComponent({
}
}

function clearSelectedText() {
if (window.getSelection) {
const selection = window.getSelection();
selection && selection.removeAllRanges();
}
}

const dragEvent = (evnt: MouseEvent) => {
evnt.preventDefault()
clearSelectedText()
const { remember, storage } = props
const { visibleHeight, visibleWidth } = getDomNode()
const marginSize = XEUtils.toNumber(props.marginSize)
Expand All @@ -911,6 +919,7 @@ export default defineComponent({
const maxWidth = visibleWidth
const maxHeight = visibleHeight
const boxElem = getBox()
const domContextmenu = document.oncontextmenu
const domMousemove = document.onmousemove
const domMouseup = document.onmouseup
const clientWidth = boxElem.clientWidth
Expand All @@ -920,8 +929,14 @@ export default defineComponent({
const offsetTop = boxElem.offsetTop
const offsetLeft = boxElem.offsetLeft
const params = { type: 'resize' }

document.oncontextmenu = evnt => {
evnt.preventDefault()
}

document.onmousemove = evnt => {
evnt.preventDefault()
clearSelectedText()
let dragLeft
let dragTop
let width
Expand Down Expand Up @@ -1042,6 +1057,7 @@ export default defineComponent({
}
document.onmouseup = () => {
reactData.revertLocat = null
document.oncontextmenu = domContextmenu
document.onmousemove = domMousemove
document.onmouseup = domMouseup
setTimeout(() => {
Expand Down Expand Up @@ -1305,9 +1321,9 @@ export default defineComponent({
? h('div', {
class: 'vxe-modal--aside'
},
asideSlot
? getSlotVNs(asideSlot({ $modal: $xeModal }))
: [
asideSlot
? getSlotVNs(asideSlot({ $modal: $xeModal }))
: [
status || iconStatus
? h('div', {
class: 'vxe-modal--status-wrapper'
Expand All @@ -1325,21 +1341,21 @@ export default defineComponent({
}, !reactData.initialized || (destroyOnClose && !reactData.visible)
? []
: [
renderHeader(),
renderBody(),
renderFooter(),
!isMsg && resize
? h('span', {
class: 'vxe-modal--resize'
}, ['wl', 'wr', 'swst', 'sest', 'st', 'swlb', 'selb', 'sb'].map(type => {
return h('span', {
class: `${type}-resize`,
type: type,
onMousedown: dragEvent
})
}))
: createCommentVNode()
])
renderHeader(),
renderBody(),
renderFooter(),
!isMsg && resize
? h('span', {
class: 'vxe-modal--resize'
}, ['wl', 'wr', 'swst', 'sest', 'st', 'swlb', 'selb', 'sb'].map(type => {
return h('span', {
class: `${type}-resize`,
type: type,
onMousedown: dragEvent
})
}))
: createCommentVNode()
])
])
])
])
Expand Down