1 Star 0 Fork 0

陈伟龙/ios

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.vue 5.06 KB
一键复制 编辑 原始数据 按行查看 历史
chenweilong20 提交于 2022-08-17 15:58 . 1.0.0
<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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/chenweilong20/ios.git
git@gitee.com:chenweilong20/ios.git
chenweilong20
ios
ios
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385