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
+250 -12
View File
@@ -13,6 +13,8 @@
* 6. 社交模块 - 朋友圈动态、点赞
*/
let websocket = WebSocket;
export class Enum {
constructor(value) {
this.v = value;
@@ -2051,6 +2053,38 @@ export class PublishFeedResp {
}
}
/**
* 删除动态请求(路径参数)
*/
export class DeleteFeedReq {
/**
* @param id: string|number 动态ID
*/
constructor(id,) {
this.id = id;
}
static fromObject(o) {
return new DeleteFeedReq(o.id,);
}
}
/**
* 删除动态响应
*/
export class DeleteFeedResp {
/**
* @param ok: boolean 是否成功
*/
constructor(ok,) {
this.ok = ok;
}
static fromObject(o) {
return new DeleteFeedResp(o.ok,);
}
}
/**
* 点赞/取消点赞请求(路径参数)
*/
@@ -2248,12 +2282,14 @@ export class Friend {
*/
export class GetFriendRequestsReq {
/**
* @param keyword: string 搜索关键词
*/
constructor() {
constructor(keyword,) {
this.keyword = keyword;
}
static fromObject(o) {
return new GetFriendRequestsReq();
return new GetFriendRequestsReq(o.keyword,);
}
}
@@ -2336,16 +2372,14 @@ export class FriendRequestListData {
*/
export class SendFriendRequestReq {
/**
* @param userId: string|number 酒友ID
* @param message: string 消息
*/
constructor(userId,message,) {
this.userId = userId;
constructor(message,) {
this.message = message;
}
static fromObject(o) {
return new SendFriendRequestReq(o.userId,o.message,);
return new SendFriendRequestReq(o.message,);
}
}
@@ -2354,12 +2388,14 @@ export class SendFriendRequestReq {
*/
export class SendFriendRequestResp {
/**
* @param inviteCode: string|number 好友请求ID
*/
constructor() {
constructor(inviteCode,) {
this.inviteCode = inviteCode;
}
static fromObject(o) {
return new SendFriendRequestResp();
return new SendFriendRequestResp(o.inviteCode,);
}
}
@@ -2569,6 +2605,82 @@ export class CreateEventResp {
}
}
/**
* 修改酒局请求
*/
export class UpdateEventReq {
/**
* @param id: string|number 酒局ID
* @param title: string 酒局标题
* @param time: string 酒局时间
* @param location: string 酒局地点
* @param maxPeople: number 最大人数
* @param geo: GeoPoint 坐标信息
* @param note: string 酒局备注
*/
constructor(id,title,time,location,maxPeople,geo,note,) {
this.id = id;
this.title = title;
this.time = time;
this.location = location;
this.maxPeople = maxPeople;
this.geo = geo;
this.note = note;
}
static fromObject(o) {
return new UpdateEventReq(o.id,o.title,o.time,o.location,o.maxPeople,o.geo,o.note,);
}
}
/**
* 修改酒局响应
*/
export class UpdateEventResp {
/**
* @param ok: boolean 是否成功
*/
constructor(ok,) {
this.ok = ok;
}
static fromObject(o) {
return new UpdateEventResp(o.ok,);
}
}
/**
* 删除酒局请求
*/
export class DeleteEventReq {
/**
* @param id: string|number 酒局ID
*/
constructor(id,) {
this.id = id;
}
static fromObject(o) {
return new DeleteEventReq(o.id,);
}
}
/**
* 删除酒局响应
*/
export class DeleteEventResp {
/**
* @param ok: boolean 是否成功
*/
constructor(ok,) {
this.ok = ok;
}
static fromObject(o) {
return new DeleteEventResp(o.ok,);
}
}
/**
* 报名/取消/签到请求(路径参数)
*/
@@ -3087,19 +3199,36 @@ export class ChatWebSocketResp {
}
}
/**
*
*/
export class ChatWebSocketReq {
/**
* @param token: string 连接 token
*/
constructor(token,) {
this.token = token;
}
static fromObject(o) {
return new ChatWebSocketReq(o.token,);
}
}
export class ChatWebSocketConn {
/**
* 构造函数
*
* @param host string 主机名
*/
constructor(host) {
constructor(host, query) {
this.host = host;
this.reconnect = true;
this.reconnectDelay = 1000;
this.maxReconnectDelay = 5000;
this.randomizationFactor = 0.5;
this.attempt = 0;
this.query = query;
this.connect();
}
backoff(attempt) {
@@ -3115,7 +3244,7 @@ export class ChatWebSocketConn {
return delayWithJitter;
}
connect() {
let socket = new WebSocket(`ws://${this.host}/api/have_a_drink/v1/chat/chat`);
let socket = new websocket(`${this.host}/api/have_a_drink/v1/chat/chat?${this.query}`);
socket.onopen = (event) => {
this.onopen(event);
};
@@ -3281,6 +3410,12 @@ export class ChatWebSocketConn {
}
}
export class Config {
host = "";
http_request = (url, params) => {};
upload = (url, params) => {};
websocket = undefined;
}
/**
* * 喝酒了么 - 后端接口 API
* 小程序:喝酒了么(uni-app 微信小程序)
@@ -3296,6 +3431,9 @@ export class ChatWebSocketConn {
*/
export default class HaveADrink {
constructor(conf) {
if (conf.websocket) {
websocket = conf.websocket;
}
this.host = conf.host;
this.http_request = conf.http_request;
this.upload = conf.upload;
@@ -3945,6 +4083,38 @@ export default class HaveADrink {
});
}
/**
* 删除动态
*/
DeleteFeed(req) {
return new Promise((reslove, reject)=>{
let data = req;
let url = `${this.host}/api/have_a_drink/v1/moments/feeds`;
this.http_request(url, {
uri: '/api/have_a_drink/v1/moments/feeds',
method: 'DELETE',
data: data,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
},
}).then((data)=>{
if (data.hasOwnProperty("fail")) {
if (data.fail) {
reject(data.msg);
} else {
reslove(data.data);
}
} else {
reslove(data);
}
}).catch((err)=>reject(err));
});
}
/**
* 点赞
*/
@@ -4329,6 +4499,70 @@ export default class HaveADrink {
});
}
/**
* 修改酒局
*/
UpdateEvent(req) {
return new Promise((reslove, reject)=>{
let data = req;
let url = `${this.host}/api/have_a_drink/v1/events/events/update`;
this.http_request(url, {
uri: '/api/have_a_drink/v1/events/events/update',
method: 'POST',
data: data,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
},
}).then((data)=>{
if (data.hasOwnProperty("fail")) {
if (data.fail) {
reject(data.msg);
} else {
reslove(data.data);
}
} else {
reslove(data);
}
}).catch((err)=>reject(err));
});
}
/**
* 删除酒局
*/
DeleteEvent(req) {
return new Promise((reslove, reject)=>{
let data = req;
let url = `${this.host}/api/have_a_drink/v1/events/events/delete`;
this.http_request(url, {
uri: '/api/have_a_drink/v1/events/events/delete',
method: 'POST',
data: data,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
},
}).then((data)=>{
if (data.hasOwnProperty("fail")) {
if (data.fail) {
reject(data.msg);
} else {
reslove(data.data);
}
} else {
reslove(data);
}
}).catch((err)=>reject(err));
});
}
/**
* 报名酒局
*/
@@ -4556,9 +4790,13 @@ export default class HaveADrink {
/**
* 注意:连接建立后,服务端会先验证 token,然后推送 connected 事件
*/
ChatWebSocket() {
ChatWebSocket(input) {
const url = new URL(this.host);
return new ChatWebSocketConn(url.host);
let host = "ws://" + url.host;
if (url.protocol == 'https:') {
host = "wss://" + url.host;
}
return new ChatWebSocketConn(host, new URLSearchParams(Object.fromEntries(Object.entries(input).filter(([_, v]) => v !== '' && v !== null && v !== undefined))).toString());
}
}