Initial commit
This commit is contained in:
42
wechat-mini-program/pages/message/index.js
Normal file
42
wechat-mini-program/pages/message/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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))
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user