agilebuilder-ui 1.0.87-temp2 → 1.0.87-temp4

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,307 +1,291 @@
1
1
  <template>
2
2
  <span class="select-top-span">
3
3
  <el-select
4
- ref="dynamicDataSourceRef"
5
- :allow-create="allowCreate"
6
- :clearable="clearable"
7
- :filterable="remote"
8
- :loading="loading"
9
- :model-value="value"
10
- :placeholder="placeholder"
11
- :remote="remote"
12
- :remote-method="remoteMethod"
13
- :reserve-keyword="true"
14
- :size="size"
15
- :style="fullWidth ? { width: '100%', height: '100%' } : {}"
16
- :title="getClassOptionTitle(value)"
17
- :value-key="valueAttribute"
18
- default-first-option
19
- v-bind="myProps"
20
- @blur="blurEvent($event)"
21
- @change="changeEvent"
22
- @clear="clear"
23
- @focus="focus"
24
- @visible-change="visibleChange"
25
- @remove-tag="removeTag(remote, $event)"
4
+ ref="dynamicDataSourceRef"
5
+ :allow-create="allowCreate"
6
+ :clearable="clearable"
7
+ :filterable="remote"
8
+ :loading="loading"
9
+ :model-value="value"
10
+ :placeholder="placeholder"
11
+ :remote="remote"
12
+ :remote-method="remoteMethod"
13
+ :reserve-keyword="true"
14
+ :size="size"
15
+ :style="fullWidth ? { width: '100%', height: '100%' } : {}"
16
+ :title="getClassOptionTitle(value)"
17
+ :value-key="valueAttribute"
18
+ default-first-option
19
+ v-bind="myProps"
20
+ @blur="blurEvent($event)"
21
+ @change="changeEvent"
22
+ @clear="clear"
23
+ @focus="focus"
24
+ @visible-change="visibleChange"
25
+ @remove-tag="removeTag(remote, $event)"
26
26
  >
27
27
  <template v-if="descriptionAttribute">
28
28
  <div v-if="optionWidth > 0" :style="{ width: optionWidth + 'px' }">
29
29
  <el-option
30
- v-for="item in optionItemList"
31
- :key="item.value"
32
- :label="item._label_"
33
- :title="item._description_?item._label_ + item._description_:item._label_"
34
- :value="baseProps.multiple && item.value==='saveAll'?item.value:item[valueAttribute]"
30
+ v-for="item in optionItemList"
31
+ :key="item.value"
32
+ :label="item._label_"
33
+ :title="item._description_ ? item._label_ + item._description_ : item._label_"
34
+ :value="baseProps.multiple && item.value === 'saveAll' ? item.value : item[valueAttribute]"
35
35
  >
36
36
  <div style="display: flex">
37
37
  <span>{{ item._label_ }}</span>
38
- <span
39
- style="color: #8492a6; font-size: 13px; margin-left: 30px"
40
- >{{ item._description_? item._description_: item._label_}}</span
41
- >
38
+ <span style="color: #8492a6; font-size: 13px; margin-left: 30px">{{
39
+ item._description_ ? item._description_ : item._label_
40
+ }}</span>
42
41
  </div>
43
42
  </el-option>
44
43
  </div>
45
- <el-option
46
- v-else
47
- v-for="item in optionItemList"
48
- :key="item.value"
49
- :label="item._label_"
50
- :title="item._description_?item._label_ + item._description_:item._label_"
51
- :value="baseProps.multiple && item.value==='saveAll'?item.value:item[valueAttribute]"
52
- >
53
- <span style="float: left">{{ item._label_ }}</span>
54
- <span
55
- style="
56
- float: right;
57
- color: #8492a6;
58
- font-size: 13px;
59
- margin-left: 30px;
60
- "
61
- >{{ item._description_? item._description_: item._label_ }}</span
62
- >
63
- </el-option>
44
+ <el-option
45
+ v-else
46
+ v-for="item in optionItemList"
47
+ :key="item.value"
48
+ :label="item._label_"
49
+ :title="item._description_ ? item._label_ + item._description_ : item._label_"
50
+ :value="baseProps.multiple && item.value === 'saveAll' ? item.value : item[valueAttribute]"
51
+ >
52
+ <span style="float: left">{{ item._label_ }}</span>
53
+ <span style="float: right; color: #8492a6; font-size: 13px; margin-left: 30px">{{
54
+ item._description_ ? item._description_ : item._label_
55
+ }}</span>
56
+ </el-option>
64
57
  </template>
65
58
  <template v-else>
66
- <div
67
- v-if="optionWidth > 0"
68
- :style="{ width: optionWidth + 'px', position: 'relative' }"
69
- >
59
+ <div v-if="optionWidth > 0" :style="{ width: optionWidth + 'px', position: 'relative' }">
70
60
  <el-option
71
- v-for="item in optionItemList"
72
- :key="item.value"
73
- :label="item._label_"
74
- :value="baseProps.multiple && item.value==='saveAll'?item.value:item[valueAttribute]"
61
+ v-for="item in optionItemList"
62
+ :key="item.value"
63
+ :label="item._label_"
64
+ :value="baseProps.multiple && item.value === 'saveAll' ? item.value : item[valueAttribute]"
75
65
  />
76
66
  </div>
77
- <el-option
78
- v-else
79
- v-for="item in optionItemList"
80
- :key="item.value"
81
- :label="item._label_"
82
- :value="baseProps.multiple && item.value==='saveAll'?item.value:item[valueAttribute]"
83
- />
67
+ <el-option
68
+ v-else
69
+ v-for="item in optionItemList"
70
+ :key="item.value"
71
+ :label="item._label_"
72
+ :value="baseProps.multiple && item.value === 'saveAll' ? item.value : item[valueAttribute]"
73
+ />
84
74
  </template>
85
75
  </el-select>
86
76
  </span>
87
77
  </template>
88
78
 
89
79
  <script>
90
- import {$on} from '../../utils/gogocodeTransfer'
80
+ import { $on } from '../../utils/gogocodeTransfer'
91
81
  import dynamicSourceSelectService from './dynamic-source-select-service'
92
82
  import events from './events'
93
83
  import eventBus from '../../../src/utils/eventBus'
94
- import {getEntityFieldValue, getPropNameWhenJoinTable, setEntityFieldValue} from '../../../src/utils/util'
84
+ import { getEntityFieldValue, getPropNameWhenJoinTable, setEntityFieldValue } from '../../../src/utils/util'
95
85
 
96
86
  export default {
97
- name: 'DynamicSourceSelect',
98
- components: {},
99
- model: {
100
- prop: 'value',
101
- event: 'input',
102
- },
103
- props: {
104
- // 字段配置 只有列表行编辑时候才用
105
- column: {
106
- type: Object,
107
- default: null,
108
- },
109
- value: {
110
- type: [String, Boolean, Number, Array],
111
- default: null,
112
- },
113
- baseProps: {
114
- type: Object,
115
- default: null,
116
- },
117
- entity: {
118
- type: Object,
119
- default: null,
120
- },
121
- // dynamicDataSourceCode、valueSetOptions、isSql(默认是false,在配置系统中使用时需要是true)、additionalParameter( json字符串)
122
- options: {
123
- type: Object,
124
- default: null,
125
- },
126
- // 列表组件行编辑使用,sql查询时数据表名称,用于自定义系统中列表组件中字段多表查询带有别名时,将点"."改成两个下划线"__"时使用
127
- tableName: {
128
- type: String,
129
- default: null,
130
- },
131
- // 列表组件行编辑使用,是否是关联表,用于确定属性名是否需要拼接tableName
132
- isJoinTable: {
133
- type: Boolean,
134
- default: false,
135
- },
136
- // 子表行编辑时,父表单数据
137
- parent: {
138
- type: Object,
139
- default: null,
140
- },
141
- // 所在的列表编码
142
- listCode: {
143
- type: String,
144
- default: null,
145
- },
146
- // 所在的表单编码
147
- formCode: {
148
- type: String,
149
- default: null,
150
- },
151
- listToolbarFormData: {
152
- type: Object,
153
- default: () => {
154
- return {}
155
- },
156
- },
157
- fullWidth: {
158
- type: Boolean,
159
- default: true,
160
- },
161
- clearable: {
162
- type: Boolean,
163
- default: true,
164
- },
165
- size: {
166
- type: String,
167
- default: 'default',
168
- },
169
- allowCreate: {
170
- type: Boolean,
171
- default: false,
172
- },
173
- analysisArea: {
174
- type: Number,
175
- default: null,
176
- // 1 为工具栏解析
177
- },
178
- placeholder: {
179
- type: String,
180
- default: null,
181
- },
182
- // 下拉框配置宽度
183
- optionWidth: {
184
- default: 0,
185
- },
186
- },
187
- // 是否是页面预览, 从页面管理传递
188
- inject: {
189
- isPageInfo: {value: 'isPageInfo', default: false},
190
- },
191
- data() {
192
- const myProps = Object.assign({}, this.baseProps)
193
- let markValue
194
- if (this.entity) {
195
- markValue = JSON.stringify(this.entity)
196
- }
197
- let lastValues = []
198
- if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
199
- if (this.value !== undefined && this.value !== null && Array.isArray(this.value)) {
200
- lastValues = JSON.parse(JSON.stringify(this.value))
201
- }
202
- }
203
- return {
204
- /**
205
- * 用于回显动态数据源选择的默认值,因为初始进入编辑状态时,没有获取映射关系,
206
- * 如果当前字段是保存的label值则无法确定当前选项组的值对应哪一个,导致row中的对应字段变成了空值,所以备份一份
207
- * 然后在获取动态数据源选项组后,给上默认值
208
- */
209
- markValue,
210
- optionItems: [],
211
- myProps,
212
- valueSetOptions: [], // 字段映射集合配置
213
- dynamicDataSourceCode: '', // 动态数据源编码
214
- loading: false, // 是否在加载
215
- valueAttribute: null, // 选项值字段,即控制下拉框组件的value-key属性的
216
- remote: false, // 是否是远程搜索
217
- additionalParameterStr: this.options.additionalParameter, // 附加参数json字符串
218
- isLoaded: false, // 动态数据源是否直接显示静态页面
219
- watchAttr: null, // 监控的entity属性名,多个属性名逗号分隔。即当该属性修改时,需要走后台重新获得当前下拉选的选项集合
220
- backendUrl: null, // 后台访问路径
221
- descriptionAttribute: null,
222
- queryParam: {}, // 请求参数,
223
- lastValues, // 最后一次的value值,用于判断是否是增加元素
224
- optionItemList: [] // 多选时会多一个saveAll 全选 选项
225
- }
226
- },
227
- watch: {
228
- baseProps: {
229
- deep: true,
230
- handler(newModels) {
231
- this.myProps = Object.assign({}, newModels)
232
- },
233
- },
234
- },
235
- created() {
236
- if (this.options && this.options.backendUrl) {
237
- this.backendUrl = this.options.backendUrl
238
- }
239
- if (this.options && this.options.dynamicDataSourceCode) {
240
- this.dynamicDataSourceCode = this.options.dynamicDataSourceCode.trim()
241
- const param = {
242
- _listCode: this.listCode,
243
- _formCode: this.formCode,
244
- _tableName: this.tableName,
245
- }
246
- if (this.parent) {
247
- param.parent = this.parent
248
- }
249
- if (!this.isPageInfo) {
250
- this.packageDynamicDataSourceInfo(this.dynamicDataSourceCode, param)
251
- .then((dynamicDataSourceDto) => {
252
- // console.log('UI获取的数据', dynamicDataSourceDto)
253
- if (dynamicDataSourceDto.backendUrl) {
254
- this.backendUrl = dynamicDataSourceDto.backendUrl
255
- }
256
- if (
257
- dynamicDataSourceDto.fuzzyQuery !== undefined &&
258
- dynamicDataSourceDto.fuzzyQuery === true
259
- ) {
260
- // 是否启用远程搜索
261
- this.remote = true
262
- }
263
- if (this.options && this.options.valueSetOptions) {
264
- this.valueSetOptions = this.options.valueSetOptions
265
- }
266
- if (
267
- this.options &&
268
- this.options.isSql !== undefined &&
269
- this.options.isSql !== null
270
- ) {
271
- this.isSql = this.options.isSql
272
- }
273
- if (this.watchAttr) {
274
- let initWatchValue
275
- const watchAttrs = this.watchAttr.split(',')
276
- watchAttrs.forEach((attr) => {
277
- // 初始化下拉选内容
278
- if (this.entity) {
279
- initWatchValue = this.entity[attr]
280
- }
281
- this.$watch('entity.' + attr, function (newValue, oldValue) {
282
- this.watchAttrValueChange(newValue)
283
- // this.inputValue('')
284
- const items = this.optionItems.filter(
285
- (item) => item[this.valueAttribute] === newValue
286
- )
287
- if (!items) {
288
- this.inputValue('')
289
- }
290
- })
291
- })
292
- this.watchAttrValueChange(initWatchValue)
293
- }
294
- this.isLoaded = true
295
- // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
296
- // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
297
- // this.$nextTick(() => {
298
- // // this.$refs['dynamicDataSourceRef'].setSelected()
299
- // })
300
- // }
301
- // 默认选中处理
302
- if (dynamicDataSourceDto.defaultSelect && (this.value === undefined || this.value === null || this.value === '')) {
303
- // 多选处理
304
- /**
87
+ name: 'DynamicSourceSelect',
88
+ components: {},
89
+ model: {
90
+ prop: 'value',
91
+ event: 'input'
92
+ },
93
+ props: {
94
+ // 字段配置 只有列表行编辑时候才用
95
+ column: {
96
+ type: Object,
97
+ default: null
98
+ },
99
+ value: {
100
+ type: [String, Boolean, Number, Array],
101
+ default: null
102
+ },
103
+ baseProps: {
104
+ type: Object,
105
+ default: null
106
+ },
107
+ entity: {
108
+ type: Object,
109
+ default: null
110
+ },
111
+ // dynamicDataSourceCode、valueSetOptions、isSql(默认是false,在配置系统中使用时需要是true)、additionalParameter( json字符串)
112
+ options: {
113
+ type: Object,
114
+ default: null
115
+ },
116
+ // 列表组件行编辑使用,sql查询时数据表名称,用于自定义系统中列表组件中字段多表查询带有别名时,将点"."改成两个下划线"__"时使用
117
+ tableName: {
118
+ type: String,
119
+ default: null
120
+ },
121
+ // 列表组件行编辑使用,是否是关联表,用于确定属性名是否需要拼接tableName
122
+ isJoinTable: {
123
+ type: Boolean,
124
+ default: false
125
+ },
126
+ // 子表行编辑时,父表单数据
127
+ parent: {
128
+ type: Object,
129
+ default: null
130
+ },
131
+ // 所在的列表编码
132
+ listCode: {
133
+ type: String,
134
+ default: null
135
+ },
136
+ // 所在的表单编码
137
+ formCode: {
138
+ type: String,
139
+ default: null
140
+ },
141
+ listToolbarFormData: {
142
+ type: Object,
143
+ default: () => {
144
+ return {}
145
+ }
146
+ },
147
+ fullWidth: {
148
+ type: Boolean,
149
+ default: true
150
+ },
151
+ clearable: {
152
+ type: Boolean,
153
+ default: true
154
+ },
155
+ size: {
156
+ type: String,
157
+ default: 'default'
158
+ },
159
+ allowCreate: {
160
+ type: Boolean,
161
+ default: false
162
+ },
163
+ analysisArea: {
164
+ type: Number,
165
+ default: null
166
+ // 1 为工具栏解析
167
+ },
168
+ placeholder: {
169
+ type: String,
170
+ default: null
171
+ },
172
+ // 下拉框配置宽度
173
+ optionWidth: {
174
+ default: 0
175
+ }
176
+ },
177
+ // 是否是页面预览, 从页面管理传递
178
+ inject: {
179
+ isPageInfo: { value: 'isPageInfo', default: false }
180
+ },
181
+ data() {
182
+ const myProps = Object.assign({}, this.baseProps)
183
+ let markValue
184
+ if (this.entity) {
185
+ markValue = JSON.stringify(this.entity)
186
+ }
187
+ let lastValues = []
188
+ if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
189
+ if (this.value !== undefined && this.value !== null && Array.isArray(this.value)) {
190
+ lastValues = JSON.parse(JSON.stringify(this.value))
191
+ }
192
+ }
193
+ return {
194
+ /**
195
+ * 用于回显动态数据源选择的默认值,因为初始进入编辑状态时,没有获取映射关系,
196
+ * 如果当前字段是保存的label值则无法确定当前选项组的值对应哪一个,导致row中的对应字段变成了空值,所以备份一份
197
+ * 然后在获取动态数据源选项组后,给上默认值
198
+ */
199
+ markValue,
200
+ optionItems: [],
201
+ myProps,
202
+ valueSetOptions: [], // 字段映射集合配置
203
+ dynamicDataSourceCode: '', // 动态数据源编码
204
+ loading: false, // 是否在加载
205
+ valueAttribute: null, // 选项值字段,即控制下拉框组件的value-key属性的
206
+ remote: false, // 是否是远程搜索
207
+ additionalParameterStr: this.options.additionalParameter, // 附加参数json字符串
208
+ isLoaded: false, // 动态数据源是否直接显示静态页面
209
+ watchAttr: null, // 监控的entity属性名,多个属性名逗号分隔。即当该属性修改时,需要走后台重新获得当前下拉选的选项集合
210
+ backendUrl: null, // 后台访问路径
211
+ descriptionAttribute: null,
212
+ queryParam: {}, // 请求参数,
213
+ lastValues, // 最后一次的value值,用于判断是否是增加元素
214
+ optionItemList: [] // 多选时会多一个saveAll 全选 选项
215
+ }
216
+ },
217
+ watch: {
218
+ baseProps: {
219
+ deep: true,
220
+ handler(newModels) {
221
+ this.myProps = Object.assign({}, newModels)
222
+ }
223
+ }
224
+ },
225
+ created() {
226
+ if (this.options && this.options.backendUrl) {
227
+ this.backendUrl = this.options.backendUrl
228
+ }
229
+ if (this.options && this.options.dynamicDataSourceCode) {
230
+ this.dynamicDataSourceCode = this.options.dynamicDataSourceCode.trim()
231
+ const param = {
232
+ _listCode: this.listCode,
233
+ _formCode: this.formCode,
234
+ _tableName: this.tableName
235
+ }
236
+ if (this.parent) {
237
+ param.parent = this.parent
238
+ }
239
+ if (!this.isPageInfo) {
240
+ this.packageDynamicDataSourceInfo(this.dynamicDataSourceCode, param)
241
+ .then((dynamicDataSourceDto) => {
242
+ // console.log('UI获取的数据', dynamicDataSourceDto)
243
+ if (dynamicDataSourceDto.backendUrl) {
244
+ this.backendUrl = dynamicDataSourceDto.backendUrl
245
+ }
246
+ if (dynamicDataSourceDto.fuzzyQuery !== undefined && dynamicDataSourceDto.fuzzyQuery === true) {
247
+ // 是否启用远程搜索
248
+ this.remote = true
249
+ }
250
+ if (this.options && this.options.valueSetOptions) {
251
+ this.valueSetOptions = this.options.valueSetOptions
252
+ }
253
+ if (this.options && this.options.isSql !== undefined && this.options.isSql !== null) {
254
+ this.isSql = this.options.isSql
255
+ }
256
+ if (this.watchAttr) {
257
+ let initWatchValue
258
+ const watchAttrs = this.watchAttr.split(',')
259
+ watchAttrs.forEach((attr) => {
260
+ // 初始化下拉选内容
261
+ if (this.entity) {
262
+ initWatchValue = this.entity[attr]
263
+ }
264
+ this.$watch('entity.' + attr, function (newValue, oldValue) {
265
+ this.watchAttrValueChange(newValue)
266
+ // this.inputValue('')
267
+ const items = this.optionItems.filter((item) => item[this.valueAttribute] === newValue)
268
+ if (!items) {
269
+ this.inputValue('')
270
+ }
271
+ })
272
+ })
273
+ this.watchAttrValueChange(initWatchValue)
274
+ }
275
+ this.isLoaded = true
276
+ // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
277
+ // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
278
+ // this.$nextTick(() => {
279
+ // // this.$refs['dynamicDataSourceRef'].setSelected()
280
+ // })
281
+ // }
282
+ // 默认选中处理
283
+ if (
284
+ dynamicDataSourceDto.defaultSelect &&
285
+ (this.value === undefined || this.value === null || this.value === '')
286
+ ) {
287
+ // 多选处理
288
+ /**
305
289
  if (this.baseProps.multiple) {
306
290
  this.$emit('set-default-value', [
307
291
  this.optionItems[0][this.valueAttribute],
@@ -315,628 +299,576 @@ export default {
315
299
  )
316
300
  }
317
301
  } */
318
- this.setValues(this.optionItems[0][this.valueAttribute])
319
- }
320
- // console.log('判断参数',this.analysisArea);
321
- // console.log('判断参数',this.remote);
322
- if (this.analysisArea !== 1 && this.remote) {
323
- // 传递初始化查询供重置用
324
- const that = this
325
- $on(eventBus, 'remoteMethod', () => {
326
- that.remoteMethod('')
327
- })
328
- // console.log('传递了参数');
329
- }
330
- this.$emit('load-completed', dynamicDataSourceDto)
331
- })
332
- .catch((error) => {
333
- console.log(error)
334
- this.$emit('load-completed', {
335
- code: this.dynamicDataSourceCode,
336
- error: error,
337
- })
338
- this.isLoaded = true
339
- })
340
- }
341
- } else {
342
- this.isLoaded = true
343
- }
344
- },
345
- methods: {
346
- ...dynamicSourceSelectService,
347
- ...events,
348
- blurEvent(event) {
349
- // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
350
- // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === false) {
351
- // this.$nextTick(() => {
352
- // // this.$refs['dynamicDataSourceRef'].setSelected()
353
- // })
354
- // }
355
- this.$emit('blur', event)
356
- },
357
- changeEvent(newValue){
358
- this.inputValue(newValue)
359
- this.$emit('change', newValue)
360
- },
361
- /**
362
- * @description: 获取提示标题
363
- * @Date: 2023-08-04 10:04:42
364
- * @param {*}
365
- * @return {*}
366
- */
367
- getClassOptionTitle(val) {
368
- if (val !== null && val !== undefined && val !== '' && val.length > 0) {
369
- let selectTittle = ''
370
- if (typeof val === 'string') {
371
- // 单选
372
- if (this.descriptionAttribute) {
373
- this.optionItems.forEach((item) => {
374
- if (item[this.valueAttribute] === val) {
375
- selectTittle = item._label_ + item._description_
376
- }
377
- })
378
- } else {
379
- this.optionItems.forEach((Ttem) => {
380
- if (Ttem[this.valueAttribute] === val) {
381
- selectTittle = Ttem._label_
382
- }
383
- })
384
- }
385
- } else {
386
- // 多选
387
- if (this.descriptionAttribute) {
388
- this.optionItems.forEach((item) => {
389
- val.forEach((Vtem) => {
390
- if (item[this.valueAttribute] === Vtem) {
391
- selectTittle = selectTittle + item._label_ + ','
392
- }
393
- })
394
- })
395
- selectTittle = selectTittle.slice(0, selectTittle.length - 1)
396
- } else {
397
- this.optionItems.forEach((Ttem) => {
398
- val.forEach((Vtem) => {
399
- if (Ttem[this.valueAttribute] === Vtem) {
400
- selectTittle = selectTittle + Ttem._label_ + ','
401
- }
402
- })
403
- })
404
- selectTittle = selectTittle.slice(0, selectTittle.length - 1)
405
- }
406
- }
407
- return selectTittle
408
- }
409
- },
410
- // 必须有该方法,否则无法给字段赋值
411
- inputValue(newValue) {
412
- let isClickSaveAll = false
413
- if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true && newValue && newValue.indexOf('saveAll') >= 0) {
414
- // 表示点击了全选选项
415
- isClickSaveAll = true
416
- if (newValue.length - 1 >= this.optionItems.length) {
417
- // 表示需要取消全选
418
- newValue = []
419
- } else {
420
- // 表示需要全选
421
- const allValues = []
422
- for (let i = 0; i < this.optionItems.length; i++) {
423
- const item = this.optionItems[i]
424
- allValues.push(item[this.valueAttribute])
425
- }
426
- newValue = allValues
427
- }
428
- }
429
- this.$emit('update:value', newValue)
430
- if (this.remote && (newValue === null || newValue === undefined || newValue === '')) {
431
- this.remoteQueryMethod(newValue)
432
- }
433
- this.setValues(newValue, isClickSaveAll)
434
- },
435
- packageDynamicDataSourceInfo(dynamicDataSourceCode, param) {
436
- return new Promise((resolve, reject) => {
437
- this.findDynamicDataSourceByCode(
438
- dynamicDataSourceCode,
439
- this.entity,
440
- param,
441
- this.additionalParameterStr,
442
- this.backendUrl
443
- )
444
- .then((dynamicDataSourceDto) => {
445
- if (dynamicDataSourceDto) {
446
- if (dynamicDataSourceDto.options) {
447
- this.optionItems = dynamicDataSourceDto.options
448
- let optionsResult = dynamicDataSourceDto.options
449
- if(this.baseProps.multiple !== undefined && this.baseProps.multiple === true && optionsResult && optionsResult.length > 0){
450
- const saveAll = {value: 'saveAll', _label_: this.$t('superGrid.selectAll')}
451
- optionsResult = [saveAll,...optionsResult]
452
- }
453
- this.optionItemList = optionsResult
454
- // if (this.watchAttr) {
455
- // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
456
- // if (
457
- // this.baseProps.multiple !== undefined &&
458
- // this.baseProps.multiple === true
459
- // ) {
460
- // this.$nextTick(() => {
461
- // // this.$refs['dynamicDataSourceRef'].setSelected()
462
- // })
463
- // }
464
- // }
465
- //
466
- if (this.column) {
467
- // 只有行编辑时处理
468
- // 设置选项组数据、 选项组值字段、 映射关系
469
- if (
470
- this.column.prop !== dynamicDataSourceDto.valueAttribute
471
- ) {
472
- this.column['_dynamic-source-data-' + this.column.prop] = {
473
- valueSetOptions: this.options.valueSetOptions,
474
- optionItems: this.optionItems,
475
- valueAttribute: dynamicDataSourceDto.valueAttribute,
476
- }
477
- }
478
- for (
479
- let i = 0;
480
- i < this.options.valueSetOptions.length;
481
- i++
482
- ) {
483
- const valueSetOption = this.options.valueSetOptions[i]
484
- if (
485
- dynamicDataSourceDto.valueAttribute ===
486
- valueSetOption.columnName
487
- ) {
488
- if (this.markValue) {
489
- const muMarkValue = JSON.parse(this.markValue)
490
- if (
491
- muMarkValue &&
492
- muMarkValue[valueSetOption.valueColumn.dbColumnName]
493
- ) {
494
- let targeValue = (
495
- muMarkValue[
496
- valueSetOption.valueColumn.dbColumnName
497
- ] + ''
498
- ).split(',')
499
- if (this.column.componentType === 'select') {
500
- // 如果是单选
501
- targeValue = targeValue[0]
502
- }
503
- // 不需要再赋值了 如果当前字段不上动态数据源的值字段,那就表示不需要回显
504
- // if (valueSetOption.valueColumn.dbColumnName === this.column.prop) {
505
- // this.$emit('set-value', {
506
- // value: targeValue,
507
- // targetColumnName: this.column.prop,
508
- // options: this.optionItems,
509
- // valueAttribute: this.valueAttribute
510
- // })
511
- // }
512
- }
513
- }
514
- break
515
- }
516
- }
517
- }
518
- } else {
519
- this.optionItems = []
520
- }
521
- if (dynamicDataSourceDto.valueAttribute) {
522
- this.valueAttribute = dynamicDataSourceDto.valueAttribute
523
- }
524
- if (dynamicDataSourceDto.descriptionAttribute) {
525
- this.descriptionAttribute =
526
- dynamicDataSourceDto.descriptionAttribute
527
- }
528
- this.valueAttribute = this.getValueAttribute()
529
- this.watchAttr = dynamicDataSourceDto.watchAttr
530
- this.$emit('load-completed', dynamicDataSourceDto)
531
- resolve(dynamicDataSourceDto)
532
- } else {
533
- resolve()
534
- }
535
- })
536
- .catch((error) => {
537
- reject(error)
538
- })
539
- })
540
- },
541
- // 远程搜索方法
542
- remoteQuery(searchText, watchAttrValue) {
543
- if (
544
- (searchText !== null && searchText !== undefined) ||
545
- (watchAttrValue !== null && watchAttrValue !== undefined)
546
- ) {
547
- const param = {
548
- _listCode: this.listCode,
549
- _formCode: this.formCode,
550
- _tableName: this.tableName,
551
- }
552
- if (searchText !== null && searchText !== undefined) {
553
- param.searchText = searchText
554
- }
555
- if (watchAttrValue !== null && watchAttrValue !== undefined) {
556
- // 监控的属性值改变了远程搜索方法
557
- if (
558
- Object.prototype.toString.apply(watchAttrValue) === '[object Array]'
559
- ) {
560
- param.watchAttrValue = watchAttrValue.join(',')
561
- } else {
562
- param.watchAttrValue = watchAttrValue + ''
563
- }
564
- } else if (this.entity) {
565
- // 搜索时下拉选项的集合
566
- const watchValue = this.entity[this.watchAttr]
567
- if (watchValue !== null && watchValue !== undefined) {
568
- if (
569
- Object.prototype.toString.apply(watchValue) === '[object Array]'
570
- ) {
571
- param.watchAttrValue = watchValue.join(',')
572
- } else {
573
- param.watchAttrValue = watchValue + ''
574
- }
575
- }
576
- }
577
- if (this.parent) {
578
- param.parent = this.parent
579
- }
580
- this.loading = true
581
- this.packageDynamicDataSourceInfo(this.dynamicDataSourceCode, param)
582
- .then((dynamicDataSourceDto) => {
583
- // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
584
- // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
585
- // this.$nextTick(() => {
586
- // // this.$refs['dynamicDataSourceRef'].setSelected()
587
- // })
588
- // }
589
- this.loading = false
590
- })
591
- .catch((error) => {
592
- console.log(error)
593
- this.loading = false
594
- })
595
- }
596
- },
597
- // 远程搜索方法
598
- remoteQueryMethod(searchText) {
599
- if (Array.isArray(this.value)) {
600
- if (this.value.length === 0) {
601
- this.remoteQuery(searchText, null)
602
- }
603
- } else {
604
- this.remoteQuery(searchText, null)
605
- }
606
- },
607
- /**
608
- * 输入框输入查询值时搜索方法,
609
- * 不使用remoteQueryMethod, 解决输入框第一次输入时可查询,第二次输入时没有触发查询方法问题
610
- * @param {*} searchText
611
- */
612
- remoteMethod(searchText) {
613
- this.remoteQuery(searchText, null)
614
- },
615
- // 监控的属性值改变了远程搜索方法
616
- watchAttrValueChange(watchAttrValues) {
617
- this.remoteQuery(null, watchAttrValues)
618
- },
619
- getValueAttribute() {
620
- return !this.valueAttribute || this.valueAttribute === '[label]'
621
- ? '_label_'
622
- : this.valueAttribute
623
- },
624
- setValues(newValue, isClickSaveAll) {
625
- if (this.valueSetOptions && this.valueSetOptions.length > 0) {
626
- if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
627
- // 多选时
628
- this.setColumnValueWhenMulti(newValue, isClickSaveAll)
629
- } else {
630
- // 单选时
631
- this.valueSetOptions.forEach((columnInfo) => {
632
- const sourceColumnName = columnInfo.columnName
633
- let value
634
- if (this.optionItems && sourceColumnName) {
635
- value = this.getTargetColumnValue(newValue, sourceColumnName)
636
- }
637
- let targetColumnName = null
638
- const targetColumnInfo = columnInfo.valueColumn
639
- if (targetColumnInfo) {
640
- targetColumnName = targetColumnInfo.name
641
- if (this.isSql === true) {
642
- targetColumnName = targetColumnInfo.dbColumnName
643
- targetColumnName = getPropNameWhenJoinTable(
644
- targetColumnName,
645
- this.isJoinTable,
646
- this.tableName
647
- )
648
- }
649
- }
650
- if (
651
- this.entity &&
652
- targetColumnName &&
653
- targetColumnName !== null &&
654
- targetColumnName !== ''
655
- ) {
656
- setEntityFieldValue(this.entity, targetColumnName, value)
657
- }
658
- const item = this.getSelectedOptionItem(newValue)
659
- this.$emit('set-value', {
660
- value: value,
661
- sourceColumnName: sourceColumnName,
662
- targetColumnName: targetColumnName,
663
- options: this.optionItems,
664
- valueAttribute: this.valueAttribute,
665
- selectedItem: item,
666
- })
667
- })
668
- }
669
- }
670
- },
671
- // 设置字段的值
672
- setColumnValue(sourceColumnName, value, columnInfo) {
673
- let targetColumnName = null
674
- const targetColumnInfo = columnInfo.valueColumn
675
- if (targetColumnInfo) {
676
- targetColumnName = targetColumnInfo.name
677
- if (this.isSql === true) {
678
- targetColumnName = targetColumnInfo.dbColumnName
679
- targetColumnName = getPropNameWhenJoinTable(
680
- targetColumnName,
681
- this.isJoinTable,
682
- this.tableName
683
- )
684
- }
685
- }
686
- if (
687
- this.entity &&
688
- targetColumnName &&
689
- targetColumnName !== null &&
690
- targetColumnName !== ''
691
- ) {
692
- setEntityFieldValue(this.entity, targetColumnName, value)
693
- }
694
- this.$emit('set-value', {
695
- value: value,
696
- sourceColumnName: sourceColumnName,
697
- targetColumnName: targetColumnName,
698
- options: this.optionItems,
699
- valueAttribute: this.valueAttribute
700
- })
701
- },
702
- // 多选下拉框时处理增加tag、减少tag时,映射字段赋值问题
703
- setColumnValueWhenMulti(newValue, isClickSaveAll) {
704
- // 是否添加tag
705
- let isAddTag = false
706
- let removeTag
707
- this.valueSetOptions.forEach(columnInfo => {
708
- const sourceColumnName = columnInfo.columnName
709
- if (sourceColumnName === this.valueAttribute) {
710
- // 是当前下拉选组件对应的字段时,才需要走该方法
711
- // 字段的值
712
- let value
713
- if (this.optionItems && sourceColumnName) {
714
- value = this.getTargetColumnValue(newValue, sourceColumnName)
715
- }
716
- this.setColumnValue(sourceColumnName, value, columnInfo)
717
- if (this.lastValues.length < newValue.length) {
718
- // 表示是增加tag
719
- isAddTag = true
720
- } else if (this.lastValues.length > newValue.length) {
721
- // 表示减少tag
722
- isAddTag = false
723
- const totalArr = [...this.lastValues, ...newValue]
724
- const totalSet = new Set(totalArr)
725
- const arr = Array.from(totalSet)
726
- const removeTagArr = [...arr.filter(item => !this.lastValues.includes(item)), ...arr.filter(item => !newValue.includes(item))]
727
- if (removeTagArr && removeTagArr.length > 0) {
728
- removeTag = removeTagArr[0]
729
- }
730
- }
731
- this.lastValues = JSON.parse(JSON.stringify(newValue))
732
- // 跳出forEach循环
733
-
734
- }
735
- })
736
- if (isAddTag) {
737
- // 表示是增加tag
738
- const isRemove = false
739
- if (isClickSaveAll) {
740
- // 全选
741
- this.setAllTagValue(isRemove)
742
- } else {
743
- const lastSelectTag = newValue[newValue.length - 1]
744
- const items = this.optionItems.filter(
745
- item => item[this.valueAttribute] === lastSelectTag
746
- )
747
- if (items && items.length > 0) {
748
- this.setTagValue(null, isRemove, items[0])
749
- }
750
- }
751
- } else {
752
- // 表示是减少tag
753
- const isRemove = true
754
- if (isClickSaveAll) {
755
- this.setAllTagValue(isRemove)
756
- } else {
757
- this.setTagValue(removeTag, isRemove)
758
- }
759
- }
760
- },
761
- setAllTagValue(isRemove) {
762
- if (this.valueSetOptions && this.valueSetOptions.length > 0) {
763
- this.valueSetOptions.forEach(columnInfo => {
764
- const sourceColumnName = columnInfo.columnName
765
- if (sourceColumnName !== this.valueAttribute) {
766
- let targetColumnName = null
767
- const targetColumnInfo = columnInfo.valueColumn
768
- if (targetColumnInfo) {
769
- targetColumnName = targetColumnInfo.name
770
- if (this.isSql === true) {
771
- targetColumnName = targetColumnInfo.dbColumnName
772
- targetColumnName = getPropNameWhenJoinTable(
773
- targetColumnName,
774
- this.isJoinTable,
775
- this.tableName
776
- )
777
- }
778
- }
779
- let value
780
- if (targetColumnName) {
781
- if (isRemove) {
782
- // 移除tag
783
- value = null
784
- } else {
785
- // 添加tag
786
- let originalValue = ''
787
- if (this.optionItems && this.optionItems.length > 0) {
788
- this.optionItems.forEach(selectItem => {
789
- const addValue = selectItem[sourceColumnName]
790
- if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
791
- originalValue = originalValue + ',' + addValue
792
- } else {
793
- originalValue = addValue
794
- }
795
- })
796
- value = originalValue
797
- }
798
- }
799
- }
800
- this.setTargetColumnValue(sourceColumnName, targetColumnName, value)
801
- }
802
- })
803
- }
804
- },
805
- setTargetColumnValue(sourceColumnName, targetColumnName, value) {
806
- if (
807
- this.entity &&
808
- targetColumnName &&
809
- targetColumnName !== null &&
810
- targetColumnName !== ''
811
- ) {
812
- setEntityFieldValue(this.entity, targetColumnName, value)
813
- }
814
- this.$emit('set-value', {
815
- value: value,
816
- sourceColumnName: sourceColumnName,
817
- targetColumnName: targetColumnName,
818
- options: this.optionItems,
819
- valueAttribute: this.valueAttribute
820
- })
821
- },
822
- // 根据tag参数设置映射字段的值
823
- setTagValue(tag, isRemove, selectItem) {
824
- if (this.valueSetOptions && this.valueSetOptions.length > 0) {
825
- this.valueSetOptions.forEach(columnInfo => {
826
- const sourceColumnName = columnInfo.columnName
827
- if (sourceColumnName !== this.valueAttribute) {
828
- let targetColumnName = null
829
- const targetColumnInfo = columnInfo.valueColumn
830
- if (targetColumnInfo) {
831
- targetColumnName = targetColumnInfo.name
832
- if (this.isSql === true) {
833
- targetColumnName = targetColumnInfo.dbColumnName
834
- targetColumnName = getPropNameWhenJoinTable(
835
- targetColumnName,
836
- this.isJoinTable,
837
- this.tableName
838
- )
839
- }
840
- }
841
- let value
842
- if (targetColumnName) {
843
- const originalValue = getEntityFieldValue(this.entity, targetColumnName)
844
- if (isRemove) {
845
- // 移除tag
846
- const index = this.value.indexOf(tag)
847
- if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
848
- const originalVals = originalValue.split(',')
849
- originalVals.splice(index, 1)
850
- value = originalVals.join(',')
851
- }
852
- } else {
853
- // 添加tag
854
- let addValue
855
- if (selectItem) {
856
- addValue = selectItem[sourceColumnName]
857
- }
858
- if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
859
- value = originalValue + ',' + addValue
860
- } else {
861
- value = addValue
862
- }
863
- }
864
- }
865
- this.setTargetColumnValue(sourceColumnName, targetColumnName, value)
866
- }
867
- })
868
- }
869
- },
870
- // 获得目的字段的值
871
- getTargetColumnValue(newValue, sourceColumnName) {
872
- if (newValue) {
873
- let value = ''
874
- if (
875
- this.baseProps.multiple !== undefined &&
876
- this.baseProps.multiple === true &&
877
- Array.isArray(newValue)
878
- ) {
879
- // 多选值处理,数组信息,使用逗号分开的格式设置其它字段的值
880
- let i = 0
881
- newValue.forEach((itemValue) => {
882
- const items = this.optionItems.filter(
883
- (item) => item[this.valueAttribute] === itemValue
884
- )
885
- if (items && items.length > 0) {
886
- value += items[0][sourceColumnName]
887
- if (i < newValue.length - 1) {
888
- // 最后一个元素不加逗号
889
- value += ','
890
- }
891
- i++
892
- }
893
- })
894
- } else {
895
- // 单选
896
- const items = this.optionItems.filter(
897
- (item) => item[this.valueAttribute] === newValue
898
- )
899
- if (items && items.length > 0) {
900
- value = items[0][sourceColumnName]
901
- }
902
- }
903
- return value
904
- }
905
- },
906
- // 移除所有tag和clear时候清除markValue的值解决清除选项时关联字段清空了但是当前动态数据源控件仍然有值问题
907
- clearMarkValue() {
908
- if (this.markValue && this.entity) {
909
- const muMarkValue = JSON.parse(this.markValue)
910
- for (let i = 0; i < this.options.valueSetOptions.length; i++) {
911
- const valueSetOption = this.options.valueSetOptions[i]
912
- muMarkValue[valueSetOption.valueColumn.dbColumnName] = null
913
- }
914
- this.markValue = JSON.stringify(muMarkValue)
915
- }
916
- },
917
- },
918
- emits: [
919
- 'set-default-value',
920
- 'load-completed',
921
- 'update:value',
922
- 'set-value',
923
- 'update:value',
924
- 'focus',
925
- 'blur',
926
- 'visible-change',
927
- 'change'
928
- ],
302
+ this.setValues(this.optionItems[0][this.valueAttribute])
303
+ }
304
+ // console.log('判断参数',this.analysisArea);
305
+ // console.log('判断参数',this.remote);
306
+ if (this.analysisArea !== 1 && this.remote) {
307
+ // 传递初始化查询供重置用
308
+ const that = this
309
+ $on(eventBus, 'remoteMethod', () => {
310
+ that.remoteMethod('')
311
+ })
312
+ // console.log('传递了参数');
313
+ }
314
+ this.$emit('load-completed', dynamicDataSourceDto)
315
+ })
316
+ .catch((error) => {
317
+ console.log(error)
318
+ this.$emit('load-completed', {
319
+ code: this.dynamicDataSourceCode,
320
+ error: error
321
+ })
322
+ this.isLoaded = true
323
+ })
324
+ }
325
+ } else {
326
+ this.isLoaded = true
327
+ }
328
+ },
329
+ methods: {
330
+ ...dynamicSourceSelectService,
331
+ ...events,
332
+ blurEvent(event) {
333
+ // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
334
+ // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === false) {
335
+ // this.$nextTick(() => {
336
+ // // this.$refs['dynamicDataSourceRef'].setSelected()
337
+ // })
338
+ // }
339
+ this.$emit('blur', event)
340
+ },
341
+ changeEvent(newValue) {
342
+ this.inputValue(newValue)
343
+ this.change(newValue)
344
+ },
345
+ /**
346
+ * @description: 获取提示标题
347
+ * @Date: 2023-08-04 10:04:42
348
+ * @param {*}
349
+ * @return {*}
350
+ */
351
+ getClassOptionTitle(val) {
352
+ if (val !== null && val !== undefined && val !== '' && val.length > 0) {
353
+ let selectTittle = ''
354
+ if (typeof val === 'string') {
355
+ // 单选
356
+ if (this.descriptionAttribute) {
357
+ this.optionItems.forEach((item) => {
358
+ if (item[this.valueAttribute] === val) {
359
+ selectTittle = item._label_ + item._description_
360
+ }
361
+ })
362
+ } else {
363
+ this.optionItems.forEach((Ttem) => {
364
+ if (Ttem[this.valueAttribute] === val) {
365
+ selectTittle = Ttem._label_
366
+ }
367
+ })
368
+ }
369
+ } else {
370
+ // 多选
371
+ if (this.descriptionAttribute) {
372
+ this.optionItems.forEach((item) => {
373
+ val.forEach((Vtem) => {
374
+ if (item[this.valueAttribute] === Vtem) {
375
+ selectTittle = selectTittle + item._label_ + ','
376
+ }
377
+ })
378
+ })
379
+ selectTittle = selectTittle.slice(0, selectTittle.length - 1)
380
+ } else {
381
+ this.optionItems.forEach((Ttem) => {
382
+ val.forEach((Vtem) => {
383
+ if (Ttem[this.valueAttribute] === Vtem) {
384
+ selectTittle = selectTittle + Ttem._label_ + ','
385
+ }
386
+ })
387
+ })
388
+ selectTittle = selectTittle.slice(0, selectTittle.length - 1)
389
+ }
390
+ }
391
+ return selectTittle
392
+ }
393
+ },
394
+ // 必须有该方法,否则无法给字段赋值
395
+ inputValue(newValue) {
396
+ let isClickSaveAll = false
397
+ if (
398
+ this.baseProps.multiple !== undefined &&
399
+ this.baseProps.multiple === true &&
400
+ newValue &&
401
+ newValue.indexOf('saveAll') >= 0
402
+ ) {
403
+ // 表示点击了全选选项
404
+ isClickSaveAll = true
405
+ if (newValue.length - 1 >= this.optionItems.length) {
406
+ // 表示需要取消全选
407
+ newValue = []
408
+ } else {
409
+ // 表示需要全选
410
+ const allValues = []
411
+ for (let i = 0; i < this.optionItems.length; i++) {
412
+ const item = this.optionItems[i]
413
+ allValues.push(item[this.valueAttribute])
414
+ }
415
+ newValue = allValues
416
+ }
417
+ }
418
+ this.$emit('update:value', newValue)
419
+ if (this.remote && (newValue === null || newValue === undefined || newValue === '')) {
420
+ this.remoteQueryMethod(newValue)
421
+ }
422
+ this.setValues(newValue, isClickSaveAll)
423
+ },
424
+ packageDynamicDataSourceInfo(dynamicDataSourceCode, param) {
425
+ return new Promise((resolve, reject) => {
426
+ this.findDynamicDataSourceByCode(
427
+ dynamicDataSourceCode,
428
+ this.entity,
429
+ param,
430
+ this.additionalParameterStr,
431
+ this.backendUrl
432
+ )
433
+ .then((dynamicDataSourceDto) => {
434
+ if (dynamicDataSourceDto) {
435
+ if (dynamicDataSourceDto.options) {
436
+ this.optionItems = dynamicDataSourceDto.options
437
+ let optionsResult = dynamicDataSourceDto.options
438
+ if (
439
+ this.baseProps.multiple !== undefined &&
440
+ this.baseProps.multiple === true &&
441
+ optionsResult &&
442
+ optionsResult.length > 0
443
+ ) {
444
+ const saveAll = { value: 'saveAll', _label_: this.$t('superGrid.selectAll') }
445
+ optionsResult = [saveAll, ...optionsResult]
446
+ }
447
+ this.optionItemList = optionsResult
448
+ // if (this.watchAttr) {
449
+ // // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
450
+ // if (
451
+ // this.baseProps.multiple !== undefined &&
452
+ // this.baseProps.multiple === true
453
+ // ) {
454
+ // this.$nextTick(() => {
455
+ // // this.$refs['dynamicDataSourceRef'].setSelected()
456
+ // })
457
+ // }
458
+ // }
459
+ //
460
+ if (this.column) {
461
+ // 只有行编辑时处理
462
+ // 设置选项组数据、 选项组值字段、 映射关系
463
+ if (this.column.prop !== dynamicDataSourceDto.valueAttribute) {
464
+ this.column['_dynamic-source-data-' + this.column.prop] = {
465
+ valueSetOptions: this.options.valueSetOptions,
466
+ optionItems: this.optionItems,
467
+ valueAttribute: dynamicDataSourceDto.valueAttribute
468
+ }
469
+ }
470
+ for (let i = 0; i < this.options.valueSetOptions.length; i++) {
471
+ const valueSetOption = this.options.valueSetOptions[i]
472
+ if (dynamicDataSourceDto.valueAttribute === valueSetOption.columnName) {
473
+ if (this.markValue) {
474
+ const muMarkValue = JSON.parse(this.markValue)
475
+ if (muMarkValue && muMarkValue[valueSetOption.valueColumn.dbColumnName]) {
476
+ let targeValue = (muMarkValue[valueSetOption.valueColumn.dbColumnName] + '').split(',')
477
+ if (this.column.componentType === 'select') {
478
+ // 如果是单选
479
+ targeValue = targeValue[0]
480
+ }
481
+ // 不需要再赋值了 如果当前字段不上动态数据源的值字段,那就表示不需要回显
482
+ // if (valueSetOption.valueColumn.dbColumnName === this.column.prop) {
483
+ // this.$emit('set-value', {
484
+ // value: targeValue,
485
+ // targetColumnName: this.column.prop,
486
+ // options: this.optionItems,
487
+ // valueAttribute: this.valueAttribute
488
+ // })
489
+ // }
490
+ }
491
+ }
492
+ break
493
+ }
494
+ }
495
+ }
496
+ } else {
497
+ this.optionItems = []
498
+ }
499
+ if (dynamicDataSourceDto.valueAttribute) {
500
+ this.valueAttribute = dynamicDataSourceDto.valueAttribute
501
+ }
502
+ if (dynamicDataSourceDto.descriptionAttribute) {
503
+ this.descriptionAttribute = dynamicDataSourceDto.descriptionAttribute
504
+ }
505
+ this.valueAttribute = this.getValueAttribute()
506
+ this.watchAttr = dynamicDataSourceDto.watchAttr
507
+ this.$emit('load-completed', dynamicDataSourceDto)
508
+ resolve(dynamicDataSourceDto)
509
+ } else {
510
+ resolve()
511
+ }
512
+ })
513
+ .catch((error) => {
514
+ reject(error)
515
+ })
516
+ })
517
+ },
518
+ // 远程搜索方法
519
+ remoteQuery(searchText, watchAttrValue) {
520
+ if (
521
+ (searchText !== null && searchText !== undefined) ||
522
+ (watchAttrValue !== null && watchAttrValue !== undefined)
523
+ ) {
524
+ const param = {
525
+ _listCode: this.listCode,
526
+ _formCode: this.formCode,
527
+ _tableName: this.tableName
528
+ }
529
+ if (searchText !== null && searchText !== undefined) {
530
+ param.searchText = searchText
531
+ }
532
+ if (watchAttrValue !== null && watchAttrValue !== undefined) {
533
+ // 监控的属性值改变了远程搜索方法
534
+ if (Object.prototype.toString.apply(watchAttrValue) === '[object Array]') {
535
+ param.watchAttrValue = watchAttrValue.join(',')
536
+ } else {
537
+ param.watchAttrValue = watchAttrValue + ''
538
+ }
539
+ } else if (this.entity) {
540
+ // 搜索时下拉选项的集合
541
+ const watchValue = this.entity[this.watchAttr]
542
+ if (watchValue !== null && watchValue !== undefined) {
543
+ if (Object.prototype.toString.apply(watchValue) === '[object Array]') {
544
+ param.watchAttrValue = watchValue.join(',')
545
+ } else {
546
+ param.watchAttrValue = watchValue + ''
547
+ }
548
+ }
549
+ }
550
+ if (this.parent) {
551
+ param.parent = this.parent
552
+ }
553
+ this.loading = true
554
+ this.packageDynamicDataSourceInfo(this.dynamicDataSourceCode, param)
555
+ .then((dynamicDataSourceDto) => {
556
+ // 解决当监控值变化时,数据源重新加载后select输入框中显示的值和下拉中的值不一致问题
557
+ // if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
558
+ // this.$nextTick(() => {
559
+ // // this.$refs['dynamicDataSourceRef'].setSelected()
560
+ // })
561
+ // }
562
+ this.loading = false
563
+ })
564
+ .catch((error) => {
565
+ console.log(error)
566
+ this.loading = false
567
+ })
568
+ }
569
+ },
570
+ // 远程搜索方法
571
+ remoteQueryMethod(searchText) {
572
+ if (Array.isArray(this.value)) {
573
+ if (this.value.length === 0) {
574
+ this.remoteQuery(searchText, null)
575
+ }
576
+ } else {
577
+ this.remoteQuery(searchText, null)
578
+ }
579
+ },
580
+ /**
581
+ * 输入框输入查询值时搜索方法,
582
+ * 不使用remoteQueryMethod 解决输入框第一次输入时可查询,第二次输入时没有触发查询方法问题
583
+ * @param {*} searchText
584
+ */
585
+ remoteMethod(searchText) {
586
+ this.remoteQuery(searchText, null)
587
+ },
588
+ // 监控的属性值改变了远程搜索方法
589
+ watchAttrValueChange(watchAttrValues) {
590
+ this.remoteQuery(null, watchAttrValues)
591
+ },
592
+ getValueAttribute() {
593
+ return !this.valueAttribute || this.valueAttribute === '[label]' ? '_label_' : this.valueAttribute
594
+ },
595
+ setValues(newValue, isClickSaveAll) {
596
+ if (this.valueSetOptions && this.valueSetOptions.length > 0) {
597
+ if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true) {
598
+ // 多选时
599
+ this.setColumnValueWhenMulti(newValue, isClickSaveAll)
600
+ } else {
601
+ // 单选时
602
+ this.valueSetOptions.forEach((columnInfo) => {
603
+ const sourceColumnName = columnInfo.columnName
604
+ let value
605
+ if (this.optionItems && sourceColumnName) {
606
+ value = this.getTargetColumnValue(newValue, sourceColumnName)
607
+ }
608
+ let targetColumnName = null
609
+ const targetColumnInfo = columnInfo.valueColumn
610
+ if (targetColumnInfo) {
611
+ targetColumnName = targetColumnInfo.name
612
+ if (this.isSql === true) {
613
+ targetColumnName = targetColumnInfo.dbColumnName
614
+ targetColumnName = getPropNameWhenJoinTable(targetColumnName, this.isJoinTable, this.tableName)
615
+ }
616
+ }
617
+ if (this.entity && targetColumnName && targetColumnName !== null && targetColumnName !== '') {
618
+ setEntityFieldValue(this.entity, targetColumnName, value)
619
+ }
620
+ const item = this.getSelectedOptionItem(newValue)
621
+ this.$emit('set-value', {
622
+ value: value,
623
+ sourceColumnName: sourceColumnName,
624
+ targetColumnName: targetColumnName,
625
+ options: this.optionItems,
626
+ valueAttribute: this.valueAttribute,
627
+ selectedItem: item
628
+ })
629
+ })
630
+ }
631
+ }
632
+ },
633
+ // 设置字段的值
634
+ setColumnValue(sourceColumnName, value, columnInfo) {
635
+ let targetColumnName = null
636
+ const targetColumnInfo = columnInfo.valueColumn
637
+ if (targetColumnInfo) {
638
+ targetColumnName = targetColumnInfo.name
639
+ if (this.isSql === true) {
640
+ targetColumnName = targetColumnInfo.dbColumnName
641
+ targetColumnName = getPropNameWhenJoinTable(targetColumnName, this.isJoinTable, this.tableName)
642
+ }
643
+ }
644
+ if (this.entity && targetColumnName && targetColumnName !== null && targetColumnName !== '') {
645
+ setEntityFieldValue(this.entity, targetColumnName, value)
646
+ }
647
+ this.$emit('set-value', {
648
+ value: value,
649
+ sourceColumnName: sourceColumnName,
650
+ targetColumnName: targetColumnName,
651
+ options: this.optionItems,
652
+ valueAttribute: this.valueAttribute
653
+ })
654
+ },
655
+ // 多选下拉框时处理增加tag、减少tag时,映射字段赋值问题
656
+ setColumnValueWhenMulti(newValue, isClickSaveAll) {
657
+ // 是否添加tag
658
+ let isAddTag = false
659
+ let removeTag
660
+ this.valueSetOptions.forEach((columnInfo) => {
661
+ const sourceColumnName = columnInfo.columnName
662
+ if (sourceColumnName === this.valueAttribute) {
663
+ // 是当前下拉选组件对应的字段时,才需要走该方法
664
+ // 字段的值
665
+ let value
666
+ if (this.optionItems && sourceColumnName) {
667
+ value = this.getTargetColumnValue(newValue, sourceColumnName)
668
+ }
669
+ this.setColumnValue(sourceColumnName, value, columnInfo)
670
+ if (this.lastValues.length < newValue.length) {
671
+ // 表示是增加tag
672
+ isAddTag = true
673
+ } else if (this.lastValues.length > newValue.length) {
674
+ // 表示减少tag
675
+ isAddTag = false
676
+ const totalArr = [...this.lastValues, ...newValue]
677
+ const totalSet = new Set(totalArr)
678
+ const arr = Array.from(totalSet)
679
+ const removeTagArr = [
680
+ ...arr.filter((item) => !this.lastValues.includes(item)),
681
+ ...arr.filter((item) => !newValue.includes(item))
682
+ ]
683
+ if (removeTagArr && removeTagArr.length > 0) {
684
+ removeTag = removeTagArr[0]
685
+ }
686
+ }
687
+ this.lastValues = JSON.parse(JSON.stringify(newValue))
688
+ // 跳出forEach循环
689
+ }
690
+ })
691
+ if (isAddTag) {
692
+ // 表示是增加tag
693
+ const isRemove = false
694
+ if (isClickSaveAll) {
695
+ // 全选
696
+ this.setAllTagValue(isRemove)
697
+ } else {
698
+ const lastSelectTag = newValue[newValue.length - 1]
699
+ const items = this.optionItems.filter((item) => item[this.valueAttribute] === lastSelectTag)
700
+ if (items && items.length > 0) {
701
+ this.setTagValue(null, isRemove, items[0])
702
+ }
703
+ }
704
+ } else {
705
+ // 表示是减少tag
706
+ const isRemove = true
707
+ if (isClickSaveAll) {
708
+ this.setAllTagValue(isRemove)
709
+ } else {
710
+ this.setTagValue(removeTag, isRemove)
711
+ }
712
+ }
713
+ },
714
+ setAllTagValue(isRemove) {
715
+ if (this.valueSetOptions && this.valueSetOptions.length > 0) {
716
+ this.valueSetOptions.forEach((columnInfo) => {
717
+ const sourceColumnName = columnInfo.columnName
718
+ if (sourceColumnName !== this.valueAttribute) {
719
+ let targetColumnName = null
720
+ const targetColumnInfo = columnInfo.valueColumn
721
+ if (targetColumnInfo) {
722
+ targetColumnName = targetColumnInfo.name
723
+ if (this.isSql === true) {
724
+ targetColumnName = targetColumnInfo.dbColumnName
725
+ targetColumnName = getPropNameWhenJoinTable(targetColumnName, this.isJoinTable, this.tableName)
726
+ }
727
+ }
728
+ let value
729
+ if (targetColumnName) {
730
+ if (isRemove) {
731
+ // 移除tag
732
+ value = null
733
+ } else {
734
+ // 添加tag
735
+ let originalValue = ''
736
+ if (this.optionItems && this.optionItems.length > 0) {
737
+ this.optionItems.forEach((selectItem) => {
738
+ const addValue = selectItem[sourceColumnName]
739
+ if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
740
+ originalValue = originalValue + ',' + addValue
741
+ } else {
742
+ originalValue = addValue
743
+ }
744
+ })
745
+ value = originalValue
746
+ }
747
+ }
748
+ }
749
+ this.setTargetColumnValue(sourceColumnName, targetColumnName, value)
750
+ }
751
+ })
752
+ }
753
+ },
754
+ setTargetColumnValue(sourceColumnName, targetColumnName, value) {
755
+ if (this.entity && targetColumnName && targetColumnName !== null && targetColumnName !== '') {
756
+ setEntityFieldValue(this.entity, targetColumnName, value)
757
+ }
758
+ this.$emit('set-value', {
759
+ value: value,
760
+ sourceColumnName: sourceColumnName,
761
+ targetColumnName: targetColumnName,
762
+ options: this.optionItems,
763
+ valueAttribute: this.valueAttribute
764
+ })
765
+ },
766
+ // 根据tag参数设置映射字段的值
767
+ setTagValue(tag, isRemove, selectItem) {
768
+ if (this.valueSetOptions && this.valueSetOptions.length > 0) {
769
+ this.valueSetOptions.forEach((columnInfo) => {
770
+ const sourceColumnName = columnInfo.columnName
771
+ if (sourceColumnName !== this.valueAttribute) {
772
+ let targetColumnName = null
773
+ const targetColumnInfo = columnInfo.valueColumn
774
+ if (targetColumnInfo) {
775
+ targetColumnName = targetColumnInfo.name
776
+ if (this.isSql === true) {
777
+ targetColumnName = targetColumnInfo.dbColumnName
778
+ targetColumnName = getPropNameWhenJoinTable(targetColumnName, this.isJoinTable, this.tableName)
779
+ }
780
+ }
781
+ let value
782
+ if (targetColumnName) {
783
+ const originalValue = getEntityFieldValue(this.entity, targetColumnName)
784
+ if (isRemove) {
785
+ // 移除tag
786
+ const index = this.value.indexOf(tag)
787
+ if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
788
+ const originalVals = originalValue.split(',')
789
+ originalVals.splice(index, 1)
790
+ value = originalVals.join(',')
791
+ }
792
+ } else {
793
+ // 添加tag
794
+ let addValue
795
+ if (selectItem) {
796
+ addValue = selectItem[sourceColumnName]
797
+ }
798
+ if (originalValue !== undefined && originalValue !== null && originalValue !== '') {
799
+ value = originalValue + ',' + addValue
800
+ } else {
801
+ value = addValue
802
+ }
803
+ }
804
+ }
805
+ this.setTargetColumnValue(sourceColumnName, targetColumnName, value)
806
+ }
807
+ })
808
+ }
809
+ },
810
+ // 获得目的字段的值
811
+ getTargetColumnValue(newValue, sourceColumnName) {
812
+ if (newValue) {
813
+ let value = ''
814
+ if (this.baseProps.multiple !== undefined && this.baseProps.multiple === true && Array.isArray(newValue)) {
815
+ // 多选值处理,数组信息,使用逗号分开的格式设置其它字段的值
816
+ let i = 0
817
+ newValue.forEach((itemValue) => {
818
+ const items = this.optionItems.filter((item) => item[this.valueAttribute] === itemValue)
819
+ if (items && items.length > 0) {
820
+ value += items[0][sourceColumnName]
821
+ if (i < newValue.length - 1) {
822
+ // 最后一个元素不加逗号
823
+ value += ','
824
+ }
825
+ i++
826
+ }
827
+ })
828
+ } else {
829
+ // 单选
830
+ const items = this.optionItems.filter((item) => item[this.valueAttribute] === newValue)
831
+ if (items && items.length > 0) {
832
+ value = items[0][sourceColumnName]
833
+ }
834
+ }
835
+ return value
836
+ }
837
+ },
838
+ // 移除所有tag和clear时候清除markValue的值解决清除选项时关联字段清空了但是当前动态数据源控件仍然有值问题
839
+ clearMarkValue() {
840
+ if (this.markValue && this.entity) {
841
+ const muMarkValue = JSON.parse(this.markValue)
842
+ for (let i = 0; i < this.options.valueSetOptions.length; i++) {
843
+ const valueSetOption = this.options.valueSetOptions[i]
844
+ muMarkValue[valueSetOption.valueColumn.dbColumnName] = null
845
+ }
846
+ this.markValue = JSON.stringify(muMarkValue)
847
+ }
848
+ }
849
+ },
850
+ emits: [
851
+ 'set-default-value',
852
+ 'load-completed',
853
+ 'update:value',
854
+ 'set-value',
855
+ 'update:value',
856
+ 'focus',
857
+ 'blur',
858
+ 'visible-change',
859
+ 'change'
860
+ ]
929
861
  }
930
862
  </script>
931
863
 
932
864
  <style>
933
865
  .select-top-span {
934
- width: 100%;
866
+ width: 100%;
935
867
  }
936
868
  </style>
937
869
 
938
870
  <style lang="scss" scoped>
939
871
  :deep(.el-select-dropdown__item) {
940
- display: inline-block;
872
+ display: inline-block;
941
873
  }
942
874
  </style>