Files
HnyhuaXCX/app.js

206 lines
6.4 KiB
JavaScript

//app.js
var that=null
App({
onLaunch: function () {
console.log('App Launch')
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
that=this
},
getUserInfo:function(){
var userId = wx.getStorageSync("userId")
var LoginId = wx.getStorageSync("LoginId")
if(!userId||!LoginId){
//调用登录接口
that.onLogin()
}else{
var viewid = wx.getStorageSync('viewid')
var viewpoid = wx.getStorageSync('viewpoid')
if(viewid){
wx.removeStorageSync('viewid')
wx.removeStorageSync('viewpoid')
wx.navigateTo({
url: "../details/index?id=" + viewid + (viewpoid?"&poid=" +viewpoid:"")
})
}
var videoid = wx.getStorageSync('videoid0')
if(videoid){
if(videoid!=""){
wx.switchTab({
url: "../myvideo/index"
})
}
}
}
},
onLogin: function () {
wx.login({
success: function (res) {
if (res.code) {
//发起网络请求
var tguid = wx.getStorageSync('tguid');
wx.request({
url: that.globalData.apiurl+'/xapiajax.ashx',
method:"Get",
dataType:"json",
data: {
action:"onLogin",
tguid:(!tguid?"":tguid),
code: res.code
},
success: function(res0) {
if(res0.data.status==1){
wx.setStorageSync('userId', res0.data.userId)
wx.setStorageSync('LoginId', res0.data.LoginId)
wx.removeStorageSync('openid')
wx.removeStorageSync('IFLogin') //是微信登录0还是账号登录1
wx.removeStorageSync('IFYYD')
that.globalData.IFRefreshmy=1
that.globalData.IFRefreshindex=1
that.globalData.IFRefreshshop=1
wx.setStorageSync('userInfo', JSON.stringify(res0.data.userInfo))
if(res0.data.userInfo.uLevel2==2){
wx.setStorageSync('IFagent', 1);
}else{
wx.setStorageSync('IFagent', 0);
}
if(that.globalData.IFwxLogin==1){
that.globalData.IFwxLogin=0
wx.showToast({
title: res0.data.msg,
icon: "none",
duration: 2000
})
var sopenFrame=setInterval(function (){
clearInterval(sopenFrame);
wx.navigateBack({})
}, 1000)
}else{
var viewid = wx.getStorageSync('viewid')
var viewpoid = wx.getStorageSync('viewpoid')
if(viewid){
wx.removeStorageSync('viewid')
wx.removeStorageSync('viewpoid')
wx.navigateTo({
url: "../details/index?id=" + viewid + (viewpoid?"&poid=" +viewpoid:"")
})
}
var videoid = wx.getStorageSync('videoid0')
if(videoid){
if(videoid!=""){
wx.navigateTo({
url: "../myvideo/index"
})
}
}
}
}else{
wx.showToast({
title: res0.data.msg,
icon: "none",
duration: 3000
})
}
}
})
} else {
wx.showToast({
title: '登录失败!' + res.errMsg,
icon: "none",
duration: 3000
})
}
}
})
},
onShow: function () {
console.log('App Show')
},
onHide: function () {
console.log('App Hide')
},isNumber:function (s) {//判断是否是数字
var regu = "^[0-9]+$";
var re = new RegExp(regu);
if (re.test(s)) {
return true;
} else {
return false;
}
},isamount:function(s) {
var fix_amountTest=/^(([1-9]\d*)|\d)(\.\d{1,2})?$/;
if(fix_amountTest.test(s)==false){
return false;
}else{
return true;
}
},isNumberOr_Letter:function(s) {//判断是否是数字或字母
var regu = "^[0-9a-zA-Z]+$";
var re = new RegExp(regu);
if (re.test(s)) {
return true;
} else {
b = false;
}
},changeTwoDecimal_f:function(x) {
var f_x = parseFloat(x);
var f_x = Math.round(x * 100) / 100;
var s_x = f_x.toString();
var pos_decimal = s_x.indexOf('.');
if (pos_decimal < 0) {
pos_decimal = s_x.length;
s_x += '.';
}
while (s_x.length <= pos_decimal + 2) {
s_x += '0';
}
return s_x;
},ccityname: function(value){
if(value){
value=value.replace("市","").replace("自治州","").replace("同治州","").replace("地区","");
}
return value
},replacebody: function(value){
if(value){
value=value.replace("<br>","");
}
return value
},
globalData:{
userInfo:null,
apiurl:"https://g.hnyhua.cn", //https://g.hnyhua.cn
IFRefreshCart:0,
IFRefreshsell:0,
IFRefreshsell0:0,
IFRefreshsell1:0,
IFRefreshmy:0,
IFRefreshindex:0,
IFRefreshshop:0,
IFRefreshordershop0:0,
IFRefreshmypt:0,
IFRefreshmydhm:0,
IFRefreshshangquan:0,
IFRefreshmyaddress:0,
IFRefreshmyagent_products:0,
IFRefreshmyhongbao:0,
IFRefreshmyorder:0,
IFRefreshduihuan:0,
IFRefreshmybalance:0,
IFRefreshzzjf:0,
selladdress:{},
selladdress0:{},
IFYGM:0,
IFwxLogin:0,//是否点击微信一键登录1还是扫码自动登录0
servermsg:""
}
})