代码拉取完成,页面将自动刷新
<script>
import {push} from '@/js_sdk/chengzi-push/chengzi-push/push.js'
import {version} from './package.json'
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
export default {
userData:{},
readyPlus:false,
onLaunch: function() {
var that = this;
this.$myRequest({
url:"sys/getServerConfig",
common:function(res){
that.$socket.initServer();
}
}).then(function(res){
that.$socket.initServer(res.data);
})
//版本信息
//是否进入引导页
var launchFlag = uni.getStorageSync('launchFlag');
this.$myRequest({
url: 'user/check_version',
}).then((res)=>{
if(res.code===200){
uni.setStorageSync("check_version",res.data)
//引导页图片不为空并且安装完第一次打开
if(res.data.imgs&&!launchFlag){
uni.reLaunch({
url: '/pages/code-elf-guide/code-elf-guide'
});
}
}
},(res2)=>{
console.log(res2)
})
let platform = uni.getSystemInfoSync().platform
if(platform== 'ios'){
//拉起麦克风权限
this.$recorder.createreCorder();
this.$recorder.recorderManager.start({
duration:1000
});
this.$recorder.recorderManager.stop();
}
this.readyPlus = true;
plus.screen.lockOrientation("portrait-primary"); //锁定竖屏
//监听网络变化
this.userData = uni.getStorageSync('userData');
uni.onNetworkStatusChange(function (res) {
if(!res.isConnected){
uni.showModal({
title:"系统警告",
content:"请检查您的网络,当前您已断网"
})
that.$socket.close(true); //关闭socket,并且规定不允许主动重连
}else{
that.showContent("网络已连接,当前网络【" + res.networkType + "】");
that.$socket.createSocket(); //重启socket
}
});
/**
* 配置监听
* @param {Object} msg
*/
push.pushEvent = function(msg){
msg = msg.payload ? msg.payload : {};
console.log(msg)
if(msg.type === 'message'){
//公告消息
setTimeout(function(){
uni.navigateTo({
url:'/pages/user/message'
})
},500)
}else if(msg.type === 'immsg'){
//聊天消息
setTimeout(function(){
uni.navigateTo({
url:'/pages/index/index'
})
},500)
}else{
console.log("未明确操作,不做处理")
}
}
//引入消息推送
var intval = setInterval(function(){
if(that.userData.id === undefined){
that.userData = uni.getStorageSync('userData');
}
if(that.userData.id !== undefined){
clearInterval(intval); //初始化之后,关闭定时器
push.getClient(function(info){
that.$socket.send('bindToken',{
token:info.clientid,
user:that.userData.id,
type:2
}); //绑定token
});
push.init();
let platform = uni.getSystemInfoSync().platform
if (platform == 'ios') {
//ios默认会有通知 不需要手动设置
} else if (platform == 'android') {
/* 获取当前手机是否有通知权限 */
// #ifdef APP-PLUS
let main = plus.android.runtimeMainActivity();
let pkName = main.getPackageName();
let NotificationManagerCompat = plus.android.importClass("androidx.core.app.NotificationManagerCompat");
let packageNames = NotificationManagerCompat.from(main);
if (!packageNames.areNotificationsEnabled()) { //手机没有开启通知的权限
//设置通知权限,需要用户确认
uni.showModal({
title:"系统提示",
content:"第哥第在您切换APP时发送订单通知,因此需要设置通知权限",
success(res) {
if(res.confirm){
//用户点击确认
let uid = main.getApplicationInfo().plusGetAttribute("uid");
let Intent = plus.android.importClass('android.content.Intent');
let Build = plus.android.importClass("android.os.Build");
let intent = '';
//android 8.0引导
if (Build.VERSION.SDK_INT >= 26) {
intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
intent.putExtra('android.provider.extra.APP_PACKAGE', pkName);
} else if (Build.VERSION.SDK_INT >= 21) { //android 5.0-7.0
intent = new Intent('android.settings.APP_NOTIFICATION_SETTINGS');
intent.putExtra("app_package", pkName);
intent.putExtra("app_uid", uid);
} else { //(<21)其他--跳转到该应用管理的详情页
let Settings = plus.android.importClass("android.provider.Settings");
let Uri = plus.android.importClass("android.net.Uri");
intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
let uri = Uri.fromParts("package", main.getPackageName(), null);
intent.setData(uri);
}
// 跳转到该应用的系统通知设置页
main.startActivity(intent);
}
}
})
}else{
that.gaodedingwei(); //高德定位
}
// #endif
/* 获取当前手机是否有通知权限 */
}
}
},1000); //可能没有登录不存在用户信息,那么等到存在用户信息的时候再实例化推送以及上传推送token
// if(this.checkLogin()){
// //关闭启动界面
// // if (plus.runtime.appid !== 'HBuilder') { // 真机运行不需要检查更新,真机运行时appid固定为'HBuilder',这是调试基座的appid
// // checkUpdate()
// // }
// plus.navigator.closeSplashscreen();
// }else{
// let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
// if(routes[routes.length - 1] !== undefined){
// let curRoute = routes[routes.length - 1].route //获取当前页面路由
// let curParam = routes[routes.length - 1].options; //获取路由参数
// if(curRoute.indexOf('/pages/login/login')){
// return true;
// }
// }
// // uni.reLaunch({url:'/pages/login/login',success() {
// // plus.navigator.closeSplashscreen();
// // },fail(error) {
// // console.log('失败',error)
// // }})
// return false;
// }
},
onShow: function() {
uni.setStorageSync('appshow',true)
//检测socket连接是否正常
var i = 0;
var that = this;
var socketTnt = setInterval(function(){
try{
if(i >= 5){
if(!(that.$socket.socketTest && that.$socket.is_open_socket)){ //已断开连接
clearInterval(socketTnt)
that.$socket.initSocket(); //初始化
that.$socket.createSocket(); //开启一条新的连接
}
}else{
if((that.$socket.socketTest && that.$socket.is_open_socket)){ //已断开连接
clearInterval(socketTnt)
}
}
}catch(e){
//TODO handle the exception
console.log(e)
}
},5000)
//检测高德是否正常
if(this.readyPlus){
this.gaodedingwei(true); //高德定位
}
},
onHide: function() {
uni.setStorageSync('appshow',false)
console.log('app进入后台')
},
onUnload() {
uni.setStorageSync('appshow',false)
console.log("app进程被杀死")
}
}
</script>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
/* #ifndef APP-NVUE */
view{
margin: 0;
padding: 0;
box-sizing: border-box;
}
*{
box-sizing: border-box;
margin: 0 ;
padding: 0;
border: none;
}
ul,li{ padding:0;margin:0;list-style:none}
/* #endif */
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。