vue2-client 1.12.102 → 1.13.1

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