vue2-client 1.12.63 → 1.12.65

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