|
|
|
|
@ -1,12 +1,15 @@ |
|
|
|
|
import Vue from 'vue' |
|
|
|
|
import Main from './main.vue' |
|
|
|
|
import {PopupManager} from 'element-ui/lib/utils/popup' |
|
|
|
|
import {isEmpty} from "@/utils" |
|
|
|
|
|
|
|
|
|
let Constructor = Vue.extend(Main) |
|
|
|
|
|
|
|
|
|
const PuzzleVerify = function ({left = 0, top = 0} = {}) { |
|
|
|
|
const instance = new Constructor({data: {positionLeft: left}}) |
|
|
|
|
instance.positionTop = top - Math.round((instance.height + 130) / 2) |
|
|
|
|
const PuzzleVerify = function ({left, top} = {}) { |
|
|
|
|
const instance = new Constructor() |
|
|
|
|
const position = getPosition({height: instance.height + 130, width: instance.width + 20, left, top}) |
|
|
|
|
instance.positionTop = position.top |
|
|
|
|
instance.positionLeft = position.left |
|
|
|
|
instance.$mount() |
|
|
|
|
document.body.appendChild(instance.$el) |
|
|
|
|
instance.$el.style.zIndex = PopupManager.nextZIndex() |
|
|
|
|
@ -17,4 +20,27 @@ const PuzzleVerify = function ({left = 0, top = 0} = {}) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getPosition({height, width, left, top} = {}) { |
|
|
|
|
const windowHeight = window.innerHeight |
|
|
|
|
const windowWidth = window.innerWidth |
|
|
|
|
|
|
|
|
|
//若任一位置信息为空,直接返回居中位置
|
|
|
|
|
if (isEmpty(left, top)) { |
|
|
|
|
return { |
|
|
|
|
top: center(windowHeight, height), |
|
|
|
|
left: center(windowWidth, width) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//判断位置是否超出屏幕外
|
|
|
|
|
if (windowWidth < left + width) left = center(windowWidth, width) |
|
|
|
|
if (windowHeight < top + height) top = center(windowHeight, height) |
|
|
|
|
|
|
|
|
|
return {left, top} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function center(full, part) { |
|
|
|
|
return Math.round((full - part) / 2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default PuzzleVerify |
|
|
|
|
|