xs-common-plugins 1.2.6 → 1.2.7

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