1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<template>
<div ref="orgDept" class="app-cur-org-dept">
<van-collapse v-model="active">
<van-collapse-item :name="1">
<div slot="title" class="org-title-content">
<div class="org-icon"><img :src="baseUrl+'/assets/images/org-dept/team.svg'" alt=""></div>
<div class="org-title">{{visibleTitle}}</div>
</div>
<div class="org-item" v-for="item in datas" :key="item.id" @click="itemClick(item)">
<div class="org-item-left">
<div class="org-icon"><img :src="baseUrl+'/assets/images/org-dept/user.svg'" alt=""></div>
<div class="user-name">{{item.label}}</div>
</div>
<div class="checkbox">
<div class="org-icon-small">
<img v-if="item.check" :src="baseUrl+'/assets/images/org-dept/check-circle-colour.svg'" alt="">
<img v-else :src="baseUrl+'/assets/images/org-dept/check-circle.svg'" alt="">
</div>
</div>
</div>
</van-collapse-item>
</van-collapse>
</div>
</template>
<script lang="ts">
import { Environment } from "@/environments/environment";
import { LogUtil } from "ibiz-core";
import { Vue, Component, Prop, Watch } from "vue-property-decorator";
@Component({})
export default class AppCommonMicrocom extends Vue {
/**
* 图片基础路径
* @type {any}
* @memberof AppCommonMicrocom
*/
public baseUrl = process.env.NODE_ENV === 'development' ? '' : '/' + Environment.AppName.toLowerCase();
/**
* 数据接口地址
*
* @type {string}
* @memberof AppCommonMicrocom
*/
@Prop()
public url!: string;
/**
* 填充属性
*
* @type {*}
* @memberof AppCommonMicrocom
*/
@Prop()
public fillMap!: any;
/**
* 关联属性
*
* @type {string}
* @memberof AppCommonMicrocom
*/
@Prop()
public valueitem!: string;
/**
* 表单项名称
*
* @type {string}
* @memberof AppCommonMicrocom
*/
@Prop()
public name!: string;
/**
* 局部上下文导航参数
*
* @type {any}
* @memberof AppCheckBox
*/
@Prop() public localContext!: any;
/**
* 局部导航参数
*
* @type {any}
* @memberof AppCheckBox
*/
@Prop() public localParam!: any;
/**
* 上下文
*
* @type {*}
* @memberof AppCommonMicrocom
*/
@Prop()
public context!: any;
/**
* 视图参数
*
* @type {*}
* @memberof AppCommonMicrocom
*/
@Prop()
public viewparams!: any;
/**
* 表单数据对象
*
* @type {*}
* @memberof AppCommonMicrocom
*/
@Prop()
public data!: any;
/**
* 是否启用
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
@Prop()
public disabled?: boolean;
/**
* 只读模式
*
* @type {boolean}
*/
@Prop({ default: false })
public readonly?: boolean;
/**
* 是否多选
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
@Prop({ default: 'false' })
public multiple?: string;
/**
* 是否多选
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
public relMultiple:boolean = false;
/**
* 地址过滤参数
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
@Prop()
public filter!: string;
/**
* 请求方式
*
* @type {string}
* @memberof AppCommonMicrocom
*/
@Prop({ default: "get" })
public requestMode!: "get" | "post" | "delete" | "put";
/**
* 激活项
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
public active:Array<any> = [1];
/**
* 请求结束
*
* @type {boolean}
* @memberof AppCommonMicrocom
*/
public overLoadding:boolean = false;
/**
* 表单项标题
*
* @type {string}
* @memberof AppCommonMicrocom
*/
public title:string = '';
/**
* 显示标题
*
* @type {string}
* @memberof AppCommonMicrocom
*/
get visibleTitle(){
return `${this.title}${this.overLoadding?'('+this.datas.length+')':''}`
}
/**
* 选中项集合
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public selects: any[] = [];
/**
* 数据集合
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public datas: any[] = [];
/**
* 回显值
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public selectArray: any[] = [];
/**
* 主键属性
*
* @type {*}
* @memberof AppCommonMicrocom
*/
keyFile:string = '';
/**
* 文本属性
*
* @type {*}
* @memberof AppCommonMicrocom
*/
labelFile:string = '';
/**
* 项点击
*
* @type {*}
* @memberof AppCommonMicrocom
*/
itemClick(item:any){
const isCheck = !item.check;
if(!this.relMultiple){
this.datas.forEach((_item) => {
if(item.id != _item.id){
_item.check = false;
}else{
_item.check = isCheck;
}
});
}else{
item.check = isCheck;
}
this.selectChange(item);
this.$forceUpdate();
}
/**
* 值变化
*
* @type {*}
* @memberof AppGroupSelect
*/
@Watch("data", {
immediate: true,
deep: true,
})
onValueChange(newVal: any, oldVal: any) {
console.log(newVal);
this.selects = [];
if (newVal) {
let item: any = {};
item.label = this.data[this.name] ? this.data[this.name].split(",") : [];
item.id = this.data[this.valueitem]
? this.data[this.valueitem].split(",")
: [];
this.selectArray = item.id;
if (this.fillMap) {
for (let key in this.fillMap) {
item[this.fillMap[key]] = this.data[key]
? this.data[key].split(",")
: [];
}
}
if (item.label.length > 0) {
item.label.forEach((val: string, index: number) => {
let _item: any = {};
for (let key in item) {
_item[key] = item[key][index] ? item[key][index] : null;
}
this.selects.push(_item);
});
}
}
}
/**
* 生命周期
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public created() {
this.relMultiple = this.multiple =='true'?true:false;
const keyRep = this.fillMap?.replace("{id:'","");
const keyRepArr = keyRep?.split("',");
if(keyRepArr){
this.keyFile = keyRepArr[0];
}
const textArr = this.fillMap?.replace("label:'","").split(",")
if(textArr){
this.labelFile = textArr[1]?.replace("'}","");
}
this.load();
}
/**
* 处理特殊filter参数
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public handleFilterValue(value: string) {
if (value && value.startsWith("%") && value.endsWith("%")) {
const key = value.slice(1, value.length - 1);
if (this.data && this.data.hasOwnProperty(key)) {
return this.data[key];
} else if (this.context && this.context[key]) {
return this.context[key];
} else if (this.viewparams && this.viewparams[key]) {
return this.viewparams[key];
}
}
return value;
}
/**
* 解析URL
*
* @type {*}
* @param context 上下文参数
* @param viewparams 视图参数
* @memberof AppCommonMicrocom
*/
public parseURL(context: any, viewparams: any) {
let url = this.url;
const filterArr: Array<any> = this.filter ? this.filter.split("|") : [];
const urlParm = url.match(/\${(.+?)\}/g);
if (urlParm) {
urlParm.forEach((item: string) => {
const key = item.substring(2, item.length - 1).toLowerCase();
const res = new RegExp("\\${" + key + "}");
let value = null;
const isFilterKey = key.match(/filter/g) ? true : false;
if (isFilterKey) {
const filterIndex = key.slice(6);
if (filterIndex) {
if (
isNaN(parseInt(filterIndex)) ||
filterArr.length < parseInt(filterIndex) - 1
) {
LogUtil.warn(this.$t("components.microcom.filterwarn"));
} else {
value = this.handleFilterValue(
filterArr[parseInt(filterIndex) - 1]
);
}
} else {
value = filterArr[0];
}
} else {
if (this.data && this.data.hasOwnProperty(key)) {
value = this.data[key];
} else if (context && context[key]) {
value = context[key];
} else if (viewparams && viewparams[key]) {
value = viewparams[key];
}
}
url = url.replace(res, value);
});
}
return url;
}
/**
* 公共参数处理
*
* @param {*} arg
* @returns
* @memberof AppCheckBox
*/
public handlePublicParams(arg: any) {
// 合并表单参数
arg.param = this.viewparams
? JSON.parse(JSON.stringify(this.viewparams))
: {};
arg.context = this.context ? JSON.parse(JSON.stringify(this.context)) : {};
// 附加参数处理
if (this.localContext && Object.keys(this.localContext).length > 0) {
let _context = this.$util.computedNavData(
this.data,
arg.context,
arg.param,
this.localContext
);
Object.assign(arg.context, _context);
}
if (this.localParam && Object.keys(this.localParam).length > 0) {
let _param = this.$util.computedNavData(
this.data,
arg.param,
arg.param,
this.localParam
);
Object.assign(arg.param, _param);
}
}
/**
* 加载数据
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public load() {
let data: any = {};
this.handlePublicParams(data);
// 参数处理
let context = data.context;
let viewparam = data.param;
const url = this.parseURL(context, viewparam);
if (url) {
this.datas = [];
this.$http[this.requestMode](url)
.then((response: any) => {
if (response && response.status == 200) {
this.overLoadding = true;
if (response.data.length > 0) {
let item: any;
response.data.forEach((_item: any) => {
item = _item;
item.label = _item[this.labelFile];
item.id = _item[this.keyFile];
this.datas.push(item);
});
}
}
console.log(this.datas);
})
.catch((response: any) => {
console.log(this.datas);
});
}
}
/**
* 选中数据改变
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public selectChange(item: any) {
this.selects = [];
if (this.relMultiple) {
this.datas.forEach((_item: any) => {
if (_item.check) {
this.selects.push(_item);
}
});
} else {
this.selects.push(item);
}
this.setValue();
}
/**
* 设置值
*
* @type {*}
* @memberof AppCommonMicrocom
*/
public setValue() {
let item: any = {};
item[this.name] = null;
if (this.valueitem) {
item[this.valueitem] = null;
}
if (this.relMultiple == true) {
this.selects.forEach((select: any) => {
item[this.name] = item[this.name]
? `${item[this.name]},${select.label}`
: select.label;
if (this.valueitem) {
item[this.valueitem] = item[this.valueitem]
? `${item[this.valueitem]},${select.id}`
: select.id;
}
});
} else {
item[this.name] = this.selects.length > 0 ? this.selects[0].label : null;
if (this.valueitem) {
item[this.valueitem] =
this.selects.length > 0 ? this.selects[0].id : null;
}
}
for (let key in item) {
// 抛出当前表单项与值项
if (Object.is(key, this.name) || Object.is(key, this.valueitem)) {
this.$emit("formitemvaluechange", { name: key, value: item[key] });
}
}
}
mounted(){
//删除元素标题 自定义绘制
const orgDept:any = this.$refs.orgDept;
const parent = orgDept?.parentNode;
const label:any = parent?.previousElementSibling;
if(label){
this.title = label.textContent;
label.style.display="none";
}
// 默认填满
if(parent){
parent.style.width= '100%';
}
}
}
</script>
<style lang='less'>
@import "./app-cur-org-dept.less";
</style>