Browse Source

定时查询未读消息

master
陈裕财 4 years ago
parent
commit
18ce099bd4
  1. 47
      src/api/cpd.js
  2. 50
      src/components/NoticeMsgBar/index.vue
  3. 6
      src/store/modules/noticeMsg.js
  4. 52
      src/views/myWork/message/notifyMsg.vue

47
src/api/cpd.js

@ -10,3 +10,50 @@ let base = config.getSysBasePath();
export const getNoticeMsg = params => {
return axios.get(`${base}/sys/notifyMsg/list`, { params: params });
};
export const goToPage = (that,item) => {
var curlDomain=window.location.protocol+"//"+window.location.host; // 返回https://mp.csdn.net
if(item.objType=='1'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmProject/XmProjectInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmProject/XmProjectInfoRoute?id="+item.bizId)
}
}else if(item.objType=='2'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmTask/XmTaskDetailRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmTask/XmTaskDetailRoute?id="+item.bizId)
}
}else if(item.objType=='3'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmProduct/XmProductInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmProduct/XmProductInfoRoute?id="+item.bizId)
}
}else if(item.objType=='4'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmMenu/XmMenuDetailRoute",query:{menuId:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmMenu/XmMenuDetailRoute?menuId="+item.bizId)
}
}else if(item.objType=='5'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmQuestion/XmQuestionDetailRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmQuestion/XmQuestionDetailRoute?id="+item.bizId)
}
}else if(item.objType=='6'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmIteration/XmIterationInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmIteration/XmIterationInfoRoute?id="+item.bizId)
}
}else if(item.objType=='7'){
if(process.env.CONTEXT=='xm'){
that.$router.push({path:"/xm/core/xmGroup/xmGroupRoute",query:{projectId:item.pbizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmGroup/xmGroupRoute?projectId="+item.pbizId)
}
}
}

50
src/components/NoticeMsgBar/index.vue

@ -23,9 +23,9 @@
</div>
</template>
<script>
<script>
import {
getNoticeMsg
getNoticeMsg,goToPage
} from '@/api/cpd'
export default {
computed: {
@ -36,8 +36,27 @@ export default {
var msgs=this.$store.getters.noticeMsg
if(!msgs){
return 0;
}
return msgs.filter(k=>k.hadRead!='1').length;
}
},
watch:{
unreadMsgCount(count){
var that = this;
if(count>1){
this.$notify.warning({title:'未读消息',message:'有'+count+'条未读消息待处理',showClose:true,position:'bottom-right',
onClick:function(){
that.goToMsgCenter();
}
})
}else if(count==1){
var msgObj=this.noticeMsg.filter(k=>k.hadRead!='1')[0]
that.$notify.warning({title:'未读消息',message:msgObj.msg,showClose:true,position:'bottom-right',
onClick:function(){
that.goToPage(msgObj);
}
})
}
return msgs.filter(k=>k.hadRead!='1').length;
}
},
data(){
@ -49,10 +68,18 @@ export default {
goToMsgCenter(){
this.$router.push({path:"/my/work/message"});
},
goToPage(item){
if(item.hadRead!='1'){
editSomeFieldsNotifyMsg({ids:[item.id],hadRead:'1'}).then(res=>{
item.hadRead="1"
this.$store.dispatch("setNoticeMsg",this.notifyMsgs)
})
}
goToPage(this,item);
},
doGetNoticeMsgNoTips(){
this.load.list=true;
getNoticeMsg({}).then(res=>{
getNoticeMsg({pageSize:20,pageNum:1,count:false,orderBy:'oper_time desc'}).then(res=>{
this.load.list=false;
var tips = res.data.tips;
if(tips.isOk){
@ -62,9 +89,22 @@ export default {
}
})
},
doGetNoticeMsgNoRead(){
this.load.list=true;
getNoticeMsg({hadRead:'0',pageSize:20,pageNum:1,count:false,orderBy:'oper_time desc'}).then(res=>{
this.load.list=false;
var tips = res.data.tips;
if(tips.isOk&&res.data.data.length>0){
this.$store.dispatch("setNoticeMsg",res.data.data)
}else if(!tips.isOk){
this.$message.error(tips.msg)
}
})
},
},
mounted(){
this.doGetNoticeMsgNoTips()
setInterval(this.doGetNoticeMsgNoRead, 60000 * 5);
}
}
</script>

6
src/store/modules/noticeMsg.js

@ -25,9 +25,5 @@ const noticeMsg = {
}
}
var noticeMsgLocal=localStorage.getItem("noticeMsg");
if(noticeMsgLocal){
noticeMsg.state.noticeMsg=JSON.parse(noticeMsgLocal)
}
export default noticeMsg

52
src/views/myWork/message/notifyMsg.vue

@ -24,7 +24,7 @@
<script>
import {
getNoticeMsg
getNoticeMsg,goToPage
} from '@/api/cpd'
import {
@ -35,7 +35,9 @@ export default {
props:['msgClass'],
computed: {
...mapGetters(['userInfo']),
noticeMsg() {
return this.$store.getters.noticeMsg
},
},
data() {
return {
@ -95,52 +97,10 @@ export default {
if(item.hadRead!='1'){
editSomeFieldsNotifyMsg({ids:[item.id],hadRead:'1'}).then(res=>{
item.hadRead="1"
this.$store.dispatch("setNoticeMsg",this.notifyMsgs)
})
}
var curlDomain=window.location.protocol+"//"+window.location.host; // https://mp.csdn.net
if(item.objType=='1'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmProject/XmProjectInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmProject/XmProjectInfoRoute?id="+item.bizId)
}
}else if(item.objType=='2'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmTask/XmTaskDetailRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmTask/XmTaskDetailRoute?id="+item.bizId)
}
}else if(item.objType=='3'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmProduct/XmProductInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmProduct/XmProductInfoRoute?id="+item.bizId)
}
}else if(item.objType=='4'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmMenu/XmMenuDetailRoute",query:{menuId:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmMenu/XmMenuDetailRoute?menuId="+item.bizId)
}
}else if(item.objType=='5'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmQuestion/XmQuestionDetailRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmQuestion/XmQuestionDetailRoute?id="+item.bizId)
}
}else if(item.objType=='6'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmIteration/XmIterationInfoRoute",query:{id:item.bizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmIteration/XmIterationInfoRoute?id="+item.bizId)
}
}else if(item.objType=='7'){
if(process.env.CONTEXT=='xm'){
this.$router.push({path:"/xm/core/xmGroup/xmGroupRoute",query:{projectId:item.pbizId}})
}else{
window.open(curlDomain+"/xm/"+process.env.VERSION+"/#/xm/core/xmGroup/xmGroupRoute?projectId="+item.pbizId)
}
}
goToPage(this,item);
}
},

Loading…
Cancel
Save