fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import store from '@/store'
export default {
  bind: function (el, binding, vnode, oldVnode) {
    el.onmousedown = function (e) {
      store.commit('updateMousedown', { startTime: new Date() })
      document.getElementById('diy-aside').style.overflowY = 'hidden'
      document.getElementById('main-container').style.overflowY = 'hidden'
      const diyPage = document.getElementById('diy-page')
      const ol = parseInt(diyPage.offsetLeft) //  距离浏览器左边宽度,鼠标client应该减去这个值
      const ot = parseInt(diyPage.offsetTop) //  距离浏览器顶部边高度,鼠标client应该减去这个值
      const mst = document.getElementById('main-container').scrollTop // main容器卷起高度,热点定位需要加上这个高度
      const st = document.getElementById('diy-aside').scrollTop // 容器卷起高度,热点定位需要加上这个高度
      const x = e.offsetX
      const y = e.offsetY
      el.style.cursor = 'move'
      e.stopPropagation()
      document.onmousemove = function (e) {
        const w = parseInt(el.style.width)
        const h = parseInt(el.style.height)
        const l = e.clientX - ol - x <= 10 ? 10 : e.clientX - ol - x + w >= 365 ? 365 - w : e.clientX - ol - x
        const maxH = parseInt(document.getElementById('diy-page').offsetHeight) - 10 + 44
        const t = e.clientY - ot + st + mst - y <= 44 ? 44 : e.clientY - ot + st + mst - y + h >= maxH ? maxH - h : e.clientY - ot + st + mst - y
        el.style.left = l + 'px'
        el.style.top = t + 'px'
        store.commit('updateDiylistById', { id: el.id, update: { x: l, y: t } })
      }
      el.onmouseup = function () {
        el.style.cursor = 'auto'
        document.onmousemove = el.onmouseup = null
        document.getElementById('diy-aside').style.overflowY = 'auto'
        document.getElementById('main-container').style.overflowY = 'auto'
      }
    }
  }
}