msmq.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Notification } from 'element-ui';
  2. import Bus from '@/utils/bus.js'
  3. const MSMQ = {
  4. msgTypeMap: {
  5. "Success": "success",
  6. "Error": "error",
  7. "Warning": "warning",
  8. "Info": "info",
  9. },
  10. moduleMap: {//消息模块映射
  11. "Model": "模型文件管理"
  12. },
  13. handleMsg (message, projects, userId, unreadNum ) {
  14. let data
  15. try {
  16. data = JSON.parse(message.body)
  17. } catch (err) {
  18. return false
  19. }
  20. if(data.ProjectId && projects.some((item) => {return item.id == data.ProjectId})) { //判断消息是否是当前用户拥有的项目
  21. if(!data.UserList || (userId && data.UserList && data.UserList.includes(userId))){//判断消息接收人是否是当前用户
  22. if(data.Module && data.Module == 'Model'){ //模型文件的消息触发模型文件列表刷新事件
  23. Bus.$emit('modelStatusChange', data)
  24. }
  25. Notification({
  26. title: `${data.Title?data.Title:''}`,
  27. dangerouslyUseHTMLString: true,
  28. message: `【${this.moduleMap[data.Module]?this.moduleMap[data.Module]:data.Module}】${data.Content?data.Content.Message?data.Content.Message:'':''}`,
  29. type: this.msgTypeMap[data.Type]?this.msgTypeMap[data.Type]:'info'
  30. })
  31. // Notification.info({ title: '消息',dangerouslyUseHTMLString: true, message: `项目编号:${data.projectId}<br>消息类型:${data.type}<br>描述信息:${data.description}<br>` })
  32. unreadNum++
  33. Bus.$emit('messageListUpdate', data)//消息驱动消息列表刷新
  34. return unreadNum
  35. }
  36. }
  37. }
  38. }
  39. export default MSMQ