周宾
8 小时以前 ce7bdf6065e66474c01a45e2bb967ead46cab541
海川开心-本地推送通知公告标题
已修改2个文件
48 ■■■■ 文件已修改
src/api/login.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/index.vue 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/login.js
@@ -43,9 +43,9 @@
}
// 获取未过期公告数量
export function noticesCount(params) {
export function noticesList(params) {
  return request({
    url: '/home/noticesCount',
    url: '/collaborativeApproval/notice/page',
    method: 'get',
    params: params
  })
src/pages/index.vue
@@ -154,9 +154,10 @@
        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";
@@ -567,14 +568,21 @@
            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();
@@ -585,34 +593,31 @@
                    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)
@@ -626,10 +631,9 @@
        getUserLoginFacotryList()
        // 启动通知状态定时器
        startStatusTimer()
        // getNoticesCount()
    });
    onShow(()=>{
        getNoticesCount()
        getNoticesList()
    })
</script>