xs-common-plugins 1.2.6 → 1.2.8

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/README.md CHANGED
@@ -307,3 +307,9 @@
307
307
  1.2.6
308
308
  1.新增 el-input 回车执行查询方法
309
309
  ```
310
+
311
+ ```
312
+ 1.2.7
313
+ 1.优化common.popup弹窗方法。
314
+ 2.优化common.clone方法
315
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xs-common-plugins",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "private": false,
5
5
  "description": "向上公共代码部分",
6
6
  "author": "祝玲云 <1902733517@qq.com>",
@@ -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
  /**
@@ -246,103 +248,133 @@ common.confirm = (that, message, title, callBack) => {
246
248
  *
247
249
  */
248
250
  common.popup = (options) => {
249
- if (!options) return;
250
- let { title, component, srcData, width, showButton, callBack, props, dialogCfg } = common.clone(options);
251
- if (!component) return;
252
- let e = document.createElement("div");
253
- document.getElementsByTagName("body")[0].appendChild(e);
254
- let template = '';
255
- let v = '';
256
- if (typeof component == 'string') {
257
- } else {
258
- let button = '';
259
- if (showButton) {
260
- button = `<div style="text-align:right"><el-button size="medium" type='primary' @click="confirm">确认</el-button><el-button size="medium" @click="cancel()">取消</el-button></div>`
261
- }
262
- template = `<div v-if="visible"> <el-dialog :title="title" v-bind="dialogCfg" :visible.sync="visible" :width="width" :before-close="beforeClose" append-to-body><child ref="child" v-bind="props" :srcData="srcData" @close="close" @cancel="cancel" />${button}</el-dialog></div>`
263
- }
264
- v = new Vue({
265
- el: e,
266
- template: template,
267
- router,
268
- store,
269
- data: function () {
270
- return {
271
- title: title ? title : '弹窗组件',
272
- visible: true,
273
- width: width ? width : '30%',
274
- props: props ? props : null,
275
- srcData: srcData ? srcData : null,
276
- dialogCfg: dialogCfg ? dialogCfg: null
277
- }
278
- },
279
- components: {
280
- child: component
281
- },
282
- methods: {
283
- confirm() {
284
- if (this.$refs.child.confirm) {
285
- this.$refs.child.confirm();
286
- }
287
- },
288
- beforeClose(done) {
289
- if (this.$refs.child.beforeClose) {
290
- this.$refs.child.beforeClose(done);
291
- } else {
292
- done()
293
- }
294
- },
295
- cancel () {
296
- this.visible = false
297
- },
298
- close(res) {
299
- if (callBack) {
300
- callBack(res);
301
- }
302
- this.visible = false
303
- }
304
- }
305
- })
306
- return v
251
+ if (!options) return;
252
+ const { title, component, srcData, width, showButton, callBack, props, dialogCfg } = common.clone(options);
253
+ if (!component) return;
254
+
255
+ const div = document.createElement("div");
256
+ document.body.appendChild(div);
257
+
258
+ const dialogComponent = {
259
+ components: {
260
+ child: component
261
+ },
262
+ props: {
263
+ title: {
264
+ type: String,
265
+ default: '弹窗组件',
266
+ },
267
+ srcData: {
268
+ type: Object,
269
+ default: null,
270
+ },
271
+ showButton: {
272
+ type: Boolean,
273
+ default: true,
274
+ },
275
+ width: {
276
+ type: String,
277
+ default: '30%',
278
+ },
279
+ dialogCfg: {
280
+ type: Object,
281
+ default: null,
282
+ },
283
+ props: {
284
+ type: Object,
285
+ default: null,
286
+ },
287
+ callBack: {
288
+ type: Function,
289
+ default: null,
290
+ },
291
+ },
292
+ data() {
293
+ return {
294
+ visible: true,
295
+ };
296
+ },
297
+ methods: {
298
+ confirm() {
299
+ if (this.$refs.child.confirm) {
300
+ this.$refs.child.confirm();
301
+ }
302
+ },
303
+ beforeClose(done) {
304
+ if (this.$refs.child.beforeClose) {
305
+ this.$refs.child.beforeClose(done);
306
+ } else {
307
+ done();
308
+ }
309
+ },
310
+ cancel() {
311
+ this.visible = false;
312
+ },
313
+ close(res) {
314
+ if (this.callBack) {
315
+ this.callBack(res);
316
+ }
317
+ this.visible = false;
318
+ }
319
+ },
320
+ template: `
321
+ <div>
322
+ <el-dialog :title="title" el-drag-dialog :visible.sync="visible" :width="width" :before-close="beforeClose" v-bind="dialogCfg" append-to-body>
323
+ <child ref="child" :srcData="srcData" v-bind="props" @close="close" @cancel="cancel"/>
324
+ <div v-if="showButton" style="text-align: right;">
325
+ <el-button size="medium" type="primary" @click="confirm">确认</el-button>
326
+ <el-button size="medium" @click="cancel">取消</el-button>
327
+ </div>
328
+ </el-dialog>
329
+ </div>
330
+ `,
331
+ };
332
+
333
+ return new Vue({
334
+ el: div,
335
+ render(h) {
336
+ return h(dialogComponent, {
337
+ props: {
338
+ title,
339
+ srcData,
340
+ width,
341
+ showButton,
342
+ callBack,
343
+ props,
344
+ dialogCfg,
345
+ },
346
+ });
347
+ },
348
+ });
307
349
  }
308
350
 
351
+
352
+
309
353
  /**
310
354
  * 深度拷贝
311
355
  */
312
356
  common.clone = (obj) => {
313
- // 其他类型
314
- if (null == obj || 'object' == typeof (obj)) {
315
- return obj
316
- }
317
- // 日期类型
318
- if (obj instanceof Date) {
319
- let copy = new Date();
320
- copy.setTime(obj.getTime());
321
- return copy;
322
- }
323
- //数组类型
324
- if (obj instanceof Array) {
325
- let copy = [];
326
- for (let i = 0; index < obj.length; index++) {
327
- copy[i] = common.clone(obj[i])
328
- }
329
- return copy
330
- }
331
- //对象类型
332
- if (obj instanceof Object) {
333
- let copy = {}
334
- for (const key in obj) {
335
- if (Object.hasOwnProperty.call(object, key)) {
336
- copy[key] = common.copy(obj[key])
337
- }
338
- }
339
- return copy
340
- }
357
+ if (obj === null || typeof obj !== 'object') {
358
+ return obj;
359
+ }
360
+
361
+ if (obj instanceof Date) {
362
+ return new Date(obj.getTime());
363
+ }
341
364
 
342
- throw new Error("无法复制对象!不支持其类型")
365
+ const clone = Array.isArray(obj) ? [] : {};
366
+
367
+ for (const key in obj) {
368
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
369
+ clone[key] = common.clone(obj[key]);
370
+ }
371
+ }
372
+
373
+ return clone;
343
374
  }
344
375
 
345
376
 
377
+
346
378
  /**
347
379
  *导出数据报表
348
380
  *@param query 默认 列表上的 query 条件去掉 data
@@ -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
+ }
@@ -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