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
<template>
<!-- 消息弹出框绘制开始 -->
<el-badge :is-dot="showIsDot" :hidden="badgeIsHidden" class="app-message-popover" @click="OpenPopover">
<el-popover
placement="bottom"
popper-class="message-popover-container"
v-model="showPopover"
trigger="click"
width="400"
@show="initTabCnt"
@hide="initTabCnt"
>
<el-tabs :value="default_tab_pane" :stretch="true">
<!-- 待办 -->
<el-tab-pane
:label="
this.$t('components.appmessagepopover.myTasksLabel') +
(myTasks.length == 0 ? '' : '(' + myTasks.length + ')')
"
name="first"
style="height: 300px; overflow: auto"
:draggable="false"
>
<template v-for="(myTask, index) in myTasks">
<template v-if="index < taskShowCnt">
<el-row class="popover__content" :key="index" :draggable="false">
<el-col :span="3" class="popover__content__avatar" :draggable="false">
<el-avatar
icon="el-icon-s-check"
size="small"
:draggable="false"
style="color: white; background-color: #409eff"
></el-avatar>
</el-col>
<el-col :span="21" class="popover__content__caption" :draggable="false">
<el-row :draggable="false">
<el-col :span="16" :draggable="false" style="width: 65%">
<div
class="process-definition-name"
:draggable="false"
@click="handleTag(myTask)"
>
<strong>{{ myTask.usertaskname }}</strong>
</div>
<!-- <div class="description" :draggable="false">{{myTask.description}}</div>
<div class="createtime" :draggable="false">{{ formatDate(myTask.createTime, 'MM-DD hh:mm') }}</div> -->
</el-col>
<!-- <el-col :span="5" :draggable="false" style="display: flex; align-items: center">
<el-tag
:type="'success'"
size="small"
style="overflow: hidden; text-overflow: ellipsis"
:draggable="false"
>
成功
</el-tag>
</el-col> -->
</el-row>
</el-col>
</el-row>
</template>
</template>
<template>
<div class="popover__show-more" @click="showMore('taskShowCnt')">
<label v-if="taskShowCnt < myTasks.length">{{
this.$t('components.appmessagepopover.loadmore')
}}</label>
<label v-else>{{ this.$t('components.appmessagepopover.nomore') }}</label>
</div>
</template>
</el-tab-pane>
<!-- 通知 -->
<el-tab-pane
:label="
myMsgs.length == 0
? this.$t('components.appmessagepopover.myNotificationsLabel')
: this.$t('components.appmessagepopover.myNotificationsLabel') + '(' + myMsgs.length + ')'
"
name="second"
:style="{ height: '300px', overflow: 'auto' }"
:draggable="false"
>
<template v-for="(myMsg, index) in myMsgs">
<template v-if="index < msgShowCnt">
<el-row class="popover__content" style="position:relative;" :key="index" :draggable="false">
<el-col :span="3" class="popover__content__avatar" :draggable="false">
<i class="fa fa-tasks" style="color: #409eff;font-size: 24px;"></i>
</el-col>
<el-col :span="21" class="popover__content__caption" :draggable="false">
<el-row :draggable="false">
<el-col :span="24" :draggable="false">
<div
:draggable="false"
style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;"
>
<strong>{{ myMsg.name }}</strong>
</div>
<div
:draggable="false"
style="display: flex;justify-content: space-between;align-items: center;"
>
<div v-if="myMsg.state !== 20">{{ myMsg.begintime }}</div>
<div v-if="myMsg.state === 20">{{ `${myMsg.stepinfo}(${myMsg.completionrate}%)` }}</div>
<div>
<el-tag
:type="
myMsg.state === 40
? 'danger'
: myMsg.state === 30
? 'success'
: myMsg.state === 20
? 'info'
: '-'
"
size="small"
style="overflow: hidden;text-overflow: ellipsis;"
:draggable="false"
>
{{ myMsg.stateText }}
</el-tag>
</div>
</div>
</el-col>
</el-row>
</el-col>
<div :style="getProgressStyle(myMsg)"></div>
</el-row>
</template>
</template>
<template>
<div class="popover__show-more" @click="showMore('msgShowCnt')">
<label v-if="msgShowCnt < myMsgs.length">{{
this.$t('components.appmessagepopover.loadmore')
}}</label>
<label v-else>{{ this.$t('components.appmessagepopover.nomore') }}</label>
</div>
</template>
</el-tab-pane>
</el-tabs>
<i id="bell-btn" size="20" slot="reference" class="el-icon-bell"></i>
</el-popover>
</el-badge>
<!-- 消息弹出框绘制结束 -->
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import { Subscription } from 'rxjs';
import { AppServiceBase, LogUtil } from 'ibiz-core';
import { ActionState, AppCenterService, AppNoticeService, NotificationFactory, SubType } from 'ibiz-vue';
import moment from 'moment';
@Component({})
export default class AppMessagePopover extends Vue {
// 是否显示Popover
public showPopover: boolean = false;
// 是否显示小圆点
public showIsDot: any = false;
// 默认显示的tab页
public default_tab_pane: any = 'first';
// 待办列表
public myTasks: any = [];
// 待办面板显示条数
public taskShowCnt: number = 0;
// 消息列表
public myMsgs: any = [];
// 信息面板显示条数
public msgShowCnt: number = 0;
// 环境配置对象
public environment: any = AppServiceBase.getInstance().getAppEnvironment();
// 应用状态事件
public appStateEvent: Subscription | undefined;
// 标记是否隐藏
public badgeIsHidden = false;
// 标记计数器
public bellTimer: any;
/**
* 获取进度条样式
*
* @param item
*/
public getProgressStyle(item: any) {
const itemStyle = {
position: 'absolute',
height: '100%',
background: 'linear-gradient(to right, #fff, #409eff)',
'z-index': -100,
};
Object.assign(itemStyle, { width: item.state === 20 ? `${item.completionrate}%` : '0' });
return itemStyle;
}
/**
* vue创建
*/
created(): void {
// 全局刷新通知
if (AppCenterService.getMessageCenter()) {
this.appStateEvent = AppCenterService.getMessageCenter().subscribe(
({ name, action, data }: { name: string; action: string; data: any }) => {
if (Object.is(name, 'SysTodo') && Object.is(action, 'appRefresh')) {
if (!this.environment.workflow) {
return;
}
this.getMyTasks();
return;
}
if (
Object.is(name, 'Notification') &&
(Object.is(action, 'AddItem') || Object.is(action, 'InitItem'))
) {
this.getMyMsgs();
this.handleAsyncActionNotification(name, action, data);
}
},
);
}
}
/**
* vue挂载
*/
mounted(): void {
if (this.environment.workflow) {
// 首次获取待办列表
this.getMyTasks();
// 定时器:每隔1分钟重新获取待办列表
const timer = setInterval(() => {
this.getMyTasks();
}, 60000);
// 监听定时器,在vue销毁前清除定时器
this.$once('hook:beforeDestroy', () => {
// 清除定时器
clearInterval(timer);
});
}
}
/**
* 处理异步作业通知
*/
public handleAsyncActionNotification(name: string, action: string, data: any) {
if (Object.is(action, 'AddItem') && data && data.subtype === SubType.ASYNCACTION) {
const targetData = data.data;
// 已经执行完成
if (targetData.actionstate === ActionState.CREATED) {
AppNoticeService.getInstance().success(`${targetData.asyncacitonname}异步作业执行成功`, {
duration: 0,
showClose: true,
position: 'top-right',
});
}
// 执行失败
if (targetData.actionstate === ActionState.FAILED) {
AppNoticeService.getInstance().error(`${targetData.asyncacitonname}异步作业执行异常`, {
duration: 0,
showClose: true,
position: 'top-right',
});
}
this.badgeIsHidden = true;
if(this.bellTimer){
clearTimeout(this.bellTimer);
}
this.bellTimer = setTimeout(() => {
this.badgeIsHidden = false;
}, 500);
}
}
/**
* 获取待办列表
*/
public getMyTasks() {
let url: any = '/wfcore/mytasks';
this.$http
.get(url)
.then((response: any) => {
if (response && response.status == 200) {
const data: any = response.data;
if (data && data.length > 0) {
this.myTasks = data;
this.showIsDot = true;
} else {
this.myTasks = [];
this.showIsDot = false;
}
}
})
.catch((error: any) => {
LogUtil.warn(this.$t('components.appmessagepopover.error'));
});
}
/**
* 获取消息列表
*/
public getMyMsgs() {
this.myMsgs = NotificationFactory.getInstance().getItems(true);
if (this.myMsgs && this.myMsgs.length > 0) {
this.showIsDot = true;
this.$forceUpdate();
}
}
/**
* 点击标签事件
*/
public handleTag(data: any) {
if (!data) return this.$throw(this.$t('components.appmessagepopover.geterror'), 'handleTag');
this.$http
.post(`/systodos/${data.usertaskid}/getlinkurl`, {
todourltype: 'RouterUrl',
todosubtype: 'Todo',
srfapptype: 'pc',
srfapp: AppServiceBase.getInstance().getAppModelDataObject().codeName,
})
.then((response: any) => {
if (response && response.status == 200 && response.data && response.data.linkurl) {
this.showPopover = false;
let targetUrl: string = response.data.linkurl;
if (targetUrl.indexOf('/') != 0) {
targetUrl = '/' + targetUrl;
}
targetUrl = `${targetUrl.slice(0, targetUrl.indexOf(';srffullscreen=true'))}`;
targetUrl += `;srfwf=Todo`;
this.$router.push('/index' + targetUrl);
} else {
if (response) {
this.$throw(response);
}
}
})
.catch((response: any) => {
this.$throw(response);
});
}
/**
* 销毁之前
*/
beforeDestroy(): void {
// 清空数据
this.showIsDot = false;
this.myTasks = [];
this.myMsgs = [];
}
/**
* 组件销毁
*/
destroyed() {
if (this.appStateEvent) {
this.appStateEvent.unsubscribe();
}
}
/**
* 时间格式转换
*/
public formatDate(date: string, format: string) {
if (date && format) {
return moment(date).format(format);
}
return date;
}
/**
* 加载更多
*/
public showMore(cnt: string) {
if (Object.is('taskShowCnt', cnt)) {
this.taskShowCnt + 10 < this.myTasks.length
? (this.taskShowCnt += 10)
: (this.taskShowCnt += this.myTasks.length - this.taskShowCnt);
}
if (Object.is('msgShowCnt', cnt)) {
this.msgShowCnt + 10 < this.myMsgs.length
? (this.msgShowCnt += 10)
: (this.msgShowCnt += this.myMsgs.length - this.msgShowCnt);
}
}
/**
* 弹出框 显示/隐藏 时显示条数初始化
*/
public initTabCnt() {
this.taskShowCnt = this.myTasks.length >= 10 ? 10 : this.myTasks.length;
this.msgShowCnt = this.myMsgs.length >= 10 ? 10 : this.myMsgs.length;
}
/**
* 弹出框显示处理
*/
public OpenPopover() {
this.showPopover = !this.showPopover;
}
}
</script>