Files
inchstep/miniapp/pages/social/friends/index.js
T
zeronline b01a5f91c3
CI / Server (Go) (push) Has been cancelled
CI / Web (Next.js) (push) Has been cancelled
CI / Mobile (React Native) (push) Has been cancelled
CI / Admin (React) (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
提交修改
2026-06-29 16:49:54 +08:00

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) {} }
}})
}
})