vue2-client 1.13.15 → 1.13.17

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