forked from AkkomaGang/admin-fe
feature: add drag dialog (#477)
This commit is contained in:
parent
7003a79ef6
commit
14fee27a92
6 changed files with 106 additions and 1 deletions
46
src/directive/el-dragDialog/drag.js
Normal file
46
src/directive/el-dragDialog/drag.js
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
export default{
|
||||||
|
bind(el, binding) {
|
||||||
|
const dialogHeaderEl = el.querySelector('.el-dialog__header')
|
||||||
|
const dragDom = el.querySelector('.el-dialog')
|
||||||
|
dialogHeaderEl.style = 'cursor:move;'
|
||||||
|
|
||||||
|
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
|
||||||
|
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
|
||||||
|
|
||||||
|
dialogHeaderEl.onmousedown = (e) => {
|
||||||
|
// 鼠标按下,计算当前元素距离可视区的距离
|
||||||
|
const disX = e.clientX - dialogHeaderEl.offsetLeft
|
||||||
|
const disY = e.clientY - dialogHeaderEl.offsetTop
|
||||||
|
|
||||||
|
// 获取到的值带px 正则匹配替换
|
||||||
|
let styL, styT
|
||||||
|
|
||||||
|
// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
|
||||||
|
if (sty.left.includes('%')) {
|
||||||
|
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
|
||||||
|
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
|
||||||
|
} else {
|
||||||
|
styL = +sty.left.replace(/\px/g, '')
|
||||||
|
styT = +sty.top.replace(/\px/g, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
document.onmousemove = function(e) {
|
||||||
|
// 通过事件委托,计算移动的距离
|
||||||
|
const l = e.clientX - disX
|
||||||
|
const t = e.clientY - disY
|
||||||
|
|
||||||
|
// 移动当前元素
|
||||||
|
dragDom.style.left = `${l + styL}px`
|
||||||
|
dragDom.style.top = `${t + styT}px`
|
||||||
|
|
||||||
|
// 将此时的位置传出去
|
||||||
|
// binding.value({x:e.pageX,y:e.pageY})
|
||||||
|
}
|
||||||
|
|
||||||
|
document.onmouseup = function(e) {
|
||||||
|
document.onmousemove = null
|
||||||
|
document.onmouseup = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
src/directive/el-dragDialog/index.js
Normal file
13
src/directive/el-dragDialog/index.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import drag from './drag'
|
||||||
|
|
||||||
|
const install = function(Vue) {
|
||||||
|
Vue.directive('el-drag-dialog', drag)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.Vue) {
|
||||||
|
window['el-drag-dialog'] = drag
|
||||||
|
Vue.use(install); // eslint-disable-line
|
||||||
|
}
|
||||||
|
|
||||||
|
drag.install = install
|
||||||
|
export default drag
|
|
@ -18,6 +18,7 @@ export default {
|
||||||
countTo: 'CountTo',
|
countTo: 'CountTo',
|
||||||
componentMixin: 'Mixin',
|
componentMixin: 'Mixin',
|
||||||
backToTop: 'BackToTop',
|
backToTop: 'BackToTop',
|
||||||
|
dragDialog: 'Drag Dialog',
|
||||||
charts: 'Charts',
|
charts: 'Charts',
|
||||||
keyboardChart: 'Keyboard Chart',
|
keyboardChart: 'Keyboard Chart',
|
||||||
lineChart: 'Line Chart',
|
lineChart: 'Line Chart',
|
||||||
|
|
|
@ -18,6 +18,7 @@ export default {
|
||||||
countTo: 'CountTo',
|
countTo: 'CountTo',
|
||||||
componentMixin: '小组件',
|
componentMixin: '小组件',
|
||||||
backToTop: '返回顶部',
|
backToTop: '返回顶部',
|
||||||
|
dragDialog: '拖拽 Dialog',
|
||||||
charts: '图表',
|
charts: '图表',
|
||||||
keyboardChart: '键盘图表',
|
keyboardChart: '键盘图表',
|
||||||
lineChart: '折线图',
|
lineChart: '折线图',
|
||||||
|
|
|
@ -111,7 +111,8 @@ export const asyncRouterMap = [
|
||||||
{ path: 'sticky', component: _import('components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky' }},
|
{ path: 'sticky', component: _import('components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky' }},
|
||||||
{ path: 'count-to', component: _import('components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo' }},
|
{ path: 'count-to', component: _import('components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo' }},
|
||||||
{ path: 'mixin', component: _import('components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
|
{ path: 'mixin', component: _import('components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
|
||||||
{ path: 'back-to-top', component: _import('components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop' }}
|
{ path: 'back-to-top', component: _import('components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop' }},
|
||||||
|
{ path: 'drag-dialog', component: _import('components-demo/dragDialog'), name: 'dragDialog-demo', meta: { title: 'dragDialog' }}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
43
src/views/components-demo/dragDialog.vue
Normal file
43
src/views/components-demo/dragDialog.vue
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<template>
|
||||||
|
<div class="components-container">
|
||||||
|
<el-button type="primary" @click="dialogTableVisible = true">open a Drag Dialog</el-button>
|
||||||
|
<el-dialog v-el-drag-dialog title="Shipping address" :visible.sync="dialogTableVisible">
|
||||||
|
<el-table :data="gridData">
|
||||||
|
<el-table-column property="date" label="Date" width="150"></el-table-column>
|
||||||
|
<el-table-column property="name" label="Name" width="200"></el-table-column>
|
||||||
|
<el-table-column property="address" label="Address"></el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'dragDialog-demo',
|
||||||
|
directives: { elDragDialog },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
dialogTableVisible: false,
|
||||||
|
gridData: [{
|
||||||
|
date: '2016-05-02',
|
||||||
|
name: 'John Smith',
|
||||||
|
address: 'No.1518, Jinshajiang Road, Putuo District'
|
||||||
|
}, {
|
||||||
|
date: '2016-05-04',
|
||||||
|
name: 'John Smith',
|
||||||
|
address: 'No.1518, Jinshajiang Road, Putuo District'
|
||||||
|
}, {
|
||||||
|
date: '2016-05-01',
|
||||||
|
name: 'John Smith',
|
||||||
|
address: 'No.1518, Jinshajiang Road, Putuo District'
|
||||||
|
}, {
|
||||||
|
date: '2016-05-03',
|
||||||
|
name: 'John Smith',
|
||||||
|
address: 'No.1518, Jinshajiang Road, Putuo District'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in a new issue