首次提交
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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) {} }
|
||||
}})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
{ "navigationBarTitleText": "好友", "usingComponents": {} }
|
||||
@@ -0,0 +1,12 @@
|
||||
<view class="add-section">
|
||||
<input class="input-field" value="{{addPhone}}" bindinput="onPhoneInput" placeholder="输入手机号添加" style="flex:1;margin-bottom:0" />
|
||||
<button class="add-btn" bindtap="onAdd" disabled="{{!addPhone.trim()}}">添加</button>
|
||||
</view>
|
||||
|
||||
<text class="section-title">好友列表 ({{friends.length}})</text>
|
||||
<view wx:for="{{friends}}" wx:key="id" class="friend-item">
|
||||
<view class="friend-avatar">{{item.nickname?.[0] || '?'}}</view>
|
||||
<text class="friend-name">{{item.nickname || '用户'}}</text>
|
||||
<button class="remove-btn" data-id="{{item.id}}" bindtap="onRemove">删除</button>
|
||||
</view>
|
||||
<view class="empty" wx:if="{{!loading && friends.length===0}}"><text class="empty-text">还没有好友</text></view>
|
||||
@@ -0,0 +1,10 @@
|
||||
.add-section { display: flex; gap: 8px; padding: 12px 16px; align-items: center; }
|
||||
.add-btn { padding: 10px 20px; background: #FF6B35; color: white; border: none; border-radius: 10px; font-size: 14px; }
|
||||
.add-btn[disabled] { background: #E5E5EA; }
|
||||
.section-title { font-size: 15px; color: #86868B; padding: 16px 16px 8px; display: block; }
|
||||
.friend-item { display: flex; align-items: center; gap: 10px; background: white; margin: 4px 16px; padding: 12px 16px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
|
||||
.friend-avatar { width: 36px; height: 36px; border-radius: 18px; background: linear-gradient(135deg,#FF6B35,#FF4D6D); display: flex; align-items: center; justify-content: center; color: white; font-size: 14px; font-weight: 600; }
|
||||
.friend-name { flex: 1; font-size: 15px; }
|
||||
.remove-btn { background: none; border: none; color: #FF3B30; font-size: 13px; padding: 4px 8px; }
|
||||
.empty { text-align: center; padding: 40px; }
|
||||
.empty-text { font-size: 15px; color: #86868B; }
|
||||
Reference in New Issue
Block a user