af-mobile-client-vue3 1.0.84 → 1.0.86

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 (25) hide show
  1. package/package.json +1 -1
  2. package/src/components/data/XCellList/index.vue +5 -2
  3. package/src/components/data/XCellListFilter/index.vue +1 -1
  4. package/src/components/data/XFormItem/index.vue +16 -2
  5. package/src/components/data/XReportGrid/XAddReport/XAddReport.vue +202 -0
  6. package/src/components/data/XReportGrid/XAddReport/index.js +3 -0
  7. package/src/components/data/XReportGrid/XAddReport/index.md +56 -0
  8. package/src/components/data/XReportGrid/XAddReport/index.ts +10 -0
  9. package/src/components/data/XReportGrid/XReport.vue +973 -0
  10. package/src/components/data/XReportGrid/XReportDemo.vue +33 -0
  11. package/src/components/data/XReportGrid/XReportDesign.vue +597 -0
  12. package/src/components/data/XReportGrid/XReportDrawer/XReportDrawer.vue +148 -0
  13. package/src/components/data/XReportGrid/XReportDrawer/index.js +3 -0
  14. package/src/components/data/XReportGrid/XReportDrawer/index.ts +10 -0
  15. package/src/components/data/XReportGrid/XReportJsonRender.vue +386 -0
  16. package/src/components/data/XReportGrid/XReportTrGroup.vue +592 -0
  17. package/src/components/data/XReportGrid/index.md +44 -0
  18. package/src/components/data/XReportGrid/print.js +184 -0
  19. package/src/layout/GridView/index.vue +16 -0
  20. package/src/layout/PageLayout.vue +5 -4
  21. package/src/router/routes.ts +18 -0
  22. package/src/views/component/XCellListView/index.vue +5 -5
  23. package/src/views/component/XFormGroupView/index.vue +2 -2
  24. package/src/views/component/XReportGridView/index.vue +18 -0
  25. package/src/views/component/index.vue +4 -0
@@ -0,0 +1,973 @@
1
+ <script setup lang="ts">
2
+ import { computed, nextTick, onBeforeMount, onBeforeUnmount, onMounted, provide, ref, watch } from 'vue'
3
+ import { storeToRefs } from 'pinia'
4
+ import {
5
+ Button as VanButton,
6
+ Card as VanCard,
7
+ Icon as VanIcon,
8
+ RadioGroup as VanRadioGroup,
9
+ Radio as VanRadio,
10
+ Row as VanRow,
11
+ Col as VanCol,
12
+ Space as VanSpace,
13
+ Skeleton as VanSkeleton,
14
+ showDialog
15
+ } from 'vant'
16
+ import { getConfigByName, runLogic } from '@af-mobile-client-vue3/services/api/common'
17
+ import { executeStrFunctionByContext } from '@af-mobile-client-vue3/utils/runEvalFunction'
18
+ import { printElement } from '@af-mobile-client-vue3/components/data/XReportGrid/print'
19
+ import XReportDesign from '@af-mobile-client-vue3/components/data/XReportGrid/XReportDesign.vue'
20
+ import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
21
+
22
+ // import HtmlToPdf from '@/utils/htmlToPDF'
23
+
24
+ // Props
25
+ const props = defineProps({
26
+ files: {
27
+ type: Array,
28
+ default: () => [],
29
+ },
30
+ authority: {
31
+ type: String,
32
+ default: 'user',
33
+ },
34
+ editMode: {
35
+ type: Boolean,
36
+ default: true,
37
+ },
38
+ configName: {
39
+ type: String,
40
+ required: true,
41
+ },
42
+ activatedSlotName: {
43
+ type: String,
44
+ default: undefined,
45
+ },
46
+ localConfig: {
47
+ type: Object,
48
+ default: undefined,
49
+ },
50
+ dontFormat: {
51
+ type: Boolean,
52
+ default: true,
53
+ },
54
+ showImgInCell: {
55
+ type: Boolean,
56
+ default: false,
57
+ },
58
+ configData: {
59
+ type: Object,
60
+ default: undefined,
61
+ },
62
+ serverName: {
63
+ type: String,
64
+ default: '',
65
+ },
66
+ env: {
67
+ type: String,
68
+ default: 'prod',
69
+ },
70
+ displayOnly: {
71
+ type: Boolean,
72
+ default: true,
73
+ },
74
+ noPadding: {
75
+ type: Boolean,
76
+ default: true,
77
+ },
78
+ noTopBorder: {
79
+ type: Boolean,
80
+ default: false,
81
+ },
82
+ showTitle: {
83
+ type: Boolean,
84
+ default: true,
85
+ },
86
+ showSaveButton: {
87
+ type: Boolean,
88
+ default: false,
89
+ },
90
+ registerMap: {
91
+ type: Array,
92
+ default: undefined,
93
+ },
94
+ isWidget: {
95
+ type: Boolean,
96
+ default: true,
97
+ },
98
+ useOssForImg: {
99
+ type: Boolean,
100
+ default: true,
101
+ },
102
+ imgPrefix: {
103
+ type: String,
104
+ default: undefined,
105
+ },
106
+ })
107
+
108
+ // Emits
109
+ const emit = defineEmits(['updateImg', 'selectRow', 'cancel'])
110
+
111
+ // Store
112
+ const userStore = useUserStore()
113
+ // const { user: currUser } = storeToRefs(userStore)
114
+
115
+ // Refs
116
+ // const XReportDesign = ref()
117
+ const xAddReport = ref()
118
+ const xReportDrawer = ref()
119
+
120
+ // 状态
121
+ const showSkeleton = ref(true)
122
+ const config = ref()
123
+ const type = ref('design')
124
+ const onlyDisplay = ref(false)
125
+ const _maxColSpan = ref(12)
126
+ const scanFinish = ref(false)
127
+ const activeConfig = ref(null)
128
+ const originalConfig = ref(null)
129
+ const configFromWeb = ref({})
130
+ const timer = ref()
131
+ const hasImages = ref(false)
132
+ const imageList = ref([])
133
+ const dataCache = ref()
134
+ const diff = ref([])
135
+ const globalData = ref({})
136
+
137
+ // Computed
138
+ const widget = computed(() => props.isWidget)
139
+
140
+ // 在provide之前定义getGlobalData函数
141
+ const getGlobalData = () => globalData.value
142
+
143
+ const setGlobalData = (obj: any) => {
144
+ globalData.value = obj
145
+ }
146
+
147
+ // 然后再进行provide
148
+ provide('runLogic', runLogic)
149
+ provide('openDialog', openDialog)
150
+ provide('registerComponent', registerComponent)
151
+ provide('getComponentByName', getComponentByName)
152
+ provide('getParentComponentByName', getComponentByName)
153
+ provide('getConfigByName', getConfigByName)
154
+ provide('isWidget', widget)
155
+ // provide('currUser', currUser)
156
+ provide('setGlobalData', setGlobalData)
157
+ provide('getGlobalData', getGlobalData)
158
+
159
+ // Methods
160
+ function slotRendered() {
161
+ if (config.value?.mountedFunction) {
162
+ let func = config.value.mountedFunction
163
+ if (func && func.startsWith('function')) {
164
+ func = func.replace('function', 'async function')
165
+ executeStrFunctionByContext(null, func, [])
166
+ }
167
+ }
168
+ }
169
+
170
+ function registerComponent(componentName: string, component: any) {
171
+ console.log('内部注册', componentName)
172
+ if (XReportDesign.value)
173
+ XReportDesign.value[componentName] = component
174
+
175
+ console.log('内部注册完成')
176
+ }
177
+
178
+ // 数据处理方法
179
+ function transformArray(inputList: any[]) {
180
+ let operationIndex = 0
181
+ let operationList = []
182
+ const outputList = []
183
+ for (const lst of inputList) {
184
+ if (lst.length >= 1 && !lst.every(x => Array.isArray(x) || Array.isArray(lst[0]) || x.rowSpan === lst[0].rowSpan)) {
185
+ operationList = lst
186
+ break
187
+ }
188
+ else {
189
+ operationIndex += 1
190
+ }
191
+ }
192
+
193
+ let maxMergeRow = 0
194
+
195
+ if (operationList.length === 0) {
196
+ return inputList
197
+ }
198
+ else {
199
+ const maxRow = Math.max(...operationList.map(item => item.rowSpan))
200
+ let mergeIndexCol = 0
201
+ for (let index = 0; index < operationList.length; index++) {
202
+ const row = operationList[index]
203
+ let rowSpan = row.rowSpan
204
+ let mergeIndexRow = operationIndex + 1
205
+ const rows = []
206
+ if (rowSpan < maxRow && mergeIndexRow < inputList.length)
207
+ rows.push([row])
208
+
209
+ while (rowSpan < maxRow && mergeIndexRow < inputList.length) {
210
+ rowSpan += inputList[mergeIndexRow][mergeIndexCol].rowSpan
211
+ rows.push([inputList[mergeIndexRow][mergeIndexCol]])
212
+ if (mergeIndexRow > maxMergeRow)
213
+ maxMergeRow = mergeIndexRow
214
+
215
+ mergeIndexRow++
216
+ }
217
+ if (rows.length !== 0)
218
+ operationList[index] = rows
219
+
220
+ if (row.rowSpan !== maxRow)
221
+ mergeIndexCol++
222
+ }
223
+ }
224
+
225
+ let putindex = 0
226
+ while (operationIndex > 0) {
227
+ outputList.push(inputList[putindex])
228
+ putindex++
229
+ operationIndex -= 1
230
+ }
231
+
232
+ outputList.push(operationList)
233
+
234
+ while (maxMergeRow < inputList.length - 1) {
235
+ outputList.push(inputList[maxMergeRow + 1])
236
+ maxMergeRow += 1
237
+ }
238
+
239
+ return transformArray(outputList)
240
+ }
241
+
242
+ // 组件操作方法
243
+ function getComponentByName(componentName: string) {
244
+ console.log('内部取组件', componentName)
245
+ return XReportDesign.value?.[componentName]
246
+ }
247
+
248
+ // 对话框操作
249
+ function openDialog(configName: string, selectedId: any, mixinData: any, outEnv = {}, attr = {}) {
250
+ console.log('openDialog', configName, selectedId)
251
+ xAddReport.value?.init({
252
+ configName,
253
+ selectedId,
254
+ mixinData,
255
+ outEnv,
256
+ attr,
257
+ })
258
+ }
259
+
260
+ function openDrawer(configName: string, selectedId: any, mixinData: any, outEnv = {}, attr = {}) {
261
+ console.log('openDrawer', configName, selectedId)
262
+ xReportDrawer.value?.init({
263
+ configName,
264
+ selectedId,
265
+ mixinData,
266
+ outEnv,
267
+ attr,
268
+ })
269
+ }
270
+
271
+ // 数据导出和打印
272
+ function updateImg(data: any) {
273
+ emit('updateImg', data)
274
+ }
275
+
276
+ function exportData() {
277
+ let tempData
278
+ if (!activeConfig.value) {
279
+ tempData = originalConfig.value.data
280
+ }
281
+ else {
282
+ const tempDataKeys = Object.keys(activeConfig.value.tempData)
283
+ tempDataKeys.forEach((key) => {
284
+ changeDeepObject(activeConfig.value.data, key, activeConfig.value.tempData[key])
285
+ })
286
+ tempData = activeConfig.value.data
287
+ }
288
+
289
+ diff.value = []
290
+ compareProps(tempData, dataCache.value)
291
+
292
+ diff.value.forEach((eachDiff) => {
293
+ const arr = eachDiff.split('.')
294
+ let targetData = tempData[arr[0]]
295
+ if (arr.length !== 1) {
296
+ for (let i = 1; i < arr.length - 1; i++) {
297
+ const path = arr[i]
298
+ targetData = targetData[path]
299
+ }
300
+ }
301
+ targetData.update = true
302
+ })
303
+
304
+ return tempData
305
+ }
306
+
307
+ function printDocument() {
308
+ const printContent = window.rawDocument.getElementById('printReady')
309
+ // printElement(printContent)
310
+ showDialog({ message: '操作成功!' })
311
+ }
312
+
313
+ function exportPDF() {
314
+ const date = getDate()
315
+ let title = config.value.title
316
+ title = title.replace(/<[^>]+>/g, '')
317
+ const fileName = `${date}${title}`
318
+ // HtmlToPdf.getPdf(fileName, '#printReady')
319
+ }
320
+
321
+ // 配置处理方法
322
+ function configInit() {
323
+ console.log('拼接完成', config.value)
324
+ originalConfig.value = Object.assign({}, config.value)
325
+ if (!props.dontFormat)
326
+ formatConfigRow(config.value)
327
+
328
+ activeConfig.value = config.value
329
+ showSkeleton.value = false
330
+
331
+ // 处理动态Index
332
+ activeConfig.value.columns.forEach((row: any[]) => {
333
+ row.forEach((cell) => {
334
+ if (cell.dynamicDataIndex === true) {
335
+ // eslint-disable-next-line no-eval
336
+ const func = eval(`(${cell.customFunctionForDynamicDataIndex})`)
337
+ cell.dataIndex = func(config.value)
338
+ }
339
+ if (['action', 'click'].includes(cell.eventType) && cell.customFunction && !cell.events) {
340
+ cell.events = []
341
+ cell.events.push({
342
+ type: cell.eventType,
343
+ customFunction: cell.customFunction,
344
+ })
345
+ }
346
+ })
347
+ })
348
+
349
+ activeConfig.value.tempData = {}
350
+ activeConfig.value.columns.forEach((row: any[]) => {
351
+ row.forEach((cell) => {
352
+ if (cell.dataIndex?.includes('@@@'))
353
+ activeConfig.value.tempData[cell.dataIndex] = getDeepObject(activeConfig.value.data, cell.dataIndex)
354
+ })
355
+ })
356
+
357
+ console.log('转换前配置', config.value)
358
+ originalConfig.value.columns = transformArray(JSON.parse(JSON.stringify(config.value.columns)))
359
+ console.log('转换后的列描述', originalConfig.value.columns)
360
+
361
+ scanFinish.value = true
362
+ }
363
+
364
+ // 格式化配置行方法
365
+ function formatConfigRow(config: any) {
366
+ for (let i = 0; i < config.columns.length; i++) {
367
+ // 对原始数组进行递归,依次将该位置拆分为三个部分,当前处理位置之前的,当前处理位置,当前处理位置之后的
368
+ const before = config.columns.slice(0, i)
369
+ const after = config.columns.slice(i + 1, config.columns.length)
370
+
371
+ // 将当前处理的数组交给处理的方法
372
+ const x = checkRow(config.columns[i])
373
+
374
+ const newArr = []
375
+
376
+ // 拼接之前的数组
377
+ if (before.length > 0) {
378
+ if (before.length >= 1) {
379
+ before.forEach((item) => {
380
+ newArr.push(item)
381
+ })
382
+ }
383
+ else {
384
+ newArr.push(before)
385
+ }
386
+ }
387
+
388
+ // 拼接不需要更改当前节点处理完成的数组
389
+ newArr.push(x.old)
390
+
391
+ // 如果处理了新加的数据,拼接
392
+ if (x.add.length > 0) {
393
+ for (let j = 0; j < x.add.length; j++) {
394
+ if (x.add[j]) {
395
+ newArr.push(x.add[j])
396
+ i++
397
+ }
398
+ }
399
+ }
400
+
401
+ // 拼接之后的数组
402
+ if (after.length > 0) {
403
+ if (after.length >= 1) {
404
+ after.forEach((item) => {
405
+ newArr.push(item)
406
+ })
407
+ }
408
+ else {
409
+ newArr.push(after)
410
+ }
411
+ }
412
+
413
+ config.columns = newArr
414
+ }
415
+ }
416
+
417
+ // 处理行数据
418
+ function checkRow(rowArr: any[]) {
419
+ // 不需要更改的数据
420
+ const original = []
421
+ // 需要更改新加的数据
422
+ const addArr = []
423
+ // 统计rowspan出现的总和
424
+ let count = 0
425
+ // 统计声明列需要的rowspan总数
426
+ let total = 0
427
+ // 是否为声明行
428
+ let titleCellFlag = false
429
+ // 是否为声明行后第一行
430
+ let firstSubLine = false
431
+ // 需要处理的行,新的index值
432
+ let subRowIndex = 0
433
+ // 新生成的行,临时存储
434
+ const waitForAddArr = []
435
+ // 用于记录声明行的colspan避免格式错误
436
+ let preColSpan = 0
437
+ // 用于统计循环次数,判断是否是最后一次
438
+ let forEachCount = 0
439
+
440
+ // 标记所有数据
441
+ rowArr.forEach((cell) => {
442
+ forEachCount++
443
+ // 如果该行没有rowspan则默认其为1,不要影响统计结果
444
+ if (!cell.rowSpan)
445
+ cell.rowSpan = 0
446
+
447
+ if (cell.text && total !== 0) { // 如果遇到了下一个声明行,证明rowspan少了一行,需要补充一个占位格
448
+ const nullObj = {
449
+ type: 'placeHolderColumn',
450
+ order: subRowIndex,
451
+ noBoarder: true,
452
+ needSplit: true,
453
+ colSpan: preColSpan,
454
+ dontShowRow: true,
455
+ }
456
+ subRowIndex++
457
+ waitForAddArr.push(nullObj)
458
+ total = 0
459
+ count = 0
460
+ titleCellFlag = false
461
+ firstSubLine = false
462
+ }
463
+ else if ((total !== count + cell.rowSpan) && forEachCount === rowArr.length) {
464
+ // 如果没有遇到了下一个声明行,但已经是当前行最后一个数据,也证明rowspan少了一行,需要补充一个占位格
465
+ const nullObj = {
466
+ type: 'placeHolderColumn',
467
+ order: subRowIndex,
468
+ noBoarder: true,
469
+ needSplit: true,
470
+ colSpan: preColSpan,
471
+ dontShowRow: true,
472
+ }
473
+ subRowIndex++
474
+ waitForAddArr.push(nullObj)
475
+ total = 0
476
+ count = 0
477
+ titleCellFlag = false
478
+ firstSubLine = false
479
+ }
480
+
481
+ // 判断是否为声明行
482
+ if (cell.text && total === 0) {
483
+ // 将声明行声明的rowspan作为总数,判断下方rowspan相加是否等于声明行声明的数量
484
+ total = cell.rowSpan
485
+ titleCellFlag = false
486
+ firstSubLine = true
487
+ subRowIndex = 1
488
+ cell.show = true
489
+ cell.showRowSpan = total
490
+ }
491
+ else if (cell.rowSpan > 0 && !titleCellFlag && firstSubLine) { // 判断是否为声明行后首行,因为首行不需要移动
492
+ count += cell.rowSpan
493
+ firstSubLine = false
494
+ cell.noBoarder = true
495
+ cell.show = true
496
+ cell.showRowSpan = total
497
+ }
498
+ else if (cell.rowSpan > 0 && !titleCellFlag && !firstSubLine) { // 既非声明行,也非首行,需要移动
499
+ count += cell.rowSpan
500
+ cell.needSplit = true
501
+ cell.order = subRowIndex
502
+ cell.dontShowRow = true
503
+ subRowIndex++
504
+
505
+ // 如果之前添加过空行补充位置,刚好最后一位还有内容,将其互换
506
+ if (forEachCount === rowArr.length && !waitForAddArr[waitForAddArr.length - 1].dataIndex) {
507
+ waitForAddArr[waitForAddArr.length - 1].order += 1
508
+ cell.order -= 1
509
+ waitForAddArr.push(cell)
510
+ }
511
+ else {
512
+ waitForAddArr.push(cell)
513
+ }
514
+ }
515
+
516
+ // 如果count和total相等了,证明已经处理完成。将计数器还原
517
+ if (count === total) {
518
+ total = 0
519
+ count = 0
520
+ titleCellFlag = false
521
+ firstSubLine = false
522
+ }
523
+ // 保存上一个的colspan,保持生成的格子与原格式一致
524
+ preColSpan = cell.colSpan
525
+ })
526
+
527
+ // 将所有不需要移动的放入original
528
+ rowArr.forEach((cell) => {
529
+ if (cell.needSplit !== true)
530
+ original.push(cell)
531
+ })
532
+
533
+ // 增加新的数组
534
+ waitForAddArr.forEach((cell) => {
535
+ const target = cell.order
536
+ cell.noBoarder = true
537
+ if (addArr[target] === undefined) {
538
+ const temp = []
539
+ temp.push(cell)
540
+ addArr[target] = temp
541
+ }
542
+ else if (addArr[target].length > 0) {
543
+ addArr[target].push(cell)
544
+ }
545
+ })
546
+
547
+ // 如果没有新增,将单元格边框设置为显示
548
+ if (addArr.length < 1) {
549
+ original.forEach((cell) => {
550
+ if (cell.type === 'input' || cell.type === 'inputs')
551
+ cell.noBoarder = false
552
+ })
553
+ }
554
+
555
+ return {
556
+ old: original,
557
+ add: addArr,
558
+ }
559
+ }
560
+
561
+ // 配置扫描方法
562
+ function checkSlotDefine(config: any) {
563
+ const slotsDeclare = config.slotsDeclare
564
+ const total = slotsDeclare.length
565
+ let count = 0
566
+ slotsDeclare.forEach((declare: string) => {
567
+ config.columns.forEach((row: any[]) => {
568
+ row.forEach((cell) => {
569
+ if (cell.slotConfig === declare) {
570
+ count++
571
+ }
572
+ })
573
+ })
574
+ })
575
+ return count === total
576
+ }
577
+
578
+ function scanConfigName(config: any, result: string[]) {
579
+ if (config.slotsDeclare) {
580
+ config.slotsDeclare.forEach((name: string) => {
581
+ result.push(name)
582
+ })
583
+ }
584
+ }
585
+
586
+ function scanConfigSlot(config: any) {
587
+ const columnsArr = config.columns
588
+ for (let i = 0; i < columnsArr.length; i++) {
589
+ for (let j = 0; j < columnsArr[i].length; j++) {
590
+ if (columnsArr[i][j].type === 'slot') {
591
+ const targetName = columnsArr[i][j].slotConfig
592
+ if (!configFromWeb.value[targetName] || !configFromWeb.value[targetName].columns) {
593
+ console.error('无法找到目标插槽的配置!')
594
+ return
595
+ }
596
+
597
+ config.columns[i] = []
598
+ const before = config.columns.slice(0, i)
599
+ let after = config.columns.slice(i + 1, config.columns.length)
600
+
601
+ const addArr = []
602
+ for (let k = 0; k < configFromWeb.value[targetName].columns.length; k++) {
603
+ const temp = []
604
+ configFromWeb.value[targetName].columns[k].forEach((cell: any) => {
605
+ temp.push(cell)
606
+ })
607
+ addArr.push(temp)
608
+ }
609
+
610
+ const newArr = []
611
+ if (before.length > 0) {
612
+ before.forEach((item) => {
613
+ newArr.push(item)
614
+ })
615
+ }
616
+
617
+ addArr.forEach((arr) => {
618
+ newArr.push(arr)
619
+ })
620
+
621
+ if (after.length === 1) {
622
+ if (after[0].type === 'slot' || after[0][0].type === 'slot')
623
+ after = []
624
+ }
625
+ if (after.length > 0) {
626
+ after.forEach((item) => {
627
+ newArr.push(item)
628
+ })
629
+ }
630
+
631
+ config.columns = newArr
632
+ config.slotsDeclare = configFromWeb.value[targetName].slotsDeclare || []
633
+
634
+ if (config.data.images && configFromWeb.value[targetName].data.images) {
635
+ config.data.images = { ...config.data.images, ...configFromWeb.value[targetName].data.images }
636
+ delete configFromWeb.value[targetName].data.images
637
+ }
638
+ config.data = { ...config.data, ...configFromWeb.value[targetName].data }
639
+ }
640
+ }
641
+ }
642
+ config.value = config
643
+ }
644
+
645
+ // 数据比较方法
646
+ function compareProps(obj1: any, obj2: any, path = '') {
647
+ for (const key in obj1) {
648
+ if (typeof obj2[key] === 'undefined') {
649
+ diff.value.push(path + key)
650
+ }
651
+ else if (Array.isArray(obj1) && Array.isArray(obj2)) {
652
+ if (obj1[key].length !== obj2[key].length)
653
+ diff.value.push(path + key)
654
+ }
655
+ else if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') {
656
+ compareProps(obj1[key], obj2[key], `${path + key}.`)
657
+ }
658
+ else if (obj1[key] !== obj2[key]) {
659
+ diff.value.push(path + key)
660
+ }
661
+ }
662
+ }
663
+
664
+ // 数据处理辅助方法
665
+ function getDeepObject(obj: any, strPath: string) {
666
+ const arr = strPath.split('@@@')
667
+ let result = obj[arr[0]]
668
+ arr.shift()
669
+ try {
670
+ while (arr.length > 0) {
671
+ result = result[arr[0]]
672
+ arr.shift()
673
+ }
674
+ }
675
+ catch (e) {
676
+ result = undefined
677
+ }
678
+ return result
679
+ }
680
+
681
+ function changeDeepObject(obj: any, strPath: string, newVal: any) {
682
+ const arr = strPath.split('@@@')
683
+ if (obj[arr[0]] === undefined)
684
+ obj = obj.images
685
+
686
+ if (arr.length === 1) {
687
+ obj[arr[0]] = newVal
688
+ }
689
+ else {
690
+ let result = obj[arr[0]]
691
+ arr.shift()
692
+ while (arr.length > 1) {
693
+ result = result[arr[0]]
694
+ arr.shift()
695
+ }
696
+ if (result)
697
+ result[arr[0]] = newVal
698
+ }
699
+ }
700
+
701
+ // 日期处理方法
702
+ function getDate() {
703
+ const currentDate = new Date()
704
+ const year = currentDate.getFullYear()
705
+ const month = String(currentDate.getMonth() + 1).padStart(2, '0')
706
+ const day = String(currentDate.getDate()).padStart(2, '0')
707
+ return `${year}_${month}_${day}`
708
+ }
709
+
710
+ // 表格操作方法
711
+ function tabChanged(key: string) {
712
+ scanFinish.value = false
713
+ originalConfig.value.data = { ...originalConfig.value.data, ...config.value.data }
714
+ config.value.data = originalConfig.value.data
715
+
716
+ if (type.value === 'display') {
717
+ const tempDataKeys = Object.keys(activeConfig.value.tempData)
718
+ tempDataKeys.forEach((key) => {
719
+ changeDeepObject(activeConfig.value.data, key, activeConfig.value.tempData[key])
720
+ })
721
+
722
+ let count = 0
723
+ imageList.value = []
724
+ const keys = Object.keys(config.value.data.images)
725
+ keys.forEach((key) => {
726
+ if (config.value.data.images[key].length > 0) {
727
+ imageList.value = [...imageList.value, ...config.value.data.images[key]]
728
+ count++
729
+ }
730
+ })
731
+ hasImages.value = count > 0
732
+ }
733
+ else {
734
+ hasImages.value = false
735
+ }
736
+
737
+ scanFinish.value = true
738
+ }
739
+
740
+ function saveConfig() {
741
+ const funcStr = config.value.confirmFunction
742
+ executeStrFunctionByContext(null, funcStr, [])
743
+ }
744
+
745
+ function cancelConfig() {
746
+ emit('cancel')
747
+ }
748
+
749
+ // 在其他方法后面添加
750
+ function jsonConfigInit() {
751
+ if (props.configData === undefined) {
752
+ console.error('未找到数据!')
753
+ return
754
+ }
755
+
756
+ originalConfig.value = Object.assign({}, config.value)
757
+ originalConfig.value.data = JSON.parse(JSON.stringify(props.configData))
758
+ type.value = 'display'
759
+ // onlyDisplay.value = true
760
+ showSkeleton.value = false
761
+
762
+ nextTick(() => {
763
+ scanFinish.value = true
764
+ })
765
+ }
766
+
767
+ // 生命周期
768
+ onBeforeMount(() => {
769
+ if (props.displayOnly) {
770
+ onlyDisplay.value = true
771
+ type.value = 'display'
772
+ }
773
+
774
+ if (props.localConfig) {
775
+ if (props.localConfig.designMode === 'json') {
776
+ config.value = props.localConfig
777
+ if (props.configData !== undefined)
778
+ config.value.data = props.configData
779
+
780
+ jsonConfigInit()
781
+ }
782
+ else {
783
+ config.value = props.localConfig
784
+ if (props.configData !== undefined)
785
+ config.value.data = props.configData
786
+
787
+ if (config.value.data.images === undefined)
788
+ config.value.data.images = {}
789
+
790
+ configInit()
791
+ }
792
+ }
793
+ else {
794
+ getConfigByName(props.configName, (res: any) => {
795
+ config.value = JSON.parse(JSON.stringify(res))
796
+ if (config.value.designMode === 'json') {
797
+ if (props.configData !== undefined)
798
+ config.value.data = props.configData
799
+
800
+ jsonConfigInit()
801
+ }
802
+ else {
803
+ if (props.configData !== undefined)
804
+ config.value.data = props.configData
805
+
806
+ if (config.value.data.images === undefined)
807
+ config.value.data.images = {}
808
+
809
+ configInit()
810
+ }
811
+ }, props.serverName)
812
+ }
813
+ })
814
+
815
+ onMounted(() => {
816
+ if (props.registerMap !== undefined) {
817
+ props.registerMap.push({
818
+ exportData,
819
+ printDocument,
820
+ exportPDF,
821
+ })
822
+ }
823
+
824
+ if (props.configData)
825
+ dataCache.value = JSON.parse(JSON.stringify(props.configData))
826
+ else if (config.value?.data)
827
+ dataCache.value = JSON.parse(JSON.stringify(config.value.data))
828
+ })
829
+
830
+ onBeforeUnmount(() => {
831
+ clearInterval(timer.value)
832
+ })
833
+
834
+ // Watch
835
+ watch(() => props.configName, (val) => {
836
+ if (val) {
837
+ getConfigByName(props.configName, (res: any) => {
838
+ config.value = res
839
+ configInit()
840
+ }, props.serverName)
841
+ }
842
+ })
843
+
844
+ watch(() => props.localConfig, (val) => {
845
+ if (val) {
846
+ config.value = val
847
+ configInit()
848
+ }
849
+ })
850
+
851
+ // 暴露方法
852
+ defineExpose({
853
+ exportData,
854
+ printDocument,
855
+ exportPDF,
856
+ getComponentByName,
857
+ })
858
+
859
+ // 选择行方法
860
+ function selectRow(selectedRowKeys: any[], selectedRows: any[]) {
861
+ console.log('XReport selectRow')
862
+ emit('selectRow', selectedRowKeys, selectedRows)
863
+ }
864
+ </script>
865
+
866
+ <template>
867
+ <div>
868
+ <!-- 骨架屏 -->
869
+ <VanCard v-if="showSkeleton">
870
+ <VanSkeleton active />
871
+ </VanCard>
872
+ <template v-if="noPadding">
873
+ <!-- 主体表格 -->
874
+ <XReportDesign
875
+ v-if="scanFinish"
876
+ :show-img-in-cell="showImgInCell"
877
+ :img-prefix="imgPrefix"
878
+ :use-oss-for-img="useOssForImg"
879
+ :display-only="displayOnly"
880
+ :config="type === 'display' ? originalConfig : activeConfig"
881
+ :slot-config-name="type === 'display' ? undefined : activatedSlotName"
882
+ @update-img="updateImg"
883
+ :for-display="type === 'display'"
884
+ @select-row="selectRow"
885
+ ref="XReportDesign"
886
+ @slotRendered="slotRendered"
887
+ :server-name="serverName"
888
+ :env="env"
889
+ :show-title="showTitle"
890
+ :no-padding="noPadding"
891
+ :no-top-border="noTopBorder"
892
+ :show-images="hasImages"
893
+ :image-list="imageList"
894
+ />
895
+
896
+ <VanRow v-if="showSaveButton" type="flex" justify="end">
897
+ <VanSpace>
898
+ <VanButton @click="saveConfig">
899
+ 提交
900
+ </VanButton>
901
+ <VanButton @click="cancelConfig">
902
+ 取消
903
+ </VanButton>
904
+ </VanSpace>
905
+ </VanRow>
906
+ </template>
907
+ <template v-else>
908
+ <!-- 用以包裹整个页面 -->
909
+ <div v-if="!showSkeleton">
910
+ <!-- 切换菜单 -->
911
+ <VanRadioGroup
912
+ v-show="!onlyDisplay && editMode"
913
+ v-model="type"
914
+ default-value="a"
915
+ button-style="solid"
916
+ @change="tabChanged"
917
+ >
918
+ <VanRadio v-if="!onlyDisplay" name="design">
919
+ 设计
920
+ </VanRadio>
921
+ <VanRadio name="display" style="border-radius: 0">
922
+ 预览
923
+ </VanRadio>
924
+ </VanRadioGroup>
925
+
926
+ <!-- 主体表格 -->
927
+ <XReportDesign
928
+ v-if="scanFinish"
929
+ :show-img-in-cell="showImgInCell"
930
+ :img-prefix="imgPrefix"
931
+ :use-oss-for-img="useOssForImg"
932
+ :display-only="displayOnly"
933
+ :config="type === 'display' ? originalConfig : activeConfig"
934
+ :slot-config-name="type === 'display' ? undefined : activatedSlotName"
935
+ :for-display="type === 'display'"
936
+ @update-img="updateImg"
937
+ :no-padding="noPadding"
938
+ @select-row="selectRow"
939
+ :no-top-border="noTopBorder"
940
+ @slotRendered="slotRendered"
941
+ :show-title="showTitle"
942
+ ref="XReportDesign"
943
+ :server-name="serverName"
944
+ :env="env"
945
+ :show-images="hasImages"
946
+ :image-list="imageList"
947
+ />
948
+ </div>
949
+ </template>
950
+
951
+ <!-- 弹出框 -->
952
+ <!-- <x-add-report
953
+ ref="xAddReport"
954
+ :env="env"
955
+ />-->
956
+ <!-- 弹出框 -->
957
+ <!-- <x-report-drawer
958
+ ref="xReportDrawer"
959
+ :env="env"
960
+ /> -->
961
+ </div>
962
+ </template>
963
+
964
+ <style lang="less" scoped>
965
+ .tools {
966
+ text-align: center;
967
+ cursor: pointer;
968
+
969
+ .toolsItem {
970
+ display: inline-block;
971
+ }
972
+ }
973
+ </style>