vue2-client 1.12.78 → 1.12.80

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.
@@ -1,1014 +1,1014 @@
1
- <template>
2
- <div>
3
- <!-- 骨架屏 -->
4
- <a-card v-if="showSkeleton">
5
- <a-skeleton active />
6
- </a-card>
7
- <!-- 主体表格 -->
8
- <XReportDesign
9
- @selectRow="selectRow"
10
- @slotRendered="slotRendered"
11
- v-if="scanFinish"
12
- :display-only="displayOnly"
13
- :config="originalConfig"
14
- :slot-config-name="undefined"
15
- :for-display="true"
16
- ref="XReportDesign"
17
- :server-name="serverName"
18
- :env="env"
19
- :show-title="showTitle"
20
- >
21
- </XReportDesign>
22
- <a-row
23
- type="flex"
24
- justify="end"
25
- v-if="showSaveButton"
26
- >
27
- <a-space>
28
- <a-button @click="saveConfig">
29
- 提交
30
- </a-button>
31
- <a-button @click="cancelConfig">
32
- 取消
33
- </a-button>
34
- </a-space>
35
- </a-row>
36
- <!-- 弹出框 -->
37
- <x-add-report
38
- :env="env"
39
- ref="xAddReport"
40
- />
41
- <!-- 弹出框 -->
42
- <x-report-drawer
43
- :env="env"
44
- ref="xReportDrawer"
45
- />
46
- </div>
47
- </template>
48
-
49
- <script>
50
- // 转PDF用
51
- import { mapState } from 'vuex'
52
- import { getConfigByName, runLogic } from '@vue2-client/services/api/common'
53
- import XReportDesign from './XReportDesign.vue'
54
- import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
55
-
56
- // import XAddReport from '@vue2-client/base-client/components/common/XAddReport'
57
-
58
- export default {
59
- name: 'XReport',
60
- props: {
61
- files: {
62
- type: Array,
63
- default: () => {
64
- return []
65
- },
66
- },
67
- // 控制用户权限,user和admin
68
- authority: {
69
- type: String,
70
- default: 'user',
71
- },
72
- // 是否为编辑模式
73
- editMode: {
74
- type: Boolean,
75
- default: true,
76
- },
77
- // 配置名
78
- configName: {
79
- type: String,
80
- required: true,
81
- },
82
- // 插槽名
83
- activatedSlotName: {
84
- type: String,
85
- default: undefined,
86
- },
87
- // 本地配��,调试用
88
- localConfig: {
89
- type: Object,
90
- default: undefined,
91
- },
92
- // 兼容老版本配置
93
- dontFormat: {
94
- type: Boolean,
95
- default: true,
96
- },
97
- showImgInCell: {
98
- type: Boolean,
99
- default: false,
100
- },
101
- // 数据
102
- configData: {
103
- type: Object,
104
- default: undefined,
105
- },
106
- // 命名空间
107
- serverName: {
108
- type: String,
109
- default: process.env.VUE_APP_SYSTEM_NAME,
110
- },
111
- // 环境
112
- env: {
113
- type: String,
114
- default: 'prod',
115
- },
116
- // 只做展示
117
- displayOnly: {
118
- type: Boolean,
119
- default: true,
120
- },
121
- // 表格没有边距
122
- noPadding: {
123
- type: Boolean,
124
- default: true,
125
- },
126
- // 表格没有上边框,与noPadding搭配可以实现连续表格
127
- noTopBorder: {
128
- type: Boolean,
129
- default: false,
130
- },
131
- // 是否展示标题
132
- showTitle: {
133
- type: Boolean,
134
- default: true,
135
- },
136
- // 是否展示保存按钮
137
- showSaveButton: {
138
- type: Boolean,
139
- default: false,
140
- },
141
- // 是否将组件注册到外层提供的容器中,方便外侧统一保存
142
- registerMap: {
143
- type: Array,
144
- default: undefined,
145
- },
146
- // 是否小插件模式,小插件模式不会有各种边境
147
- isWidget: {
148
- type: Boolean,
149
- default: false,
150
- },
151
- // 图片是否使用OSS来保存
152
- useOssForImg: {
153
- type: Boolean,
154
- default: true,
155
- },
156
- // 图片上传后添加前缀
157
- imgPrefix: {
158
- type: String,
159
- default: undefined,
160
- },
161
- },
162
- components: {
163
- XAddReport: () =>
164
- import('@vue2-client/base-client/components/common/XAddReport'),
165
- XReportDrawer: () =>
166
- import('@vue2-client/base-client/components/common/XReportDrawer'),
167
- XReportDesign,
168
- },
169
- data () {
170
- return {
171
- // 控制骨架屏显隐
172
- showSkeleton: true,
173
- // 配置
174
- config: undefined,
175
- // 当前显示模式,编辑模式,预览模式
176
- type: 'design',
177
- // 仅供展示,不可编辑
178
- onlyDisplay: false,
179
- // 每行最大列数,非必要请勿更改,现在的设计器完全是基于每行12列来设计的
180
- maxColSpan: 12,
181
- // 定义是否完成配置的扫描,未完成不要渲染子组件
182
- scanFinish: false,
183
- // 当前激活的配置文件
184
- activeConfig: null,
185
- // 原始配置文件
186
- // 用于展示。某些情况下“设计页”中的内容仅为“预览页”表格其中的一部分
187
- originalConfig: null,
188
- // 扫描到的配置
189
- configFromWeb: {},
190
- // 用于获取配置的锁
191
- timer: undefined,
192
- // 是否包含图片
193
- hasImages: false,
194
- // 图片列表
195
- imageList: [],
196
- // 保存最原始的数据,用于判断哪些数据被更改了
197
- dataCache: undefined,
198
- // 判断哪些数据被更改了,存储对应的key
199
- diff: [],
200
- globalData: {},
201
- }
202
- },
203
- beforeDestroy () {
204
- clearInterval(this.timer)
205
- },
206
- watch: {
207
- // 如果配置名更改了,重新获取配置
208
- configName (val) {
209
- if (val) {
210
- getConfigByName(
211
- this.configName,
212
- undefined,
213
- (res) => {
214
- this.config = res
215
- this.configInit()
216
- },
217
- this.env === 'dev'
218
- )
219
- }
220
- },
221
- // 如果本地配置更改了,重新初始化
222
- localConfig: {
223
- deep: true,
224
- immediate: true,
225
- handler (val) {
226
- if (val) {
227
- this.config = val
228
- this.configInit()
229
- }
230
- },
231
- },
232
- },
233
- provide () {
234
- return {
235
- runLogic: runLogic,
236
- openDialog: this.openDialog,
237
- openDrawer: this.openDrawer,
238
- registerComponent: this.registerComponent,
239
- getComponentByName: this.getComponentByName,
240
- getParentComponentByName: this.getComponentByName,
241
- getConfigByName: getConfigByName,
242
- isWidget: this.widget,
243
- currUser: this.currUser,
244
- getGlobalData: this.getGlobalData,
245
- setGlobalData: this.setGlobalData
246
- }
247
- },
248
- methods: {
249
- slotRendered () {
250
- if (this.config?.mountedFunction) {
251
- let func = this.config.mountedFunction
252
- if (func && func.startsWith('function')) {
253
- func = func.replace('function', 'async function')
254
- executeStrFunctionByContext(this, func, [])
255
- }
256
- }
257
- },
258
- // 把组件注册到refs中,方便调用
259
- registerComponent (componentName, component) {
260
- console.log('内部注册', this.$options.name, componentName)
261
- this.$refs[componentName] = component
262
- console.log('内部注册完成', this.$refs)
263
- },
264
-
265
- // 把设计的table布局转换成可显示的珊格布局
266
- transformArray (inputList) {
267
- let operationIndex = 0
268
- let operationList = []
269
- const outputList = []
270
- for (const lst of inputList) {
271
- // 如果列表为空或只有一个元素,则所有元素相等。比较列表中每个元素是否与第一个元素相等
272
- if (
273
- lst.length >= 1 &&
274
- !lst.every(
275
- (x) =>
276
- Array.isArray(x) ||
277
- Array.isArray(lst[0]) ||
278
- x.rowSpan === lst[0].rowSpan
279
- )
280
- ) {
281
- operationList = lst
282
- break // 使用 break 退出整个循环
283
- } else {
284
- // 被操作的行
285
- operationIndex += 1
286
- }
287
- }
288
-
289
- let maxMergeRow = 0
290
-
291
- // 没有需要合并的行,直接返回
292
- if (operationList.length === 0) {
293
- return inputList
294
- } else {
295
- // 当前行的最大值
296
- const maxRow = Math.max(...operationList.map((item) => item.rowSpan))
297
- let mergeIndexCol = 0
298
- for (let index = 0; index < operationList.length; index++) {
299
- const row = operationList[index]
300
- let rowSpan = row.rowSpan
301
- // 需要合并的行
302
- let mergeIndexRow = operationIndex + 1
303
- // 存放合并后的行
304
- const rows = []
305
- // 添加当前行
306
- if (rowSpan < maxRow && mergeIndexRow < inputList.length) {
307
- rows.push([row])
308
- }
309
- // 当前需要被操作并且操作行没有超出列表的高度
310
- while (rowSpan < maxRow && mergeIndexRow < inputList.length) {
311
- rowSpan += inputList[mergeIndexRow][mergeIndexCol].rowSpan
312
- // 放一行到合并结果
313
- rows.push([inputList[mergeIndexRow][mergeIndexCol]])
314
- if (mergeIndexRow > maxMergeRow) {
315
- // 记录最多操作到了哪行
316
- maxMergeRow = mergeIndexRow
317
- }
318
- mergeIndexRow++
319
- }
320
- // operation_list赋值, 没有变化的,不处理
321
- if (rows.length !== 0) {
322
- operationList[index] = rows
323
- }
324
- if (row.rowSpan !== maxRow) {
325
- mergeIndexCol++ // 操作列转为下一列
326
- }
327
- }
328
- }
329
-
330
- // 组成outputlist, operation_list前部填入
331
- let putindex = 0
332
- while (operationIndex > 0) {
333
- outputList.push(inputList[putindex])
334
- putindex++
335
- operationIndex -= 1
336
- }
337
-
338
- outputList.push(operationList)
339
-
340
- // 组成outputlist, operation_list后部填入
341
- while (maxMergeRow < inputList.length - 1) {
342
- outputList.push(inputList[maxMergeRow + 1])
343
- maxMergeRow += 1
344
- }
345
-
346
- return this.transformArray(outputList)
347
- },
348
- // 根据名字从注册到组件中获取组件
349
- getComponentByName (componentName) {
350
- console.log('内部取组件', this.$options.name, componentName)
351
- console.log('内部组件内容', this.$refs)
352
- return this.$refs[componentName]
353
- },
354
- getGlobalData () {
355
- return this.globalData
356
- },
357
- setGlobalData (obj) {
358
- this.globalData = obj
359
- },
360
- /**
361
- * @param configName 栅格配置名称
362
- * @param selectedId 选中得id
363
- * @param mixinData 需要混入得数据
364
- * @param outEnv 其他传递给打开窗口的数据
365
- * @param attr 传递给Modal弹框用的信息
366
- */
367
- openDialog (configName, selectedId, mixinData, outEnv = {}, attr = {}) {
368
- console.log('openDialog', configName, selectedId)
369
- this.$refs.xAddReport.init({
370
- configName: configName,
371
- selectedId: selectedId,
372
- mixinData: mixinData,
373
- outEnv: outEnv,
374
- attr,
375
- })
376
- },
377
- openDrawer (configName, selectedId, mixinData, outEnv = {}, attr = {}) {
378
- console.log('openDialog', configName, selectedId)
379
- this.$refs.xReportDrawer.init({
380
- configName,
381
- selectedId,
382
- mixinData,
383
- outEnv,
384
- attr,
385
- })
386
- },
387
- // 向外暴露图片修改后的数据,某些外部需要自己管理图片的保存与修改
388
- updateImg (data) {
389
- this.$emit('updateImg', data)
390
- },
391
- // 导出数据,某些外部需要统一控制数据的变动
392
- exportData () {
393
- // 获取当前修改后的数据
394
- let tempData
395
- if (this.activeConfig === undefined || this.activeConfig === null) {
396
- tempData = this.originalConfig.data
397
- } else {
398
- const tempDataKeys = Object.keys(this.activeConfig.tempData)
399
- tempDataKeys.forEach((key) => {
400
- this.changeDeepObject(
401
- this.activeConfig.data,
402
- key,
403
- this.activeConfig.tempData[key]
404
- )
405
- })
406
- tempData = this.activeConfig.data
407
- }
408
- // 对比数据的差异
409
- this.diff = []
410
- this.compareProps(tempData, this.dataCache)
411
- this.diff.forEach((eachDiff) => {
412
- const arr = eachDiff.split('.')
413
- let targetData = tempData[arr[0]]
414
- if (arr.length !== 1) {
415
- for (let i = 1; i < arr.length - 1; i++) {
416
- const path = arr[i]
417
- targetData = targetData[path]
418
- }
419
- }
420
- // 将修改的数���,添加update = true属性
421
- targetData.update = true
422
- })
423
- return tempData
424
- },
425
- // 对比两个obj有哪里不同
426
- compareProps (obj1, obj2, path = '') {
427
- for (const key in obj1) {
428
- // 如果一个是undefined
429
- if (typeof obj2[key] === 'undefined') {
430
- this.diff.push(path + key)
431
- // 如果是数组长度不一样
432
- } else if (Array.isArray(obj1) && Array.isArray(obj2)) {
433
- if (obj1[key].length !== obj2[key].length) {
434
- this.diff.push(path + key)
435
- }
436
- // 如果都是对象,并且存在同样的key,递归子key
437
- } else if (
438
- typeof obj1[key] === 'object' &&
439
- typeof obj2[key] === 'object'
440
- ) {
441
- this.compareProps(obj1[key], obj2[key], path + key + '.')
442
- // 如果不是obj,对比其数据
443
- } else if (obj1[key] !== obj2[key]) {
444
- this.diff.push(path + key)
445
- }
446
- }
447
- },
448
- selectRow (selectedRowKeys, selectedRows) {
449
- this.table_selectedRowKeys = selectedRowKeys
450
- this.table_selectedRows = selectedRows
451
- console.log('')
452
- this.$emit('selectRow', selectedRowKeys, selectedRows)
453
- },
454
- // 注册组件到$refs中
455
- registerComponentToRefs (componentName, component) {
456
- this.$refs[componentName] = component
457
- },
458
-
459
- // 提交处理,调用配置中的函数
460
- saveConfig () {
461
- const funcStr = this.config.confirmFunction
462
- executeStrFunctionByContext(this, funcStr, [this])
463
- },
464
-
465
- // 取消处理
466
- cancelConfig () {
467
- this.$emit('cancel')
468
- },
469
-
470
- // 通过@@@分割临时变量,找到对应的key,并修改它的值
471
- changeDeepObject (obj, strPath, newVal) {
472
- const arr = strPath.split('@@@')
473
- if (obj[arr[0]] === undefined) {
474
- obj = obj.images
475
- }
476
- if (arr.length === 1) {
477
- obj[arr[0]] = newVal
478
- } else {
479
- let result = obj[arr[0]]
480
- arr.shift()
481
- while (arr.length > 1) {
482
- result = result[arr[0]]
483
- arr.shift()
484
- }
485
- if (result) {
486
- result[arr[0]] = newVal
487
- }
488
- }
489
- },
490
- // 检查slot是否在配置文件中包含,如果没有包含,则视为非法获取
491
- checkSlotDefine (config) {
492
- const slotsDeclare = config.slotsDeclare
493
- const total = slotsDeclare.length
494
- let count = 0
495
- slotsDeclare.forEach((declare) => {
496
- config.columns.forEach((row) => {
497
- row.forEach((cell) => {
498
- if (cell.slotConfig === declare) {
499
- count++
500
- }
501
- })
502
- })
503
- })
504
-
505
- return count === total
506
- },
507
- // 用于分割配置中的colums,将需要处理的数组提取出来
508
- formatConfigRow () {
509
- for (let i = 0; i < this.config.columns.length; i++) {
510
- // 对原始数组进行递归,依次将该位置拆分为三个部分,当前处理位置之前的,当前处理位置,当前处理位置之后的
511
- const before = this.config.columns.slice(0, i)
512
- const after = this.config.columns.slice(
513
- i + 1,
514
- this.config.columns.length
515
- )
516
-
517
- // 将当前处理的数组交给处理的方法
518
- const x = this.checkRow(this.config.columns[i])
519
-
520
- const newArr = []
521
-
522
- // 拼接之前的数组
523
- if (before.length > 0) {
524
- if (before.length >= 1) {
525
- before.forEach((item) => {
526
- newArr.push(item)
527
- })
528
- } else {
529
- newArr.push(before)
530
- }
531
- }
532
-
533
- // 拼接不需要更改当前节点处理完成的数组
534
- newArr.push(x.old)
535
-
536
- // 如果处理了新加的数据,拼接
537
- if (x.add.length > 0) {
538
- for (let j = 0; j < x.add.length; j++) {
539
- if (x.add[j]) {
540
- newArr.push(x.add[j])
541
- i++
542
- }
543
- }
544
- }
545
-
546
- // 拼接之后的数组
547
- if (after.length > 0) {
548
- if (after.length >= 1) {
549
- after.forEach((item) => {
550
- newArr.push(item)
551
- })
552
- } else {
553
- newArr.push(after)
554
- }
555
- }
556
-
557
- this.config.columns = newArr
558
- }
559
- },
560
- // 路径中含有@@@的key,将其解析,并返回其数据
561
- getDeepObject (obj, strPath) {
562
- const arr = strPath.split('@@@')
563
- let result = obj[arr[0]]
564
- arr.shift()
565
- try {
566
- while (arr.length > 0) {
567
- result = result[arr[0]]
568
- arr.shift()
569
- }
570
- } catch (e) {
571
- result = undefined
572
- }
573
- return result
574
- },
575
- // 处理colums数组,为声明了rowspan的单元格,自动匹配格式
576
- checkRow (rowArr) {
577
- // 不需要更改的数据
578
- const original = []
579
- // 需要更改新加的数据
580
- const addArr = []
581
- // 统计rowspan出现的总和
582
- let count = 0
583
- // 统计声明列需要的rowspan总数
584
- let total = 0
585
- // 是否为声明行
586
- let titleCellFlag = false
587
- // 是否为声明行后第一行
588
- let firstSubLine = false
589
- // 需要处理的行,新的index值
590
- let subRowIndex = 0
591
- // 新生成的行,临时存储
592
- const waitForAddArr = []
593
- // 用于记录声明行的colspan避免格式错误
594
- let preColSpan = 0
595
- // 用于统计循环次数,判断是否是最后一次
596
- let forEachCount = 0
597
-
598
- // 标记所有数据
599
- rowArr.forEach((cell) => {
600
- forEachCount++
601
- // 如果该行没有rowspan则默认其为1,不要影响统计结果
602
- if (!cell.rowSpan) {
603
- cell.rowSpan = 0
604
- }
605
-
606
- if (cell.text && total !== 0) {
607
- // 如果遇到了下一个声明行,证明rowspan少了一行,需要补充一个占位格
608
- const nullObj = {
609
- type: 'placeHolderColumn',
610
- order: subRowIndex,
611
- noBoarder: true,
612
- needSplit: true,
613
- colSpan: preColSpan,
614
- dontShowRow: true,
615
- }
616
- subRowIndex++
617
- waitForAddArr.push(nullObj)
618
- total = 0
619
- count = 0
620
- titleCellFlag = false
621
- firstSubLine = false
622
- } else if (
623
- total !== count + cell.rowSpan &&
624
- forEachCount === rowArr.length
625
- ) {
626
- // 如果没有遇到了下一个声明行,但已经是当前行最后一个数据,也证明rowspan少了一行,需要补充一个占位格
627
- const nullObj = {
628
- type: 'placeHolderColumn',
629
- order: subRowIndex,
630
- noBoarder: true,
631
- needSplit: true,
632
- colSpan: preColSpan,
633
- dontShowRow: true,
634
- }
635
- subRowIndex++
636
- waitForAddArr.push(nullObj)
637
- total = 0
638
- count = 0
639
- titleCellFlag = false
640
- firstSubLine = false
641
- }
642
-
643
- // 判断是否为声明行
644
- if (cell.text && total === 0) {
645
- // 将声明行声明的rowspan作为总数,判断下方rowspan相加是否等于声明行声明的数量
646
- total = cell.rowSpan
647
- titleCellFlag = false
648
- firstSubLine = true
649
- subRowIndex = 1
650
- cell.show = true
651
- cell.showRowSpan = total
652
- } else if (cell.rowSpan > 0 && !titleCellFlag && firstSubLine) {
653
- // 判断是否为声明行后首行,因为首行不需要移动
654
- count += cell.rowSpan
655
- firstSubLine = false
656
- cell.noBoarder = true
657
- cell.show = true
658
- cell.showRowSpan = total
659
- } else if (cell.rowSpan > 0 && !titleCellFlag && !firstSubLine) {
660
- // 既非声明行,也非首行,需要移动
661
- count += cell.rowSpan
662
- // cell.type = 'notShow'
663
- cell.needSplit = true
664
- cell.order = subRowIndex
665
- cell.dontShowRow = true
666
- subRowIndex++
667
-
668
- // 如果之前添加过空行补充位置,刚好最后一位还有内容,将其互换
669
- if (
670
- forEachCount === rowArr.length &&
671
- !waitForAddArr[waitForAddArr.length - 1].dataIndex
672
- ) {
673
- waitForAddArr[waitForAddArr.length - 1].order += 1
674
- cell.order -= 1
675
- waitForAddArr.push(cell)
676
- } else {
677
- waitForAddArr.push(cell)
678
- }
679
- }
680
-
681
- // 如果count和total相等了,证明已经处理完成。将计数器还原
682
- if (count === total) {
683
- total = 0
684
- count = 0
685
- titleCellFlag = false
686
- firstSubLine = false
687
- }
688
- // 保存上一个的colspan���保持生成的格子与原格式一致
689
- preColSpan = cell.colSpan
690
- })
691
-
692
- // 将所有不需要移动的放入original
693
- rowArr.forEach((cell) => {
694
- if (cell.needSplit !== true) {
695
- original.push(cell)
696
- }
697
- })
698
-
699
- // 增加新的数组
700
- waitForAddArr.forEach((cell) => {
701
- const target = cell.order
702
- // if (cell.type === 'notShow') {
703
- // cell.type = 'inputs'
704
- // }
705
- cell.noBoarder = true
706
- if (addArr[target] === undefined) {
707
- const temp = []
708
- temp.push(cell)
709
- addArr[target] = temp
710
- } else if (addArr[target].length > 0) {
711
- addArr[target].push(cell)
712
- }
713
- })
714
-
715
- // 如果没有新增,将单元格边框设置为显示
716
- if (addArr.length < 1) {
717
- original.forEach((cell) => {
718
- if (cell.type === 'input' || cell.type === 'inputs') {
719
- cell.noBoarder = false
720
- }
721
- })
722
- }
723
-
724
- return {
725
- old: original,
726
- add: addArr,
727
- }
728
- },
729
- // 扫描配置,如果有插槽则拼接插槽
730
- scanConfigSlot (config) {
731
- const columnsArr = config.columns
732
- for (let i = 0; i < columnsArr.length; i++) {
733
- for (let j = 0; j < columnsArr[i].length; j++) {
734
- // 如果发现type为slot,开始匹配对应的slot配置文件
735
- if (columnsArr[i][j].type === 'slot') {
736
- const targetName = columnsArr[i][j].slotConfig
737
- // 找不到目标插槽配置
738
- if (
739
- !this.configFromWeb[targetName] ||
740
- !this.configFromWeb[targetName].columns
741
- ) {
742
- console.error('无法找到目标插槽的配置!')
743
- return
744
- }
745
-
746
- // 替换columns,合并data
747
- config.columns[i] = []
748
- const before = config.columns.slice(0, i)
749
- let after = config.columns.slice(i + 1, config.columns.length)
750
-
751
- const addArr = []
752
- for (
753
- let k = 0;
754
- k < this.configFromWeb[targetName].columns.length;
755
- k++
756
- ) {
757
- const temp = []
758
- this.configFromWeb[targetName].columns[k].forEach((cell) => {
759
- temp.push(cell)
760
- })
761
- addArr.push(temp)
762
- }
763
-
764
- const newArr = []
765
- // 拼接之前的数组
766
- if (before.length > 0) {
767
- if (before.length >= 1) {
768
- before.forEach((item) => {
769
- newArr.push(item)
770
- })
771
- } else {
772
- newArr.push(before)
773
- }
774
- }
775
-
776
- addArr.forEach((arr) => {
777
- newArr.push(arr)
778
- })
779
-
780
- // 拼接之后的数组
781
- if (after.length === 1) {
782
- if (after[0].type === 'slot' || after[0][0].type === 'slot') {
783
- after = []
784
- }
785
- }
786
- if (after.length > 0) {
787
- if (after.length >= 1) {
788
- after.forEach((item) => {
789
- newArr.push(item)
790
- })
791
- } else {
792
- newArr.push(after)
793
- }
794
- }
795
-
796
- config.columns = newArr
797
- if (this.configFromWeb[targetName].slotsDeclare) {
798
- config.slotsDeclare = this.configFromWeb[targetName].slotsDeclare
799
- } else {
800
- config.slotsDeclare = []
801
- }
802
-
803
- if (
804
- config.data.images &&
805
- this.configFromWeb[targetName].data.images
806
- ) {
807
- config.data.images = {
808
- ...config.data.images,
809
- ...this.configFromWeb[targetName].data.images,
810
- }
811
- delete this.configFromWeb[targetName].data.images
812
- }
813
- config.data = {
814
- ...config.data,
815
- ...this.configFromWeb[targetName].data,
816
- }
817
- }
818
- }
819
- }
820
- this.config = config
821
- },
822
- // 扫描所有插槽名
823
- scanConfigName (config, resut) {
824
- if (config.slotsDeclare) {
825
- config.slotsDeclare.forEach((name) => {
826
- resut.push(name)
827
- })
828
- }
829
- },
830
- // 获取插槽
831
- getConfigAndJoin (config, outerLock) {
832
- // 检查主配置插槽声明是否合法
833
- const check = this.checkSlotDefine(config)
834
- const waitForDownloadSlotName = []
835
- if (check) {
836
- // 扫描主配置中声明的插槽名
837
- this.scanConfigName(config, waitForDownloadSlotName)
838
-
839
- const total = waitForDownloadSlotName.length
840
- let count = 0
841
-
842
- // 挨个获取插槽
843
- waitForDownloadSlotName.forEach((configName) => {
844
- getConfigByName(
845
- configName,
846
- this.serverName,
847
- (res) => {
848
- this.configFromWeb[configName] = res
849
- count++
850
- },
851
- this.env === 'dev'
852
- )
853
- })
854
-
855
- // 使用定时器循环判断锁状态,用于多个插槽,要等待统一获取完成之后,再进行下一步初始化
856
- const timer = setInterval(() => {
857
- console.log('插槽下载进度,当前:' + count + '/' + total)
858
- if (count >= total) {
859
- clearInterval(timer)
860
- this.scanConfigSlot(config)
861
- if (config.slotsDeclare.length > 0) {
862
- const lock = { status: true }
863
- this.getConfigAndJoin(config, lock)
864
- const innerTimer = setInterval(() => {
865
- if (!lock.status) {
866
- clearInterval(innerTimer)
867
- outerLock.status = false
868
- }
869
- }, 100)
870
- } else {
871
- outerLock.status = false
872
- }
873
- }
874
- }, 100)
875
- } else {
876
- console.error('插槽配置有误!')
877
- outerLock.status = false
878
- }
879
- },
880
- // 获取配置之后的初始化
881
- configInit () {
882
- console.log('拼接完成', this.config)
883
- // 将初始化好的配置拷贝一份留存
884
- this.originalConfig = Object.assign({}, this.config)
885
- if (!this.dontFormat) {
886
- // 扫描配置文件中有没有rowSpan,进行格式化调整
887
- this.formatConfigRow(this.config)
888
- }
889
- this.activeConfig = this.config
890
- this.showSkeleton = false
891
- // 判断是否有动态Index
892
- this.activeConfig.columns.forEach((row) => {
893
- row.forEach((cell) => {
894
- if (cell.dynamicDataIndex === true) {
895
- // 如果有动态index,取其函数,运行函数得到真实index保存
896
- // eslint-disable-next-line no-eval
897
- const func = eval(
898
- '(' + cell.customFunctionForDynamicDataIndex + ')'
899
- )
900
- cell.dataIndex = func(this.config)
901
- }
902
- // 处理 自定义函数的旧逻辑
903
- if (
904
- ['action', 'click'].includes(cell.eventType) &&
905
- cell.customFunction &&
906
- !cell.events
907
- ) {
908
- cell.events = []
909
- cell.events.push({
910
- type: cell.eventType,
911
- customFunction: cell.customFunction,
912
- })
913
- }
914
- })
915
- })
916
- // 将数据复制到临时数据中,带有@@@的数据,我们将其整体作为一个key保存,当编辑完成后,再将其解析,回填到需要的数据中
917
- this.activeConfig.tempData = {}
918
- // 是否有@@@深层引用
919
- this.activeConfig.columns.forEach((row) => {
920
- row.forEach((cell) => {
921
- // 将@@@解析
922
- if (
923
- cell.dataIndex !== undefined &&
924
- cell.dataIndex.indexOf('@@@') !== -1
925
- ) {
926
- this.activeConfig.tempData[cell.dataIndex] = this.getDeepObject(
927
- this.activeConfig.data,
928
- cell.dataIndex
929
- )
930
- }
931
- })
932
- })
933
-
934
- // 对配置进行转换
935
- console.log('转换前配置', this.config)
936
- this.originalConfig.columns = this.transformArray(
937
- JSON.parse(JSON.stringify(this.config.columns))
938
- )
939
- console.log('转换后的列描述', this.originalConfig.columns)
940
-
941
- this.$nextTick(() => {
942
- this.scanFinish = true
943
- })
944
- },
945
- },
946
- beforeMount () {
947
- // 如果只是展示
948
- if (this.displayOnly) {
949
- this.onlyDisplay = true
950
- this.type = 'display'
951
- }
952
- // 如果有本地配置,优先使用本地配置
953
- if (this.localConfig) {
954
- // 如果配置是普通渲染器
955
- this.config = this.localConfig
956
- if (this.configData !== undefined) {
957
- this.config.data = this.configData
958
- }
959
- if (this.config.data.images === undefined) {
960
- this.config.data.images = {}
961
- }
962
- this.configInit()
963
- } else {
964
- // 如果本地配置没有值,则从琉璃中获取
965
- getConfigByName(
966
- this.configName,
967
- this.serverName,
968
- (res) => {
969
- this.config = JSON.parse(JSON.stringify(res))
970
- if (this.configData !== undefined) {
971
- this.config.data = this.configData
972
- }
973
- if (this.config.data.images === undefined) {
974
- this.config.data.images = {}
975
- }
976
- this.configInit()
977
- },
978
- this.env === 'dev'
979
- )
980
- }
981
- },
982
- computed: {
983
- ...mapState('account', { currUser: 'user' }),
984
- widget () {
985
- return this.isWidget // 返回isWidget的值
986
- },
987
- },
988
- mounted () {
989
- // 如果外界传来了registerMap,我们将本VM对象注册到map中
990
- if (this.registerMap !== undefined) {
991
- this.registerMap.push(this)
992
- }
993
- // 将原始数据备份保存
994
- if (this.configData) {
995
- this.dataCache = JSON.parse(JSON.stringify(this.configData))
996
- } else {
997
- if (this.config?.data) {
998
- this.dataCache = JSON.parse(JSON.stringify(this.config.data))
999
- }
1000
- }
1001
- },
1002
- }
1003
- </script>
1004
-
1005
- <style lang="less" scoped>
1006
- .tools {
1007
- text-align: center;
1008
- cursor: pointer;
1009
-
1010
- .toolsItem {
1011
- display: inline-block;
1012
- }
1013
- }
1014
- </style>
1
+ <template>
2
+ <div>
3
+ <!-- 骨架屏 -->
4
+ <a-card v-if="showSkeleton">
5
+ <a-skeleton active />
6
+ </a-card>
7
+ <!-- 主体表格 -->
8
+ <XReportDesign
9
+ @selectRow="selectRow"
10
+ @slotRendered="slotRendered"
11
+ v-if="scanFinish"
12
+ :display-only="displayOnly"
13
+ :config="originalConfig"
14
+ :slot-config-name="undefined"
15
+ :for-display="true"
16
+ ref="XReportDesign"
17
+ :server-name="serverName"
18
+ :env="env"
19
+ :show-title="showTitle"
20
+ >
21
+ </XReportDesign>
22
+ <a-row
23
+ type="flex"
24
+ justify="end"
25
+ v-if="showSaveButton"
26
+ >
27
+ <a-space>
28
+ <a-button @click="saveConfig">
29
+ 提交
30
+ </a-button>
31
+ <a-button @click="cancelConfig">
32
+ 取消
33
+ </a-button>
34
+ </a-space>
35
+ </a-row>
36
+ <!-- 弹出框 -->
37
+ <x-add-report
38
+ :env="env"
39
+ ref="xAddReport"
40
+ />
41
+ <!-- 弹出框 -->
42
+ <x-report-drawer
43
+ :env="env"
44
+ ref="xReportDrawer"
45
+ />
46
+ </div>
47
+ </template>
48
+
49
+ <script>
50
+ // 转PDF用
51
+ import { mapState } from 'vuex'
52
+ import { getConfigByName, runLogic } from '@vue2-client/services/api/common'
53
+ import XReportDesign from './XReportDesign.vue'
54
+ import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
55
+
56
+ // import XAddReport from '@vue2-client/base-client/components/common/XAddReport'
57
+
58
+ export default {
59
+ name: 'XReport',
60
+ props: {
61
+ files: {
62
+ type: Array,
63
+ default: () => {
64
+ return []
65
+ },
66
+ },
67
+ // 控制用户权限,user和admin
68
+ authority: {
69
+ type: String,
70
+ default: 'user',
71
+ },
72
+ // 是否为编辑模式
73
+ editMode: {
74
+ type: Boolean,
75
+ default: true,
76
+ },
77
+ // 配置名
78
+ configName: {
79
+ type: String,
80
+ required: true,
81
+ },
82
+ // 插槽名
83
+ activatedSlotName: {
84
+ type: String,
85
+ default: undefined,
86
+ },
87
+ // 本地配��,调试用
88
+ localConfig: {
89
+ type: Object,
90
+ default: undefined,
91
+ },
92
+ // 兼容老版本配置
93
+ dontFormat: {
94
+ type: Boolean,
95
+ default: true,
96
+ },
97
+ showImgInCell: {
98
+ type: Boolean,
99
+ default: false,
100
+ },
101
+ // 数据
102
+ configData: {
103
+ type: Object,
104
+ default: undefined,
105
+ },
106
+ // 命名空间
107
+ serverName: {
108
+ type: String,
109
+ default: process.env.VUE_APP_SYSTEM_NAME,
110
+ },
111
+ // 环境
112
+ env: {
113
+ type: String,
114
+ default: 'prod',
115
+ },
116
+ // 只做展示
117
+ displayOnly: {
118
+ type: Boolean,
119
+ default: true,
120
+ },
121
+ // 表格没有边距
122
+ noPadding: {
123
+ type: Boolean,
124
+ default: true,
125
+ },
126
+ // 表格没有上边框,与noPadding搭配可以实现连续表格
127
+ noTopBorder: {
128
+ type: Boolean,
129
+ default: false,
130
+ },
131
+ // 是否展示标题
132
+ showTitle: {
133
+ type: Boolean,
134
+ default: true,
135
+ },
136
+ // 是否展示保存按钮
137
+ showSaveButton: {
138
+ type: Boolean,
139
+ default: false,
140
+ },
141
+ // 是否将组件注册到外层提供的容器中,方便外侧统一保存
142
+ registerMap: {
143
+ type: Array,
144
+ default: undefined,
145
+ },
146
+ // 是否小插件模式,小插件模式不会有各种边境
147
+ isWidget: {
148
+ type: Boolean,
149
+ default: false,
150
+ },
151
+ // 图片是否使用OSS来保存
152
+ useOssForImg: {
153
+ type: Boolean,
154
+ default: true,
155
+ },
156
+ // 图片上传后添加前缀
157
+ imgPrefix: {
158
+ type: String,
159
+ default: undefined,
160
+ },
161
+ },
162
+ components: {
163
+ XAddReport: () =>
164
+ import('@vue2-client/base-client/components/common/XAddReport'),
165
+ XReportDrawer: () =>
166
+ import('@vue2-client/base-client/components/common/XReportDrawer'),
167
+ XReportDesign,
168
+ },
169
+ data () {
170
+ return {
171
+ // 控制骨架屏显隐
172
+ showSkeleton: true,
173
+ // 配置
174
+ config: undefined,
175
+ // 当前显示模式,编辑模式,预览模式
176
+ type: 'design',
177
+ // 仅供展示,不可编辑
178
+ onlyDisplay: false,
179
+ // 每行最大列数,非必要请勿更改,现在的设计器完全是基于每行12列来设计的
180
+ maxColSpan: 12,
181
+ // 定义是否完成配置的扫描,未完成不要渲染子组件
182
+ scanFinish: false,
183
+ // 当前激活的配置文件
184
+ activeConfig: null,
185
+ // 原始配置文件
186
+ // 用于展示。某些情况下“设计页”中的内容仅为“预览页”表格其中的一部分
187
+ originalConfig: null,
188
+ // 扫描到的配置
189
+ configFromWeb: {},
190
+ // 用于获取配置的锁
191
+ timer: undefined,
192
+ // 是否包含图片
193
+ hasImages: false,
194
+ // 图片列表
195
+ imageList: [],
196
+ // 保存最原始的数据,用于判断哪些数据被更改了
197
+ dataCache: undefined,
198
+ // 判断哪些数据被更改了,存储对应的key
199
+ diff: [],
200
+ globalData: {},
201
+ }
202
+ },
203
+ beforeDestroy () {
204
+ clearInterval(this.timer)
205
+ },
206
+ watch: {
207
+ // 如果配置名更改了,重新获取配置
208
+ configName (val) {
209
+ if (val) {
210
+ getConfigByName(
211
+ this.configName,
212
+ undefined,
213
+ (res) => {
214
+ this.config = res
215
+ this.configInit()
216
+ },
217
+ this.env === 'dev'
218
+ )
219
+ }
220
+ },
221
+ // 如果本地配置更改了,重新初始化
222
+ localConfig: {
223
+ deep: true,
224
+ immediate: true,
225
+ handler (val) {
226
+ if (val) {
227
+ this.config = val
228
+ this.configInit()
229
+ }
230
+ },
231
+ },
232
+ },
233
+ provide () {
234
+ return {
235
+ runLogic: runLogic,
236
+ openDialog: this.openDialog,
237
+ openDrawer: this.openDrawer,
238
+ registerComponent: this.registerComponent,
239
+ getComponentByName: this.getComponentByName,
240
+ getParentComponentByName: this.getComponentByName,
241
+ getConfigByName: getConfigByName,
242
+ isWidget: this.widget,
243
+ currUser: this.currUser,
244
+ getGlobalData: this.getGlobalData,
245
+ setGlobalData: this.setGlobalData
246
+ }
247
+ },
248
+ methods: {
249
+ slotRendered () {
250
+ if (this.config?.mountedFunction) {
251
+ let func = this.config.mountedFunction
252
+ if (func && func.startsWith('function')) {
253
+ func = func.replace('function', 'async function')
254
+ executeStrFunctionByContext(this, func, [])
255
+ }
256
+ }
257
+ },
258
+ // 把组件注册到refs中,方便调用
259
+ registerComponent (componentName, component) {
260
+ console.log('内部注册', this.$options.name, componentName)
261
+ this.$refs[componentName] = component
262
+ console.log('内部注册完成', this.$refs)
263
+ },
264
+
265
+ // 把设计的table布局转换成可显示的珊格布局
266
+ transformArray (inputList) {
267
+ let operationIndex = 0
268
+ let operationList = []
269
+ const outputList = []
270
+ for (const lst of inputList) {
271
+ // 如果列表为空或只有一个元素,则所有元素相等。比较列表中每个元素是否与第一个元素相等
272
+ if (
273
+ lst.length >= 1 &&
274
+ !lst.every(
275
+ (x) =>
276
+ Array.isArray(x) ||
277
+ Array.isArray(lst[0]) ||
278
+ x.rowSpan === lst[0].rowSpan
279
+ )
280
+ ) {
281
+ operationList = lst
282
+ break // 使用 break 退出整个循环
283
+ } else {
284
+ // 被操作的行
285
+ operationIndex += 1
286
+ }
287
+ }
288
+
289
+ let maxMergeRow = 0
290
+
291
+ // 没有需要合并的行,直接返回
292
+ if (operationList.length === 0) {
293
+ return inputList
294
+ } else {
295
+ // 当前行的最大值
296
+ const maxRow = Math.max(...operationList.map((item) => item.rowSpan))
297
+ let mergeIndexCol = 0
298
+ for (let index = 0; index < operationList.length; index++) {
299
+ const row = operationList[index]
300
+ let rowSpan = row.rowSpan
301
+ // 需要合并的行
302
+ let mergeIndexRow = operationIndex + 1
303
+ // 存放合并后的行
304
+ const rows = []
305
+ // 添加当前行
306
+ if (rowSpan < maxRow && mergeIndexRow < inputList.length) {
307
+ rows.push([row])
308
+ }
309
+ // 当前需要被操作并且操作行没有超出列表的高度
310
+ while (rowSpan < maxRow && mergeIndexRow < inputList.length) {
311
+ rowSpan += inputList[mergeIndexRow][mergeIndexCol].rowSpan
312
+ // 放一行到合并结果
313
+ rows.push([inputList[mergeIndexRow][mergeIndexCol]])
314
+ if (mergeIndexRow > maxMergeRow) {
315
+ // 记录最多操作到了哪行
316
+ maxMergeRow = mergeIndexRow
317
+ }
318
+ mergeIndexRow++
319
+ }
320
+ // operation_list赋值, 没有变化的,不处理
321
+ if (rows.length !== 0) {
322
+ operationList[index] = rows
323
+ }
324
+ if (row.rowSpan !== maxRow) {
325
+ mergeIndexCol++ // 操作列转为下一列
326
+ }
327
+ }
328
+ }
329
+
330
+ // 组成outputlist, operation_list前部填入
331
+ let putindex = 0
332
+ while (operationIndex > 0) {
333
+ outputList.push(inputList[putindex])
334
+ putindex++
335
+ operationIndex -= 1
336
+ }
337
+
338
+ outputList.push(operationList)
339
+
340
+ // 组成outputlist, operation_list后部填入
341
+ while (maxMergeRow < inputList.length - 1) {
342
+ outputList.push(inputList[maxMergeRow + 1])
343
+ maxMergeRow += 1
344
+ }
345
+
346
+ return this.transformArray(outputList)
347
+ },
348
+ // 根据名字从注册到组件中获取组件
349
+ getComponentByName (componentName) {
350
+ console.log('内部取组件', this.$options.name, componentName)
351
+ console.log('内部组件内容', this.$refs)
352
+ return this.$refs[componentName]
353
+ },
354
+ getGlobalData () {
355
+ return this.globalData
356
+ },
357
+ setGlobalData (obj) {
358
+ this.globalData = obj
359
+ },
360
+ /**
361
+ * @param configName 栅格配置名称
362
+ * @param selectedId 选中得id
363
+ * @param mixinData 需要混入得数据
364
+ * @param outEnv 其他传递给打开窗口的数据
365
+ * @param attr 传递给Modal弹框用的信息
366
+ */
367
+ openDialog (configName, selectedId, mixinData, outEnv = {}, attr = {}) {
368
+ console.log('openDialog', configName, selectedId)
369
+ this.$refs.xAddReport.init({
370
+ configName: configName,
371
+ selectedId: selectedId,
372
+ mixinData: mixinData,
373
+ outEnv: outEnv,
374
+ attr,
375
+ })
376
+ },
377
+ openDrawer (configName, selectedId, mixinData, outEnv = {}, attr = {}) {
378
+ console.log('openDialog', configName, selectedId)
379
+ this.$refs.xReportDrawer.init({
380
+ configName,
381
+ selectedId,
382
+ mixinData,
383
+ outEnv,
384
+ attr,
385
+ })
386
+ },
387
+ // 向外暴露图片修改后的数据,某些外部需要自己管理图片的保存与修改
388
+ updateImg (data) {
389
+ this.$emit('updateImg', data)
390
+ },
391
+ // 导出数据,某些外部需要统一控制数据的变动
392
+ exportData () {
393
+ // 获取当前修改后的数据
394
+ let tempData
395
+ if (this.activeConfig === undefined || this.activeConfig === null) {
396
+ tempData = this.originalConfig.data
397
+ } else {
398
+ const tempDataKeys = Object.keys(this.activeConfig.tempData)
399
+ tempDataKeys.forEach((key) => {
400
+ this.changeDeepObject(
401
+ this.activeConfig.data,
402
+ key,
403
+ this.activeConfig.tempData[key]
404
+ )
405
+ })
406
+ tempData = this.activeConfig.data
407
+ }
408
+ // 对比数据的差异
409
+ this.diff = []
410
+ this.compareProps(tempData, this.dataCache)
411
+ this.diff.forEach((eachDiff) => {
412
+ const arr = eachDiff.split('.')
413
+ let targetData = tempData[arr[0]]
414
+ if (arr.length !== 1) {
415
+ for (let i = 1; i < arr.length - 1; i++) {
416
+ const path = arr[i]
417
+ targetData = targetData[path]
418
+ }
419
+ }
420
+ // 将修改的数���,添加update = true属性
421
+ targetData.update = true
422
+ })
423
+ return tempData
424
+ },
425
+ // 对比两个obj有哪里不同
426
+ compareProps (obj1, obj2, path = '') {
427
+ for (const key in obj1) {
428
+ // 如果一个是undefined
429
+ if (typeof obj2[key] === 'undefined') {
430
+ this.diff.push(path + key)
431
+ // 如果是数组长度不一样
432
+ } else if (Array.isArray(obj1) && Array.isArray(obj2)) {
433
+ if (obj1[key].length !== obj2[key].length) {
434
+ this.diff.push(path + key)
435
+ }
436
+ // 如果都是对象,并且存在同样的key,递归子key
437
+ } else if (
438
+ typeof obj1[key] === 'object' &&
439
+ typeof obj2[key] === 'object'
440
+ ) {
441
+ this.compareProps(obj1[key], obj2[key], path + key + '.')
442
+ // 如果不是obj,对比其数据
443
+ } else if (obj1[key] !== obj2[key]) {
444
+ this.diff.push(path + key)
445
+ }
446
+ }
447
+ },
448
+ selectRow (selectedRowKeys, selectedRows) {
449
+ this.table_selectedRowKeys = selectedRowKeys
450
+ this.table_selectedRows = selectedRows
451
+ console.log('')
452
+ this.$emit('selectRow', selectedRowKeys, selectedRows)
453
+ },
454
+ // 注册组件到$refs中
455
+ registerComponentToRefs (componentName, component) {
456
+ this.$refs[componentName] = component
457
+ },
458
+
459
+ // 提交处理,调用配置中的函数
460
+ saveConfig () {
461
+ const funcStr = this.config.confirmFunction
462
+ executeStrFunctionByContext(this, funcStr, [this])
463
+ },
464
+
465
+ // 取消处理
466
+ cancelConfig () {
467
+ this.$emit('cancel')
468
+ },
469
+
470
+ // 通过@@@分割临时变量,找到对应的key,并修改它的值
471
+ changeDeepObject (obj, strPath, newVal) {
472
+ const arr = strPath.split('@@@')
473
+ if (obj[arr[0]] === undefined) {
474
+ obj = obj.images
475
+ }
476
+ if (arr.length === 1) {
477
+ obj[arr[0]] = newVal
478
+ } else {
479
+ let result = obj[arr[0]]
480
+ arr.shift()
481
+ while (arr.length > 1) {
482
+ result = result[arr[0]]
483
+ arr.shift()
484
+ }
485
+ if (result) {
486
+ result[arr[0]] = newVal
487
+ }
488
+ }
489
+ },
490
+ // 检查slot是否在配置文件中包含,如果没有包含,则视为非法获取
491
+ checkSlotDefine (config) {
492
+ const slotsDeclare = config.slotsDeclare
493
+ const total = slotsDeclare.length
494
+ let count = 0
495
+ slotsDeclare.forEach((declare) => {
496
+ config.columns.forEach((row) => {
497
+ row.forEach((cell) => {
498
+ if (cell.slotConfig === declare) {
499
+ count++
500
+ }
501
+ })
502
+ })
503
+ })
504
+
505
+ return count === total
506
+ },
507
+ // 用于分割配置中的colums,将需要处理的数组提取出来
508
+ formatConfigRow () {
509
+ for (let i = 0; i < this.config.columns.length; i++) {
510
+ // 对原始数组进行递归,依次将该位置拆分为三个部分,当前处理位置之前的,当前处理位置,当前处理位置之后的
511
+ const before = this.config.columns.slice(0, i)
512
+ const after = this.config.columns.slice(
513
+ i + 1,
514
+ this.config.columns.length
515
+ )
516
+
517
+ // 将当前处理的数组交给处理的方法
518
+ const x = this.checkRow(this.config.columns[i])
519
+
520
+ const newArr = []
521
+
522
+ // 拼接之前的数组
523
+ if (before.length > 0) {
524
+ if (before.length >= 1) {
525
+ before.forEach((item) => {
526
+ newArr.push(item)
527
+ })
528
+ } else {
529
+ newArr.push(before)
530
+ }
531
+ }
532
+
533
+ // 拼接不需要更改当前节点处理完成的数组
534
+ newArr.push(x.old)
535
+
536
+ // 如果处理了新加的数据,拼接
537
+ if (x.add.length > 0) {
538
+ for (let j = 0; j < x.add.length; j++) {
539
+ if (x.add[j]) {
540
+ newArr.push(x.add[j])
541
+ i++
542
+ }
543
+ }
544
+ }
545
+
546
+ // 拼接之后的数组
547
+ if (after.length > 0) {
548
+ if (after.length >= 1) {
549
+ after.forEach((item) => {
550
+ newArr.push(item)
551
+ })
552
+ } else {
553
+ newArr.push(after)
554
+ }
555
+ }
556
+
557
+ this.config.columns = newArr
558
+ }
559
+ },
560
+ // 路径中含有@@@的key,将其解析,并返回其数据
561
+ getDeepObject (obj, strPath) {
562
+ const arr = strPath.split('@@@')
563
+ let result = obj[arr[0]]
564
+ arr.shift()
565
+ try {
566
+ while (arr.length > 0) {
567
+ result = result[arr[0]]
568
+ arr.shift()
569
+ }
570
+ } catch (e) {
571
+ result = undefined
572
+ }
573
+ return result
574
+ },
575
+ // 处理colums数组,为声明了rowspan的单元格,自动匹配格式
576
+ checkRow (rowArr) {
577
+ // 不需要更改的数据
578
+ const original = []
579
+ // 需要更改新加的数据
580
+ const addArr = []
581
+ // 统计rowspan出现的总和
582
+ let count = 0
583
+ // 统计声明列需要的rowspan总数
584
+ let total = 0
585
+ // 是否为声明行
586
+ let titleCellFlag = false
587
+ // 是否为声明行后第一行
588
+ let firstSubLine = false
589
+ // 需要处理的行,新的index值
590
+ let subRowIndex = 0
591
+ // 新生成的行,临时存储
592
+ const waitForAddArr = []
593
+ // 用于记录声明行的colspan避免格式错误
594
+ let preColSpan = 0
595
+ // 用于统计循环次数,判断是否是最后一次
596
+ let forEachCount = 0
597
+
598
+ // 标记所有数据
599
+ rowArr.forEach((cell) => {
600
+ forEachCount++
601
+ // 如果该行没有rowspan则默认其为1,不要影响统计结果
602
+ if (!cell.rowSpan) {
603
+ cell.rowSpan = 0
604
+ }
605
+
606
+ if (cell.text && total !== 0) {
607
+ // 如果遇到了下一个声明行,证明rowspan少了一行,需要补充一个占位格
608
+ const nullObj = {
609
+ type: 'placeHolderColumn',
610
+ order: subRowIndex,
611
+ noBoarder: true,
612
+ needSplit: true,
613
+ colSpan: preColSpan,
614
+ dontShowRow: true,
615
+ }
616
+ subRowIndex++
617
+ waitForAddArr.push(nullObj)
618
+ total = 0
619
+ count = 0
620
+ titleCellFlag = false
621
+ firstSubLine = false
622
+ } else if (
623
+ total !== count + cell.rowSpan &&
624
+ forEachCount === rowArr.length
625
+ ) {
626
+ // 如果没有遇到了下一个声明行,但已经是当前行最后一个数据,也证明rowspan少了一行,需要补充一个占位格
627
+ const nullObj = {
628
+ type: 'placeHolderColumn',
629
+ order: subRowIndex,
630
+ noBoarder: true,
631
+ needSplit: true,
632
+ colSpan: preColSpan,
633
+ dontShowRow: true,
634
+ }
635
+ subRowIndex++
636
+ waitForAddArr.push(nullObj)
637
+ total = 0
638
+ count = 0
639
+ titleCellFlag = false
640
+ firstSubLine = false
641
+ }
642
+
643
+ // 判断是否为声明行
644
+ if (cell.text && total === 0) {
645
+ // 将声明行声明的rowspan作为总数,判断下方rowspan相加是否等于声明行声明的数量
646
+ total = cell.rowSpan
647
+ titleCellFlag = false
648
+ firstSubLine = true
649
+ subRowIndex = 1
650
+ cell.show = true
651
+ cell.showRowSpan = total
652
+ } else if (cell.rowSpan > 0 && !titleCellFlag && firstSubLine) {
653
+ // 判断是否为声明行后首行,因为首行不需要移动
654
+ count += cell.rowSpan
655
+ firstSubLine = false
656
+ cell.noBoarder = true
657
+ cell.show = true
658
+ cell.showRowSpan = total
659
+ } else if (cell.rowSpan > 0 && !titleCellFlag && !firstSubLine) {
660
+ // 既非声明行,也非首行,需要移动
661
+ count += cell.rowSpan
662
+ // cell.type = 'notShow'
663
+ cell.needSplit = true
664
+ cell.order = subRowIndex
665
+ cell.dontShowRow = true
666
+ subRowIndex++
667
+
668
+ // 如果之前添加过空行补充位置,刚好最后一位还有内容,将其互换
669
+ if (
670
+ forEachCount === rowArr.length &&
671
+ !waitForAddArr[waitForAddArr.length - 1].dataIndex
672
+ ) {
673
+ waitForAddArr[waitForAddArr.length - 1].order += 1
674
+ cell.order -= 1
675
+ waitForAddArr.push(cell)
676
+ } else {
677
+ waitForAddArr.push(cell)
678
+ }
679
+ }
680
+
681
+ // 如果count和total相等了,证明已经处理完成。将计数器还原
682
+ if (count === total) {
683
+ total = 0
684
+ count = 0
685
+ titleCellFlag = false
686
+ firstSubLine = false
687
+ }
688
+ // 保存上一个的colspan���保持生成的格子与原格式一致
689
+ preColSpan = cell.colSpan
690
+ })
691
+
692
+ // 将所有不需要移动的放入original
693
+ rowArr.forEach((cell) => {
694
+ if (cell.needSplit !== true) {
695
+ original.push(cell)
696
+ }
697
+ })
698
+
699
+ // 增加新的数组
700
+ waitForAddArr.forEach((cell) => {
701
+ const target = cell.order
702
+ // if (cell.type === 'notShow') {
703
+ // cell.type = 'inputs'
704
+ // }
705
+ cell.noBoarder = true
706
+ if (addArr[target] === undefined) {
707
+ const temp = []
708
+ temp.push(cell)
709
+ addArr[target] = temp
710
+ } else if (addArr[target].length > 0) {
711
+ addArr[target].push(cell)
712
+ }
713
+ })
714
+
715
+ // 如果没有新增,将单元格边框设置为显示
716
+ if (addArr.length < 1) {
717
+ original.forEach((cell) => {
718
+ if (cell.type === 'input' || cell.type === 'inputs') {
719
+ cell.noBoarder = false
720
+ }
721
+ })
722
+ }
723
+
724
+ return {
725
+ old: original,
726
+ add: addArr,
727
+ }
728
+ },
729
+ // 扫描配置,如果有插槽则拼接插槽
730
+ scanConfigSlot (config) {
731
+ const columnsArr = config.columns
732
+ for (let i = 0; i < columnsArr.length; i++) {
733
+ for (let j = 0; j < columnsArr[i].length; j++) {
734
+ // 如果发现type为slot,开始匹配对应的slot配置文件
735
+ if (columnsArr[i][j].type === 'slot') {
736
+ const targetName = columnsArr[i][j].slotConfig
737
+ // 找不到目标插槽配置
738
+ if (
739
+ !this.configFromWeb[targetName] ||
740
+ !this.configFromWeb[targetName].columns
741
+ ) {
742
+ console.error('无法找到目标插槽的配置!')
743
+ return
744
+ }
745
+
746
+ // 替换columns,合并data
747
+ config.columns[i] = []
748
+ const before = config.columns.slice(0, i)
749
+ let after = config.columns.slice(i + 1, config.columns.length)
750
+
751
+ const addArr = []
752
+ for (
753
+ let k = 0;
754
+ k < this.configFromWeb[targetName].columns.length;
755
+ k++
756
+ ) {
757
+ const temp = []
758
+ this.configFromWeb[targetName].columns[k].forEach((cell) => {
759
+ temp.push(cell)
760
+ })
761
+ addArr.push(temp)
762
+ }
763
+
764
+ const newArr = []
765
+ // 拼接之前的数组
766
+ if (before.length > 0) {
767
+ if (before.length >= 1) {
768
+ before.forEach((item) => {
769
+ newArr.push(item)
770
+ })
771
+ } else {
772
+ newArr.push(before)
773
+ }
774
+ }
775
+
776
+ addArr.forEach((arr) => {
777
+ newArr.push(arr)
778
+ })
779
+
780
+ // 拼接之后的数组
781
+ if (after.length === 1) {
782
+ if (after[0].type === 'slot' || after[0][0].type === 'slot') {
783
+ after = []
784
+ }
785
+ }
786
+ if (after.length > 0) {
787
+ if (after.length >= 1) {
788
+ after.forEach((item) => {
789
+ newArr.push(item)
790
+ })
791
+ } else {
792
+ newArr.push(after)
793
+ }
794
+ }
795
+
796
+ config.columns = newArr
797
+ if (this.configFromWeb[targetName].slotsDeclare) {
798
+ config.slotsDeclare = this.configFromWeb[targetName].slotsDeclare
799
+ } else {
800
+ config.slotsDeclare = []
801
+ }
802
+
803
+ if (
804
+ config.data.images &&
805
+ this.configFromWeb[targetName].data.images
806
+ ) {
807
+ config.data.images = {
808
+ ...config.data.images,
809
+ ...this.configFromWeb[targetName].data.images,
810
+ }
811
+ delete this.configFromWeb[targetName].data.images
812
+ }
813
+ config.data = {
814
+ ...config.data,
815
+ ...this.configFromWeb[targetName].data,
816
+ }
817
+ }
818
+ }
819
+ }
820
+ this.config = config
821
+ },
822
+ // 扫描所有插槽名
823
+ scanConfigName (config, resut) {
824
+ if (config.slotsDeclare) {
825
+ config.slotsDeclare.forEach((name) => {
826
+ resut.push(name)
827
+ })
828
+ }
829
+ },
830
+ // 获取插槽
831
+ getConfigAndJoin (config, outerLock) {
832
+ // 检查主配置插槽声明是否合法
833
+ const check = this.checkSlotDefine(config)
834
+ const waitForDownloadSlotName = []
835
+ if (check) {
836
+ // 扫描主配置中声明的插槽名
837
+ this.scanConfigName(config, waitForDownloadSlotName)
838
+
839
+ const total = waitForDownloadSlotName.length
840
+ let count = 0
841
+
842
+ // 挨个获取插槽
843
+ waitForDownloadSlotName.forEach((configName) => {
844
+ getConfigByName(
845
+ configName,
846
+ this.serverName,
847
+ (res) => {
848
+ this.configFromWeb[configName] = res
849
+ count++
850
+ },
851
+ this.env === 'dev'
852
+ )
853
+ })
854
+
855
+ // 使用定时器循环判断锁状态,用于多个插槽,要等待统一获取完成之后,再进行下一步初始化
856
+ const timer = setInterval(() => {
857
+ console.log('插槽下载进度,当前:' + count + '/' + total)
858
+ if (count >= total) {
859
+ clearInterval(timer)
860
+ this.scanConfigSlot(config)
861
+ if (config.slotsDeclare.length > 0) {
862
+ const lock = { status: true }
863
+ this.getConfigAndJoin(config, lock)
864
+ const innerTimer = setInterval(() => {
865
+ if (!lock.status) {
866
+ clearInterval(innerTimer)
867
+ outerLock.status = false
868
+ }
869
+ }, 100)
870
+ } else {
871
+ outerLock.status = false
872
+ }
873
+ }
874
+ }, 100)
875
+ } else {
876
+ console.error('插槽配置有误!')
877
+ outerLock.status = false
878
+ }
879
+ },
880
+ // 获取配置之后的初始化
881
+ configInit () {
882
+ console.log('拼接完成', this.config)
883
+ // 将初始化好的配置拷贝一份留存
884
+ this.originalConfig = Object.assign({}, this.config)
885
+ if (!this.dontFormat) {
886
+ // 扫描配置文件中有没有rowSpan,进行格式化调整
887
+ this.formatConfigRow(this.config)
888
+ }
889
+ this.activeConfig = this.config
890
+ this.showSkeleton = false
891
+ // 判断是否有动态Index
892
+ this.activeConfig.columns.forEach((row) => {
893
+ row.forEach((cell) => {
894
+ if (cell.dynamicDataIndex === true) {
895
+ // 如果有动态index,取其函数,运行函数得到真实index保存
896
+ // eslint-disable-next-line no-eval
897
+ const func = eval(
898
+ '(' + cell.customFunctionForDynamicDataIndex + ')'
899
+ )
900
+ cell.dataIndex = func(this.config)
901
+ }
902
+ // 处理 自定义函数的旧逻辑
903
+ if (
904
+ ['action', 'click'].includes(cell.eventType) &&
905
+ cell.customFunction &&
906
+ !cell.events
907
+ ) {
908
+ cell.events = []
909
+ cell.events.push({
910
+ type: cell.eventType,
911
+ customFunction: cell.customFunction,
912
+ })
913
+ }
914
+ })
915
+ })
916
+ // 将数据复制到临时数据中,带有@@@的数据,我们将其整体作为一个key保存,当编辑完成后,再将其解析,回填到需要的数据中
917
+ this.activeConfig.tempData = {}
918
+ // 是否有@@@深层引用
919
+ this.activeConfig.columns.forEach((row) => {
920
+ row.forEach((cell) => {
921
+ // 将@@@解析
922
+ if (
923
+ cell.dataIndex !== undefined &&
924
+ cell.dataIndex.indexOf('@@@') !== -1
925
+ ) {
926
+ this.activeConfig.tempData[cell.dataIndex] = this.getDeepObject(
927
+ this.activeConfig.data,
928
+ cell.dataIndex
929
+ )
930
+ }
931
+ })
932
+ })
933
+
934
+ // 对配置进行转换
935
+ console.log('转换前配置', this.config)
936
+ this.originalConfig.columns = this.transformArray(
937
+ JSON.parse(JSON.stringify(this.config.columns))
938
+ )
939
+ console.log('转换后的列描述', this.originalConfig.columns)
940
+
941
+ this.$nextTick(() => {
942
+ this.scanFinish = true
943
+ })
944
+ },
945
+ },
946
+ beforeMount () {
947
+ // 如果只是展示
948
+ if (this.displayOnly) {
949
+ this.onlyDisplay = true
950
+ this.type = 'display'
951
+ }
952
+ // 如果有本地配置,优先使用本地配置
953
+ if (this.localConfig) {
954
+ // 如果配置是普通渲染器
955
+ this.config = this.localConfig
956
+ if (this.configData !== undefined) {
957
+ this.config.data = this.configData
958
+ }
959
+ if (this.config.data.images === undefined) {
960
+ this.config.data.images = {}
961
+ }
962
+ this.configInit()
963
+ } else {
964
+ // 如果本地配置没有值,则从琉璃中获取
965
+ getConfigByName(
966
+ this.configName,
967
+ this.serverName,
968
+ (res) => {
969
+ this.config = JSON.parse(JSON.stringify(res))
970
+ if (this.configData !== undefined) {
971
+ this.config.data = this.configData
972
+ }
973
+ if (this.config.data.images === undefined) {
974
+ this.config.data.images = {}
975
+ }
976
+ this.configInit()
977
+ },
978
+ this.env === 'dev'
979
+ )
980
+ }
981
+ },
982
+ computed: {
983
+ ...mapState('account', { currUser: 'user' }),
984
+ widget () {
985
+ return this.isWidget // 返回isWidget的值
986
+ },
987
+ },
988
+ mounted () {
989
+ // 如果外界传来了registerMap,我们将本VM对象注册到map中
990
+ if (this.registerMap !== undefined) {
991
+ this.registerMap.push(this)
992
+ }
993
+ // 将原始数据备份保存
994
+ if (this.configData) {
995
+ this.dataCache = JSON.parse(JSON.stringify(this.configData))
996
+ } else {
997
+ if (this.config?.data) {
998
+ this.dataCache = JSON.parse(JSON.stringify(this.config.data))
999
+ }
1000
+ }
1001
+ },
1002
+ }
1003
+ </script>
1004
+
1005
+ <style lang="less" scoped>
1006
+ .tools {
1007
+ text-align: center;
1008
+ cursor: pointer;
1009
+
1010
+ .toolsItem {
1011
+ display: inline-block;
1012
+ }
1013
+ }
1014
+ </style>