0.0.48 • Published 5 years ago
im-itool v0.0.48
一个基于 websocket 的通用的 im 服务
通用 im 解决方案
TODO
- 前后台切换尝试使用通知
- 后台 切换 前台 时连接断开则重连
- 切换 到 后台 不再检测网络连接 (不再尝试重连ws)
- 网络变化时重连,网络恢复时重连
- 向外反馈 连接状态 WS连接状态变化(向外发送通知)
如何安装
npm i im-itool --save
如何使用
普通html 文件中
<script src="./node_modules/it-itool/im-itool.min.js"></script>
<script>
var options = {
key: 'zhujian_app',
url: 'http://debug.itool.store/',
platform: 'browser',
isIm: true
}
var result = imItool(options);
// 默认以 uuid 的方式激活服务
result.register().then(res => {
console.log(res)
}).catch(e => {
console.log(e);
})
// 传递 请求拦截器 及 相应拦截器
result.register({
token?: string; // 以 token 方式激活
responseInterceptor(methodname, data){
console.log('response', methodname, data)
// 不做处理原样返回
return data;
},
requestInterceptor(methodname, headers){
console.log('request', methodname, headers)
return headers
}
}).then(res => {
console.log(res)
}).catch(e => {
console.log(e);
})
// 以token 方式激活 不添加拦截器
result.register(token).then(res => {
console.log(res)
}).catch(e => {
console.log(e);
})
</script>
模块化项目中
import imItool from 'im-itool'
const options = {
key: 'xxxx',
url: 'http://debug.itool.store',
platform: 'browser',
isIm: true,
dataLayer: { // 是否采用自定义的本地缓存数据介质,不传递此参数默认使用localStorage
setItem(key, data){ // 具体的设置逻辑 },
getItem(key){ // 具体的获取逻辑 },
removeItem(key){ // 具体的删除逻辑 }
}
}
const { bbs, comment, common, queue, shop, register, noticeListener } = imItool(options)
Vue.prototype.$bbs = bbs;
Vue.prototype.$comment = comment;
Vue.prototype.$common = common;
Vue.prototype.$queue = queue;
Vue.prototype.$shop = shop;
noticeListener.on('ready', notice => {
console.log('连接好的ws实例', notice)
})
register().then(res => {
const { notice, getData } = res;
notice.on('*', data => console.log(data))
Vue.prototype.$notice = notice;
console.log('userInfo', getData('userInfo'))
}).catch(err => {
console.log(err)
})
BBS 文章相关业务
使用示例 this.\$bbs.addArticles(data).then(res => {}).catch(err => {})
- addArticles 添加文章
- getArticles 搜索文章信息并获取指定属性
- getArticlesByAttrs 根据属性搜索文章信息
- getUserArticles 获取用户发表的信息并指定属性
- getUserArticlesByAttrs 根据属性搜索当前用户参与的信息
- getHistoryArticles 获取用户浏览历史
- updateArticles 修改文章
- delArticles 删除文章
- addArticleAttr 添加文章属性
- updateArticleAttr 修改文章属性
- delArticleAttr 删除文章属性
- getArticleItem 获取指定文章信息
- watchArticle 关注文章
- unwatchArticle 取消关注
- starArticle 文章点赞
- unstarArticle 取消文章点赞
- readArticle 添加文章阅读量
- getType 查询指定分类信息含子集信息
- getTypes 查询分类信息
- getUserTypes 查询用户分类信息
- addType 添加分类信息
- updateType 修改分类信息
- delType 删除分类信息
- addTypeAttr 添加分类属性信息
- updateTypeAttr 修改分类属性信息
- delTypeAttr 删除分类属性信息
COMMENT 评论相关业务
使用示例 this.\$comment.getComment(data).then(res => {}).catch(err => {})
- getComment 获取评论
- addComment 添加评论
- updateComment 修改评论
- delComment 删除评论
- getReplyComment 获取回复评论回复
- addReplyComment 添加回复评论
- starComment 评论点赞
- unstarComment 取消评论点赞
- starReplyComment 回复评论点赞
- unstarReplyComment 取消回复评论点赞
- addCommentAttr 添加评论属性
- updateCommentAttr 修改评论属性
- delCommentAttr 删除评论属性
- updateCommentReply 修改评论回复
- delCommentReply 删除评论回复
COMMON 公共业务
使用示例 this.\$common.getUserInfo(data).then(res => {}).catch(err => {})
- fetch 通用方法 调用
- logoutByToken 根据用户 token 退出登录
- getUserInfo 根据 token 获取用户信息
- registerUser 注册用户
- updateUserInfo 修改用户信息
- getUserList 获取客户端缓存用户列表
- registerUserBySms 短信注册用户
- smsUserBindPhone 短信用户绑定手机号
- smsUserUpdatePassword 短信用户修改密码
- smsUserLogin 短信用户登录
- fetchUserList 获取用户列表
- getUserInfoById 根据用户
id
获取用户信息 - getUserInfoByIdAndSetCache 根据用户
id
获取用户信息,并设置缓存 - loginByUserName 根据用户名 密码登录
- loginByPhone 根据手机号密码 登录
- loginBySms 根据手机号短信验证码 登录
- loginByKey 根据 UUID 登录
- loginByOpenid 根据第三方平台 openid 登录
- updateUserInfoParas 修改用户扩展参数
- logoutSocketByServiceToken 退出 SocketClient 根据 ServiceToken
- logoutSocketByToken 退出 socket 根据 token
QUEUE 通知消息发送
使用示例 this.\$queue.sendText(data).then(res => {}).catch(err => {})
- sendQueue 通用消息发送
- sendText 发送文本类消息
- sendImg 发送图片类消息
- sendVoice 发送音频
- sendProduct 发送商品信息
- sendHttp 发送网址
- sendUserCard 发送用户名片
- sendGroupCard 发送群组名片
SHOP 电商相关业务
使用示例 this.\$shop.getOrderDetails(data).then(res => {}).catch(err => {})
- getOrderDetails 查询指定订单详情
- getUserOrderCounts 查询指定用户订单统计
- getOrders 查询用户订单
- getUserOrders 查询用户订单
- addOrder 下订单
- aliApplyPay 订单发起付款 支付宝
- wChatApplyPay 订单发起付款 微信
- okPayment 订单已付款
- shipment 订单产品发货
- okShipment 订单产品发货确认
- returnApply 订单退货申请
- returnShipment 退货订单发货
- refundApply 订单退款申请
- serviceApply 订单申请售后
- accident 订单额外事件
- updateServiceApply 修改售后相关信息
- updateRefundStatus 退款申请状态处理
- updateRefundPrice 修改退款订单金额
- updateAddress 修改地址
- updatePayment 修改订单付款金额
- cancelOrder 取消指定订单
- delOrder 删除指定订单
- getUserAddress 获取用户地址信息
- addUserAddress 添加用户地址信息
- updateUserAddress 修改地址信息
- delUserAddress 删除地址
- getUserCart 获取购物车信息
- addUserCart 加入商品到用户购物车
- addOrderByUserCart 根据购物车下单
- delUserCart 删除购物车指定商品
- updateUserCart 修改购物车数量信息
- getProduct 获取指定产品模板
- getProductsByType 获取指定分类产品模板
- getProducts 获取产品模板
- getProductsByAttr 根据搜索产品模板根据属性
- confirmProduct 确认产品模板
- addProduct 添加模板
- updateProduct 修改模板
- delProduct 删除模板
- getProductTypes 获取分类集合
- getProductType 获取指定分类
- addProductType 添加分类
- updateProductType 修改分类信息
- delProductType 删除分类
NOTICE 通知消息接收
! 注意初始化时必须设置 isIm 为 true 时才可以使用以下方法 使用示例 this.\$notice.on('*', function(data){ console.log('接收到所有类别的消息', data) })
- on 订阅通知消息
- off 取消订阅通知消息
this.$notice.on('*', function(data){ console.log('订阅notice接收到的所有类别的消息', data) })
this.$notice.on('type:text', function(data){ console.log('订阅notice接收到的type为text类别的消息', data) })
this.$notice.on('type:img', function(data){ console.log('订阅notice接收到的type为img类别的消息', data) })
……
this.$notice.on('user:userId', function(data){ console.log('订阅notice接收到来自userId的用户的消息', data) })
this.$notice.on('group:groupId', function(data){ console.log('订阅notice接收到来自groupId的群组的消息', data) }) // 开发中
0.0.48
5 years ago
0.0.47
5 years ago
0.0.46
5 years ago
0.0.45
5 years ago
0.0.44
6 years ago
0.0.42
6 years ago
0.0.43
6 years ago
0.0.41
6 years ago
0.0.40
6 years ago
0.0.39
6 years ago
0.0.38
6 years ago
0.0.37
6 years ago
0.0.36
6 years ago
0.0.35
6 years ago
0.0.34
6 years ago
0.0.33
6 years ago
0.0.32
6 years ago
0.0.31
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago