zhangwencui
2 天以前 49b6ad612dcc44e9e45c7e1256acfad24ff94393
消息推送及消息列表,点击已读
已修改3个文件
87 ■■■■ 文件已修改
src/App.vue 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/login.js 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/message.vue 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/App.vue
@@ -7,6 +7,7 @@
<script setup>
  import { ref, onMounted } from "vue";
  import Splash from "./components/Splash.vue";
  import { confirmMessage } from "@/api/login.js";
  const showSplash = ref(true);
  onMounted(() => {
@@ -54,16 +55,21 @@
  // 处理推送消息点击事件
  const handlePushClick = msg => {
    console.log("点击推送消息:", msg);
    console.log("解析后:", msg.payload.noticeId);
    try {
      if (msg.payload.indexOf("/") === 0) {
        uni.navigateTo({
          url: msg.payload,
        });
      } else {
        uni.navigateTo({
          url: "/" + msg.payload,
        });
      }
      confirmMessage(msg.payload.noticeId, 1).then(res => {
        if (msg.payload.url) {
          if (msg.payload.url.indexOf("/") === 0) {
            uni.navigateTo({
              url: msg.payload.url,
            });
          } else {
            uni.navigateTo({
              url: "/" + msg.payload.url,
            });
          }
        }
      });
    } catch (error) {
      uni.showToast({
        title: "路径:" + msg.payload,
src/api/login.js
@@ -76,4 +76,30 @@
    method: 'get',
    params: { consigneeId }
  })
}
}
// 标记消息为已读
export function markAsRead(noticeId, status) {
  return request({
    url: "/system/notice",
    method: "put",
    data: { noticeId, status },
  });
}
// 一键标记所有消息为已读
export function markAllAsRead() {
  return request({
    url: "/system/notice/readAll",
    method: "post",
  });
}
// 确认消息
export function confirmMessage(noticeId, status) {
  return request({
    url: "/system/notice",
    method: "put",
    data: { noticeId, status },
  });
}
src/pages/message.vue
@@ -37,10 +37,11 @@
            <text class="message-time">{{ formatTime(item.createTime) }}</text>
          </view>
          <text class="message-desc">{{ item.noticeContent }}</text>
          <view class="message-footer">
          <view v-if="activeTab === 0"
                class="message-footer">
            <text class="message-view"
                  @click="goToDetail(item)">
              去查看 >
              确认消息
            </text>
          </view>
        </view>
@@ -61,7 +62,7 @@
<script setup>
  import { ref, reactive, onMounted } from "vue";
  import { listNotice } from "@/api/login.js";
  import { listNotice, confirmMessage } from "@/api/login.js";
  import useUserStore from "@/store/modules/user";
  // 标签页数据
@@ -100,15 +101,25 @@
  // 跳转到详情页
  const goToDetail = item => {
    if (item.appJumpPath.indexOf("/") === 0) {
      uni.navigateTo({
        url: item.appJumpPath,
      });
    } else {
      uni.navigateTo({
        url: "/" + item.appJumpPath,
      });
    }
    confirmMessage(item.noticeId, 1).then(res => {
      if (res.code === 200) {
        uni.showToast({ title: "确认成功", icon: "success" });
        loadMessages(false);
        if (item.appJumpPath) {
          if (item.appJumpPath.indexOf("/") === 0) {
            uni.navigateTo({
              url: item.appJumpPath,
            });
          } else {
            uni.navigateTo({
              url: "/" + item.appJumpPath,
            });
          }
        }
      } else {
        uni.showToast({ title: "确认失败", icon: "none" });
      }
    });
  };
  const userStore = useUserStore();
  const userId = ref("");