xs-common-plugins 1.2.0 → 1.2.3

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.
Files changed (58) hide show
  1. package/README.md +298 -290
  2. package/common.js +110 -110
  3. package/index.js +1 -1
  4. package/package.json +16 -16
  5. package/src/common/common.js +548 -548
  6. package/src/components/CheckBox_Cmp/index.vue +62 -62
  7. package/src/components/FormItem/index.vue +92 -92
  8. package/src/components/ReportCmp/index.vue +76 -76
  9. package/src/components/Search/index.scss +219 -219
  10. package/src/components/Search/index.vue +410 -406
  11. package/src/components/Search/product_option/index.scss +1 -1
  12. package/src/components/Search/product_option/index.vue +1 -8
  13. package/src/components/Search/product_option/methods.js +16 -4
  14. package/src/components/Search_filter/index.scss +104 -104
  15. package/src/components/TableItem/TableItem.vue +55 -55
  16. package/src/components/TextOVer/index.vue +55 -55
  17. package/src/components/UploadImg/index.vue +177 -177
  18. package/src/components/im/index.vue +155 -155
  19. package/src/components/im/pages/chatList/index.vue +45 -45
  20. package/src/components/im/pages/chatRoom/index.vue +159 -159
  21. package/src/components/xsSelect/index.vue +125 -125
  22. package/src/mixin/keepAlive.js +52 -0
  23. package/src/plugins/im/components/chat/index.scss +163 -163
  24. package/src/plugins/im/components/chat/index.vue +144 -144
  25. package/src/plugins/im/components/chat/methods.js +149 -149
  26. package/src/plugins/im/components/msg-image/index.vue +40 -40
  27. package/src/plugins/im/components/send-msg/index.scss +164 -164
  28. package/src/plugins/im/components/send-msg/index.vue +107 -107
  29. package/src/plugins/im/components/send-msg/methods.js +125 -125
  30. package/src/plugins/im/components/template-message/index.vue +76 -76
  31. package/src/plugins/im/components/without.vue +19 -19
  32. package/src/plugins/im/index.js +31 -31
  33. package/src/plugins/im/utils/services.js +625 -625
  34. package/src/plugins/index.js +60 -60
  35. package/src/plugins/row-col-cmp/index.js +20 -20
  36. package/src/router/permission.js +126 -126
  37. package/src/store/modules/dic.js +74 -74
  38. package/src/store/modules/oss.js +40 -40
  39. package/src/styles/index.scss +91 -91
  40. package/src/styles/table.scss +90 -90
  41. package/src/utils/api.js +54 -54
  42. package/src/utils/auth.js +38 -38
  43. package/src/utils/concat_batch_btns.js +88 -88
  44. package/src/utils/enum.js +150 -150
  45. package/src/utils/filter.js +5 -5
  46. package/src/utils/filterRules.js +55 -55
  47. package/src/utils/getMenu.js +82 -82
  48. package/src/utils/global_directive.js +10 -0
  49. package/src/utils/ossService.js +55 -55
  50. package/src/utils/prototype.js +46 -46
  51. package/src/utils/search.js +33 -33
  52. package/src/utils/signalR.js +24 -24
  53. package/src/views/callback/index.vue +35 -35
  54. package/src/views/home/index.vue +25 -25
  55. package/src/views/layout/components/AppMain.vue +21 -5
  56. package/src/views/layout/components/Navbar.vue +20 -13
  57. package/src/views/layout/components/TagsView/index.vue +130 -91
  58. package/src/views/slienceAuth/index.vue +42 -42
@@ -1,549 +1,549 @@
1
- import Vue from 'vue'
2
- import ask from '@/automatically/api'
3
- import router from '@/router/index'
4
- import store from '@/store/index'
5
- import {OrgEnum} from '@/utils/enum'
6
- import filterRules from '@/utils/filterRules'
7
- import request from "xs-request";
8
- import moduleCfg from '@/modules/module.config.js'
9
- const common = {}
10
-
11
- /**
12
- * 查询列表数据
13
- * @param {*} that
14
- * @param {String} url 接口地址
15
- * @param {Object} query 接口参数, 默认取页面变量 data 为查询条件
16
- * @param {Function} callBack 返回函数, 页面在接口返回后自行处理
17
- */
18
- common.getList = (that, url, query, callBack) => {
19
- let newQuery = {}
20
- if (query) newQuery = query
21
- else {
22
- let obj = Object.assign({}, that.data)
23
- if (obj.pageInfo === undefined) {
24
- that.$set(obj, 'pageInfo', {page: 1, pageSize: 30})
25
- } // 移除空项查询条件
26
- for (const key in obj) {
27
- if(obj[key] == null || obj[key] === '')
28
- delete obj[key]
29
- }
30
- delete obj.data
31
- newQuery = obj
32
- }
33
- let request = common.getObject(url)
34
- request(query ? query : newQuery).then((res)=>{
35
- if(callBack) {
36
- callBack(res);
37
- return;
38
- }
39
- if(res.code == 0) {
40
- that.data = res.data
41
- }
42
- })
43
- }
44
-
45
- /**
46
- *根据请求URL解析对象
47
- **/
48
- common.getObject = (url, obj = ask) => {
49
- let value = obj
50
- let keys = url.split('.')
51
- for (let i = 1; i < keys.length; i++) {
52
- value = value[keys[i]]
53
- }
54
- return value
55
- }
56
-
57
- /**
58
- * 表单的单据保存
59
- * @param {*} that 指向 传入 this
60
- * @param {*} url api 地址
61
- * @param {*} query 查询条件 默认this.postForm
62
- * @param {*} ref 表单校验 捆绑对象 想使用表单保存方法, 但不进行校验, 传值 false
63
- * @param {*} callBack 接口返回后, 页面要进行后续操作,默认
64
- *
65
- * 调用方法后, 默认关闭弹窗页, 如果 不关闭弹窗, 或有其他业务处理, 参数 callBack(res) 回调当前页面处理
66
- * 表单校验后,调用 api 之前, 如果要修改保存的值, 默认执行页面上 beforeSaveData (data)方法, return 返回处理好格式的数据
67
-
68
- */
69
- common.saveData = (that, url, query, ref, callBack) => {
70
- let newQuery = query ? query : JSON.parse(JSON.stringify(that.postForm)); // 深拷贝, 避免影响页面显示
71
- if(ref === false) {
72
- common.handleData(that, url, newQuery, callBack)
73
- } else {
74
- let newRef = ref ? ref : that.$refs.pageDetail.$refs.postForm
75
- newRef.validate(res => {
76
- if(!res) return
77
- if (that.beforeSaveData) {
78
- newQuery = that['beforeSaveData'](newQuery);
79
- }
80
- common.handleData(that, url, newQuery, callBack)
81
- })
82
- }
83
- }
84
- /**
85
- * 保存数据 一般作为 common.saveData 的内嵌方法使用, 不推荐单独使用 (表单提交,原则上要经过表单校验)
86
- * @param {*} that 指向 传入 this
87
- * @param {*} url api 地址
88
- * @param {*} query 查询条件 默认this.postForm
89
- * @param {*} callBack 接口返回后, 页面要进行后续操作
90
- */
91
-
92
- common.handleData = (that, url, query, callBack)=> {
93
- let newQuery = query ? query : that.postForm;
94
- if (that.loading !== undefined) that.loading = true;
95
- let request = common.getObject(url)
96
- request(newQuery ? newQuery : undefined).then((res) => {
97
- if (that.loading !== undefined) that.loading = false;
98
- if (res.code == 0) {
99
- that.$message('保存成功');
100
- if(!callBack) that.$emit('close')
101
- }
102
- if (callBack) callBack(res.data)
103
- })
104
-
105
- }
106
-
107
-
108
- /**
109
- * 查询单条信息
110
- * @param {*} that
111
- * @param {String} url 接口地址
112
- * @param {Object} param 接口参数
113
- * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
114
- */
115
- common.getById = (that, url, query, callBack) => {
116
- let request = common.getObject(url)
117
- request(query).then((res)=>{
118
- if (res.code == 0) {
119
- if (callBack) { callBack(res.data) }
120
- else that.postForm = res.data
121
- }
122
- })
123
- }
124
-
125
- /**
126
- * 修改单条信息
127
- * @param {*} that
128
- * @param {String} url 接口地址
129
- * @param {Object} query 接口参数
130
- * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
131
- */
132
- common.updateById = (that, url, query, callBack) => {
133
- let newQuery = query ? query : that.postForm;
134
- let request = common.getObject(url)
135
- request(newQuery).then((res)=>{
136
- if (res.code == 0) {
137
- that.$message('操作成功');
138
- if (callBack) { callBack(res.data) }
139
- }
140
- })
141
- }
142
- /**
143
- * 判断多条数据 返回 true/false 或者 重新拼接好的 ids []
144
- * @param {Object} that 传 this
145
- * @param {Array} row 要判断的数据
146
- * @param {String} title 无数据/ 提示操作的 关键字
147
- * @param {String} prop 默认 id 要取出数组中哪个字段汇成新数组
148
- * @param {Boolean} check 默认 true 二次弹窗确认即将要做的提醒
149
- *
150
- * 使用场景 (列表页上批量操作数据后刷新列表页)
151
- * async updateRows () {
152
- * let ids = await this.$common.checkRows(this, this.selectRows, 'xxx')
153
- * if(!ids) retuen
154
- * this.$common.updateData(that, 'ask.xxx.xxx', {保存对象})
155
- * }
156
- */
157
- common.checkRows = async (that, row, title, prop = "id", check = true) => {
158
- if(row.length == 0) {
159
- common.message(that, `请选择数据`, 'error');
160
- return false;
161
- }
162
- if(check) {
163
- try {
164
- await common.confirm(that, `您确定进行${title}操作`, '操作提醒')
165
- return prop ? row.map(item => item[prop]) : row
166
- } catch (error) {
167
- return false
168
- }
169
- } else {
170
- return true
171
- }
172
- }
173
-
174
- /**
175
- * 修改数据后, 刷新列表页
176
- * @param {Object} that 传值 this
177
- * @param {String} url api 地址
178
- * @param {Object} query 接口参数
179
- * @param {Function} callBack 接口响应成功后, 界面上自行处理返回事件, 不传, 默认执行页面 getList 方法 (刷新列表页)
180
- */
181
- common.updateData = (that, url, query, callBack) => {
182
- let request = common.getObject(url)
183
- request(Object.assign({}, query)).then(res => {
184
- if(res.code !== 0) return
185
- common.message(that, res.message)
186
- if(callBack) callBack(res)
187
- else that.getList && that.getList()
188
- })
189
- }
190
-
191
-
192
- /**
193
- * 消息弹窗---自动消失
194
- * @param {*} that
195
- * @param {String} message 内容
196
- * @param {String} type 类型 可选值:查看element ui 文档, 默认 success
197
- */
198
- common.message = (that, message, type) => {
199
- that.$message({
200
- message: message,
201
- type: type ? type : 'success'
202
- });
203
- }
204
-
205
- /**
206
- * 对话框
207
- * @param {*} that
208
- * @param {String} message 内容
209
- * @param {String} title 标题 默认:提示
210
- * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
211
- */
212
- common.confirm = (that, message, title, callBack) => {
213
- let result = that.$confirm(message, title ? title : "提示", {
214
- confirmButtonText: "确定",
215
- cancelButtonText: "取消",
216
- type: "none"
217
- })
218
- if(callBack) {
219
- result.then(() => {
220
- callBack(true)
221
- })
222
- .catch(() => {
223
- callBack(false)
224
- });
225
- } else {
226
- return result
227
- }
228
- }
229
-
230
-
231
- /**
232
- * 发起弹窗
233
- * @param {*} options
234
- * options { 参数
235
- * title: string, 弹窗标题
236
- * component: vue, 弹窗组件 --> 弹窗组内部取消弹窗 this.$emit('close', 要带给列表页的值)
237
- * props: {id: '', name: '' }, 带给弹窗组件的 prop 集合
238
- * srcData: {} , 带给弹窗组件的值 (已废弃, 不推荐使用, 推荐使用 props)
239
- * width: string, 弹窗宽度
240
- * showButton: Boolean , 是否显示 确认/取消按钮 (默认不显示) 显示时, 确认按钮默认触发组件页面的 confirm() 方法, beforeClose() 方法弹窗关闭前被调用,同时暂停实例的关闭, 参数 done ,此时若需要关闭实例,可以调用done方法
241
- * callBack: function 获取 弹窗层返回值
242
- * dialogCfg: 弹窗的高级配置, 具体参数查看 element ui 下的 el-dialog
243
- * }
244
- *
245
- */
246
- common.popup = (options) => {
247
- if (!options) return;
248
- let { title, component, srcData, width, showButton, callBack, props, dialogCfg } = common.clone(options);
249
- if (!component) return;
250
- let e = document.createElement("div");
251
- document.getElementsByTagName("body")[0].appendChild(e);
252
- let template = '';
253
- let v = '';
254
- if (typeof component == 'string') {
255
- } else {
256
- let button = '';
257
- if (showButton) {
258
- 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>`
259
- }
260
- 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>`
261
- }
262
- v = new Vue({
263
- el: e,
264
- template: template,
265
- router,
266
- store,
267
- data: function () {
268
- return {
269
- title: title ? title : '弹窗组件',
270
- visible: true,
271
- width: width ? width : '30%',
272
- props: props ? props : null,
273
- srcData: srcData ? srcData : null,
274
- dialogCfg: dialogCfg ? dialogCfg: null
275
- }
276
- },
277
- components: {
278
- child: component
279
- },
280
- methods: {
281
- confirm() {
282
- if (this.$refs.child.confirm) {
283
- this.$refs.child.confirm();
284
- }
285
- },
286
- beforeClose(done) {
287
- if (this.$refs.child.beforeClose) {
288
- this.$refs.child.beforeClose(done);
289
- } else {
290
- done()
291
- }
292
- },
293
- cancel () {
294
- this.visible = false
295
- },
296
- close(res) {
297
- if (callBack) {
298
- callBack(res);
299
- }
300
- this.visible = false
301
- }
302
- }
303
- })
304
- return v
305
- }
306
-
307
- /**
308
- * 深度拷贝
309
- */
310
- common.clone = (obj) => {
311
- // 其他类型
312
- if (null == obj || 'object' == typeof (obj)) {
313
- return obj
314
- }
315
- // 日期类型
316
- if (obj instanceof Date) {
317
- let copy = new Date();
318
- copy.setTime(obj.getTime());
319
- return copy;
320
- }
321
- //数组类型
322
- if (obj instanceof Array) {
323
- let copy = [];
324
- for (let i = 0; index < obj.length; index++) {
325
- copy[i] = common.clone(obj[i])
326
- }
327
- return copy
328
- }
329
- //对象类型
330
- if (obj instanceof Object) {
331
- let copy = {}
332
- for (const key in obj) {
333
- if (Object.hasOwnProperty.call(object, key)) {
334
- copy[key] = common.copy(obj[key])
335
- }
336
- }
337
- return copy
338
- }
339
-
340
- throw new Error("无法复制对象!不支持其类型")
341
- }
342
-
343
-
344
- /**
345
- *导出数据报表
346
- *@param query 默认 列表上的 query 条件去掉 data
347
- *@param headers
348
- *@param {String} url 请求方法
349
- *@param {String} fileName 文件名
350
- */
351
- common.exportExcel = async (url, query, fileName = 'demo', headers = { responseType: 'arraybuffer' }) => {
352
- let newQuery = JSON.parse(JSON.stringify(query))
353
- delete newQuery.data
354
- for (const key in newQuery) {
355
- if(newQuery[key] == null || newQuery[key] === '')
356
- delete newQuery[key]
357
- }
358
- const httpRequest = common.getObject(url)
359
- const response = await httpRequest(newQuery, headers)
360
- const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
361
- const objectUrl = URL.createObjectURL(blob)
362
- const a = document.createElement('a')
363
- document.body.appendChild(a)
364
- a.style = 'display: none'
365
- a.href = objectUrl
366
- a.download = `${fileName}.xlsx`
367
- a.click()
368
- document.body.removeChild(a)
369
- }
370
-
371
- /**
372
- * 从枚举中批量获取按钮
373
- * @param {String} enumName 枚举名称
374
- * @param {String} methodName 点击按钮需要调用的方法名
375
- * @param {String} name 完整的按钮名称
376
- *
377
- */
378
- common.getBtnListByEnum = (enumName, methodName, name = '') => {
379
- let enums = OrgEnum[enumName];
380
- let list = []
381
- enums.filter(item => {
382
- if(item.Id == null) return
383
- list.push({name: name + item.Text, methodName, type: item.Id, row: item})
384
- })
385
- return list
386
- }
387
-
388
- /**
389
- * 必填项列表
390
- * @param {List} list 必填项字段名列表
391
- */
392
- common.requiredList = (list) => {
393
- let obj = {}
394
- list.forEach(key => {
395
- obj[key] = filterRules({required: true})
396
- });
397
- return obj
398
- }
399
-
400
- /**
401
- * 格式化数据样式
402
- * @param {*} value 值
403
- * @param {*} type 要格式化的类型 [date, price, price, money, enum, list(前端自定义枚举)]
404
- * @returns
405
- */
406
- common.format = (value, type="date") => {
407
- let newType = ['money', 'date', 'mdate'].includes(type) ? type : type.split('.').length > 1 ? 'enum' : 'list'
408
- switch (newType) {
409
- case 'money':
410
- return Number(value).toFixed(4);
411
- case 'date':
412
- if(value === '1970-01-01T00:00:00') return '/'
413
- return value ? value.replace('T', ' ').substr(0, 19) : ''
414
- case 'mdate':
415
- if(value === '1970-01-01T00:00:00') return '/'
416
- return value ? value.replace('T', ' ').substr(5, 19) : ''
417
- case 'price':
418
- if(typeof(value) === 'number') {
419
- return value.toFixed(2).toString().replace(/,/g,'').replace(/\d+/, function (n) { // 先提取整数部分
420
- return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
421
- return $1 + ",";
422
- });
423
- });
424
- }
425
- else return ''
426
- case 'enum':
427
- return getValueByType('enum', type, value)
428
- case 'list':
429
- return getValueByType('list', type, value)
430
- default:
431
- break;
432
- }
433
- function getValueByType (type, name, value) {
434
- if(type === 'enum') {
435
- let row = OrgEnum[name].find(item => item.Id == value)
436
- return row ? row.Text : ''
437
- } else if(type === 'list') {
438
- let row = moduleCfg.format ? moduleCfg.format[name].find(item => item.id == value) : null
439
- return row ? row.name: ''
440
- }
441
- }
442
- }
443
-
444
- /**
445
- * 获取报表配置项
446
- * @param {Object} that 指向 默认传 this
447
- * @param {String} url 获取配置项 url
448
- * @param {Object} query 接口参数
449
- * @param {Function} callBack 自定义事件, 传此参数, 接口响应后, 后续事情自定义
450
- * @param {String} methodName 接口响应后, 调用界面哪个方法
451
- */
452
- common.getReportCfg = (that, url, query, callBack, methodName = 'getReportList') => {
453
- let request = common.getObject(url)
454
- request(query).then(res => {
455
- if(callBack) {
456
- callBack(res)
457
- } else {
458
- that.config.reportList = res.data
459
- if(res.data[0]) {
460
- that.reportCfgVal = JSON.parse(res.data[0].jsonCfg)
461
- that[methodName]();
462
- }
463
- }
464
- })
465
- }
466
-
467
- /**
468
- * 获取报表列表数据
469
- * @param {*} that 指向 默认传 this
470
- * @param {*} url 获取数据 url
471
- * @param {*} query 接口参数 不传, 默认取值 this.data (查询条件) + this.reportCfgVal (报表配置项)
472
- * @param {*} callBack 接口响应后, 自定义事件
473
- */
474
- common.getReportList = (that, url, query, callBack) => {
475
- let newQuery = {}
476
- if(query) newQuery = query
477
- else {
478
- let obj = Object.assign({}, that.data)
479
- delete obj.data
480
- // 移除空项查询条件
481
- for (const key in obj) {
482
- if(obj[key] == null || obj[key] === '')
483
- delete obj[key]
484
- }
485
- newQuery = Object.assign(obj, {report: that.reportCfgVal})
486
- }
487
- let request = common.getObject(url)
488
- request(newQuery).then(res => {
489
- if(callBack) callBack(res)
490
- else that.data = res.data
491
- })
492
- }
493
-
494
-
495
- /**
496
- * 字典表 里通过Id 查 name, 或者查询多条数据 (单条返回 name, 多条返回数组)
497
- * @param {Array} props ['服务名', '表名', '字段名']
498
- * @param {String, Number, Array} val 值, 传入id, 或者 [id1, id2, ...]
499
- *
500
- * 使用案例 (异步方法)
501
- * async getValue () {
502
- * await this.$common.dic(['qccuser', 'Brand'], '10010')
503
- * }
504
- *
505
- */
506
-
507
- common.dic = async (props, val) => {
508
- let isArray = Array.isArray(val)
509
- let server = props[0] || ''
510
- let tableName = props[1] || ''
511
- let prop = props[2] || 'name'
512
- let key = server + tableName
513
- if(store.getters.dic[key]) {
514
- if(isArray) return await getDicVal()
515
- let row = store.getters.dic[key].find(item => item.id == val)
516
- if(row && (row.isNull || row[prop] === null)) { return '' }
517
- if(row) return row[prop]
518
- if(!row) return await getDicVal()
519
-
520
- } else {
521
- return await getDicVal()
522
- }
523
- async function getDicVal () {
524
- let servers = props[0] || "";
525
- let tableName = props[1] || "";
526
- let key = servers + tableName;
527
- let url = servers + "/UserAll/Search/Dic/" + tableName;
528
- let res = await request.post(url, isArray ? val : [val])
529
- if (res.code !== 0) return;
530
- store.commit("dic/SET_ASK", { key, val: res.data });
531
- if(isArray) return res.data
532
- else {
533
- let row = res.data.find(item => item.id == val)
534
- return row ? row[prop] : ''
535
- }
536
- }
537
- }
538
- /**
539
- * 快速给页面变量赋值
540
- * @param {*} url 请求接口的地址
541
- * @param {*} query 接口参数
542
- * @param {*} prop 要为哪个字段名赋值
543
- */
544
- common.getLabelList = (that, prop, url, query) => {
545
- common.getObject(url)(query).then(res => {
546
- that[prop] = res.data
547
- })
548
- }
1
+ import Vue from 'vue'
2
+ import ask from '@/automatically/api'
3
+ import router from '@/router/index'
4
+ import store from '@/store/index'
5
+ import {OrgEnum} from '@/utils/enum'
6
+ import filterRules from '@/utils/filterRules'
7
+ import request from "xs-request";
8
+ import moduleCfg from '@/modules/module.config.js'
9
+ const common = {}
10
+
11
+ /**
12
+ * 查询列表数据
13
+ * @param {*} that
14
+ * @param {String} url 接口地址
15
+ * @param {Object} query 接口参数, 默认取页面变量 data 为查询条件
16
+ * @param {Function} callBack 返回函数, 页面在接口返回后自行处理
17
+ */
18
+ common.getList = (that, url, query, callBack) => {
19
+ let newQuery = {}
20
+ if (query) newQuery = query
21
+ else {
22
+ let obj = Object.assign({}, that.data)
23
+ if (obj.pageInfo === undefined) {
24
+ that.$set(obj, 'pageInfo', {page: 1, pageSize: 30})
25
+ } // 移除空项查询条件
26
+ for (const key in obj) {
27
+ if(obj[key] == null || obj[key] === '')
28
+ delete obj[key]
29
+ }
30
+ delete obj.data
31
+ newQuery = obj
32
+ }
33
+ let request = common.getObject(url)
34
+ request(query ? query : newQuery).then((res)=>{
35
+ if(callBack) {
36
+ callBack(res);
37
+ return;
38
+ }
39
+ if(res.code == 0) {
40
+ that.data = res.data
41
+ }
42
+ })
43
+ }
44
+
45
+ /**
46
+ *根据请求URL解析对象
47
+ **/
48
+ common.getObject = (url, obj = ask) => {
49
+ let value = obj
50
+ let keys = url.split('.')
51
+ for (let i = 1; i < keys.length; i++) {
52
+ value = value[keys[i]]
53
+ }
54
+ return value
55
+ }
56
+
57
+ /**
58
+ * 表单的单据保存
59
+ * @param {*} that 指向 传入 this
60
+ * @param {*} url api 地址
61
+ * @param {*} query 查询条件 默认this.postForm
62
+ * @param {*} ref 表单校验 捆绑对象 想使用表单保存方法, 但不进行校验, 传值 false
63
+ * @param {*} callBack 接口返回后, 页面要进行后续操作,默认
64
+ *
65
+ * 调用方法后, 默认关闭弹窗页, 如果 不关闭弹窗, 或有其他业务处理, 参数 callBack(res) 回调当前页面处理
66
+ * 表单校验后,调用 api 之前, 如果要修改保存的值, 默认执行页面上 beforeSaveData (data)方法, return 返回处理好格式的数据
67
+
68
+ */
69
+ common.saveData = (that, url, query, ref, callBack) => {
70
+ let newQuery = query ? query : JSON.parse(JSON.stringify(that.postForm)); // 深拷贝, 避免影响页面显示
71
+ if(ref === false) {
72
+ common.handleData(that, url, newQuery, callBack)
73
+ } else {
74
+ let newRef = ref ? ref : that.$refs.pageDetail.$refs.postForm
75
+ newRef.validate(res => {
76
+ if(!res) return
77
+ if (that.beforeSaveData) {
78
+ newQuery = that['beforeSaveData'](newQuery);
79
+ }
80
+ common.handleData(that, url, newQuery, callBack)
81
+ })
82
+ }
83
+ }
84
+ /**
85
+ * 保存数据 一般作为 common.saveData 的内嵌方法使用, 不推荐单独使用 (表单提交,原则上要经过表单校验)
86
+ * @param {*} that 指向 传入 this
87
+ * @param {*} url api 地址
88
+ * @param {*} query 查询条件 默认this.postForm
89
+ * @param {*} callBack 接口返回后, 页面要进行后续操作
90
+ */
91
+
92
+ common.handleData = (that, url, query, callBack)=> {
93
+ let newQuery = query ? query : that.postForm;
94
+ if (that.loading !== undefined) that.loading = true;
95
+ let request = common.getObject(url)
96
+ request(newQuery ? newQuery : undefined).then((res) => {
97
+ if (that.loading !== undefined) that.loading = false;
98
+ if (res.code == 0) {
99
+ that.$message('保存成功');
100
+ if(!callBack) that.$emit('close')
101
+ }
102
+ if (callBack) callBack(res.data)
103
+ })
104
+
105
+ }
106
+
107
+
108
+ /**
109
+ * 查询单条信息
110
+ * @param {*} that
111
+ * @param {String} url 接口地址
112
+ * @param {Object} param 接口参数
113
+ * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
114
+ */
115
+ common.getById = (that, url, query, callBack) => {
116
+ let request = common.getObject(url)
117
+ request(query).then((res)=>{
118
+ if (res.code == 0) {
119
+ if (callBack) { callBack(res.data) }
120
+ else that.postForm = res.data
121
+ }
122
+ })
123
+ }
124
+
125
+ /**
126
+ * 修改单条信息
127
+ * @param {*} that
128
+ * @param {String} url 接口地址
129
+ * @param {Object} query 接口参数
130
+ * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
131
+ */
132
+ common.updateById = (that, url, query, callBack) => {
133
+ let newQuery = query ? query : that.postForm;
134
+ let request = common.getObject(url)
135
+ request(newQuery).then((res)=>{
136
+ if (res.code == 0) {
137
+ that.$message('操作成功');
138
+ if (callBack) { callBack(res.data) }
139
+ }
140
+ })
141
+ }
142
+ /**
143
+ * 判断多条数据 返回 true/false 或者 重新拼接好的 ids []
144
+ * @param {Object} that 传 this
145
+ * @param {Array} row 要判断的数据
146
+ * @param {String} title 无数据/ 提示操作的 关键字
147
+ * @param {String} prop 默认 id 要取出数组中哪个字段汇成新数组
148
+ * @param {Boolean} check 默认 true 二次弹窗确认即将要做的提醒
149
+ *
150
+ * 使用场景 (列表页上批量操作数据后刷新列表页)
151
+ * async updateRows () {
152
+ * let ids = await this.$common.checkRows(this, this.selectRows, 'xxx')
153
+ * if(!ids) retuen
154
+ * this.$common.updateData(that, 'ask.xxx.xxx', {保存对象})
155
+ * }
156
+ */
157
+ common.checkRows = async (that, row, title, prop = "id", check = true) => {
158
+ if(row.length == 0) {
159
+ common.message(that, `请选择数据`, 'error');
160
+ return false;
161
+ }
162
+ if(check) {
163
+ try {
164
+ await common.confirm(that, `您确定进行${title}操作`, '操作提醒')
165
+ return prop ? row.map(item => item[prop]) : row
166
+ } catch (error) {
167
+ return false
168
+ }
169
+ } else {
170
+ return true
171
+ }
172
+ }
173
+
174
+ /**
175
+ * 修改数据后, 刷新列表页
176
+ * @param {Object} that 传值 this
177
+ * @param {String} url api 地址
178
+ * @param {Object} query 接口参数
179
+ * @param {Function} callBack 接口响应成功后, 界面上自行处理返回事件, 不传, 默认执行页面 getList 方法 (刷新列表页)
180
+ */
181
+ common.updateData = (that, url, query, callBack) => {
182
+ let request = common.getObject(url)
183
+ request(Object.assign({}, query)).then(res => {
184
+ if(res.code !== 0) return
185
+ common.message(that, res.message)
186
+ if(callBack) callBack(res)
187
+ else that.getList && that.getList()
188
+ })
189
+ }
190
+
191
+
192
+ /**
193
+ * 消息弹窗---自动消失
194
+ * @param {*} that
195
+ * @param {String} message 内容
196
+ * @param {String} type 类型 可选值:查看element ui 文档, 默认 success
197
+ */
198
+ common.message = (that, message, type) => {
199
+ that.$message({
200
+ message: message,
201
+ type: type ? type : 'success'
202
+ });
203
+ }
204
+
205
+ /**
206
+ * 对话框
207
+ * @param {*} that
208
+ * @param {String} message 内容
209
+ * @param {String} title 标题 默认:提示
210
+ * @param {Function} callBack 返回函数, 页面在接口返回后要进行其他处理
211
+ */
212
+ common.confirm = (that, message, title, callBack) => {
213
+ let result = that.$confirm(message, title ? title : "提示", {
214
+ confirmButtonText: "确定",
215
+ cancelButtonText: "取消",
216
+ type: "none"
217
+ })
218
+ if(callBack) {
219
+ result.then(() => {
220
+ callBack(true)
221
+ })
222
+ .catch(() => {
223
+ callBack(false)
224
+ });
225
+ } else {
226
+ return result
227
+ }
228
+ }
229
+
230
+
231
+ /**
232
+ * 发起弹窗
233
+ * @param {*} options
234
+ * options { 参数
235
+ * title: string, 弹窗标题
236
+ * component: vue, 弹窗组件 --> 弹窗组内部取消弹窗 this.$emit('close', 要带给列表页的值)
237
+ * props: {id: '', name: '' }, 带给弹窗组件的 prop 集合
238
+ * srcData: {} , 带给弹窗组件的值 (已废弃, 不推荐使用, 推荐使用 props)
239
+ * width: string, 弹窗宽度
240
+ * showButton: Boolean , 是否显示 确认/取消按钮 (默认不显示) 显示时, 确认按钮默认触发组件页面的 confirm() 方法, beforeClose() 方法弹窗关闭前被调用,同时暂停实例的关闭, 参数 done ,此时若需要关闭实例,可以调用done方法
241
+ * callBack: function 获取 弹窗层返回值
242
+ * dialogCfg: 弹窗的高级配置, 具体参数查看 element ui 下的 el-dialog
243
+ * }
244
+ *
245
+ */
246
+ common.popup = (options) => {
247
+ if (!options) return;
248
+ let { title, component, srcData, width, showButton, callBack, props, dialogCfg } = common.clone(options);
249
+ if (!component) return;
250
+ let e = document.createElement("div");
251
+ document.getElementsByTagName("body")[0].appendChild(e);
252
+ let template = '';
253
+ let v = '';
254
+ if (typeof component == 'string') {
255
+ } else {
256
+ let button = '';
257
+ if (showButton) {
258
+ 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>`
259
+ }
260
+ 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>`
261
+ }
262
+ v = new Vue({
263
+ el: e,
264
+ template: template,
265
+ router,
266
+ store,
267
+ data: function () {
268
+ return {
269
+ title: title ? title : '弹窗组件',
270
+ visible: true,
271
+ width: width ? width : '30%',
272
+ props: props ? props : null,
273
+ srcData: srcData ? srcData : null,
274
+ dialogCfg: dialogCfg ? dialogCfg: null
275
+ }
276
+ },
277
+ components: {
278
+ child: component
279
+ },
280
+ methods: {
281
+ confirm() {
282
+ if (this.$refs.child.confirm) {
283
+ this.$refs.child.confirm();
284
+ }
285
+ },
286
+ beforeClose(done) {
287
+ if (this.$refs.child.beforeClose) {
288
+ this.$refs.child.beforeClose(done);
289
+ } else {
290
+ done()
291
+ }
292
+ },
293
+ cancel () {
294
+ this.visible = false
295
+ },
296
+ close(res) {
297
+ if (callBack) {
298
+ callBack(res);
299
+ }
300
+ this.visible = false
301
+ }
302
+ }
303
+ })
304
+ return v
305
+ }
306
+
307
+ /**
308
+ * 深度拷贝
309
+ */
310
+ common.clone = (obj) => {
311
+ // 其他类型
312
+ if (null == obj || 'object' == typeof (obj)) {
313
+ return obj
314
+ }
315
+ // 日期类型
316
+ if (obj instanceof Date) {
317
+ let copy = new Date();
318
+ copy.setTime(obj.getTime());
319
+ return copy;
320
+ }
321
+ //数组类型
322
+ if (obj instanceof Array) {
323
+ let copy = [];
324
+ for (let i = 0; index < obj.length; index++) {
325
+ copy[i] = common.clone(obj[i])
326
+ }
327
+ return copy
328
+ }
329
+ //对象类型
330
+ if (obj instanceof Object) {
331
+ let copy = {}
332
+ for (const key in obj) {
333
+ if (Object.hasOwnProperty.call(object, key)) {
334
+ copy[key] = common.copy(obj[key])
335
+ }
336
+ }
337
+ return copy
338
+ }
339
+
340
+ throw new Error("无法复制对象!不支持其类型")
341
+ }
342
+
343
+
344
+ /**
345
+ *导出数据报表
346
+ *@param query 默认 列表上的 query 条件去掉 data
347
+ *@param headers
348
+ *@param {String} url 请求方法
349
+ *@param {String} fileName 文件名
350
+ */
351
+ common.exportExcel = async (url, query, fileName = 'demo', headers = { responseType: 'arraybuffer' }) => {
352
+ let newQuery = JSON.parse(JSON.stringify(query))
353
+ delete newQuery.data
354
+ for (const key in newQuery) {
355
+ if(newQuery[key] == null || newQuery[key] === '')
356
+ delete newQuery[key]
357
+ }
358
+ const httpRequest = common.getObject(url)
359
+ const response = await httpRequest(newQuery, headers)
360
+ const blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' })
361
+ const objectUrl = URL.createObjectURL(blob)
362
+ const a = document.createElement('a')
363
+ document.body.appendChild(a)
364
+ a.style = 'display: none'
365
+ a.href = objectUrl
366
+ a.download = `${fileName}.xlsx`
367
+ a.click()
368
+ document.body.removeChild(a)
369
+ }
370
+
371
+ /**
372
+ * 从枚举中批量获取按钮
373
+ * @param {String} enumName 枚举名称
374
+ * @param {String} methodName 点击按钮需要调用的方法名
375
+ * @param {String} name 完整的按钮名称
376
+ *
377
+ */
378
+ common.getBtnListByEnum = (enumName, methodName, name = '') => {
379
+ let enums = OrgEnum[enumName];
380
+ let list = []
381
+ enums.filter(item => {
382
+ if(item.Id == null) return
383
+ list.push({name: name + item.Text, methodName, type: item.Id, row: item})
384
+ })
385
+ return list
386
+ }
387
+
388
+ /**
389
+ * 必填项列表
390
+ * @param {List} list 必填项字段名列表
391
+ */
392
+ common.requiredList = (list) => {
393
+ let obj = {}
394
+ list.forEach(key => {
395
+ obj[key] = filterRules({required: true})
396
+ });
397
+ return obj
398
+ }
399
+
400
+ /**
401
+ * 格式化数据样式
402
+ * @param {*} value 值
403
+ * @param {*} type 要格式化的类型 [date, price, price, money, enum, list(前端自定义枚举)]
404
+ * @returns
405
+ */
406
+ common.format = (value, type="date") => {
407
+ let newType = ['money', 'date', 'mdate'].includes(type) ? type : type.split('.').length > 1 ? 'enum' : 'list'
408
+ switch (newType) {
409
+ case 'money':
410
+ return Number(value).toFixed(4);
411
+ case 'date':
412
+ if(value === '1970-01-01T00:00:00') return '/'
413
+ return value ? value.replace('T', ' ').substr(0, 19) : ''
414
+ case 'mdate':
415
+ if(value === '1970-01-01T00:00:00') return '/'
416
+ return value ? value.replace('T', ' ').substr(5, 19) : ''
417
+ case 'price':
418
+ if(typeof(value) === 'number') {
419
+ return value.toFixed(2).toString().replace(/,/g,'').replace(/\d+/, function (n) { // 先提取整数部分
420
+ return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { // 对整数部分添加分隔符
421
+ return $1 + ",";
422
+ });
423
+ });
424
+ }
425
+ else return ''
426
+ case 'enum':
427
+ return getValueByType('enum', type, value)
428
+ case 'list':
429
+ return getValueByType('list', type, value)
430
+ default:
431
+ break;
432
+ }
433
+ function getValueByType (type, name, value) {
434
+ if(type === 'enum') {
435
+ let row = OrgEnum[name].find(item => item.Id == value)
436
+ return row ? row.Text : ''
437
+ } else if(type === 'list') {
438
+ let row = moduleCfg.format ? moduleCfg.format[name].find(item => item.id == value) : null
439
+ return row ? row.name: ''
440
+ }
441
+ }
442
+ }
443
+
444
+ /**
445
+ * 获取报表配置项
446
+ * @param {Object} that 指向 默认传 this
447
+ * @param {String} url 获取配置项 url
448
+ * @param {Object} query 接口参数
449
+ * @param {Function} callBack 自定义事件, 传此参数, 接口响应后, 后续事情自定义
450
+ * @param {String} methodName 接口响应后, 调用界面哪个方法
451
+ */
452
+ common.getReportCfg = (that, url, query, callBack, methodName = 'getReportList') => {
453
+ let request = common.getObject(url)
454
+ request(query).then(res => {
455
+ if(callBack) {
456
+ callBack(res)
457
+ } else {
458
+ that.config.reportList = res.data
459
+ if(res.data[0]) {
460
+ that.reportCfgVal = JSON.parse(res.data[0].jsonCfg)
461
+ that[methodName]();
462
+ }
463
+ }
464
+ })
465
+ }
466
+
467
+ /**
468
+ * 获取报表列表数据
469
+ * @param {*} that 指向 默认传 this
470
+ * @param {*} url 获取数据 url
471
+ * @param {*} query 接口参数 不传, 默认取值 this.data (查询条件) + this.reportCfgVal (报表配置项)
472
+ * @param {*} callBack 接口响应后, 自定义事件
473
+ */
474
+ common.getReportList = (that, url, query, callBack) => {
475
+ let newQuery = {}
476
+ if(query) newQuery = query
477
+ else {
478
+ let obj = Object.assign({}, that.data)
479
+ delete obj.data
480
+ // 移除空项查询条件
481
+ for (const key in obj) {
482
+ if(obj[key] == null || obj[key] === '')
483
+ delete obj[key]
484
+ }
485
+ newQuery = Object.assign(obj, {report: that.reportCfgVal})
486
+ }
487
+ let request = common.getObject(url)
488
+ request(newQuery).then(res => {
489
+ if(callBack) callBack(res)
490
+ else that.data = res.data
491
+ })
492
+ }
493
+
494
+
495
+ /**
496
+ * 字典表 里通过Id 查 name, 或者查询多条数据 (单条返回 name, 多条返回数组)
497
+ * @param {Array} props ['服务名', '表名', '字段名']
498
+ * @param {String, Number, Array} val 值, 传入id, 或者 [id1, id2, ...]
499
+ *
500
+ * 使用案例 (异步方法)
501
+ * async getValue () {
502
+ * await this.$common.dic(['qccuser', 'Brand'], '10010')
503
+ * }
504
+ *
505
+ */
506
+
507
+ common.dic = async (props, val) => {
508
+ let isArray = Array.isArray(val)
509
+ let server = props[0] || ''
510
+ let tableName = props[1] || ''
511
+ let prop = props[2] || 'name'
512
+ let key = server + tableName
513
+ if(store.getters.dic[key]) {
514
+ if(isArray) return await getDicVal()
515
+ let row = store.getters.dic[key].find(item => item.id == val)
516
+ if(row && (row.isNull || row[prop] === null)) { return '' }
517
+ if(row) return row[prop]
518
+ if(!row) return await getDicVal()
519
+
520
+ } else {
521
+ return await getDicVal()
522
+ }
523
+ async function getDicVal () {
524
+ let servers = props[0] || "";
525
+ let tableName = props[1] || "";
526
+ let key = servers + tableName;
527
+ let url = servers + "/UserAll/Search/Dic/" + tableName;
528
+ let res = await request.post(url, isArray ? val : [val])
529
+ if (res.code !== 0) return;
530
+ store.commit("dic/SET_ASK", { key, val: res.data });
531
+ if(isArray) return res.data
532
+ else {
533
+ let row = res.data.find(item => item.id == val)
534
+ return row ? row[prop] : ''
535
+ }
536
+ }
537
+ }
538
+ /**
539
+ * 快速给页面变量赋值
540
+ * @param {*} url 请求接口的地址
541
+ * @param {*} query 接口参数
542
+ * @param {*} prop 要为哪个字段名赋值
543
+ */
544
+ common.getLabelList = (that, prop, url, query) => {
545
+ common.getObject(url)(query).then(res => {
546
+ that[prop] = res.data
547
+ })
548
+ }
549
549
  export default common