<script>
|
import {
|
mapState,
|
mapMutations
|
} from 'vuex';
|
import utils from './utils/utils.js'
|
// #ifdef APP-PLUS
|
import idfa from './utils/idfa.js'
|
import APPUpdate from "@/utils/appUpdate.js";
|
import getClipboard from '@/utils/getClipboard.js'
|
// #endif
|
export default {
|
onLaunch: function() {
|
|
// #ifdef APP-PLUS
|
//推送开始
|
/* var info = plus.push.getClientInfo()
|
console.log(info);
|
// 获取当前设备的客户端id,传给后台,实现指定用户
|
info && uni.setStorageSync('clientInfo', info) */
|
this.getPushCid();
|
// 使用5+App的方式进行监听消息推送
|
//消息点击事件
|
//【APP在线】,收到透传消息通过,不会提醒至通知栏目,需要发送本地消息,再进行点击触发的点击事件。
|
//【APP离线】,收到离线透传消息,必须通过Java后台的Intent字符串携带payload,且符合格式才能触发click事件,格式不符合不会触发。
|
plus.push.addEventListener("click", function(msg) {
|
console.log('click', JSON.stringify(msg))
|
// IOS
|
if (uni.getSystemInfoSync().platform == 'ios') {
|
var payload;
|
if (msg.type == "click") { //APP离线点击包含click属性,这时payload是JSON对象
|
payload = msg.payload;
|
} else { //APP在线,收到消息不会包含type属性,这时的payload是JSON字符串,需要转为JSON对象
|
payload = JSON.parse(msg.payload);
|
}
|
console.log(payload);
|
if (payload != null || payload != undefined) {
|
// var messageType = payload.messageType;
|
// onLaunch 生命周期里,页面跳转有问题,跳不过去
|
// 应该是页面还没加载,加上定时后,就可以了;
|
setTimeout(() => {
|
uni.navigateTo({
|
url: payload
|
})
|
}, 1000)
|
}
|
} else { // Android
|
var payload = msg.payload;
|
if (payload != null || payload != undefined) {
|
// onLaunch 生命周期里,页面跳转有问题,跳不过去
|
// 应该是页面还没加载,加上定时后,就可以了;
|
setTimeout(() => {
|
uni.navigateTo({
|
url: payload
|
})
|
}, 1000)
|
}
|
}
|
}, false);
|
//收到透传消息
|
//只有APP在线时,才会触发receive事件,透传消息不会触发系统消息,需要创建本地消息
|
plus.push.addEventListener("receive", function(msg) {
|
console.log('receive', JSON.stringify(msg))
|
//业务代码
|
// IOS
|
if (uni.getSystemInfoSync().platform == 'ios') {
|
//【APP离线】收到消息,但没有提醒(发生在一次收到多个离线消息时,只有一个有提醒,但其他的没有提醒)
|
//【APP在线】收到消息,不会触发系统消息,需要创建本地消息,但不能重复创建。必须加msg.type验证去除死循环
|
if (msg.type == "receive") {
|
//创建本地消息,发送的本地消息也会被receive方法接收到,但没有type属性,且aps是null
|
plus.push.createMessage(msg.content, JSON.stringify(msg), {
|
title: messageTitle,
|
//icon:'/static/images/app/pushlogo.png'
|
});
|
}
|
} else { // Android
|
var payload = JSON.parse(msg.content);
|
var messageTitle = payload.title;
|
var messageContent = payload.content;
|
plus.push.createMessage(messageContent, payload, {
|
title: messageTitle
|
})
|
}
|
}, false);
|
//消息推送结束
|
plus.push.addEventListener('click', res => {
|
console.log(res);
|
});
|
APPUpdate();
|
// #endif
|
this.getAppInfo();
|
//this.that.bcInit();
|
let userInfo = uni.getStorageSync('userInfo')
|
if (userInfo.id) {
|
this.login(userInfo)
|
}
|
uni.getSystemInfo({
|
success: e => {
|
// #ifdef APP-PLUS
|
console.log(e)
|
if (e.platform == 'android') {
|
this.globalData.platform = 'android'
|
this.globalData.systemLevel = e.system
|
if (e.system < 10) {
|
plus.device.getInfo({
|
success: e => {
|
console.log(e);
|
//这里获取到imei 剩下的逻辑也写在这里面
|
var a = e.imei.indexOf(",")
|
if (a < 0) {
|
this.globalData.equipmentNumber = e.imei
|
} else {
|
this.globalData.equipmentNumber = e.imei.substring(0,
|
a);
|
}
|
//里面写接下来的逻辑
|
console.log('imei=' + imei); //这里是能获取imei的
|
}
|
})
|
} else {
|
plus.device.getOAID({
|
success: e => {
|
console.log('getOAID success: ' + e.oaid);
|
this.globalData.equipmentNumber = e.oaid;
|
}
|
});
|
}
|
} else {
|
this.globalData.platform = 'ios';
|
this.globalData.systemLevel = e.system;
|
this.globalData.equipmentNumber = idfa.value()
|
};
|
this.getArgument(true);
|
// #endif
|
}
|
})
|
|
|
},
|
globalData: {
|
platform: '',
|
systemLevel: '',
|
equipmentNumber: '',
|
userInfo: {},
|
canlisten: true,
|
appinfo: {},
|
ifwt: 0,
|
hasinit: false,
|
hasbcinit: false,
|
isLaunch: false,
|
argumentStr: ''
|
|
},
|
data(){
|
return {
|
|
}
|
},
|
onShow: function() {
|
var that = this;
|
uni.getNetworkType({
|
success: function(res) {
|
if (res.networkType == 'none') {
|
uni.showModal({
|
title: '网络链接失败',
|
content: '检测到网络权限可能设置为关闭,您可以在“设置”中检查无线数据及蜂窝移动网络'
|
})
|
} else {
|
if (!that.globalData.hasinit) {
|
that.getAppInfo();
|
}
|
if (!that.globalData.hasbcinit) {
|
console.log("初始化百川插件")
|
that.bcInit();
|
}
|
/* let appInfo = utils.getCacheSync('appInfo')
|
if(appInfo == "" || appInfo == undefined){
|
console.log("获取方法")
|
that.getAppInfo();
|
} */
|
}
|
}
|
})
|
var routes = getCurrentPages();
|
if (routes.length > 0) {
|
var route = routes[routes.length - 1].route
|
}
|
// #ifdef APP-PLUS
|
if (this.globalData.canlisten && route != 'pages/mine/tools/turnChain' && route !=
|
'pages/rankinglist/compareprice') {
|
getClipboard()
|
}
|
that.getArgument();
|
// #endif
|
},
|
onHide: function() {},
|
methods: {
|
...mapMutations(['login']),
|
bcInit: function() {
|
var that = this;
|
if (uni.getSystemInfoSync().platform == 'ios') {
|
const plug = uni.requireNativePlugin('xiguazhu-baichuan');
|
plug.init({}, result => {
|
//console.log('1111111111111111111');
|
console.log(result); // code等于0就是初始化成功
|
if (result.code == 0) {
|
that.globalData.hasbcinit = true;
|
}
|
});
|
} else {
|
that.globalData.hasbcinit = true;
|
}
|
},
|
targetArgument(args){
|
var toarg = args.replace('dafanguan://', '');
|
var argObj = JSON.parse(decodeURIComponent(toarg));
|
switch (argObj.totype) {
|
case "0": //内链
|
if(argObj.url)
|
{
|
uni.navigateTo({
|
url: argObj.url
|
});
|
}
|
break;
|
default:
|
break;
|
}
|
},
|
getArgument(isload=false) {
|
if(this.globalData.argumentStr&&this.globalData.argumentStr.length>0)
|
{
|
return;
|
}
|
try {
|
var args = plus.runtime.arguments;
|
console.log(args);
|
if (args) {
|
if(isload)
|
{
|
this.globalData.argumentStr = args;
|
return;
|
}
|
plus.runtime.arguments = "";
|
plus.runtime.arguments = null;
|
this.targetArgument(args);
|
}
|
} catch (es) {
|
console.log(es)
|
}
|
|
},
|
getPushCid: function() {
|
// #ifdef APP-PLUS
|
var info = plus.push.getClientInfo()
|
if (info && info.clientid != 'null') { // 获取当前设备的客户端id,传给后台,实现指定用户
|
uni.setStorageSync('clientInfo', info);
|
this.updatePushCid();
|
} else {
|
console.log('没有获取到');
|
setTimeout(() => {
|
this.getPushCid();
|
}, 1000)
|
}
|
// #endif
|
},
|
updatePushCid: function() {
|
let clientInfo = uni.getStorageSync('clientInfo');
|
if (clientInfo && clientInfo != 'null' && clientInfo.clientid) {
|
console.log('开始更新:'+clientInfo.clientid);
|
this.$u.api.updateCid({
|
pushcid: clientInfo.clientid
|
}).then(e => {}).catch(function(err) {})
|
} else {
|
this.getPushCid();
|
}
|
|
},
|
getAppInfo: function() {
|
var that = this;
|
that.globalData.hasinit = true;
|
this.$u.api.comminInt({}).then(e => {
|
if (e.code != 0) {
|
that.globalData.hasinit = false;
|
return that.$alert(e.msg)
|
}
|
that.globalData.appinfo = e.data.basic
|
utils.setCache('appInfo', e.data.basic)
|
utils.setCache('baseUrl', this.$u.http.config.baseUrl)
|
// #ifdef APP-PLUS
|
if (plus.os.name == 'iOS') {
|
if (that.globalData.appinfo.iosExamine && plus.runtime.version == e.data.basic
|
.IosExamineV) {
|
that.globalData.ifwt = 0
|
} else {
|
if (plus.runtime.isApplicationExist({
|
action: 'weixin://'
|
}) && plus.runtime.isApplicationExist({
|
action: 'taobao://'
|
})) {
|
that.globalData.ifwt = 1 //是否安装微信和淘宝 1代表安装
|
} else {
|
that.globalData.ifwt = 0
|
}
|
}
|
} else {
|
if (plus.runtime.isApplicationExist({
|
pname: 'com.tencent.mm',
|
action: 'weixin://'
|
})) {
|
that.globalData.ifwt = 1 //是否安装微信 1代表安装
|
} else {
|
console.log("安卓端未安装微信")
|
that.globalData.ifwt = 0
|
}
|
}
|
|
// #endif
|
}).catch(function(err) {
|
that.globalData.hasinit = false;
|
})
|
|
},
|
|
watch: function(method, istr) {
|
var obj = this.globalData
|
console.log(obj)
|
Object.defineProperty(obj, istr, {
|
configurable: true,
|
enumerable: true,
|
set: function(value) {
|
this._consumerGoodsStatus = value
|
method(value)
|
},
|
get: function(value) {
|
return this._consumerGoodsStatus
|
}
|
})
|
},
|
},
|
}
|
</script>
|
|
<style>
|
/*每个页面公共css */
|
/* #ifndef APP-NVUE */
|
@import url('./static/css/main.css');
|
@import url('./colorui/main.css');
|
@import url('./colorui/icon.css');
|
@import url('./uview-ui/iconfont.css');
|
|
page {
|
color: #333333;
|
font-size: 30rpx;
|
font-family: PingFangSC-Regular, PingFang SC;
|
font-weight: 500;
|
background-color: #F0F1F7;
|
}
|
|
/* #endif */
|
</style>
|