Files
geminiWX/wechat-mini-program/pages/message/index.js
2025-12-09 14:31:16 +08:00

43 lines
894 B
JavaScript

const app = getApp()
const { request } = require('../../utils/request.js')
Page({
data: {
notifications: [],
loading: false
},
onShow() {
this.fetchNotifications()
this.readAllNotifications()
},
fetchNotifications() {
this.setData({ loading: true })
request({ url: '/notifications/' })
.then(res => {
// Handle paginated response if any, or direct list
const list = Array.isArray(res) ? res : (res.results || [])
this.setData({
notifications: list,
loading: false
})
})
.catch(err => {
console.error(err)
this.setData({ loading: false })
})
},
readAllNotifications() {
request({
url: '/notifications/read_all/',
method: 'POST'
})
.then(res => {
console.log('All read')
})
.catch(err => console.error(err))
}
})