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
<template>
<div class="app-quick-group">
<span class="app-quick-item" v-for="item in showItems" :key="item.id" @click="handleClick(item)">
<span
v-if="!item.children"
:style="{ color: item.color }"
:class="{ 'app-selected-item': isSelectedItem(item) }"
>
<i v-if="item.iconcls && !Object.is(item.iconcls, '')" :class="item.iconcls"></i>
<img v-else-if="item.icon && !Object.is(item.icon, '')" :src="item.icon" />
<span class="app-quick-item-label">{{ item.label }}</span>
<span
v-show="
isSelectedItem(item) &&
counterService &&
counterService.counterData &&
counterService.counterData[id]
"
class="app-quick-item-counter"
>{{ itemTag(item) }}</span
>
</span>
<el-dropdown
v-if="item.children"
style="outline: none !important"
trigger="hover"
@command="handleCommand($event, item)"
>
<span :style="{ color: item.color }" :class="{ 'app-selected-item': isSelectedItem(item) }">
<i v-if="item.iconcls && !Object.is(item.iconcls, '')" :class="item.iconcls"></i>
<img v-else-if="item.icon && !Object.is(item.icon, '')" :src="item.icon" />
<span class="app-quick-item-label">{{ item.label }}</span>
<span
v-show="
counterService &&
counterService.counterData &&
counterService.counterData[item.id]
"
class="app-quick-item-counter"
>{{ itemTag(item) }}</span
>
</span>
<el-dropdown-menu slot="dropdown" placement="bottom">
<el-dropdown-item v-for="childitem in item.children" :command="childitem" :key="childitem.id">
<span :style="{ color: childitem.value == item.value ? '#557DA5' : childitem.color }">
<i
v-if="childitem.iconcls && !Object.is(childitem.iconcls, '')"
:class="childitem.iconcls"
></i>
<img v-else-if="childitem.icon && !Object.is(childitem.icon, '')" :src="childitem.icon" />
<span>{{
childitem.label
}}</span>
<span
v-show="
counterService &&
counterService.counterData &&
counterService.counterData[childitem.id]
"
class="app-quick-item-counter"
>{{ itemTag(childitem) }}</span
>
</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</span>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import { CodeListService, Util } from 'ibiz-core';
import { IPSAppCodeList, IPSCodeItem } from '@ibiz/dynamic-model-api';
@Component({})
export default class AppQuickGroup extends Vue {
/**
* 传入渲染项
*
* @type {Array<any>}
* @memberof AppQuickGroup
*/
@Prop() public items?: Array<any>;
/**
* 计数器服务名
*
* @type {string}
* @memberof AppQuickGroup
*/
@Prop() public counterService?: any;
/**
* 快速分组代码表模型
*
* @type {string}
* @memberof AppQuickGroup
*/
@Prop() public codeList?: IPSAppCodeList;
/**
* 模式(CODELIST: 代码表加载, ITEMS:使用外置分组项)
*
* @type {string}
* @memberof AppQuickGroup
*/
@Prop({ default: 'CODELIST' }) public type?: 'CODELIST' | 'ITEMS' | string;
/**
* 应用上下文
*
* @type {*}
* @memberof AppQuickGroup
*/
@Prop() public context: any;
/**
* 视图参数
*
* @type {*}
* @memberof AppQuickGroup
*/
@Prop() public viewparams: any;
/**
* UI选中项
*
* @type {*}
* @memberof AppQuickGroup
*/
public selectedUiItem: any;
/**
* 渲染列表
*
* @type {any[]}
* @memberof AppQuickGroup
*/
public showItems: any[] = [];
/**
* 翻译代码表后的初始列表
*
* @type {any[]}
* @memberof AppQuickGroup
*/
public initItems: any[] = [];
/**
* Vue生命周期 --- Created
*
* @memberof AppQuickGroup
*/
created() {
// 使用代码表加载模式
if (this.type === 'CODELIST') {
this.handleByCodeList();
} else if (this.type === 'ITEMS') {
this.handleByItems();
}
}
/**
* 处理代码表模式
*
* @memberof AppQuickGroup
*/
private async handleByCodeList() {
if (this.codeList) {
await this.codeList.fill();
const codeListService = new CodeListService({ $store: this.$store });
codeListService
.getDataItems({
tag: this.codeList.codeName,
type: this.codeList.codeListType || 'STATIC',
context: this.context,
viewparam: this.viewparams,
})
.then((codeListItems: any[]) => {
if (codeListItems && codeListItems.length) {
const items = this.handleDynamicData(Util.deepCopy(codeListItems));
this.initItems = this.handleDataSet(items);
this.showItems = Util.deepCopy(this.initItems);
const select = this.initItems.find((item: any) => item.default);
this.handleClick(select ? select : this.initItems[0]);
}
});
}
}
/**
* 处理代码表动态数据
*
* @memberof AppQuickGroup
*/
private handleDynamicData(inputArray: Array<any>) {
if (inputArray.length > 0) {
const defaultSelect: any = this.getQuickGroupDefaultSelect();
if (defaultSelect) {
let select = inputArray.find((item: any) => { return item.value === defaultSelect.value; });
if (select) select.default = true;
}
inputArray.forEach((item: any) => {
if (item.data && Object.keys(item.data).length > 0) {
Object.keys(item.data).forEach((name: any) => {
let value: any = item.data[name];
if (value && typeof (value) == 'string' && value.startsWith('%') && value.endsWith('%')) {
const key = (value.substring(1, value.length - 1)).toLowerCase();
if (this.context[key]) {
value = this.context[key];
} else if (this.viewparams[key]) {
value = this.viewparams[key];
}
}
item.data[name] = value;
})
}
})
}
return inputArray;
}
/**
* 获取快速分组默认选中
*
* @memberof AppQuickGroup
*/
private getQuickGroupDefaultSelect() {
let defaultSelect: any = null;
const codeItems: Array<IPSCodeItem> = this.codeList?.getPSCodeItems() || [];
if (codeItems.length > 0) {
for (const item of codeItems) {
const childItems = item.getPSCodeItems?.() || [];
if (childItems.length > 0) {
defaultSelect = childItems.find((_item: any) => _item.default);
}
if (item.default || defaultSelect) {
defaultSelect = item;
break;
}
}
}
return defaultSelect;
}
/**
* 处理集合模式
*
* @memberof AppQuickGroup
*/
private handleByItems() {
if (this.items && this.items.length) {
const select = this.items.find((item: any) => {
return item.default;
});
this.showItems = Util.deepCopy(this.items);
this.handleClick(select ? select : this.items[0]);
}
}
/**
* 计数器标识
*
* @memberof AppQuickGroup
*/
public itemTag(item: any) {
if (this.counterService && this.counterService.counterData && item.value) {
return this.counterService.counterData[item.value];
} else {
return '';
}
}
/**
* 是否选中当前项
*
* @param item 传入当前项
* @memberof AppQuickGroup
*/
public isSelectedItem(item: any) {
if (this.selectedUiItem && this.selectedUiItem.value === item.value) {
return true;
} else {
return false;
}
}
/**
* 处理代码表返回数据(树状结构)
*
* @param result 返回数组
* @memberof AppQuickGroup
*/
public handleDataSet(result: Array<any>) {
let list: Array<any> = [];
if (result.length === 0) {
return list;
}
result.forEach((codeItem: any) => {
if (!codeItem.pvalue) {
let valueField: string = codeItem.value;
this.setChildCodeItems(valueField, result, codeItem);
list.push(codeItem);
}
});
return list;
}
/**
* 处理非根节点数据
*
* @param pValue 父值
* @param result 返回数组
* @param codeItem 代码项
* @memberof AppQuickGroup
*/
public setChildCodeItems(pValue: string, result: Array<any>, codeItem: any) {
result.forEach((item: any) => {
if (item.pvalue == pValue) {
let valueField: string = item.value;
this.setChildCodeItems(valueField, result, item);
if (!codeItem.children) {
codeItem.children = [];
}
codeItem.children.push(item);
}
});
}
/**
* 处理点击事件
*
* @param $event 值
* @memberof AppQuickGroup
*/
public handleClick($event: any) {
if ((this.selectedUiItem && this.selectedUiItem.id === $event.id)) {
return;
}
this.selectedUiItem = $event;
for (let i = 0; i < this.showItems.length; i++) {
if (this.showItems[i].children && this.showItems[i].id !== $event.pvalue) {
this.showItems[i].label = this.initItems[i].label;
this.showItems[i].value = this.initItems[i].value;
}
}
this.$emit('valuechange', $event);
this.$forceUpdate();
}
/**
* 处理子项点击事件
*
* @param $event 值
* @param item 父值
* @memberof AppQuickGroup
*/
public handleCommand($event: any, item: any) {
item.label = $event.label;
item.value = $event.value;
this.handleClick($event);
}
}
</script>