Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
276 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule fs-admin-antdv
updated
5 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { App, nextTick } from "vue"; | ||
|
||
export const FsDragModalDirective = { | ||
install(app: App) { | ||
app.directive("drag-modal", async (el, bindings, vnode) => { | ||
await nextTick(); | ||
// @ts-ignore | ||
const { visible, destroyOnClose } = vnode.componentInstance; | ||
// 防止未定义 destroyOnClose 关闭弹窗时dom未被销毁,指令被重复调用 | ||
if (!visible) return; | ||
const [modal] = el.getElementsByClassName("ant-modal"); | ||
const [header] = el.getElementsByClassName("ant-modal-header"); | ||
let left = 0; | ||
let top = 0; | ||
|
||
// 鼠标变成可移动的指示 | ||
header.style.cursor = "move"; | ||
|
||
// 未定义 destroyOnClose 时,dom未被销毁,关闭弹窗再次打开,弹窗会停留在上一次拖动的位置 | ||
if (!destroyOnClose) { | ||
left = modal.left || 0; | ||
top = modal.top || 0; | ||
} | ||
// top 初始值为 offsetTop | ||
top = top || modal.offsetTop; | ||
header.onmousedown = (e) => { | ||
const startX = e.clientX; | ||
const startY = e.clientY; | ||
header.left = header.offsetLeft; | ||
header.top = header.offsetTop; | ||
el.onmousemove = (event) => { | ||
const endX = event.clientX; | ||
const endY = event.clientY; | ||
modal.left = header.left + (endX - startX) + left; | ||
modal.top = header.top + (endY - startY) + top; | ||
modal.style.left = modal.left + "px"; | ||
modal.style.top = modal.top + "px"; | ||
}; | ||
el.onmouseup = () => { | ||
left = modal.left; | ||
top = modal.top; | ||
el.onmousemove = null; | ||
el.onmouseup = null; | ||
header.releaseCapture && header.releaseCapture(); | ||
}; | ||
header.setCapture && header.setCapture(); | ||
}; | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./drag-modal"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.