| | |
| | | nextTick, |
| | | reactive |
| | | } from 'vue'; |
| | | import dayjs from "dayjs" |
| | | import { |
| | | userLoginFacotryList, |
| | | noticesCount |
| | | noticesList |
| | | } from "@/api/login"; |
| | | import modal from "@/plugins/modal"; |
| | | import useUserStore from "@/store/modules/user"; |
| | |
| | | uToastRef.value.success(`点击了第${name + 1}个`); // 注意:这里加1是因为通常我们是从第1个开始计数的 |
| | | } |
| | | }; |
| | | const isShowNoticesCount = ref(true) |
| | | const isShowNoticesList = ref(true) |
| | | // 获取公告数量 |
| | | const getNoticesCount = () => { |
| | | if(!isShowNoticesCount.value){ |
| | | const getNoticesList = () => { |
| | | if(!isShowNoticesList.value){ |
| | | return |
| | | } |
| | | noticesCount({}).then(resp => { |
| | | if (resp.code != 200 || !resp.data) { |
| | | const current_date = dayjs().format('YYYY-MM-DD') |
| | | noticesList({ |
| | | current:-1, |
| | | size:-1, |
| | | status: 1, |
| | | current_date |
| | | }).then(resp => { |
| | | console.log('noticesList',resp) |
| | | if (resp.code != 200 || !resp.data||!resp.data.records||!resp.data.records.length) { |
| | | return |
| | | } |
| | | const res = uni.getAppAuthorizeSetting(); |
| | |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | uni.openAppAuthorizeSetting({ |
| | | success: (res) => { |
| | | console.log('openAppAuthorizeSetting',res) |
| | | // if (res.authSetting['scope.push']) { |
| | | // createPushMessage(resp.data) |
| | | // } |
| | | } |
| | | success: (res) => {} |
| | | }); |
| | | }else{ |
| | | isShowNoticesCount.value = false |
| | | isShowNoticesList.value = false |
| | | } |
| | | } |
| | | }); |
| | | return |
| | | } |
| | | createPushMessage(resp.data) |
| | | resp.data.records.map(item=>{ |
| | | createPushMessage(item.title) |
| | | }) |
| | | |
| | | }).catch(error => { |
| | | modal.msgError('获取公告数量:', error) |
| | | console.log('获取公告数量:', error) |
| | | }) |
| | | } |
| | | |
| | | const createPushMessage = (_noticesCount) => { |
| | | const createPushMessage = (text) => { |
| | | uni.createPushMessage({ |
| | | title: '公告通知', |
| | | content: `当前有${_noticesCount}条公告通知,注意查看`, |
| | | content: text||'', |
| | | success: (resp) => { |
| | | console.log('success', resp) |
| | | isShowNoticesCount.value = false |
| | | isShowNoticesList.value = false |
| | | }, |
| | | fail: (resp) => { |
| | | console.log('fail', resp) |
| | |
| | | getUserLoginFacotryList() |
| | | // 启动通知状态定时器 |
| | | startStatusTimer() |
| | | // getNoticesCount() |
| | | }); |
| | | onShow(()=>{ |
| | | getNoticesCount() |
| | | getNoticesList() |
| | | }) |
| | | </script> |
| | | |