253 lines
8.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//app.js wx9c68fbf7886ea9c4 租房的 wxcf0a799771cf2ae6 港校的
var initial_url = 'https://app.gter.net/tenement';
var __ = require('./utils/miucms.js');
import './utils/xstat';
// // 保存原始的Page构造器
// const originPage = Page;
// // 重写Page构造器
// Page = function (pageConfig) {
// // 添加全局的onShow逻辑
// const originOnLoad = pageConfig.onLoad;
// pageConfig.onLoad = function () {
// __.statistics({})
// if (originOnLoad) originOnLoad.apply(this, arguments);
// };
// const originOnShare = pageConfig.onShareAppMessage;
// if (originOnShare) {
// // pageConfig.onShareAppMessage = function () {
// pageConfig.onShareAppMessage = function (e) {
// __.statistics({
// name: "share"
// })
// // if (originOnShare) originOnShare.apply(this, arguments);
// return originOnShare.apply(this, [e]);
// };
// }
// // 调用原始的Page函数
// return originPage(pageConfig);
// };
App({
xstatConfig: {
appKey: wx.getAccountInfoSync().miniProgram.appId, // 自动获取 小程序appid
debug: true, //是否打开调试模式
LOG_URL: 'https://stat.gter.net/send', // 上报地址
},
randomString(n) {
let str = 'abcdefghijklmnopqrstuvwxyz9876543210';
let tmp = '',
i = 0,
l = str.length;
for (i = 0; i < n; i++) {
tmp += str.charAt(Math.floor(Math.random() * l));
}
return tmp;
},
autoUpdate: function () {
var self = this
// 获取小程序更新机制兼容
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
wx.showModal({
title: '更新提示',
content: '检测到新版本,是否下载新版本并重启小程序?',
success: function (res) {
if (res.confirm) self.downLoadAndUpdate(updateManager)
else if (res.cancel) {
wx.showModal({
title: '温馨提示',
content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问',
showCancel: false,
confirmText: "确定更新",
success: function (res) {
//下载新版本,并重新应用
if (res.confirm) self.downLoadAndUpdate(updateManager)
}
})
}
}
})
}
})
} else {
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
})
}
},
downLoadAndUpdate: function (updateManager) {
var self = this
wx.showLoading();
updateManager.onUpdateReady(function () {
wx.hideLoading()
updateManager.applyUpdate()
})
updateManager.onUpdateFailed(function () {
wx.hideLoading()
// 新的版本下载失败
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
})
})
},
onLaunch: function (options) {
// __.statistics({
// data: {
// scene: options.scene
// },
// path: options.path,
// query: options.query,
// name: "onLaunch"
// })
this.globalData.options = options;
__.initial(this)
if (wx.getEnterOptionsSync().query && wx.getEnterOptionsSync().query.scancode_time) {
this.globalData.scancode_time = wx.getEnterOptionsSync().query.scancode_time
}
if (wx.getUserProfile) {
this.globalData.canIUseGetUserProfile = true;
}
try {
this.computeNavigateBarHeight();
} catch (e) {
// 获取系统信息失败
this.setData({
windowHeight: 812,
totalTopHeight: 68,
statusBarHeight: 20,
titleBarHeight: 48,
titleWidth: 87
});
}
this.autoUpdate()
let getAccountInfoSync = wx.getAccountInfoSync();
if (getAccountInfoSync.miniProgram.appId == "wx9c68fbf7886ea9c4") {
this.globalData.topTitle = "寄托香港租房"
this.globalData.miniProgram = "xg"
} else {
this.globalData.topTitle = "寄托港校租房"
this.globalData.miniProgram = "gx"
}
},
computeNavigateBarHeight: function () {
var systemInfo = wx.getSystemInfoSync();
var data = wx.getMenuButtonBoundingClientRect()
let totalTopHeight = data.bottom;
let windowHeight = systemInfo.windowHeight,
windowWidth = systemInfo.windowWidth,
statusBarHeight = data.top;
this.globalData.screen_data = {
windowHeight: windowHeight,
windowWidth: windowWidth,
totalTopHeight: totalTopHeight + 6,
statusBarHeight: statusBarHeight,
titleBarHeight: data.height,
titleWidth: data.widthinitial,
bottomLift: systemInfo.screenHeight - systemInfo.safeArea.bottom
}
},
onShow: function (options) {
this.globalData.source = options.path || '';
// 判断socket从后台打开 并且已经断开链接了,需要重启
// if (this.globalData.isHideState && this.globalData.socketTask && this.globalData.socketTask['readyState'] != 1) {
// }
// this.globalData.isHideState = false
const timer = setInterval(() => {
if (this.globalData.config && this.globalData.config.lists) {
__.useSocket()
clearInterval(timer)
}
}, 100)
},
onHide: function () {
this.globalData.isHideState = true
},
onError: function () {
// 这里回调错误信息
},
// get: function () {
// return this.globalData.config;
// },
return_data: function (res) {
var json = res.data;
var data = typeof res.data == 'string' ? JSON.parse(res.data) : res.data;
return data;
},
globalData: {
baseURL: "https://app.gter.net",
token: null,
title: null,
session: null,
code: null,
user: {},
userInfo: {},
options: {},
config: {},
notice: {},
source: '',
header: {
'content-type': 'application/json',
'Accept': 'application/json, text/plain',
'Cookie': 'miucms_session=' + wx.getStorageSync('Authorization'),
'Authorization': wx.getStorageSync('Authorization') || ''
},
new_reply: false,
// 寄托租房独有字段
choose: {},
kw: '',
status: 0,
screen_data: {},
StudentapartmentNew: null,
isUserAuthorization: 0, //用户点击授权:0未知1未授权2已授权
listTab: {},
canIUseGetUserProfile: false,
scancode_time: "",
irentCouponBig: false,
unreadMessagesState: false,
firstWxParseImgLoaddState: false,
topTitle: "", // 寄托港校租房 寄托香港租房
miniProgram: "", // 处于那个小程序 xg gx
bgColorObj: { // 列表 角的颜色
1: "#50e3c2",
6: "#b3c7f4"
},
isMapFindState: false, // 地图找房入口
isShowVideo: true, // 是否显示视频
socketTask: null, // 全局的 socket 值
isHideState: true, // 判断是否 隐藏了 在 onshow 为 true 是代表小程序后台打开
brandSelectionObj: {}, // 品牌公寓筛选全局值
personSelectionObj: {}, // 个人房源筛选全局值
intermediarySelectionObj: {}, // 中介房源筛选全局值
restSelectionObj: {}, // 求房源筛选全局值
editShelfState: "", // 判断 我的页面 在点击 编辑上架 后重新进入是否需要 刷新数据的 update 代表需要更新数据
popwindow: "", // 首页弹窗信息
isConnected: false,
offerkaipingadvertisement: {}, // 开屏广告 数据
offerkaipingadvertisementState: false, // 开屏广告 状态
initialState: false,
}
})