feat(sdk): 升级HaveADrink SDK并集成邀请系统

- 将HaveADrink依赖从1.0.8升级至1.0.12版本
- 集成邀请码功能,新增common/invite.js处理邀请链路
- 实现发送好友请求返回邀请码的新流程
- 添加删除动态功能,新增DeleteFeed接口
- 集成UniAppWebSocket适配器,重构WebSocket连接管理
- 优化好友请求支持关键词搜索功能
- 在FeedCard组件中添加删除按钮和分享按钮
- 更新SDK类型定义文件以匹配新接口规范
This commit is contained in:
cg
2026-08-04 23:32:45 +08:00
parent f988c8d868
commit 57eef74eb1
19 changed files with 1461 additions and 223 deletions
+79 -4
View File
@@ -17,7 +17,10 @@
<FeedCard
v-if="feed"
:feed="feed"
:can-delete="isMyFeed(feed)"
@like="handleLike"
@share="handleShare"
@delete="confirmDeleteFeed"
/>
<!-- 评论区 -->
@@ -62,7 +65,7 @@
import FeedCard from '../../components/FeedCard.vue'
import CommentItem from '../../components/CommentItem.vue'
import EmptyState from '../../components/EmptyState.vue'
import { GetFeedComments, AddComment, LikeFeed, UnlikeFeed } from '../../common/api'
import { GetFeedComments, AddComment, LikeFeed, UnlikeFeed, DeleteFeed } from '../../common/api'
import themeMixin from '../../common/theme-mixin'
export default {
@@ -75,11 +78,16 @@ export default {
feedId: '',
feed: null,
comments: [],
commentText: ''
commentText: '',
// 当前分享的动态
shareFeed: null,
// 分享落地页携带的动态快照参数(好友打开分享链接时兼容展示)
shareOptions: {}
}
},
onLoad(options) {
this.feedId = options.id || ''
this.shareOptions = options || {}
this.loadFeed()
this.loadComments()
},
@@ -88,10 +96,27 @@ export default {
uni.navigateBack()
},
async loadFeed() {
// 从 globalData 中查找对应动态
// 优先从 globalData 中查找对应动态
const app = getApp()
const feeds = (app.globalData && app.globalData.circleFeeds) || []
this.feed = feeds.find(f => String(f.id) === String(this.feedId)) || null
const found = feeds.find(f => String(f.id) === String(this.feedId)) || null
if (found) {
this.feed = found
return
}
// 分享落地页兼容:本地无缓存时用分享链接携带的快照参数展示
const o = this.shareOptions
if (o.nick || o.text) {
this.feed = {
id: this.feedId,
nickname: decodeURIComponent(o.nick || ''),
text: decodeURIComponent(o.text || ''),
time: decodeURIComponent(o.time || ''),
avatar: '',
likes: 0,
comments: 0
}
}
},
async loadComments() {
try {
@@ -109,6 +134,39 @@ export default {
else await UnlikeFeed({ feedId: feed.id })
} catch (e) { /* ignore */ }
},
/** 记录当前要分享的动态,供 onShareAppMessage 读取 */
handleShare(feed) {
this.shareFeed = feed
},
/** 判断是否为自己发布的动态(仅自己可删) */
isMyFeed(feed) {
let myId = ''
try {
const user = JSON.parse(uni.getStorageSync('user_info') || '{}')
myId = user.id !== undefined && user.id !== null ? String(user.id) : ''
} catch (e) { /* ignore */ }
if (!myId) return false
return feed && feed.userId !== undefined && feed.userId !== null && String(feed.userId) === myId
},
/** 删除自己的动态(二次确认),成功后返回列表 */
confirmDeleteFeed(feed) {
uni.showModal({
title: '删除动态',
content: '确定要删除这条动态吗?删除后不可恢复',
confirmText: '删除',
confirmColor: '#FF6B6B',
success: async (res) => {
if (!res.confirm) return
try {
await DeleteFeed({ feedId: feed.id })
uni.showToast({ title: '已删除', icon: 'none' })
setTimeout(() => uni.navigateBack(), 600)
} catch (e) {
// httpRequest 已全局弹错误提示(如非本人动态后端会拒绝)
}
}
})
},
async submitComment() {
const text = this.commentText.trim()
if (!text) return
@@ -128,6 +186,23 @@ export default {
uni.showToast({ title: '发送失败', icon: 'none' })
}
}
},
onShareAppMessage() {
const feed = this.shareFeed || this.feed
if (feed && feed.id) {
const text = (feed.text || '').replace(/\s+/g, ' ').trim()
const title = text
? `${feed.nickname || '酒友'}${text.length > 24 ? text.slice(0, 24) + '…' : text}`
: `${feed.nickname || '酒友'}的动态 - 碰盏日记`
return {
title,
path: `/pages/circle-detail/circle-detail?id=${feed.id}&nick=${encodeURIComponent(feed.nickname || '')}&text=${encodeURIComponent(text.slice(0, 60))}&time=${encodeURIComponent(feed.time || '')}`
}
}
return {
title: '酒友圈 - 碰盏日记',
path: '/pages/index/index'
}
}
}
</script>