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 => { export const getNoticeMsg = params => {
return axios.get(`${base}/sys/notifyMsg/list`, { params: 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> </div>
</template> </template>
<script>
<script>
import { import {
getNoticeMsg
getNoticeMsg,goToPage
} from '@/api/cpd' } from '@/api/cpd'
export default { export default {
computed: { computed: {
@ -36,8 +36,27 @@ export default {
var msgs=this.$store.getters.noticeMsg var msgs=this.$store.getters.noticeMsg
if(!msgs){ if(!msgs){
return 0; 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(){ data(){
@ -49,10 +68,18 @@ export default {
goToMsgCenter(){ goToMsgCenter(){
this.$router.push({path:"/my/work/message"}); 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(){ doGetNoticeMsgNoTips(){
this.load.list=true; this.load.list=true;
getNoticeMsg({}).then(res=>{
getNoticeMsg({pageSize:20,pageNum:1,count:false,orderBy:'oper_time desc'}).then(res=>{
this.load.list=false; this.load.list=false;
var tips = res.data.tips; var tips = res.data.tips;
if(tips.isOk){ 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(){ mounted(){
this.doGetNoticeMsgNoTips() this.doGetNoticeMsgNoTips()
setInterval(this.doGetNoticeMsgNoRead, 60000 * 5);
} }
} }
</script> </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 export default noticeMsg

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

@ -24,7 +24,7 @@
<script> <script>
import { import {
getNoticeMsg
getNoticeMsg,goToPage
} from '@/api/cpd' } from '@/api/cpd'
import { import {
@ -35,7 +35,9 @@ export default {
props:['msgClass'], props:['msgClass'],
computed: { computed: {
...mapGetters(['userInfo']), ...mapGetters(['userInfo']),
noticeMsg() {
return this.$store.getters.noticeMsg
},
}, },
data() { data() {
return { return {
@ -95,52 +97,10 @@ export default {
if(item.hadRead!='1'){ if(item.hadRead!='1'){
editSomeFieldsNotifyMsg({ids:[item.id],hadRead:'1'}).then(res=>{ editSomeFieldsNotifyMsg({ids:[item.id],hadRead:'1'}).then(res=>{
item.hadRead="1" 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