xs-common-plugins 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/common/common.js
CHANGED
|
@@ -6,6 +6,8 @@ import {OrgEnum} from '@/utils/enum'
|
|
|
6
6
|
import filterRules from '@/utils/filterRules'
|
|
7
7
|
import request from "xs-request";
|
|
8
8
|
import moduleCfg from '@/modules/module.config.js'
|
|
9
|
+
|
|
10
|
+
|
|
9
11
|
const common = {}
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -317,7 +319,7 @@ common.popup = (options) => {
|
|
|
317
319
|
},
|
|
318
320
|
template: `
|
|
319
321
|
<div>
|
|
320
|
-
<el-dialog :title="title" :visible.sync="visible" :width="width" :before-close="beforeClose" v-bind="dialogCfg" append-to-body>
|
|
322
|
+
<el-dialog :title="title" v-el-drag-dialog :visible.sync="visible" :width="width" :before-close="beforeClose" v-bind="dialogCfg" append-to-body>
|
|
321
323
|
<child ref="child" :srcData="srcData" v-bind="props" @close="close" @cancel="cancel"/>
|
|
322
324
|
<div v-if="showButton" style="text-align: right;">
|
|
323
325
|
<el-button size="medium" type="primary" @click="confirm">确认</el-button>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
bind(el, binding, vnode, oldVnode) {
|
|
3
|
+
let resizeEvent = new CustomEvent('drag-resize', { detail: '尺寸变化', bubbles: false });
|
|
4
|
+
//初始化不最大化
|
|
5
|
+
el.fullscreen = false;
|
|
6
|
+
//弹框可拉伸最小宽高
|
|
7
|
+
let minWidth = 400;
|
|
8
|
+
let minHeight = 300;
|
|
9
|
+
//当前宽高
|
|
10
|
+
let nowWidth = minWidth;
|
|
11
|
+
let nowHight = minHeight;
|
|
12
|
+
//当前顶部高度
|
|
13
|
+
let nowMarginTop = 0;
|
|
14
|
+
//获取弹框头部(这部分可双击全屏)
|
|
15
|
+
const dialogHeaderEl = el.querySelector('.el-dialog__header');
|
|
16
|
+
let hasSetBodyHight = false;
|
|
17
|
+
//弹窗
|
|
18
|
+
const dragDom = el.querySelector('.el-dialog');
|
|
19
|
+
dragDom.className += ' el-drag-dialog';
|
|
20
|
+
//清除选择头部文字效果
|
|
21
|
+
dialogHeaderEl.onselectstart = new Function("return false");
|
|
22
|
+
//头部加上可拖动cursor
|
|
23
|
+
dialogHeaderEl.style.cursor = 'move';
|
|
24
|
+
|
|
25
|
+
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
|
|
26
|
+
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
|
|
27
|
+
|
|
28
|
+
//头部插入最大化最小化元素
|
|
29
|
+
let maxMin = document.createElement("button");
|
|
30
|
+
maxMin.className += ' el-dialog__headerbtn el-dialog__minmax';
|
|
31
|
+
maxMin.style.right = '40px';
|
|
32
|
+
maxMin.style.color = '#909399';
|
|
33
|
+
maxMin.title = el.fullscreen ? '还原' : '最大化';
|
|
34
|
+
maxMin.innerHTML = '<i class=' + (el.fullscreen ? '"el-icon-crop"' : '"el-icon-full-screen"') + ' onMouseOver="this.style.color=\'#409EFF\'" onMouseOut="this.style.color=\'inherit\'"></i>';
|
|
35
|
+
dialogHeaderEl.insertBefore(maxMin, dialogHeaderEl.childNodes[1]);
|
|
36
|
+
let moveDown = (e) => {
|
|
37
|
+
// 鼠标按下,计算当前元素距离可视区的距离
|
|
38
|
+
const disX = e.clientX - dialogHeaderEl.offsetLeft;
|
|
39
|
+
const disY = e.clientY - dialogHeaderEl.offsetTop;
|
|
40
|
+
|
|
41
|
+
// 获取到的值带px 正则匹配替换
|
|
42
|
+
let styL, styT;
|
|
43
|
+
|
|
44
|
+
// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
|
|
45
|
+
if (sty.left.includes('%')) {
|
|
46
|
+
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
|
|
47
|
+
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
|
|
48
|
+
} else {
|
|
49
|
+
styL = +sty.left.replace(/\px/g, '');
|
|
50
|
+
styT = +sty.top.replace(/\px/g, '');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
document.onmousemove = function (e) {
|
|
54
|
+
// 通过事件委托,计算移动的距离
|
|
55
|
+
const l = e.clientX - disX;
|
|
56
|
+
const t = e.clientY - disY;
|
|
57
|
+
|
|
58
|
+
// 移动当前元素
|
|
59
|
+
dragDom.style.left = `${l + styL}px`;
|
|
60
|
+
dragDom.style.top = `${t + styT}px`;
|
|
61
|
+
|
|
62
|
+
//将此时的位置传出去
|
|
63
|
+
//binding.value({x:e.pageX,y:e.pageY})
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
document.onmouseup = function (e) {
|
|
67
|
+
document.onmousemove = null;
|
|
68
|
+
document.onmouseup = null;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
dialogHeaderEl.onmousedown = moveDown;
|
|
72
|
+
let bodyHeight = 'auto';
|
|
73
|
+
|
|
74
|
+
function setMaxMin() {
|
|
75
|
+
// debugger
|
|
76
|
+
if (el.fullscreen) {
|
|
77
|
+
let i = maxMin.querySelector('.el-icon-crop');
|
|
78
|
+
i.classList.remove('el-icon-crop');
|
|
79
|
+
i.classList.add('el-icon-full-screen');
|
|
80
|
+
maxMin.innerHTML = '<i class="el-icon-full-screen"></i>';
|
|
81
|
+
maxMin.title = '最大化';
|
|
82
|
+
dragDom.style.height = "auto";
|
|
83
|
+
dragDom.style.width = nowWidth + 'px';
|
|
84
|
+
dragDom.style.marginTop = nowMarginTop;
|
|
85
|
+
el.fullscreen = false;
|
|
86
|
+
dialogHeaderEl.style.cursor = 'move';
|
|
87
|
+
dialogHeaderEl.onmousedown = moveDown;
|
|
88
|
+
dragDom.querySelector('.el-dialog__body').style.height = bodyHeight;
|
|
89
|
+
hasSetBodyHight = false;
|
|
90
|
+
} else {
|
|
91
|
+
let i = maxMin.querySelector('.el-icon-full-screen');
|
|
92
|
+
i.classList.remove('el-icon-full-screen');
|
|
93
|
+
i.classList.add('el-icon-crop');
|
|
94
|
+
maxMin.title = '还原';
|
|
95
|
+
bodyHeight = dragDom.querySelector('.el-dialog__body').offsetHeight + 'px';
|
|
96
|
+
nowHight = dragDom.clientHeight;
|
|
97
|
+
nowWidth = dragDom.clientWidth;
|
|
98
|
+
nowMarginTop = dragDom.style.marginTop;
|
|
99
|
+
dragDom.style = 'width:100vw;height:100vh !important;'
|
|
100
|
+
el.fullscreen = true;
|
|
101
|
+
dialogHeaderEl.style.cursor = 'initial';
|
|
102
|
+
dialogHeaderEl.onmousedown = null;
|
|
103
|
+
if (!hasSetBodyHight) {
|
|
104
|
+
let footerHeight = dragDom.querySelector('.el-dialog__footer') && dragDom.querySelector('.el-dialog__footer').offsetHeight;
|
|
105
|
+
dragDom.querySelector('.el-dialog__body').style.height = 'calc(100% - ' + (dialogHeaderEl.offsetHeight + footerHeight) + 'px)';
|
|
106
|
+
hasSetBodyHight = true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
el.dispatchEvent(resizeEvent);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 点击放大缩小效果
|
|
113
|
+
maxMin.onclick = setMaxMin;
|
|
114
|
+
|
|
115
|
+
//双击头部效果
|
|
116
|
+
// dialogHeaderEl.ondblclick = setMaxMin;
|
|
117
|
+
|
|
118
|
+
//拉伸
|
|
119
|
+
let resizeEl = document.createElement("div");
|
|
120
|
+
dragDom.appendChild(resizeEl);
|
|
121
|
+
//在弹窗右下角加上一个10-10px的控制块
|
|
122
|
+
resizeEl.style.cursor = 'se-resize';
|
|
123
|
+
resizeEl.style.position = 'absolute';
|
|
124
|
+
resizeEl.style.height = '10px';
|
|
125
|
+
resizeEl.style.width = '10px';
|
|
126
|
+
resizeEl.style.right = '0px';
|
|
127
|
+
resizeEl.style.bottom = '0px';
|
|
128
|
+
//鼠标拉伸弹窗
|
|
129
|
+
resizeEl.onmousedown = (e) => {
|
|
130
|
+
// 记录初始x位置
|
|
131
|
+
const clientX = e.clientX;
|
|
132
|
+
// 鼠标按下,计算当前元素距离可视区的距离
|
|
133
|
+
const disX = e.clientX - resizeEl.offsetLeft;
|
|
134
|
+
const disY = e.clientY - resizeEl.offsetTop;
|
|
135
|
+
document.onmousemove = function (e) {
|
|
136
|
+
e.preventDefault(); // 移动时禁用默认事件
|
|
137
|
+
// 通过事件委托,计算移动的距离
|
|
138
|
+
const x = e.clientX - disX + (e.clientX - clientX);//这里 由于elementUI的dialog控制居中的,所以水平拉伸效果是双倍
|
|
139
|
+
const y = e.clientY - disY;
|
|
140
|
+
//比较是否小于最小宽高
|
|
141
|
+
dragDom.style.width = x > minWidth ? `${x}px` : minWidth + 'px';
|
|
142
|
+
dragDom.style.height = y > minHeight ? `${y}px` : minHeight + 'px';
|
|
143
|
+
if (!hasSetBodyHight) {
|
|
144
|
+
let footerHeight = dragDom.querySelector('.el-dialog__footer') && dragDom.querySelector('.el-dialog__footer').offsetHeight;
|
|
145
|
+
dragDom.querySelector('.el-dialog__body').style.height = 'calc(100% - ' + (dialogHeaderEl.offsetHeight + footerHeight) + 'px)';
|
|
146
|
+
hasSetBodyHight = true;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
//拉伸结束
|
|
150
|
+
document.onmouseup = function (e) {
|
|
151
|
+
document.onmousemove = null;
|
|
152
|
+
document.onmouseup = null;
|
|
153
|
+
el.dispatchEvent(resizeEvent);
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
package/src/plugins/index.js
CHANGED
|
@@ -4,9 +4,14 @@ import utils from 'xs-component/lib/utils'
|
|
|
4
4
|
import base from 'xs-component/lib/base'
|
|
5
5
|
import api from '@/automatically/api'
|
|
6
6
|
import Vue from 'vue'
|
|
7
|
+
import FullScreenDirective from "../common/fullScreenDirective";
|
|
7
8
|
import store from '../store/index'
|
|
8
9
|
import {request, requestApi} from 'xs-request'
|
|
9
10
|
import ossService from '@/utils/ossService'
|
|
11
|
+
|
|
12
|
+
Vue.directive('el-drag-dialog',FullScreenDirective)
|
|
13
|
+
|
|
14
|
+
|
|
10
15
|
// 以上部分为 xs-component 引入
|
|
11
16
|
base.install(api ? api : {}) // 请求及api映射
|
|
12
17
|
|