319 lines
9.9 KiB
JavaScript
319 lines
9.9 KiB
JavaScript
import apiArr from './api/water_filter';
|
||
import util from './utils/util';
|
||
import apiAddr from '/api/base';
|
||
App({
|
||
|
||
globalData: {
|
||
isIpx: false,
|
||
userInfo: null,
|
||
id: '',
|
||
navHeight: 0,
|
||
navTop: 0,
|
||
windowHeight: 0,
|
||
isShow: false,
|
||
isShare: false, // 用于判断是否来源于分享
|
||
nav_list:[],
|
||
foot_width:'20%',
|
||
|
||
},
|
||
|
||
|
||
getFootNav() {
|
||
console.log(789789);
|
||
let that = this;
|
||
// util.postUrl(apiArr.footer,{},res=>{
|
||
// that.globalData.nav_list = res;
|
||
// that.globalData.foot_width = (100 / res.length).toFixed(2) + '%';
|
||
// })
|
||
wx.request({
|
||
url: apiArr.footer,
|
||
data: {},
|
||
method: 'POST',
|
||
header: {
|
||
'content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
success: f => {
|
||
console.log('successddd');
|
||
if (f.data.code == "-101" || f.data.code == "-102") {
|
||
successfn(f.data);
|
||
} else if (f.data.code == "-103") {
|
||
successfn(f.data);
|
||
} else {
|
||
successfn(f.data);
|
||
}
|
||
},
|
||
error: f => {
|
||
console.log('error');
|
||
wx.showToast({
|
||
title: '系统繁忙',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
})
|
||
},
|
||
onLaunch(options) {
|
||
let that = this;
|
||
that.getFootNav()
|
||
if (options.scene) {
|
||
const scene = decodeURIComponent(options.scene); // 解码 scene
|
||
console.log('scene:', scene);
|
||
}
|
||
|
||
if (options.query.scene) {
|
||
let scene = decodeURIComponent(options.query.scene);
|
||
that.d.scene = scene;
|
||
}
|
||
this.globalData.sysinfo = wx.getSystemInfoSync()
|
||
//获取系统信息
|
||
wx.getSystemInfo({
|
||
success: res => {
|
||
that.system = res
|
||
}
|
||
})
|
||
//获取胶囊信息
|
||
that.menu = wx.getMenuButtonBoundingClientRect();
|
||
// console.log(that.menu)
|
||
// 判断是否为 iPhone X
|
||
wx.getSystemInfo({
|
||
success: function (res) {
|
||
// X 及以上的异形屏top为44,非异形屏为20
|
||
if (res.safeArea.top > 20) {
|
||
that.globalData.isIpx = true
|
||
}
|
||
}
|
||
})
|
||
|
||
let menuButtonObject = wx.getMenuButtonBoundingClientRect();
|
||
wx.getSystemInfo({
|
||
success: res => {
|
||
let statusBarHeight = res.statusBarHeight,
|
||
navTop = menuButtonObject.top, //胶囊按钮与顶部的距离
|
||
navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; //导航高度
|
||
this.globalData.navHeight = navHeight;
|
||
this.globalData.navTop = navTop;
|
||
this.globalData.windowHeight = res.windowHeight;
|
||
},
|
||
fail(err) {
|
||
console.log(err);
|
||
}
|
||
})
|
||
|
||
this.autoUpdate()
|
||
},
|
||
onShow(options) {
|
||
const updateManager = wx.getUpdateManager();
|
||
updateManager.onCheckForUpdate(function (res) {
|
||
if (res.hasUpdate) {
|
||
// updateManager.onUpdateReady(function () {
|
||
// wx.showModal({
|
||
// title: '温馨提示',
|
||
// content: '系统检测到有新版本并已准备好更新,是否重启应用?',
|
||
// success: () => {
|
||
// if (res.confirm) updateManager.applyUpdate();
|
||
// }
|
||
// })
|
||
// })
|
||
// updateManager.onUpdateFailed(function () {
|
||
// wx.showModal({
|
||
// title: '温馨提示',
|
||
// content: '系统检测到有新版本,请删除当前小程序,重新搜索打开'
|
||
// })
|
||
// })
|
||
}
|
||
});
|
||
if (options.scene == 1007) {
|
||
// 通过单人聊天会话分享进入
|
||
this.globalData.isShare = true;
|
||
}
|
||
if (options.scene == 1008) {
|
||
// 通过群聊会话分享进入
|
||
this.globalData.isShare = true;
|
||
}
|
||
},
|
||
/** 5d444af49568c61c47aa7b84dfe7c575
|
||
* @description 获取本地用户数据
|
||
* @method getLocalUserInfo
|
||
* @returns {Object} // 返回用户数据
|
||
*/
|
||
getLocalUserInfo(){
|
||
let userInfo = wx.getStorageSync('userInfo');
|
||
return !userInfo ? {} : JSON.parse(userInfo);
|
||
},
|
||
getSessionKey() {
|
||
let userSessionKey = wx.getStorageSync('session_key');
|
||
return userSessionKey || '';
|
||
},
|
||
/**
|
||
* @description 验证用户是否点击授权
|
||
* @method hasUserAuth
|
||
* @param {String} errMsg // 提示信息
|
||
* @returns {Boolean} // 返回 Boolean
|
||
*/
|
||
hasUserAuth(errMsg){
|
||
let [ msg_1, msg_2 ] = errMsg.split(':');
|
||
return msg_2 === 'ok';
|
||
},
|
||
initCustomNavbar(){
|
||
let { top, height, left } = wx.getMenuButtonBoundingClientRect();
|
||
let { statusBarHeight, screenWidth } = wx.getSystemInfoSync();
|
||
let navBarHeight = (top - statusBarHeight) * 2 + height + statusBarHeight;
|
||
let navBarDetail = {
|
||
top: statusBarHeight,
|
||
right: screenWidth - left,
|
||
height: navBarHeight,
|
||
};
|
||
return navBarDetail;
|
||
},
|
||
changeHeaderColor(){
|
||
wx.request({
|
||
url: apiAddr.get_site_color,
|
||
method: 'post',
|
||
header: {
|
||
'Content-type': 'application/x-www-form-urlencoded'
|
||
},
|
||
dataType:'json',
|
||
success: (result) => {
|
||
var color = result.data.mobile_color ? result.data.mobile_color : '#ffffff';
|
||
var font_color = result.data.font_color ? result.data.font_color : '#000000';
|
||
wx.setStorageSync('mobile_color',color);
|
||
wx.setNavigationBarColor({
|
||
frontColor: font_color,
|
||
backgroundColor: color,
|
||
animation: {
|
||
duration: 0,
|
||
timingFunc: 'linear'
|
||
}
|
||
})
|
||
},
|
||
})
|
||
},
|
||
goH5Link(event){
|
||
let url=event.currentTarget.dataset.url;
|
||
console.log(url);
|
||
wx.navigateTo({
|
||
url: `/pages/index/index?q=${url}`,
|
||
})
|
||
},
|
||
goPagesLink(event){
|
||
let url= event.currentTarget.dataset.url;
|
||
let tab1 = 'pages/index/community';
|
||
let tab2 = 'pages/booking/orderlist';
|
||
let tab3 = '/user/index';
|
||
if(url.indexOf(tab1) !== -1 || url.indexOf(tab2) !== -1 || url.indexOf(tab3) !== -1){
|
||
wx.redirectTo({
|
||
url: url,
|
||
});
|
||
}else{
|
||
wx.navigateTo({
|
||
url: url,
|
||
})
|
||
}
|
||
},
|
||
goMiniprogram(event){
|
||
wx.navigateToMiniProgram({
|
||
appId: event.currentTarget.dataset.appid
|
||
})
|
||
},
|
||
makeCall(event){
|
||
wx.makePhoneCall({
|
||
phoneNumber: event.currentTarget.dataset.tel
|
||
})
|
||
},
|
||
return:function(){
|
||
//返回到上一个页面
|
||
console.log('返回');
|
||
wx.navigateBack()
|
||
/*
|
||
var pages = getCurrentPages();//获取页面数据
|
||
var prevPage = pages[pages.length - 2]; //上一个页面
|
||
prevPage.onLoad();//对上一个页面进行刷新(执行上一个页面的onLoad方法)
|
||
prevPage.setData({ //调用上一个页面的setData方法
|
||
iconStatu: false //给A页面设置一个变量iconStatu,值为false
|
||
});
|
||
*/
|
||
|
||
},
|
||
globalData: {
|
||
appid: 'wx1addb25675dd8e70'
|
||
},
|
||
pluginHxj(){
|
||
// var createPlugin = requirePlugin("hxjlock");
|
||
// var Plugin = createPlugin()
|
||
return null;
|
||
},
|
||
pluginTts(){
|
||
return requirePlugin("ttslock");
|
||
},
|
||
initQQMapKey(){
|
||
return '';
|
||
},
|
||
autoUpdate:function(){
|
||
|
||
var self=this
|
||
let startParamObj = wx.getLaunchOptionsSync();
|
||
// 获取小程序更新机制兼容
|
||
if (wx.canIUse('getUpdateManager')&& startParamObj.scene!=1154) {
|
||
const updateManager = wx.getUpdateManager()
|
||
//1. 检查小程序是否有新版本发布
|
||
updateManager.onCheckForUpdate(function (res) {
|
||
// 请求完新版本信息的回调
|
||
if (res.hasUpdate) {
|
||
//2. 小程序有新版本,则静默下载新版本,做好更新准备
|
||
updateManager.onUpdateReady(function () {
|
||
console.log(new Date())
|
||
wx.showModal({
|
||
title: '更新提示',
|
||
content: '新版本已经准备好,是否重启应用?',
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
//3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||
updateManager.applyUpdate()
|
||
} else if (res.cancel) {
|
||
//如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
|
||
wx.showModal({
|
||
title: '温馨提示~',
|
||
content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~',
|
||
success: function (res) {
|
||
self.autoUpdate()
|
||
return;
|
||
//第二次提示后,强制更新
|
||
if (res.confirm) {
|
||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||
updateManager.applyUpdate()
|
||
} else if (res.cancel) {
|
||
//重新回到版本更新提示
|
||
self.autoUpdate()
|
||
}
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
})
|
||
updateManager.onUpdateFailed(function () {
|
||
// 新的版本下载失败
|
||
wx.showModal({
|
||
title: '已经有新版本了哟~',
|
||
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
|
||
})
|
||
})
|
||
}
|
||
})
|
||
|
||
} else {
|
||
if(startParamObj.scene==1154){
|
||
|
||
}else{
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
||
})
|
||
}
|
||
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
|
||
/* wx.showModal({
|
||
title: '提示',
|
||
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
||
})*/
|
||
}
|
||
}
|
||
}) |