dialog.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import Vue from 'vue'
  2. // Vue.directive('dialogDrag', {
  3. // bind(el, binding, vnode, oldVnode) {
  4. // // 弹框可拉伸最小宽高
  5. // const minWidth = 400
  6. // const minHeight = 300
  7. // // 初始非全屏
  8. // let isFullScreen = false
  9. // // 当前顶部高度
  10. // let nowMarginTop = 0
  11. // // 获取弹框头部(这部分可双击全屏)
  12. // const dialogHeaderEl = el.querySelector('.el-dialog__header')
  13. // // 弹窗
  14. // const dragDom = el.querySelector('.el-dialog')
  15. // // 给弹窗加上overflow auto;不然缩小时框内的标签可能超出dialog;
  16. // dragDom.style.overflow = 'auto'
  17. // // 清除选择头部文字效果
  18. // // dialogHeaderEl.onselectstart = new Function("return false");
  19. // // 头部加上可拖动cursor
  20. // dialogHeaderEl.style.cursor = 'move'
  21. // // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  22. // const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
  23. // const moveDown = e => {
  24. // // 鼠标按下,计算当前元素距离可视区的距离
  25. // const disX = e.clientX - dialogHeaderEl.offsetLeft
  26. // const disY = e.clientY - dialogHeaderEl.offsetTop
  27. // // 获取到的值带px 正则匹配替换
  28. // let styL, styT
  29. // // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  30. // if (sty.left.includes('%')) {
  31. // styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
  32. // styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
  33. // } else {
  34. // styL = +sty.left.replace(/\px/g, '')
  35. // styT = +sty.top.replace(/\px/g, '')
  36. // }
  37. // document.onmousemove = function(e) {
  38. // // 通过事件委托,计算移动的距离
  39. // const l = e.clientX - disX
  40. // const t = e.clientY - disY
  41. // // 移动当前元素
  42. // dragDom.style.left = `${l + styL}px`
  43. // dragDom.style.top = `${t + styT}px`
  44. // // 将此时的位置传出去
  45. // // binding.value({x:e.pageX,y:e.pageY})
  46. // }
  47. // document.onmouseup = function(e) {
  48. // document.onmousemove = null
  49. // document.onmouseup = null
  50. // }
  51. // }
  52. // dialogHeaderEl.onmousedown = moveDown
  53. // // 当前宽高
  54. // let nowWidth = 0
  55. // // let nowHight = 0
  56. // // 双击头部全屏效果
  57. // dialogHeaderEl.ondblclick = e => {
  58. // if (isFullScreen === false) {
  59. // // nowHight = dragDom.clientHeight
  60. // nowWidth = dragDom.clientWidth
  61. // nowMarginTop = dragDom.style.marginTop
  62. // dragDom.style.left = 0
  63. // dragDom.style.top = 0
  64. // dragDom.style.height = '100VH'
  65. // dragDom.style.width = '100VW'
  66. // dragDom.style.marginTop = 0
  67. // isFullScreen = true
  68. // dialogHeaderEl.style.cursor = 'initial'
  69. // dialogHeaderEl.onmousedown = null
  70. // } else {
  71. // dragDom.style.height = 'auto'
  72. // dragDom.style.width = nowWidth + 'px'
  73. // dragDom.style.marginTop = nowMarginTop
  74. // isFullScreen = false
  75. // dialogHeaderEl.style.cursor = 'move'
  76. // dialogHeaderEl.onmousedown = moveDown
  77. // }
  78. // }
  79. // dragDom.onmousemove = function(e) {
  80. // // let moveE = e
  81. // if (
  82. // e.clientX > dragDom.offsetLeft + dragDom.clientWidth - 10 ||
  83. // dragDom.offsetLeft + 10 > e.clientX
  84. // ) {
  85. // dragDom.style.cursor = 'w-resize'
  86. // } else if (
  87. // el.scrollTop + e.clientY >
  88. // dragDom.offsetTop + dragDom.clientHeight - 10
  89. // ) {
  90. // dragDom.style.cursor = 's-resize'
  91. // } else {
  92. // dragDom.style.cursor = 'default'
  93. //
  94. // dragDom.onmousedown = null
  95. // }
  96. // dragDom.onmousedown = e => {
  97. // const clientX = e.clientX
  98. // const clientY = e.clientY
  99. // const elW = dragDom.clientWidth
  100. // const elH = dragDom.clientHeight
  101. // const EloffsetLeft = dragDom.offsetLeft
  102. // const EloffsetTop = dragDom.offsetTop
  103. // dragDom.style.userSelect = 'none'
  104. // const ELscrollTop = el.scrollTop
  105. // // 判断点击的位置是不是为头部
  106. // if (
  107. // clientX > EloffsetLeft &&
  108. // clientX < EloffsetLeft + elW &&
  109. // clientY > EloffsetTop &&
  110. // clientY < EloffsetTop + 100
  111. // ) {
  112. // // 如果是头部在此就不做任何动作,以上有绑定dialogHeaderEl.onmousedown = moveDown;
  113. // } else {
  114. // document.onmousemove = function(e) {
  115. // // 移动时禁用默认事件
  116. // e.preventDefault()
  117. // // 左侧鼠标拖拽位置
  118. // if (clientX > EloffsetLeft && clientX < EloffsetLeft + 10) {
  119. // // 往左拖拽
  120. // if (clientX > e.clientX) {
  121. // dragDom.style.width = elW + (clientX - e.clientX) * 2 + 'px'
  122. // }
  123. // // 往右拖拽
  124. // if (clientX < e.clientX) {
  125. // if (dragDom.clientWidth < minWidth) {
  126. // console.log()
  127. // } else {
  128. // dragDom.style.width = elW - (e.clientX - clientX) * 2 + 'px'
  129. // }
  130. // }
  131. // }
  132. // // 右侧鼠标拖拽位置
  133. // if (
  134. // clientX > EloffsetLeft + elW - 10 &&
  135. // clientX < EloffsetLeft + elW
  136. // ) {
  137. // // 往左拖拽
  138. // if (clientX > e.clientX) {
  139. // if (dragDom.clientWidth < minWidth) {
  140. // console.log()
  141. // } else {
  142. // dragDom.style.width = elW - (clientX - e.clientX) * 2 + 'px'
  143. // }
  144. // }
  145. // // 往右拖拽
  146. // if (clientX < e.clientX) {
  147. // dragDom.style.width = elW + (e.clientX - clientX) * 2 + 'px'
  148. // }
  149. // }
  150. // // 底部鼠标拖拽位置
  151. // if (
  152. // ELscrollTop + clientY > EloffsetTop + elH - 20 &&
  153. // ELscrollTop + clientY < EloffsetTop + elH
  154. // ) {
  155. // // 往上拖拽
  156. // if (clientY > e.clientY) {
  157. // if (dragDom.clientHeight < minHeight) {
  158. // console.log()
  159. // } else {
  160. // dragDom.style.height = elH - (clientY - e.clientY) * 2 + 'px'
  161. // }
  162. // }
  163. // // 往下拖拽
  164. // if (clientY < e.clientY) {
  165. // dragDom.style.height = elH + (e.clientY - clientY) * 2 + 'px'
  166. // }
  167. // }
  168. // }
  169. // // 拉伸结束
  170. // document.onmouseup = function(e) {
  171. // document.onmousemove = null
  172. //
  173. // document.onmouseup = null
  174. // }
  175. // }
  176. // }
  177. // }
  178. // }
  179. // })
  180. // Vue.directive('dialogDrag', {
  181. // bind(el, binding, vnode, oldVnode) {
  182. // console.log(el)
  183. // const dialogHeaderEl = el.querySelector('.el-dialog__header')
  184. // const dragDom = el.querySelector('.el-dialog')
  185. // dialogHeaderEl.style.cursor = 'move'
  186. //
  187. // // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
  188. // const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
  189. //
  190. // dialogHeaderEl.onmousedown = (e) => {
  191. // // 鼠标按下,计算当前元素距离可视区的距离
  192. // const disX = e.clientX - dialogHeaderEl.offsetLeft
  193. // const disY = e.clientY - dialogHeaderEl.offsetTop
  194. //
  195. // // 获取到的值带px 正则匹配替换
  196. // let styL, styT
  197. //
  198. // // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
  199. // if (sty.left.includes('%')) {
  200. // styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
  201. // styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
  202. // } else {
  203. // styL = +sty.left.replace(/\px/g, '')
  204. // styT = +sty.top.replace(/\px/g, '')
  205. // }
  206. //
  207. // document.onmousemove = function(e) {
  208. // // 通过事件委托,计算移动的距离
  209. // const l = e.clientX - disX
  210. // const t = e.clientY - disY
  211. //
  212. // // 移动当前元素
  213. //
  214. // console.log(t + styT)
  215. // if ((t + styT) >= 0){
  216. // dragDom.style.top = `${t + styT}px`
  217. // }
  218. // dragDom.style.left = `${l + styL}px`
  219. // // 将此时的位置传出去
  220. // // binding.value({x:e.pageX,y:e.pageY})
  221. // }
  222. //
  223. // document.onmouseup = function(e) {
  224. // document.onmousemove = null
  225. // document.onmouseup = null
  226. // }
  227. // }
  228. // }
  229. // })