vue2-client 1.10.32 → 1.10.35

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