Files
inchstep/miniapp/pages/social/friends/index.js
T
2026-06-25 08:39:47 +08:00

22 lines
990 B
JavaScript

const api = require('../../../services/api')
Page({
data: { friends: [], addPhone: '', loading: true },
onShow() { this.loadFriends() },
async loadFriends() {
try { const f = await api.get('/api/social/friends'); this.setData({ friends: f || [] }) } catch(e) {}
this.setData({ loading: false })
},
onPhoneInput(e) { this.setData({ addPhone: e.detail.value }) },
async onAdd() {
if (!this.data.addPhone.trim()) return
try { await api.post('/api/social/friends/request', { friendId: this.data.addPhone.trim() }); wx.showToast({ title: '请求已发送' }); this.setData({ addPhone: '' }) }
catch(e) { wx.showToast({ title: e.message || '添加失败', icon: 'none' }) }
},
async onRemove(e) {
const id = e.currentTarget.dataset.id
wx.showModal({ title: '确认', content: '确定删除好友?', success: async (res) => {
if (res.confirm) { try { await api.del('/api/social/friends/' + id); this.loadFriends() } catch(e) {} }
}})
}
})