代码拉取完成,页面将自动刷新
<script>
import * as IMLib from "@/uni_modules/RongCloud-IMWrapper/js_sdk/index"
import {
init,
connect,
getTotalUnreadCount,
disconnect,
addConnectionStatusListener,
addLogInfoListener,
addRecallMessageListener,
addTypingStatusListener,
addReceiveMessageListener,
addReadReceiptReceivedListener,
addReceiptRequestListener,
addReceiptResponseListener,
setPushConfig
} from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
import config from '@/config/config.js'
export default {
data() {
return {
canReset:false,
imSetup:{
androidPushConfig: {
miAppId: '小米推送 appId',
miAppKey: '小米推送 appKey',
meizuAppId: '魅族推送 appId',
meizuAppKey: '魅族推送 appKey',
oppoAppKey: 'oppo推送 appKey',
oppoAppSecret: 'oppo推送 appSecret',
enableVIVOPush: true,//true 开启vivo 推送
enableHWPush: true, // true 开启华为推送
}
}
}
},
onShow() {
this.canReset && this.subscript()
this.canReset = true
},
onLaunch: function() {
this.subscript()
},
onShow: function() {
console.log('App Show');
},
onHide: function() {
console.log('App Hide');
},
methods: {
setPushConfigFn:function(){
const config = {
FCM: true,
HW: true,
VIVO: true,
MI: {
MI_PUSH_APPID: 'appId',
MI_PUSH_APPKEY: 'appKey',
},
MEIZU: {
MEIZU_PUSH_APPID: 'appId',
MEIZU_PUSH_APPKEY: 'appKey',
},
OPPO: {
OPPO_PUSH_APPID: 'appId',
OPPO_PUSH_APPKEY: 'appKey'
}
}
setPushConfig(config,(result) => { // 获取会话列表成功
if (result.code === 0 ) {
}
});
},
monitor:function(){ //监控
console.log("monitor - 监控")
var that = this;
addConnectionStatusListener((listener)=>{ // 监听链接状态
console.log("监听链接状态:"+listener)
})
addLogInfoListener((listener)=>{ // 添加日志信息监听函数
console.log("添加日志信息监听函数:"+listener)
})
addRecallMessageListener((listener)=>{ // 添加消息撤回监听函数
console.log("添加消息撤回监听函数:"+listener)
})
addTypingStatusListener((listener)=>{ // 添加输入状态监听函数
console.log("添加输入状态监听函数:"+listener)
})
addReceiveMessageListener((listener)=>{ // 添加消息监听函数 (接收消息)
console.log("添加消息监听函数:"+listener)
that.getTotalUnreadCountFn();
})
addReadReceiptReceivedListener((listener)=>{ // 添加私聊阅读回执监听函数
console.log("添加私聊阅读回执监听函数:"+listener)
})
addReceiptRequestListener((listener)=>{ // 添加收到消息已读回执请求监听函数
console.log("添加收到消息已读回执请求监听函数:"+listener)
})
addReceiptResponseListener((listener)=>{ // 添加消息回执响应监听函数
console.log("添加消息回执响应监听函数:"+listener)
})
},
getTotalUnreadCountFn(){
getTotalUnreadCount(({code, count}) => {
// 获取未读数成功
if(code === 0){
if(count>0){
uni.setTabBarBadge({
index: 1,
text: JSON.stringify(count)
});
console.log('APP onLaunch');
}else{
uni.removeTabBarBadge({
index:1,
})
plus.runtime.setBadgeNumber(-1);
}
}
});
},
subscript(){
let token= uni.getStorageSync('token');
let base_login_name = uni.getStorageSync('base_login_name');
if (token && base_login_name) {
//存在则关闭启动页进入首页
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen();
console.log('App Launch');
init(config.appkey);
connect(config.token, (result) => {
if (result.code === 0) {
var that = this;
IMLib.initWithSetup(config.appkey, this.imSetup);
const RCUniPush = uni.requireNativePlugin('RongCloud-Push-RCUniPush')
console.log(RCUniPush.setPushEventListener)
RCUniPush.setPushEventListener((data) => {
console.log('setPushEventListener', data);
});
this.monitor()
this.getTotalUnreadCountFn();
this.setPushConfigFn()
}else {
console.log('连接失败',result.code)
}
})
// #endif
} else {
//不存在则跳转至登录页
uni.reLaunch({
url: "/pages/login/login",
success: () => {
// #ifdef APP-PLUS
plus.navigator.closeSplashscreen();
// #endif
}
})
}
},
}
};
</script>
<style lang="scss">
/*每个页面公共css */
@import "@/static/font/iconfont.css";
button[type="primary"]{
background-color: #63c6ce;
&.button-hover,&.button-hover[type="primary"]{
background-color: #4bb5be;
}
}
button[loading][type=primary]{
background-color: #4bb5be;
}
.uni-picker-action-confirm,.uni-modal .uni-modal__btn_primary{
color: #63c6ce !important;
}
body{
color:#333333;
}
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。