acdr-ui/dist/build/mp-weixin/service/notificationService.js

2 lines
781 B
JavaScript

"use strict";const e=require("../store/user.js"),s=require("../store/message.js"),t=require("../utils/http.js");let r=null;const a=()=>{r&&(clearInterval(r),r=null)},n={startPollingUnreadMessages:()=>{try{const n=e.useUserStore(),o=s.useMessageStore();if(!n.userInfo.token)return;if(r)return;r=setInterval((()=>{n.userInfo.token?t.httpGet("/notifications").then((e=>{200===e.code&&e.data.length>0&&o.setUnreadMessages(e.data)})).catch((e=>{})):a()}),6e4)}catch(n){}},stopPollingUnreadMessages:a,markMessageAsRead:r=>{try{const a=e.useUserStore(),n=s.useMessageStore();return a.userInfo.token?t.httpPost("/notifications",{},{messageId:r}).then((e=>{200===e.code&&n.markMessageAsRead(r)})).catch((e=>{})):Promise.reject("用户未登录")}catch(a){}}};exports.notificationService=n;