vue2-client 1.16.22 → 1.16.24

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,813 +1,813 @@
1
- <template>
2
- <a-row id="has_row" type="flex" :gutter="gutter" :style="isWidget ? {margin: '0px'} : {'margin-bottom': '.5rem'}">
3
- <template v-for="(cell, cellIndex) in columns">
4
- <a-col
5
- name="trGroup"
6
- v-if="Array.isArray(cell) || !cell.dontShowRow"
7
- :key="cellIndex"
8
- :ref="`trGroup_${ cell.slotRef || cellIndex}`"
9
- @hook:mounted="(h)=>applyAllStyles(cell,cellIndex)"
10
- :span="calculateColSpan(cell)">
11
- <div id="report_widget" v-if="isWidget">
12
- <!-- 插槽渲染 -->
13
- <template v-if="Array.isArray(cell)">
14
- <!-- 处理 cell 是数组的情况 -->
15
- <div v-for="(item, index) in cell" :key="index">
16
- <x-report-tr-group
17
- :env="env"
18
- :key="index"
19
- :columns="recalculateItem(item)"
20
- :config-data="configData"
21
- :config="config"
22
- :display="true">
23
- </x-report-tr-group>
24
- </div>
25
- </template>
26
- <template v-else-if="cell.type === 'slot'">
27
- <template
28
- v-if="[
29
- 'x-form-table',
30
- 'h-form-table',
31
- 'x-add-native-form',
32
- 'h-add-native-form',
33
- 'x-tree-pro',
34
- 'x-his-editor',
35
- 'x-tab',
36
- 'h-tab',
37
- 'x-form-group',
38
- 'x-report',
39
- 'x-buttons',
40
- 'h-buttons',
41
- 'x-label-select',
42
- 'x-conversation',
43
- 'x-check-list',
44
- 'x-cardSet',
45
- 'x-collapse',
46
- 'x-h-descriptions',
47
- 'x-sidebar',
48
- 'x-list',
49
- 'x-input',
50
- 'x-time-line',
51
- 'x-radio',
52
- 'x-calendar',
53
- 'x-time-select',
54
- 'x-checkbox',
55
- 'x-title',
56
- 'x-select',
57
- 'x-tree-rows',
58
- 'x-three-test-orders',
59
- 'x-shift-schedule',
60
- 'x-charge',
61
- 'x-questionnaire',
62
- 'x-import-excel-button',
63
- 'x-chart'
64
- ].includes(cell.slotType)">
65
- <component
66
- :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
67
- :key="cellIndex"
68
- :ref="`dynamicComponent_${ cell.slotRef || cellIndex}`"
69
- v-bind="cell.attrs"
70
- :serviceName="cell.serviceName"
71
- :serverName="cell.serviceName"
72
- v-on="getEventHandlers(cell)"
73
- @hook:mounted="(h)=>onComponentMounted(h,cell,cellIndex)"
74
- @beforeDataChange="beforeDataChange"
75
- @rowClick="handleRowClick"
76
- @onExpand="onExpand"
77
- :queryParamsName="cell.slotConfig"
78
- :configName="cell.slotConfig"
79
- :countVisible="false"
80
- :env="env"
81
- />
82
- </template>
83
- </template>
84
- </div>
85
- <a-card v-else class="flexItem" :bordered="false">
86
- <!-- 插槽渲染 -->
87
- <template v-if="Array.isArray(cell)">
88
- <!-- 处理 cell 是数组的情况 -->
89
- <div v-for="(item, index) in cell" :key="index">
90
- <x-report-tr-group
91
- :server-name="serverName"
92
- :env="env"
93
- :key="index"
94
- :columns="recalculateItem(item)"
95
- :config-data="configData"
96
- :config="config"
97
- :display="true">
98
- </x-report-tr-group>
99
- </div>
100
- </template>
101
- <template v-else-if="cell.type === 'slot'">
102
- <template
103
- v-if="[
104
- 'x-form-table',
105
- 'h-form-table',
106
- 'x-add-native-form',
107
- 'h-add-native-form',
108
- 'x-tree-pro',
109
- 'x-his-editor',
110
- 'x-tab',
111
- 'h-tab',
112
- 'x-form-group',
113
- 'x-report',
114
- 'x-buttons',
115
- 'h-buttons',
116
- 'x-label-select',
117
- 'x-conversation',
118
- 'x-check-list',
119
- 'x-cardSet',
120
- 'x-collapse',
121
- 'x-h-descriptions',
122
- 'x-sidebar',
123
- 'x-list',
124
- 'x-input',
125
- 'x-time-line',
126
- 'x-radio',
127
- 'x-calendar',
128
- 'x-time-select',
129
- 'x-checkbox',
130
- 'x-title',
131
- 'x-select',
132
- 'x-tree-rows',
133
- 'x-three-test-orders',
134
- 'x-shift-schedule',
135
- 'x-charge',
136
- 'x-questionnaire',
137
- 'x-import-excel-button',
138
- 'x-chart'
139
- ].includes(cell.slotType)">
140
- <component
141
- :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
142
- :key="cellIndex"
143
- :ref="`dynamicComponent_${ cell.slotRef || cellIndex}`"
144
- v-bind="cell.attrs"
145
- :serviceName="cell.serviceName"
146
- :serverName="cell.serviceName"
147
- v-on="getEventHandlers(cell)"
148
- @hook:mounted="(h)=>onComponentMounted(h,cell,cellIndex)"
149
- @beforeDataChange="beforeDataChange"
150
- @rowClick="handleRowClick"
151
- @onExpand="onExpand"
152
- :queryParamsName="cell.slotConfig"
153
- :configName="cell.slotConfig"
154
- :countVisible="false"
155
- :env="env"
156
- />
157
- </template>
158
- </template>
159
- </a-card>
160
- </a-col>
161
- </template>
162
- </a-row>
163
- </template>
164
-
165
- <script>
166
- import Upload from '@vue2-client/base-client/components/common/Upload'
167
- import { getRealKeyData } from '@vue2-client/utils/util'
168
- import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
169
- import { getConfigByName, runLogic } from '@vue2-client/services/api/common'
170
- import { getMicroData, getWindow, isMicroAppEnv, microDispatch } from '@vue2-client/utils/microAppUtils'
171
-
172
- export default {
173
- name: 'XReportTrGroup',
174
- components: {
175
- Upload,
176
- XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue'),
177
- HFormTable: () => import('@vue2-client/base-client/components/common/HIS/HFormTable/HFormTable.vue'),
178
- XAddNativeForm: () => import('@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'),
179
- HAddNativeForm: () => import('@vue2-client/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm.vue'),
180
- XFormGroup: () => import('@vue2-client/base-client/components/common/XFormGroup/XFormGroup.vue'),
181
- XTreePro: () => import('@vue2-client/base-client/components/common/XTree/XTreePro.vue'),
182
- XHisEditor: () => import('@vue2-client/base-client/components/his/XHisEditor/XHisEditor.vue'),
183
- XTab: () => import('@vue2-client/base-client/components/common/XTab/XTab.vue'),
184
- HTab: () => import('@vue2-client/base-client/components/common/HIS/HTab/HTab.vue'),
185
- XReport: () => import('@vue2-client/base-client/components/common/XReport/XReport.vue'),
186
- XButtons: () => import('@vue2-client/base-client/components/common/XButtons/XButtons.vue'),
187
- HButtons: () => import('@vue2-client/base-client/components/common/HIS/HButtons/HButtons.vue'),
188
- XLabelSelect: () => import('@vue2-client/base-client/components/common/XLabelSelect/XLabelSelect.vue'),
189
- XConversation: () => import('@vue2-client/base-client/components/common/XConversation/XConversation.vue'),
190
- XCheckList: () => import('@vue2-client/base-client/components/common/XCheckList/XCheckList.vue'),
191
- XCardSet: () => import('@vue2-client/base-client/components/common/XCardSet/XCardSet.vue'),
192
- XCollapse: () => import('@vue2-client/base-client/components/common/XCollapse/XCollapse.vue'),
193
- XHDescriptions: () => import('@vue2-client/base-client/components/his/XHDescriptions/XHDescriptions.vue'),
194
- XSidebar: () => import('@vue2-client/base-client/components/his/XSidebar/XSidebar.vue'),
195
- XList: () => import('@vue2-client/base-client/components/his/XList/XList.vue'),
196
- XInput: () => import('@vue2-client/base-client/components/common/XInput/XInput.vue'),
197
- XTimeLine: () => import('@vue2-client/base-client/components/common/XTimeline/XTimeline.vue'),
198
- XRadio: () => import('@vue2-client/base-client/components/his/XRadio/XRadio.vue'),
199
- XCalendar: () => import('@vue2-client/base-client/components/common/XCalendar/XCalendar.vue'),
200
- XTimeSelect: () => import('@vue2-client/base-client/components/his/XTimeSelect/XTimeSelect.vue'),
201
- XCheckbox: () => import('@vue2-client/base-client/components/his/XCheckbox/XCheckbox.vue'),
202
- XTitle: () => import('@vue2-client/base-client/components/his/XTitle/XTitle.vue'),
203
- XSelect: () => import('@vue2-client/base-client/components/his/XSelect/XSelect.vue'),
204
- XTreeRows: () => import('@vue2-client/base-client/components/his/XTreeRows/XTreeRows.vue'),
205
- XThreeTestOrders: () => import('@vue2-client/base-client/components/his/threeTestOrders/threeTestOrders.vue'),
206
- XShiftSchedule: () => import('@vue2-client/base-client/components/his/XShiftSchedule/XShiftSchedule.vue'),
207
- XCharge: () => import('@vue2-client/base-client/components/his/XCharge/XCharge.vue'),
208
- XQuestionnaire: () => import('@vue2-client/base-client/components/his/XQuestionnaire/XQuestionnaire.vue'),
209
- XImportExcelButton: () => import('@vue2-client/base-client/components/his/XImportExcelButton/XImportExcelButton.vue'),
210
- XChart: () => import('@vue2-client/base-client/components/his/XChart/XChart.vue')
211
- },
212
- props: {
213
- // 每一行的配置
214
- columns: {
215
- type: Array,
216
- required: true
217
- },
218
- showImgInCell: {
219
- type: Boolean,
220
- default: false
221
- },
222
- config: {
223
- type: Object,
224
- default: function () {
225
- return {}
226
- }
227
- },
228
- // 命名空间
229
- serverName: {
230
- type: String,
231
- default: 'af-system'
232
- },
233
- // 环境
234
- env: {
235
- type: String,
236
- default: 'prod'
237
- },
238
- // 原始配置
239
- configData: {
240
- type: Object,
241
- required: true
242
- },
243
- // 是否为展示行
244
- display: {
245
- type: Boolean,
246
- default: false
247
- },
248
- },
249
- computed: {
250
- allSlotSum () {
251
- // 计算总共有多少个Slot
252
- let sum = 0
253
- this.columns.forEach((item) => {
254
- if (Array.isArray(item)) {
255
- item.forEach((cell) => {
256
- if (cell.type === 'slot') {
257
- sum++
258
- }
259
- })
260
- } else if (item.type && item.type === 'slot') {
261
- sum++
262
- }
263
- })
264
- return sum
265
- }
266
- },
267
- data () {
268
- return {
269
- gutter: [8, { xs: 8, sm: 16, md: 24, lg: 32 }], // 设置水槽大小
270
- maxColSpan: 12,
271
- uploadParams: {
272
- type: 'image',
273
- accept: ['*'],
274
- resUploadStock: 1,
275
- pathKey: 'cs'
276
- },
277
- mixinData: {},
278
- flexItemBodyState: {},
279
- // 已经渲染得插槽得数量
280
- slotRendered: 0,
281
- // tableConfig: {}
282
- }
283
- },
284
- watch: {
285
- columns: {
286
- deep: true,
287
- immediate: true,
288
- handler (newVal) {
289
- // 使用nextTick确保DOM更新
290
- this.$nextTick(() => {
291
- this.$forceUpdate()
292
- })
293
- }
294
- }
295
- },
296
- inject: {
297
- openDialog: { default: false },
298
- emitEvent: { default: false },
299
- registerComponent: { default: false },
300
- setColSpanByName: { default: false },
301
- setGlobalData: { default: false },
302
- getGlobalData: { default: false },
303
- getComponentByName: { default: false },
304
- runLogic: { default: false },
305
- getMixinData: { default: false },
306
- getSelectedId: { default: false },
307
- isInAModal: { default: false },
308
- getConfigByName: { default: false },
309
- getSelectedData: { default: false },
310
- getOutEnv: { default: false },
311
- currUser: { default: false },
312
- isWidget: { default: false },
313
- findComponentByName: { default: false },
314
- closeAddReport: { default: false }
315
- },
316
- methods: {
317
- getWindow,
318
- isMicroAppEnv,
319
- microDispatch,
320
- getMicroData,
321
- getRealKeyData,
322
- handleRowClick (record) {
323
- this.$emit('rowClick', record)
324
- },
325
- beforeDataChange (record) {
326
- this.$emit('beforeDataChange', record)
327
- },
328
- onExpand (expanded, record) {
329
- this.$emit('expand', expanded, record)
330
- },
331
- listClick (data) {
332
- this.$emit('listClick', data)
333
- },
334
- calculateColSpan (cell) {
335
- return Array.isArray(cell)
336
- ? cell[0][0]?.colSpan * 2
337
- : (cell?.colSpan ?? cell?.def?.colSpan ?? 1) * 2
338
- },
339
- applyAllStyles (cell, cellIndex) {
340
- // 应用组件样式
341
- const component = this.$refs[`trGroup_${ cell.slotRef || cellIndex}`][0]
342
- // 确保组件已经完全挂载
343
- this.$nextTick(() => {
344
- this.applyComponentStyles(component, cell, cellIndex)
345
- })
346
- },
347
- onComponentMounted (h, cell, cellIndex) {
348
- this.slotRendered += 1
349
- if (this.slotRendered >= this.allSlotSum) {
350
- this.$emit('slotRendered')
351
- }
352
- if (this.getMixinData && this.getMixinData()) {
353
- this.mixinData = this.getMixinData()
354
- }
355
- if (cell.slotRef) {
356
- this.registerComponent(cell.slotRef, this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0])
357
- }
358
- // 传递给祖先组件
359
- const shouldInit = cell.shouldInit == null ? true : cell.shouldInit
360
- if (shouldInit) {
361
- if (cell.slotType === 'x-add-native-form') {
362
- // 简易表单需要主动调用初始化方法
363
- getConfigByName(cell.slotConfig, cell.serviceName, async (res) => {
364
- // 如果配置了 表单初始化logic
365
- // 调用 logic 获取参数
366
- let param = { ...this.mixinData }
367
- let selectedId
368
- if (res.paramLogicName) {
369
- if (!!this.getSelectedId) {
370
- selectedId = this.getSelectedId()
371
- if (typeof selectedId !== 'object') {
372
- selectedId = { selectedId: selectedId }
373
- }
374
- }
375
- param = Object.assign(param, await runLogic(res.paramLogicName, selectedId, cell.serviceName))
376
- }
377
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
378
- serviceName: cell.serviceName,
379
- configName: cell.slotConfig,
380
- formItems: res.formJson,
381
- showSubmitBtn: !this.isInAModal,
382
- businessType: param.businessType || '新增',
383
- layout: res.xAddFormLayout,
384
- primaryKey: res.primaryKey,
385
- ...res,
386
- fixedAddForm: param,
387
- modifyModelData: {
388
- files: param.files,
389
- images: param.images
390
- }
391
- })
392
- }, this.env === 'dev')
393
- } else if (cell.slotType === 'x-form-group') {
394
- // 简易表单需要主动调用初始化方法
395
- getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
396
- // 如果配置了 表单初始化logic
397
- // 调用 logic 获取参数
398
- const param = { ...this.mixinData }
399
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
400
- ...res,
401
- serviceName: cell.serviceName,
402
- showSubmitBtn: !this.isInAModal,
403
- businessType: param.businessType || '新增',
404
- modifyModelData: param,
405
- showLeftTab: true,
406
- })
407
- }, this.env === 'dev')
408
- } else if (cell.slotType === 'x-label-select') {
409
- // 按钮组需要主动调用初始化方法
410
- getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
411
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
412
- ...res,
413
- serviceName: cell.serviceName,
414
- })
415
- }, this.env === 'dev')
416
- }
417
- }
418
- if (cell.slotType === 'x-report') {
419
- const param = { ...this.mixinData }
420
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init(param)
421
- }
422
- if (cell.slotType === 'x-conversation') {
423
- getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
424
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
425
- serviceName: cell.serviceName,
426
- ...res,
427
- })
428
- }, this.env === 'dev')
429
- }
430
- if (cell.slotType === 'x-check-list') {
431
- getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
432
- this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
433
- serviceName: cell.serviceName,
434
- ...res,
435
- })
436
- }, this.env === 'dev')
437
- }
438
- },
439
- recalculateItem (item) {
440
- const totalColSpan = item.reduce((sum, cell) => {
441
- // 保留手动设置的colSpan
442
- return sum + (cell._isManualColSpan ? 0 : (cell.colSpan || 1))
443
- }, 0)
444
- return item.map(cell => {
445
- // 跳过已手动设置的单元格
446
- if (cell._isManualColSpan) return cell
447
- const newColSpan = Math.round((cell.colSpan || 1) / totalColSpan * 12)
448
- return {
449
- ...cell,
450
- colSpan: newColSpan,
451
- // 标记自动计算的单元格
452
- _isAutoCalculated: true
453
- }
454
- })
455
- },
456
-
457
- getEventHandlers (cell) {
458
- const handlers = {}
459
- if (!cell?.events || cell?.events?.length === 0) {
460
- return handlers
461
- }
462
- cell.events.forEach(event => {
463
- handlers[event.type] = async (...args) => {
464
- let func = event.customFunction
465
- if (func && func.startsWith('function')) {
466
- func = func.replace('function', 'async function')
467
- }
468
- const result = await executeStrFunctionByContext(this, func, args)
469
- if (result instanceof Promise) {
470
- result.then((res) => {
471
- if (!res) return
472
- let messageType = 'success'
473
- // 如果传递了组件名字 自动调用刷新
474
- if (res?.name) {
475
- const waitRefreshRef = this.getComponentByName(res.name)
476
- if (waitRefreshRef) {
477
- waitRefreshRef.refresh()
478
- } else {
479
- console.warn(`未找到组件${res.name}无法刷新`)
480
- }
481
- }
482
- // 如果传递消息类型 自动调用消息
483
- if (res?.messageType) {
484
- messageType = res.messageType
485
- }
486
- // 如果传递了提示信息自动调用提示
487
- if (res?.message) {
488
- this.$message[messageType](res?.message)
489
- }
490
- })
491
- }
492
- }
493
- })
494
- return handlers
495
- },
496
- getComponentName (queryParamsName, serviceName, componentName) {
497
- return componentName
498
- },
499
- // 判断单元格样式
500
- determineCellStyle (cell, color = '#000', borderWidth = '1px') {
501
- // 如果声明了borderColor
502
- if (this.config.style.borderColor) {
503
- color = this.config.style.borderColor
504
- }
505
- let result = {}
506
- // 如果表格也声明了样式,用表格样式将样式覆盖
507
- if (cell.style) {
508
- if (cell.noBorder) {
509
- result = { ...cell.style }
510
- } else {
511
- if (this.noTopBorder) {
512
- result = { ...cell.style }
513
- } else {
514
- result = { ...cell.style }
515
- }
516
- }
517
- return result
518
- }
519
- return result
520
- },
521
- // 把用户定义的组件,传递到整个杉格中,方便调用
522
- passComponentNamesToAncestor (refs) {
523
- // 遍历所有 refs
524
- Object.entries(refs).forEach(([refKey, refValue]) => {
525
- // 检查 ref 是否以 dynamicComponent_ 开头
526
- if (refKey.startsWith('dynamicComponent_')) {
527
- const componentRef = refValue[0]
528
- if (componentRef) {
529
- // 去掉前缀并获取组件名字
530
- const index = refKey.replace('dynamicComponent_', '') // 去掉前缀
531
- // 传递给祖先组件
532
- this.registerComponent(index, componentRef)
533
- }
534
- }
535
- })
536
- },
537
- // 获取组件样式配置
538
- async getComponentStyleConfig (componentType) {
539
- try {
540
- // 从配置中获取样式定义
541
- const styleConfig = this.$appdata.getStylesByKey(componentType)
542
- return styleConfig || {}
543
- } catch (error) {
544
- console.error('获取组件样式配置失败:', error)
545
- return {}
546
- }
547
- },
548
-
549
- // 解析组件样式配置
550
- async parseComponentStyles (cell) {
551
- if (!cell.class) return { rootStyles: {}, childStyles: {} }
552
-
553
- const styleConfig = await this.getComponentStyleConfig(cell.slotType)
554
- if (!styleConfig) return { rootStyles: {}, childStyles: {} }
555
-
556
- const rootStyles = {}
557
- const childStyles = new Map()
558
-
559
- // 处理每个class配置
560
- cell.class.split(' ').forEach(className => {
561
- const classConfig = styleConfig[className]
562
- if (!classConfig) return
563
-
564
- // 处理根节点样式
565
- Object.entries(classConfig).forEach(([key, value]) => {
566
- if (!key.startsWith('*') && typeof key !== 'object') {
567
- rootStyles[key] = value
568
- }
569
- })
570
-
571
- // 处理子节点样式
572
- this.parseNestedStyles(classConfig, childStyles)
573
- })
574
- return {
575
- rootStyles,
576
- childStyles
577
- }
578
- },
579
-
580
- // 递归解析嵌套的样式配置
581
- parseNestedStyles (config, styleMap, parentKey = '') {
582
- Object.entries(config).forEach(([key, value]) => {
583
- if (!key.startsWith('*')) return
584
-
585
- const className = key.replace('*', '.')
586
-
587
- // 如果值是对象,检查是否包含样式和子节点
588
- if (typeof value === 'object') {
589
- const { style = {}, children = {} } = this.separateStyleAndChildren(value)
590
-
591
- // 创建或获取当前节点的样式配置
592
- if (!styleMap.has(className)) {
593
- styleMap.set(className, {
594
- styles: {},
595
- children: new Map()
596
- })
597
- }
598
-
599
- const nodeData = styleMap.get(className)
600
-
601
- // 合并样式
602
- Object.assign(nodeData.styles, style)
603
-
604
- // 递归处理子节点
605
- this.parseNestedStyles(children, nodeData.children, className)
606
- }
607
- })
608
- },
609
-
610
- // 分离样式属性和子节点配置
611
- separateStyleAndChildren (obj) {
612
- const style = {}
613
- const children = {}
614
-
615
- Object.entries(obj).forEach(([key, value]) => {
616
- if (key.startsWith('*')) {
617
- // 子节点配置
618
- children[key] = value
619
- } else {
620
- // 样式属性
621
- style[key] = value
622
- }
623
- })
624
-
625
- return { style, children }
626
- },
627
-
628
- // 应用组件样式
629
- async applyComponentStyles (component, cell, cellIndex) {
630
- if (!component || !component.$el) return
631
-
632
- const { rootStyles, childStyles } = await this.parseComponentStyles(cell)
633
-
634
- // 应用根节点样式
635
- if (Object.keys(rootStyles).length > 0) {
636
- Object.entries(rootStyles).forEach(([property, value]) => {
637
- component.$el.style.setProperty(property, value, 'important')
638
- })
639
- }
640
-
641
- // 如果没有子节点样式,直接返回
642
- if (childStyles.size === 0) return
643
-
644
- let retryCount = 0
645
- const maxRetries = 5
646
- const retryInterval = 100 // 100ms
647
-
648
- const applyStyles = () => {
649
- this.applyChildStylesOptimized(component.$el, childStyles)
650
- }
651
-
652
- // 首次应用样式
653
- applyStyles()
654
-
655
- // 创建重试机制
656
- const retryApplyStyles = () => {
657
- if (retryCount >= maxRetries) return
658
-
659
- setTimeout(() => {
660
- applyStyles()
661
- retryCount++
662
- retryApplyStyles()
663
- }, retryInterval)
664
- }
665
-
666
- // 开始重试
667
- retryApplyStyles()
668
-
669
- // 创建 MutationObserver 用于动态内容
670
- const observer = new MutationObserver((mutations) => {
671
- // 检查是否有新增节点
672
- const hasNewNodes = mutations.some(mutation =>
673
- mutation.type === 'childList' && mutation.addedNodes.length > 0
674
- )
675
-
676
- if (hasNewNodes) {
677
- applyStyles()
678
- }
679
- })
680
-
681
- // 配置 observer
682
- observer.observe(component.$el, {
683
- childList: true,
684
- subtree: true,
685
- attributes: false
686
- })
687
-
688
- // 3秒后停止观察
689
- // setTimeout(() => {
690
- // observer.disconnect()
691
- // }, 3000)
692
-
693
- // 组件销毁时清理
694
- this.$once('hook:beforeDestroy', () => {
695
- observer.disconnect()
696
- })
697
- },
698
-
699
- // 优化后的子节点样式应用方法
700
- applyChildStylesOptimized (rootElement, styleMap, parentSelector = '') {
701
- if (!rootElement) return
702
-
703
- // 处理样式映射
704
- try {
705
- for (const [selector, data] of styleMap.entries()) {
706
- const currentSelector = parentSelector ? `${parentSelector} ${selector}` : selector
707
-
708
- try {
709
- // 查找匹配的元素
710
- const elements = Array.from(rootElement.querySelectorAll(currentSelector))
711
-
712
- if (!elements.length) continue
713
-
714
- // 应用当前层级样式
715
- if (data.styles) {
716
- elements.forEach(element => {
717
- if (!element) return
718
-
719
- // 应用每个样式属性
720
- Object.entries(data.styles).forEach(([property, value]) => {
721
- try {
722
- element.style.setProperty(property, value, 'important')
723
- } catch (err) {
724
- console.warn(`设置样式失败: ${property}=${value}`, err)
725
- }
726
- })
727
- })
728
- }
729
-
730
- // 处理子层级
731
- if (data.children && data.children.size > 0) {
732
- elements.forEach(element => {
733
- if (element) {
734
- this.applyChildStylesOptimized(element, data.children, currentSelector)
735
- }
736
- })
737
- }
738
- } catch (err) {
739
- console.warn(`处理选择器失败: ${currentSelector}`, err)
740
- continue
741
- }
742
- }
743
- } catch (err) {}
744
- }
745
- },
746
- beforeMount () {
747
- if (this.useOssForImg) {
748
- this.uploadParams.resUploadMode = 'oss'
749
- }
750
- },
751
- mounted () {
752
- },
753
- }
754
-
755
- </script>
756
-
757
- <style scoped lang="less">
758
- .inputsDiv {
759
- display: flex;
760
- justify-content: space-between;
761
-
762
- .inputsDivItem {
763
- display: flex;
764
- align-items: center;
765
- padding: 0 4px;
766
- white-space: nowrap;
767
-
768
- .inputsDivItemLabel {
769
- padding: 0 4px;
770
- }
771
- }
772
- }
773
-
774
- .tdNoBorder {
775
- border-left: 1px solid #000;
776
- border-right: 1px solid #000;
777
- padding: 8px;
778
- }
779
-
780
- .tdWithBorder {
781
- border: 1px solid #000;
782
- padding: 8px;
783
- }
784
-
785
- .tdWithNoTopBorder {
786
- border-top-style: none;
787
- border-left: 1px solid #000;
788
- border-right: 1px solid #000;
789
- border-bottom: 1px solid #000;
790
- padding: 8px;
791
- }
792
-
793
- .grid-content {
794
- border-radius: 4px;
795
- min-height: 36px;
796
- text-align: center;
797
- color: #fff;
798
- background-color: #606266;
799
- }
800
-
801
- .bg-purple {
802
- background: #9254de;
803
- }
804
-
805
- .bg-purple-light {
806
- background: #b37feb;
807
- }
808
-
809
- .flexItem {
810
- border-radius: 8px;
811
- height: 100%;
812
- }
813
- </style>
1
+ <template>
2
+ <a-row id="has_row" type="flex" :gutter="gutter" :style="isWidget ? {margin: '0px'} : {'margin-bottom': '.5rem'}">
3
+ <template v-for="(cell, cellIndex) in columns">
4
+ <a-col
5
+ name="trGroup"
6
+ v-if="Array.isArray(cell) || !cell.dontShowRow"
7
+ :key="cellIndex"
8
+ :ref="`trGroup_${ cell.slotRef || cellIndex}`"
9
+ @hook:mounted="(h)=>applyAllStyles(cell,cellIndex)"
10
+ :span="calculateColSpan(cell)">
11
+ <div id="report_widget" v-if="isWidget">
12
+ <!-- 插槽渲染 -->
13
+ <template v-if="Array.isArray(cell)">
14
+ <!-- 处理 cell 是数组的情况 -->
15
+ <div v-for="(item, index) in cell" :key="index">
16
+ <x-report-tr-group
17
+ :env="env"
18
+ :key="index"
19
+ :columns="recalculateItem(item)"
20
+ :config-data="configData"
21
+ :config="config"
22
+ :display="true">
23
+ </x-report-tr-group>
24
+ </div>
25
+ </template>
26
+ <template v-else-if="cell.type === 'slot'">
27
+ <template
28
+ v-if="[
29
+ 'x-form-table',
30
+ 'h-form-table',
31
+ 'x-add-native-form',
32
+ 'h-add-native-form',
33
+ 'x-tree-pro',
34
+ 'x-his-editor',
35
+ 'x-tab',
36
+ 'h-tab',
37
+ 'x-form-group',
38
+ 'x-report',
39
+ 'x-buttons',
40
+ 'h-buttons',
41
+ 'x-label-select',
42
+ 'x-conversation',
43
+ 'x-check-list',
44
+ 'x-cardSet',
45
+ 'x-collapse',
46
+ 'x-h-descriptions',
47
+ 'x-sidebar',
48
+ 'x-list',
49
+ 'x-input',
50
+ 'x-time-line',
51
+ 'x-radio',
52
+ 'x-calendar',
53
+ 'x-time-select',
54
+ 'x-checkbox',
55
+ 'x-title',
56
+ 'x-select',
57
+ 'x-tree-rows',
58
+ 'x-three-test-orders',
59
+ 'x-shift-schedule',
60
+ 'x-charge',
61
+ 'x-questionnaire',
62
+ 'x-import-excel-button',
63
+ 'x-chart'
64
+ ].includes(cell.slotType)">
65
+ <component
66
+ :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
67
+ :key="cellIndex"
68
+ :ref="`dynamicComponent_${ cell.slotRef || cellIndex}`"
69
+ v-bind="cell.attrs"
70
+ :serviceName="cell.serviceName"
71
+ :serverName="cell.serviceName"
72
+ v-on="getEventHandlers(cell)"
73
+ @hook:mounted="(h)=>onComponentMounted(h,cell,cellIndex)"
74
+ @beforeDataChange="beforeDataChange"
75
+ @rowClick="handleRowClick"
76
+ @onExpand="onExpand"
77
+ :queryParamsName="cell.slotConfig"
78
+ :configName="cell.slotConfig"
79
+ :countVisible="false"
80
+ :env="env"
81
+ />
82
+ </template>
83
+ </template>
84
+ </div>
85
+ <a-card v-else class="flexItem" :bordered="false">
86
+ <!-- 插槽渲染 -->
87
+ <template v-if="Array.isArray(cell)">
88
+ <!-- 处理 cell 是数组的情况 -->
89
+ <div v-for="(item, index) in cell" :key="index">
90
+ <x-report-tr-group
91
+ :server-name="serverName"
92
+ :env="env"
93
+ :key="index"
94
+ :columns="recalculateItem(item)"
95
+ :config-data="configData"
96
+ :config="config"
97
+ :display="true">
98
+ </x-report-tr-group>
99
+ </div>
100
+ </template>
101
+ <template v-else-if="cell.type === 'slot'">
102
+ <template
103
+ v-if="[
104
+ 'x-form-table',
105
+ 'h-form-table',
106
+ 'x-add-native-form',
107
+ 'h-add-native-form',
108
+ 'x-tree-pro',
109
+ 'x-his-editor',
110
+ 'x-tab',
111
+ 'h-tab',
112
+ 'x-form-group',
113
+ 'x-report',
114
+ 'x-buttons',
115
+ 'h-buttons',
116
+ 'x-label-select',
117
+ 'x-conversation',
118
+ 'x-check-list',
119
+ 'x-cardSet',
120
+ 'x-collapse',
121
+ 'x-h-descriptions',
122
+ 'x-sidebar',
123
+ 'x-list',
124
+ 'x-input',
125
+ 'x-time-line',
126
+ 'x-radio',
127
+ 'x-calendar',
128
+ 'x-time-select',
129
+ 'x-checkbox',
130
+ 'x-title',
131
+ 'x-select',
132
+ 'x-tree-rows',
133
+ 'x-three-test-orders',
134
+ 'x-shift-schedule',
135
+ 'x-charge',
136
+ 'x-questionnaire',
137
+ 'x-import-excel-button',
138
+ 'x-chart'
139
+ ].includes(cell.slotType)">
140
+ <component
141
+ :is="getComponentName(cell.slotConfig, cell.serviceName, cell.slotType)"
142
+ :key="cellIndex"
143
+ :ref="`dynamicComponent_${ cell.slotRef || cellIndex}`"
144
+ v-bind="cell.attrs"
145
+ :serviceName="cell.serviceName"
146
+ :serverName="cell.serviceName"
147
+ v-on="getEventHandlers(cell)"
148
+ @hook:mounted="(h)=>onComponentMounted(h,cell,cellIndex)"
149
+ @beforeDataChange="beforeDataChange"
150
+ @rowClick="handleRowClick"
151
+ @onExpand="onExpand"
152
+ :queryParamsName="cell.slotConfig"
153
+ :configName="cell.slotConfig"
154
+ :countVisible="false"
155
+ :env="env"
156
+ />
157
+ </template>
158
+ </template>
159
+ </a-card>
160
+ </a-col>
161
+ </template>
162
+ </a-row>
163
+ </template>
164
+
165
+ <script>
166
+ import Upload from '@vue2-client/base-client/components/common/Upload'
167
+ import { getRealKeyData } from '@vue2-client/utils/util'
168
+ import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
169
+ import { getConfigByName, runLogic } from '@vue2-client/services/api/common'
170
+ import { getMicroData, getWindow, isMicroAppEnv, microDispatch } from '@vue2-client/utils/microAppUtils'
171
+
172
+ export default {
173
+ name: 'XReportTrGroup',
174
+ components: {
175
+ Upload,
176
+ XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable.vue'),
177
+ HFormTable: () => import('@vue2-client/base-client/components/common/HIS/HFormTable/HFormTable.vue'),
178
+ XAddNativeForm: () => import('@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'),
179
+ HAddNativeForm: () => import('@vue2-client/base-client/components/common/HIS/HAddNativeForm/HAddNativeForm.vue'),
180
+ XFormGroup: () => import('@vue2-client/base-client/components/common/XFormGroup/XFormGroup.vue'),
181
+ XTreePro: () => import('@vue2-client/base-client/components/common/XTree/XTreePro.vue'),
182
+ XHisEditor: () => import('@vue2-client/base-client/components/his/XHisEditor/XHisEditor.vue'),
183
+ XTab: () => import('@vue2-client/base-client/components/common/XTab/XTab.vue'),
184
+ HTab: () => import('@vue2-client/base-client/components/common/HIS/HTab/HTab.vue'),
185
+ XReport: () => import('@vue2-client/base-client/components/common/XReport/XReport.vue'),
186
+ XButtons: () => import('@vue2-client/base-client/components/common/XButtons/XButtons.vue'),
187
+ HButtons: () => import('@vue2-client/base-client/components/common/HIS/HButtons/HButtons.vue'),
188
+ XLabelSelect: () => import('@vue2-client/base-client/components/common/XLabelSelect/XLabelSelect.vue'),
189
+ XConversation: () => import('@vue2-client/base-client/components/common/XConversation/XConversation.vue'),
190
+ XCheckList: () => import('@vue2-client/base-client/components/common/XCheckList/XCheckList.vue'),
191
+ XCardSet: () => import('@vue2-client/base-client/components/common/XCardSet/XCardSet.vue'),
192
+ XCollapse: () => import('@vue2-client/base-client/components/common/XCollapse/XCollapse.vue'),
193
+ XHDescriptions: () => import('@vue2-client/base-client/components/his/XHDescriptions/XHDescriptions.vue'),
194
+ XSidebar: () => import('@vue2-client/base-client/components/his/XSidebar/XSidebar.vue'),
195
+ XList: () => import('@vue2-client/base-client/components/his/XList/XList.vue'),
196
+ XInput: () => import('@vue2-client/base-client/components/common/XInput/XInput.vue'),
197
+ XTimeLine: () => import('@vue2-client/base-client/components/common/XTimeline/XTimeline.vue'),
198
+ XRadio: () => import('@vue2-client/base-client/components/his/XRadio/XRadio.vue'),
199
+ XCalendar: () => import('@vue2-client/base-client/components/common/XCalendar/XCalendar.vue'),
200
+ XTimeSelect: () => import('@vue2-client/base-client/components/his/XTimeSelect/XTimeSelect.vue'),
201
+ XCheckbox: () => import('@vue2-client/base-client/components/his/XCheckbox/XCheckbox.vue'),
202
+ XTitle: () => import('@vue2-client/base-client/components/his/XTitle/XTitle.vue'),
203
+ XSelect: () => import('@vue2-client/base-client/components/his/XSelect/XSelect.vue'),
204
+ XTreeRows: () => import('@vue2-client/base-client/components/his/XTreeRows/XTreeRows.vue'),
205
+ XThreeTestOrders: () => import('@vue2-client/base-client/components/his/threeTestOrders/threeTestOrders.vue'),
206
+ XShiftSchedule: () => import('@vue2-client/base-client/components/his/XShiftSchedule/XShiftSchedule.vue'),
207
+ XCharge: () => import('@vue2-client/base-client/components/his/XCharge/XCharge.vue'),
208
+ XQuestionnaire: () => import('@vue2-client/base-client/components/his/XQuestionnaire/XQuestionnaire.vue'),
209
+ XImportExcelButton: () => import('@vue2-client/base-client/components/his/XImportExcelButton/XImportExcelButton.vue'),
210
+ XChart: () => import('@vue2-client/base-client/components/his/XChart/XChart.vue')
211
+ },
212
+ props: {
213
+ // 每一行的配置
214
+ columns: {
215
+ type: Array,
216
+ required: true
217
+ },
218
+ showImgInCell: {
219
+ type: Boolean,
220
+ default: false
221
+ },
222
+ config: {
223
+ type: Object,
224
+ default: function () {
225
+ return {}
226
+ }
227
+ },
228
+ // 命名空间
229
+ serverName: {
230
+ type: String,
231
+ default: 'af-system'
232
+ },
233
+ // 环境
234
+ env: {
235
+ type: String,
236
+ default: 'prod'
237
+ },
238
+ // 原始配置
239
+ configData: {
240
+ type: Object,
241
+ required: true
242
+ },
243
+ // 是否为展示行
244
+ display: {
245
+ type: Boolean,
246
+ default: false
247
+ },
248
+ },
249
+ computed: {
250
+ allSlotSum () {
251
+ // 计算总共有多少个Slot
252
+ let sum = 0
253
+ this.columns.forEach((item) => {
254
+ if (Array.isArray(item)) {
255
+ item.forEach((cell) => {
256
+ if (cell.type === 'slot') {
257
+ sum++
258
+ }
259
+ })
260
+ } else if (item.type && item.type === 'slot') {
261
+ sum++
262
+ }
263
+ })
264
+ return sum
265
+ }
266
+ },
267
+ data () {
268
+ return {
269
+ gutter: [8, { xs: 8, sm: 16, md: 24, lg: 32 }], // 设置水槽大小
270
+ maxColSpan: 12,
271
+ uploadParams: {
272
+ type: 'image',
273
+ accept: ['*'],
274
+ resUploadStock: 1,
275
+ pathKey: 'cs'
276
+ },
277
+ mixinData: {},
278
+ flexItemBodyState: {},
279
+ // 已经渲染得插槽得数量
280
+ slotRendered: 0,
281
+ // tableConfig: {}
282
+ }
283
+ },
284
+ watch: {
285
+ columns: {
286
+ deep: true,
287
+ immediate: true,
288
+ handler (newVal) {
289
+ // 使用nextTick确保DOM更新
290
+ this.$nextTick(() => {
291
+ this.$forceUpdate()
292
+ })
293
+ }
294
+ }
295
+ },
296
+ inject: {
297
+ openDialog: { default: false },
298
+ emitEvent: { default: false },
299
+ registerComponent: { default: false },
300
+ setColSpanByName: { default: false },
301
+ setGlobalData: { default: false },
302
+ getGlobalData: { default: false },
303
+ getComponentByName: { default: false },
304
+ runLogic: { default: false },
305
+ getMixinData: { default: false },
306
+ getSelectedId: { default: false },
307
+ isInAModal: { default: false },
308
+ getConfigByName: { default: false },
309
+ getSelectedData: { default: false },
310
+ getOutEnv: { default: false },
311
+ currUser: { default: false },
312
+ isWidget: { default: false },
313
+ findComponentByName: { default: false },
314
+ closeAddReport: { default: false }
315
+ },
316
+ methods: {
317
+ getWindow,
318
+ isMicroAppEnv,
319
+ microDispatch,
320
+ getMicroData,
321
+ getRealKeyData,
322
+ handleRowClick (record) {
323
+ this.$emit('rowClick', record)
324
+ },
325
+ beforeDataChange (record) {
326
+ this.$emit('beforeDataChange', record)
327
+ },
328
+ onExpand (expanded, record) {
329
+ this.$emit('expand', expanded, record)
330
+ },
331
+ listClick (data) {
332
+ this.$emit('listClick', data)
333
+ },
334
+ calculateColSpan (cell) {
335
+ return Array.isArray(cell)
336
+ ? cell[0][0]?.colSpan * 2
337
+ : (cell?.colSpan ?? cell?.def?.colSpan ?? 1) * 2
338
+ },
339
+ applyAllStyles (cell, cellIndex) {
340
+ // 应用组件样式
341
+ const component = this.$refs[`trGroup_${ cell.slotRef || cellIndex}`][0]
342
+ // 确保组件已经完全挂载
343
+ this.$nextTick(() => {
344
+ this.applyComponentStyles(component, cell, cellIndex)
345
+ })
346
+ },
347
+ onComponentMounted (h, cell, cellIndex) {
348
+ this.slotRendered += 1
349
+ if (this.slotRendered >= this.allSlotSum) {
350
+ this.$emit('slotRendered')
351
+ }
352
+ if (this.getMixinData && this.getMixinData()) {
353
+ this.mixinData = this.getMixinData()
354
+ }
355
+ if (cell.slotRef) {
356
+ this.registerComponent(cell.slotRef, this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0])
357
+ }
358
+ // 传递给祖先组件
359
+ const shouldInit = cell.shouldInit == null ? true : cell.shouldInit
360
+ if (shouldInit) {
361
+ if (cell.slotType === 'x-add-native-form') {
362
+ // 简易表单需要主动调用初始化方法
363
+ getConfigByName(cell.slotConfig, cell.serviceName, async (res) => {
364
+ // 如果配置了 表单初始化logic
365
+ // 调用 logic 获取参数
366
+ let param = { ...this.mixinData }
367
+ let selectedId
368
+ if (res.paramLogicName) {
369
+ if (!!this.getSelectedId) {
370
+ selectedId = this.getSelectedId()
371
+ if (typeof selectedId !== 'object') {
372
+ selectedId = { selectedId: selectedId }
373
+ }
374
+ }
375
+ param = Object.assign(param, await runLogic(res.paramLogicName, selectedId, cell.serviceName))
376
+ }
377
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
378
+ serviceName: cell.serviceName,
379
+ configName: cell.slotConfig,
380
+ formItems: res.formJson,
381
+ showSubmitBtn: !this.isInAModal,
382
+ businessType: param.businessType || '新增',
383
+ layout: res.xAddFormLayout,
384
+ primaryKey: res.primaryKey,
385
+ ...res,
386
+ fixedAddForm: param,
387
+ modifyModelData: {
388
+ files: param.files,
389
+ images: param.images
390
+ }
391
+ })
392
+ }, this.env === 'dev')
393
+ } else if (cell.slotType === 'x-form-group') {
394
+ // 简易表单需要主动调用初始化方法
395
+ getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
396
+ // 如果配置了 表单初始化logic
397
+ // 调用 logic 获取参数
398
+ const param = { ...this.mixinData }
399
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
400
+ ...res,
401
+ serviceName: cell.serviceName,
402
+ showSubmitBtn: !this.isInAModal,
403
+ businessType: param.businessType || '新增',
404
+ modifyModelData: param,
405
+ showLeftTab: true,
406
+ })
407
+ }, this.env === 'dev')
408
+ } else if (cell.slotType === 'x-label-select') {
409
+ // 按钮组需要主动调用初始化方法
410
+ getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
411
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
412
+ ...res,
413
+ serviceName: cell.serviceName,
414
+ })
415
+ }, this.env === 'dev')
416
+ }
417
+ }
418
+ if (cell.slotType === 'x-report') {
419
+ const param = { ...this.mixinData }
420
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init(param)
421
+ }
422
+ if (cell.slotType === 'x-conversation') {
423
+ getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
424
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
425
+ serviceName: cell.serviceName,
426
+ ...res,
427
+ })
428
+ }, this.env === 'dev')
429
+ }
430
+ if (cell.slotType === 'x-check-list') {
431
+ getConfigByName(cell.slotConfig, cell.serviceName, (res) => {
432
+ this.$refs[`dynamicComponent_${cell.slotRef || cellIndex}`][0].init({
433
+ serviceName: cell.serviceName,
434
+ ...res,
435
+ })
436
+ }, this.env === 'dev')
437
+ }
438
+ },
439
+ recalculateItem (item) {
440
+ const totalColSpan = item.reduce((sum, cell) => {
441
+ // 保留手动设置的colSpan
442
+ return sum + (cell._isManualColSpan ? 0 : (cell.colSpan || 1))
443
+ }, 0)
444
+ return item.map(cell => {
445
+ // 跳过已手动设置的单元格
446
+ if (cell._isManualColSpan) return cell
447
+ const newColSpan = Math.round((cell.colSpan || 1) / totalColSpan * 12)
448
+ return {
449
+ ...cell,
450
+ colSpan: newColSpan,
451
+ // 标记自动计算的单元格
452
+ _isAutoCalculated: true
453
+ }
454
+ })
455
+ },
456
+
457
+ getEventHandlers (cell) {
458
+ const handlers = {}
459
+ if (!cell?.events || cell?.events?.length === 0) {
460
+ return handlers
461
+ }
462
+ cell.events.forEach(event => {
463
+ handlers[event.type] = async (...args) => {
464
+ let func = event.customFunction
465
+ if (func && func.startsWith('function')) {
466
+ func = func.replace('function', 'async function')
467
+ }
468
+ const result = await executeStrFunctionByContext(this, func, args)
469
+ if (result instanceof Promise) {
470
+ result.then((res) => {
471
+ if (!res) return
472
+ let messageType = 'success'
473
+ // 如果传递了组件名字 自动调用刷新
474
+ if (res?.name) {
475
+ const waitRefreshRef = this.getComponentByName(res.name)
476
+ if (waitRefreshRef) {
477
+ waitRefreshRef.refresh()
478
+ } else {
479
+ console.warn(`未找到组件${res.name}无法刷新`)
480
+ }
481
+ }
482
+ // 如果传递消息类型 自动调用消息
483
+ if (res?.messageType) {
484
+ messageType = res.messageType
485
+ }
486
+ // 如果传递了提示信息自动调用提示
487
+ if (res?.message) {
488
+ this.$message[messageType](res?.message)
489
+ }
490
+ })
491
+ }
492
+ }
493
+ })
494
+ return handlers
495
+ },
496
+ getComponentName (queryParamsName, serviceName, componentName) {
497
+ return componentName
498
+ },
499
+ // 判断单元格样式
500
+ determineCellStyle (cell, color = '#000', borderWidth = '1px') {
501
+ // 如果声明了borderColor
502
+ if (this.config.style.borderColor) {
503
+ color = this.config.style.borderColor
504
+ }
505
+ let result = {}
506
+ // 如果表格也声明了样式,用表格样式将样式覆盖
507
+ if (cell.style) {
508
+ if (cell.noBorder) {
509
+ result = { ...cell.style }
510
+ } else {
511
+ if (this.noTopBorder) {
512
+ result = { ...cell.style }
513
+ } else {
514
+ result = { ...cell.style }
515
+ }
516
+ }
517
+ return result
518
+ }
519
+ return result
520
+ },
521
+ // 把用户定义的组件,传递到整个杉格中,方便调用
522
+ passComponentNamesToAncestor (refs) {
523
+ // 遍历所有 refs
524
+ Object.entries(refs).forEach(([refKey, refValue]) => {
525
+ // 检查 ref 是否以 dynamicComponent_ 开头
526
+ if (refKey.startsWith('dynamicComponent_')) {
527
+ const componentRef = refValue[0]
528
+ if (componentRef) {
529
+ // 去掉前缀并获取组件名字
530
+ const index = refKey.replace('dynamicComponent_', '') // 去掉前缀
531
+ // 传递给祖先组件
532
+ this.registerComponent(index, componentRef)
533
+ }
534
+ }
535
+ })
536
+ },
537
+ // 获取组件样式配置
538
+ async getComponentStyleConfig (componentType) {
539
+ try {
540
+ // 从配置中获取样式定义
541
+ const styleConfig = this.$appdata.getStylesByKey(componentType)
542
+ return styleConfig || {}
543
+ } catch (error) {
544
+ console.error('获取组件样式配置失败:', error)
545
+ return {}
546
+ }
547
+ },
548
+
549
+ // 解析组件样式配置
550
+ async parseComponentStyles (cell) {
551
+ if (!cell.class) return { rootStyles: {}, childStyles: {} }
552
+
553
+ const styleConfig = await this.getComponentStyleConfig(cell.slotType)
554
+ if (!styleConfig) return { rootStyles: {}, childStyles: {} }
555
+
556
+ const rootStyles = {}
557
+ const childStyles = new Map()
558
+
559
+ // 处理每个class配置
560
+ cell.class.split(' ').forEach(className => {
561
+ const classConfig = styleConfig[className]
562
+ if (!classConfig) return
563
+
564
+ // 处理根节点样式
565
+ Object.entries(classConfig).forEach(([key, value]) => {
566
+ if (!key.startsWith('*') && typeof key !== 'object') {
567
+ rootStyles[key] = value
568
+ }
569
+ })
570
+
571
+ // 处理子节点样式
572
+ this.parseNestedStyles(classConfig, childStyles)
573
+ })
574
+ return {
575
+ rootStyles,
576
+ childStyles
577
+ }
578
+ },
579
+
580
+ // 递归解析嵌套的样式配置
581
+ parseNestedStyles (config, styleMap, parentKey = '') {
582
+ Object.entries(config).forEach(([key, value]) => {
583
+ if (!key.startsWith('*')) return
584
+
585
+ const className = key.replace('*', '.')
586
+
587
+ // 如果值是对象,检查是否包含样式和子节点
588
+ if (typeof value === 'object') {
589
+ const { style = {}, children = {} } = this.separateStyleAndChildren(value)
590
+
591
+ // 创建或获取当前节点的样式配置
592
+ if (!styleMap.has(className)) {
593
+ styleMap.set(className, {
594
+ styles: {},
595
+ children: new Map()
596
+ })
597
+ }
598
+
599
+ const nodeData = styleMap.get(className)
600
+
601
+ // 合并样式
602
+ Object.assign(nodeData.styles, style)
603
+
604
+ // 递归处理子节点
605
+ this.parseNestedStyles(children, nodeData.children, className)
606
+ }
607
+ })
608
+ },
609
+
610
+ // 分离样式属性和子节点配置
611
+ separateStyleAndChildren (obj) {
612
+ const style = {}
613
+ const children = {}
614
+
615
+ Object.entries(obj).forEach(([key, value]) => {
616
+ if (key.startsWith('*')) {
617
+ // 子节点配置
618
+ children[key] = value
619
+ } else {
620
+ // 样式属性
621
+ style[key] = value
622
+ }
623
+ })
624
+
625
+ return { style, children }
626
+ },
627
+
628
+ // 应用组件样式
629
+ async applyComponentStyles (component, cell, cellIndex) {
630
+ if (!component || !component.$el) return
631
+
632
+ const { rootStyles, childStyles } = await this.parseComponentStyles(cell)
633
+
634
+ // 应用根节点样式
635
+ if (Object.keys(rootStyles).length > 0) {
636
+ Object.entries(rootStyles).forEach(([property, value]) => {
637
+ component.$el.style.setProperty(property, value, 'important')
638
+ })
639
+ }
640
+
641
+ // 如果没有子节点样式,直接返回
642
+ if (childStyles.size === 0) return
643
+
644
+ let retryCount = 0
645
+ const maxRetries = 5
646
+ const retryInterval = 100 // 100ms
647
+
648
+ const applyStyles = () => {
649
+ this.applyChildStylesOptimized(component.$el, childStyles)
650
+ }
651
+
652
+ // 首次应用样式
653
+ applyStyles()
654
+
655
+ // 创建重试机制
656
+ const retryApplyStyles = () => {
657
+ if (retryCount >= maxRetries) return
658
+
659
+ setTimeout(() => {
660
+ applyStyles()
661
+ retryCount++
662
+ retryApplyStyles()
663
+ }, retryInterval)
664
+ }
665
+
666
+ // 开始重试
667
+ retryApplyStyles()
668
+
669
+ // 创建 MutationObserver 用于动态内容
670
+ const observer = new MutationObserver((mutations) => {
671
+ // 检查是否有新增节点
672
+ const hasNewNodes = mutations.some(mutation =>
673
+ mutation.type === 'childList' && mutation.addedNodes.length > 0
674
+ )
675
+
676
+ if (hasNewNodes) {
677
+ applyStyles()
678
+ }
679
+ })
680
+
681
+ // 配置 observer
682
+ observer.observe(component.$el, {
683
+ childList: true,
684
+ subtree: true,
685
+ attributes: false
686
+ })
687
+
688
+ // 3秒后停止观察
689
+ // setTimeout(() => {
690
+ // observer.disconnect()
691
+ // }, 3000)
692
+
693
+ // 组件销毁时清理
694
+ this.$once('hook:beforeDestroy', () => {
695
+ observer.disconnect()
696
+ })
697
+ },
698
+
699
+ // 优化后的子节点样式应用方法
700
+ applyChildStylesOptimized (rootElement, styleMap, parentSelector = '') {
701
+ if (!rootElement) return
702
+
703
+ // 处理样式映射
704
+ try {
705
+ for (const [selector, data] of styleMap.entries()) {
706
+ const currentSelector = parentSelector ? `${parentSelector} ${selector}` : selector
707
+
708
+ try {
709
+ // 查找匹配的元素
710
+ const elements = Array.from(rootElement.querySelectorAll(currentSelector))
711
+
712
+ if (!elements.length) continue
713
+
714
+ // 应用当前层级样式
715
+ if (data.styles) {
716
+ elements.forEach(element => {
717
+ if (!element) return
718
+
719
+ // 应用每个样式属性
720
+ Object.entries(data.styles).forEach(([property, value]) => {
721
+ try {
722
+ element.style.setProperty(property, value, 'important')
723
+ } catch (err) {
724
+ console.warn(`设置样式失败: ${property}=${value}`, err)
725
+ }
726
+ })
727
+ })
728
+ }
729
+
730
+ // 处理子层级
731
+ if (data.children && data.children.size > 0) {
732
+ elements.forEach(element => {
733
+ if (element) {
734
+ this.applyChildStylesOptimized(element, data.children, currentSelector)
735
+ }
736
+ })
737
+ }
738
+ } catch (err) {
739
+ console.warn(`处理选择器失败: ${currentSelector}`, err)
740
+ continue
741
+ }
742
+ }
743
+ } catch (err) {}
744
+ }
745
+ },
746
+ beforeMount () {
747
+ if (this.useOssForImg) {
748
+ this.uploadParams.resUploadMode = 'oss'
749
+ }
750
+ },
751
+ mounted () {
752
+ },
753
+ }
754
+
755
+ </script>
756
+
757
+ <style scoped lang="less">
758
+ .inputsDiv {
759
+ display: flex;
760
+ justify-content: space-between;
761
+
762
+ .inputsDivItem {
763
+ display: flex;
764
+ align-items: center;
765
+ padding: 0 4px;
766
+ white-space: nowrap;
767
+
768
+ .inputsDivItemLabel {
769
+ padding: 0 4px;
770
+ }
771
+ }
772
+ }
773
+
774
+ .tdNoBorder {
775
+ border-left: 1px solid #000;
776
+ border-right: 1px solid #000;
777
+ padding: 8px;
778
+ }
779
+
780
+ .tdWithBorder {
781
+ border: 1px solid #000;
782
+ padding: 8px;
783
+ }
784
+
785
+ .tdWithNoTopBorder {
786
+ border-top-style: none;
787
+ border-left: 1px solid #000;
788
+ border-right: 1px solid #000;
789
+ border-bottom: 1px solid #000;
790
+ padding: 8px;
791
+ }
792
+
793
+ .grid-content {
794
+ border-radius: 4px;
795
+ min-height: 36px;
796
+ text-align: center;
797
+ color: #fff;
798
+ background-color: #606266;
799
+ }
800
+
801
+ .bg-purple {
802
+ background: #9254de;
803
+ }
804
+
805
+ .bg-purple-light {
806
+ background: #b37feb;
807
+ }
808
+
809
+ .flexItem {
810
+ border-radius: 8px;
811
+ height: 100%;
812
+ }
813
+ </style>