vue2-client 1.10.35 → 1.11.2

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,233 +1,233 @@
1
- <template>
2
- <a-card :bordered="false">
3
- <a-tabs :tabBarGutter="10" :activeKey="activeKey" @change="tabPaneChange">
4
- <a-tab-pane
5
- :forceRender="true"
6
- v-for="(tab, index) in config.data"
7
- :key="index"
8
- :tab="tab.title"
9
- >
10
- <component
11
- :is="tab.slotType"
12
- :key="index"
13
- :ref="`tab_com_${tab.slotType}_${index}`"
14
- :serviceName="tab.serviceName"
15
- :serverName="tab.serviceName"
16
- :queryParamsName="tab.slotConfig"
17
- v-on="getEventHandlers(tab,index)"
18
- @hook:mounted="(h)=>onComponentMounted(h,tab,index)"
19
- :config-name="tab.slotConfig"
20
- :env="env"
21
- />
22
- </a-tab-pane>
23
- </a-tabs>
24
- </a-card>
25
- </template>
26
-
27
- <script>
28
- import { getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
29
- import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
30
- import { getRealKeyData } from '@vue2-client/utils/util'
31
- import { getMicroData, getWindow, isMicroAppEnv, microDispatch } from '@vue2-client/utils/microAppUtils'
32
- import { mapState } from 'vuex'
33
-
34
- export default {
35
- name: 'XTab',
36
- components: {
37
- XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable'),
38
- XAddNativeForm: () => import('@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'),
39
- XReportGrid: () => import('@vue2-client/base-client/components/common/XReportGrid/XReport.vue')
40
- },
41
- inject: ['isInAModal', 'getSelectedId', 'getSelectedData', 'getOutEnv', 'setGlobalData', 'getGlobalData'],
42
- provide () {
43
- return {
44
- currUser: this.currUser,
45
- getSelectedId: this.getSelectedId
46
- }
47
- },
48
- data () {
49
- return {
50
- activeKey: 0,
51
- // 配置
52
- config: undefined,
53
- attr: {}
54
- }
55
- },
56
- computed: {
57
- ...mapState('account', { currUser: 'user' })
58
- },
59
- methods: {
60
- // 自定义函数中调用的方法 这个不能删
61
- getWindow,
62
- runLogic,
63
- isMicroAppEnv,
64
- microDispatch,
65
- getMicroData,
66
- getRealKeyData,
67
- getConfigByName,
68
- getConfigByNameAsync,
69
- tabPaneChange (newKey) {
70
- let result = {}
71
- if (this.activeKey === newKey) {
72
- return
73
- }
74
- const oldKey = this.activeKey
75
- if (this.config.changeFunc) {
76
- const args = [
77
- oldKey,
78
- newKey,
79
- this.config.data[oldKey],
80
- this.config.data[newKey],
81
- `tab_com_${this.config.data[oldKey].slotType}_${oldKey}`,
82
- `tab_com_${this.config.data[newKey].slotType}_${newKey}`,
83
- this.$refs[`tab_com_${this.config.data[oldKey].slotType}_${oldKey}`][0]
84
- ]
85
- if (!this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]) {
86
- args.push(null)
87
- console.warn('新页签示例切换页签时暂未初始化,仅调用该页签初始化方法不调用切换函数')
88
- } else {
89
- args.push(this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`][0])
90
- }
91
- result = executeStrFunctionByContext(this, this.config.changeFunc, args)
92
- if (result && result.noChange) {
93
- console.info('不切换页签作为按钮使用')
94
- } else {
95
- this.activeKey = newKey
96
- if (result && result.callback && typeof result.callback === 'function') {
97
- // 使用 $nextTick 等待 DOM 更新完成后再获取组件实例
98
- this.$nextTick(() => {
99
- const newComponent = this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]
100
- if (!newComponent || !newComponent[0]) {
101
- console.warn('组件实例尚未创建,等待组件mounted事件')
102
- // 使用 MutationObserver 监听DOM变化
103
- const observer = new MutationObserver((mutations, obs) => {
104
- const newComp = this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]
105
- if (newComp && newComp[0]) {
106
- obs.disconnect()
107
- console.log('组件已创建,执行回调')
108
- result.callback()
109
- }
110
- })
111
- observer.observe(this.$el, {
112
- childList: true,
113
- subtree: true
114
- })
115
- // 设置超时,避免无限等待
116
- setTimeout(() => {
117
- observer.disconnect()
118
- console.warn('等待组件创建超时')
119
- }, 500)
120
-
121
- return
122
- }
123
- result.callback()
124
- })
125
- }
126
- }
127
- } else {
128
- this.activeKey = newKey
129
- }
130
- },
131
- initConfig () {
132
- if (this.configName) {
133
- this.getConfig()
134
- } else if (this.localConfig) {
135
- this.config = this.localConfig
136
- }
137
- },
138
- getConfig () {
139
- getConfigByName(this.configName, this.serverName, res => {
140
- this.config = res
141
- }, this.env === 'dev')
142
- },
143
- getEventHandlers (tab, index) {
144
- const handlers = {}
145
- if (!tab?.events || tab?.events?.length === 0) {
146
- return handlers
147
- }
148
- tab.events.forEach(event => {
149
- handlers[event.type] = (...args) => {
150
- console.info('Event handled:', event.type, args)
151
- executeStrFunctionByContext(this.$refs[`tab_com_${tab.slotType}_${index}`][0], event.customFunction, args)
152
- }
153
- })
154
- return handlers
155
- },
156
- onComponentMounted (h, tab, index) {
157
- console.log(`插槽组件已经初始化 slotType ${tab.slotType},ref= tab_com_${tab.slotType}_${index} , serviceName = ${tab.serviceName}`)
158
- if (tab.slotType === 'x-add-native-form') {
159
- // 建议表单需要主动调用初始化方法
160
- getConfigByName(tab.slotConfig, tab.serviceName, async (res) => {
161
- // 如果配置了 表单初始化logic
162
- // 调用 logic 获取参数
163
- let param = {}
164
- let selectedId
165
- if (res.paramLogicName) {
166
- if (!!this.getSelectedId) {
167
- selectedId = this.getSelectedId()
168
- if (typeof selectedId !== 'object') {
169
- selectedId = { selectedId: selectedId }
170
- }
171
- }
172
- param = Object.assign(param, await runLogic(res.paramLogicName, selectedId, tab.serviceName))
173
- }
174
- this.$refs[`tab_com_${tab.slotType}_${index}`][0].init({
175
- formItems: res.formJson,
176
- showSubmitBtn: !this.isInAModal,
177
- businessType: '新增',
178
- layout: res.xAddFormLayout,
179
- ...res,
180
- fixedAddForm: param,
181
- modifyModelData: {
182
- files: param.files,
183
- images: param.images
184
- }
185
- })
186
- }, this.env === 'dev')
187
- }
188
- },
189
- },
190
- props: {
191
- // 配置名
192
- configName: {
193
- type: String,
194
- default: undefined
195
- },
196
- serverName: {
197
- type: String,
198
- default: undefined
199
- },
200
- env: {
201
- type: String,
202
- default: 'prod'
203
- },
204
- // 本地配置,调试用
205
- localConfig: {
206
- type: Object,
207
- default: undefined
208
- },
209
- },
210
- watch: {
211
- configName: {
212
- deep: true,
213
- immediate: true,
214
- handler (val) {
215
- this.initConfig()
216
- }
217
- },
218
- // 如果本地配置更改了,重新初始化
219
- localConfig: {
220
- deep: true,
221
- immediate: true,
222
- handler (val) {
223
- this.initConfig()
224
- }
225
- },
226
- },
227
- }
228
- </script>
229
- <style scoped>
230
- :deep(.ant-tabs-bar) {
231
- margin: 0
232
- }
233
- </style>
1
+ <template>
2
+ <a-card :bordered="false">
3
+ <a-tabs :tabBarGutter="10" :activeKey="activeKey" @change="tabPaneChange">
4
+ <a-tab-pane
5
+ :forceRender="true"
6
+ v-for="(tab, index) in config.data"
7
+ :key="index"
8
+ :tab="tab.title"
9
+ >
10
+ <component
11
+ :is="tab.slotType"
12
+ :key="index"
13
+ :ref="`tab_com_${tab.slotType}_${index}`"
14
+ :serviceName="tab.serviceName"
15
+ :serverName="tab.serviceName"
16
+ :queryParamsName="tab.slotConfig"
17
+ v-on="getEventHandlers(tab,index)"
18
+ @hook:mounted="(h)=>onComponentMounted(h,tab,index)"
19
+ :config-name="tab.slotConfig"
20
+ :env="env"
21
+ />
22
+ </a-tab-pane>
23
+ </a-tabs>
24
+ </a-card>
25
+ </template>
26
+
27
+ <script>
28
+ import { getConfigByName, getConfigByNameAsync, runLogic } from '@vue2-client/services/api/common'
29
+ import { executeStrFunctionByContext } from '@vue2-client/utils/runEvalFunction'
30
+ import { getRealKeyData } from '@vue2-client/utils/util'
31
+ import { getMicroData, getWindow, isMicroAppEnv, microDispatch } from '@vue2-client/utils/microAppUtils'
32
+ import { mapState } from 'vuex'
33
+
34
+ export default {
35
+ name: 'XTab',
36
+ components: {
37
+ XFormTable: () => import('@vue2-client/base-client/components/common/XFormTable/XFormTable'),
38
+ XAddNativeForm: () => import('@vue2-client/base-client/components/common/XAddNativeForm/XAddNativeForm.vue'),
39
+ XReportGrid: () => import('@vue2-client/base-client/components/common/XReportGrid/XReport.vue')
40
+ },
41
+ inject: ['isInAModal', 'getSelectedId', 'getSelectedData', 'getOutEnv', 'setGlobalData', 'getGlobalData'],
42
+ provide () {
43
+ return {
44
+ currUser: this.currUser,
45
+ getSelectedId: this.getSelectedId
46
+ }
47
+ },
48
+ data () {
49
+ return {
50
+ activeKey: 0,
51
+ // 配置
52
+ config: undefined,
53
+ attr: {}
54
+ }
55
+ },
56
+ computed: {
57
+ ...mapState('account', { currUser: 'user' })
58
+ },
59
+ methods: {
60
+ // 自定义函数中调用的方法 这个不能删
61
+ getWindow,
62
+ runLogic,
63
+ isMicroAppEnv,
64
+ microDispatch,
65
+ getMicroData,
66
+ getRealKeyData,
67
+ getConfigByName,
68
+ getConfigByNameAsync,
69
+ tabPaneChange (newKey) {
70
+ let result = {}
71
+ if (this.activeKey === newKey) {
72
+ return
73
+ }
74
+ const oldKey = this.activeKey
75
+ if (this.config.changeFunc) {
76
+ const args = [
77
+ oldKey,
78
+ newKey,
79
+ this.config.data[oldKey],
80
+ this.config.data[newKey],
81
+ `tab_com_${this.config.data[oldKey].slotType}_${oldKey}`,
82
+ `tab_com_${this.config.data[newKey].slotType}_${newKey}`,
83
+ this.$refs[`tab_com_${this.config.data[oldKey].slotType}_${oldKey}`][0]
84
+ ]
85
+ if (!this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]) {
86
+ args.push(null)
87
+ console.warn('新页签示例切换页签时暂未初始化,仅调用该页签初始化方法不调用切换函数')
88
+ } else {
89
+ args.push(this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`][0])
90
+ }
91
+ result = executeStrFunctionByContext(this, this.config.changeFunc, args)
92
+ if (result && result.noChange) {
93
+ console.info('不切换页签作为按钮使用')
94
+ } else {
95
+ this.activeKey = newKey
96
+ if (result && result.callback && typeof result.callback === 'function') {
97
+ // 使用 $nextTick 等待 DOM 更新完成后再获取组件实例
98
+ this.$nextTick(() => {
99
+ const newComponent = this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]
100
+ if (!newComponent || !newComponent[0]) {
101
+ console.warn('组件实例尚未创建,等待组件mounted事件')
102
+ // 使用 MutationObserver 监听DOM变化
103
+ const observer = new MutationObserver((mutations, obs) => {
104
+ const newComp = this.$refs[`tab_com_${this.config.data[newKey].slotType}_${newKey}`]
105
+ if (newComp && newComp[0]) {
106
+ obs.disconnect()
107
+ console.log('组件已创建,执行回调')
108
+ result.callback()
109
+ }
110
+ })
111
+ observer.observe(this.$el, {
112
+ childList: true,
113
+ subtree: true
114
+ })
115
+ // 设置超时,避免无限等待
116
+ setTimeout(() => {
117
+ observer.disconnect()
118
+ console.warn('等待组件创建超时')
119
+ }, 500)
120
+
121
+ return
122
+ }
123
+ result.callback()
124
+ })
125
+ }
126
+ }
127
+ } else {
128
+ this.activeKey = newKey
129
+ }
130
+ },
131
+ initConfig () {
132
+ if (this.configName) {
133
+ this.getConfig()
134
+ } else if (this.localConfig) {
135
+ this.config = this.localConfig
136
+ }
137
+ },
138
+ getConfig () {
139
+ getConfigByName(this.configName, this.serverName, res => {
140
+ this.config = res
141
+ }, this.env === 'dev')
142
+ },
143
+ getEventHandlers (tab, index) {
144
+ const handlers = {}
145
+ if (!tab?.events || tab?.events?.length === 0) {
146
+ return handlers
147
+ }
148
+ tab.events.forEach(event => {
149
+ handlers[event.type] = (...args) => {
150
+ console.info('Event handled:', event.type, args)
151
+ executeStrFunctionByContext(this.$refs[`tab_com_${tab.slotType}_${index}`][0], event.customFunction, args)
152
+ }
153
+ })
154
+ return handlers
155
+ },
156
+ onComponentMounted (h, tab, index) {
157
+ console.log(`插槽组件已经初始化 slotType ${tab.slotType},ref= tab_com_${tab.slotType}_${index} , serviceName = ${tab.serviceName}`)
158
+ if (tab.slotType === 'x-add-native-form') {
159
+ // 建议表单需要主动调用初始化方法
160
+ getConfigByName(tab.slotConfig, tab.serviceName, async (res) => {
161
+ // 如果配置了 表单初始化logic
162
+ // 调用 logic 获取参数
163
+ let param = {}
164
+ let selectedId
165
+ if (res.paramLogicName) {
166
+ if (!!this.getSelectedId) {
167
+ selectedId = this.getSelectedId()
168
+ if (typeof selectedId !== 'object') {
169
+ selectedId = { selectedId: selectedId }
170
+ }
171
+ }
172
+ param = Object.assign(param, await runLogic(res.paramLogicName, selectedId, tab.serviceName))
173
+ }
174
+ this.$refs[`tab_com_${tab.slotType}_${index}`][0].init({
175
+ formItems: res.formJson,
176
+ showSubmitBtn: !this.isInAModal,
177
+ businessType: '新增',
178
+ layout: res.xAddFormLayout,
179
+ ...res,
180
+ fixedAddForm: param,
181
+ modifyModelData: {
182
+ files: param.files,
183
+ images: param.images
184
+ }
185
+ })
186
+ }, this.env === 'dev')
187
+ }
188
+ },
189
+ },
190
+ props: {
191
+ // 配置名
192
+ configName: {
193
+ type: String,
194
+ default: undefined
195
+ },
196
+ serverName: {
197
+ type: String,
198
+ default: undefined
199
+ },
200
+ env: {
201
+ type: String,
202
+ default: 'prod'
203
+ },
204
+ // 本地配置,调试用
205
+ localConfig: {
206
+ type: Object,
207
+ default: undefined
208
+ },
209
+ },
210
+ watch: {
211
+ configName: {
212
+ deep: true,
213
+ immediate: true,
214
+ handler (val) {
215
+ this.initConfig()
216
+ }
217
+ },
218
+ // 如果本地配置更改了,重新初始化
219
+ localConfig: {
220
+ deep: true,
221
+ immediate: true,
222
+ handler (val) {
223
+ this.initConfig()
224
+ }
225
+ },
226
+ },
227
+ }
228
+ </script>
229
+ <style scoped>
230
+ :deep(.ant-tabs-bar) {
231
+ margin: 0
232
+ }
233
+ </style>