wlzboy
5 天以前 c098f1e3a3e052aa3d65584aae6dc003a70d75ad
app/pages/message/index.vue
@@ -2,6 +2,10 @@
  <view class="message-container">
    <view class="message-header">
      <view class="header-title">消息中心</view>
      <view class="subscribe-btn" v-if="!subscribed" @click="subscribeMessage">
        <uni-icons type="bell" size="20" color="#007AFF"></uni-icons>
        <text>订阅通知</text>
      </view>
    </view>
    
    <scroll-view class="message-list-scroll" scroll-y="true">
@@ -35,13 +39,15 @@
<script>
  import { getMyMessages, markAsRead } from '@/api/message'
  import { formatDateTime } from '@/utils/common'
  import subscribeManager from '@/utils/subscribe'
  
  export default {
    data() {
      return {
        // 消息列表
        messages: [],
        loading: false
        loading: false,
        subscribed: false,
      }
    },
    computed: {
@@ -61,6 +67,8 @@
    },
    onLoad() {
      this.loadMessages()
      // 自动订阅(如果未订阅则显示确认弹窗)
      this.autoSubscribeOnLaunch()
    },
    onShow() {
      // 每次显示页面时刷新消息
@@ -74,6 +82,21 @@
      })
    },
    methods: {
      // 自动订阅(页面加载时调用)
      autoSubscribeOnLaunch() {
        subscribeManager.autoSubscribe()
          .then((result) => {
            if (result.skipped) {
              console.log('用户已订阅,无需重复订阅')
            } else if (result.success) {
              console.log('自动订阅成功')
            }
          })
          .catch((error) => {
            console.log('自动订阅取消或失败:', error)
          })
      },
      // 加载消息列表
      async loadMessages() {
        try {
@@ -157,6 +180,23 @@
      formatMessageTime(dateTime) {
        if (!dateTime) return ''
        return formatDateTime(dateTime, 'MM-DD HH:mm')
      },
      // 订阅任务通知
      subscribeMessage() {
        subscribeManager.subscribeWithConfirm()
          .then((result) => {
            if (result.success) {
              uni.showToast({
                title: '订阅成功,您将收到任务通知',
                icon: 'success',
                duration: 2000
              })
            }
          })
          .catch((error) => {
            console.log('订阅失败:', error)
          })
      }
    }
  }
@@ -199,6 +239,24 @@
      font-size: 36rpx;
      font-weight: bold;
    }
    .subscribe-btn {
      display: flex;
      align-items: center;
      padding: 10rpx 20rpx;
      background-color: #f0f9ff;
      border-radius: 30rpx;
      text {
        margin-left: 8rpx;
        font-size: 26rpx;
        color: #007AFF;
      }
      &:active {
        opacity: 0.7;
      }
    }
  }
  
  .message-list-scroll {