26 lines
1.1 KiB
JavaScript
26 lines
1.1 KiB
JavaScript
const api = require('../../../services/api')
|
|
const app = getApp()
|
|
Page({
|
|
data: { friends: [], addPhone: '', loading: true, themeMode: 'light' },
|
|
onShow() {
|
|
this.setData({ themeMode: app.globalData.themeMode })
|
|
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) {} }
|
|
}})
|
|
}
|
|
})
|