first commit
This commit is contained in:
127
衣莎项目/源码/YiShaXiYi/app.js
Normal file
127
衣莎项目/源码/YiShaXiYi/app.js
Normal file
@@ -0,0 +1,127 @@
|
||||
//app.js
|
||||
import config from './config/config'
|
||||
App({
|
||||
onLaunch: function (options) {
|
||||
if (!!options.query.scene) {
|
||||
wx.setStorageSync(`${config.prefix}inviteId`, options.query.scene)
|
||||
}
|
||||
let that = this;
|
||||
that.getSystem()
|
||||
// 版本更新
|
||||
if (wx.canIUse('getUpdateManager')) {
|
||||
const updateManager = wx.getUpdateManager()
|
||||
updateManager.onCheckForUpdate(function (res) {
|
||||
// 请求完新版本信息的回调
|
||||
if (res.hasUpdate) {
|
||||
updateManager.onUpdateReady(function () {
|
||||
wx.showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
updateManager.onUpdateFailed(function () {
|
||||
// 新的版本下载失败
|
||||
wx.showModal({
|
||||
title: '已经有新版本了哟~',
|
||||
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
// 获取设备信息的方法
|
||||
getSystem: function () {
|
||||
var that = this;
|
||||
wx.getSystemInfo({
|
||||
success: function (res) {
|
||||
var statusHeight = res.statusBarHeight;
|
||||
that.globalData.system = {
|
||||
screenHeight: res.screenHeight,
|
||||
titleHeight: 45,
|
||||
statusHeight: statusHeight,
|
||||
pageHeight: res.windowHeight - 45 - statusHeight
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
globalData: {
|
||||
isToken: false,
|
||||
share: false, // 分享默认为false
|
||||
system: null,
|
||||
isOrderList: false,//如果在详情页取消订单则改为true
|
||||
cartNum: 0,//商城的角标
|
||||
userInfo: {},//用户个人信息
|
||||
showSkeleton: true,//首页骨架屏显示关闭
|
||||
temCart: {//暂存勾选的购物车商品 商城的购物车
|
||||
total: 0,//勾选的总价
|
||||
allCart: [],//勾选的商品
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 小程序的变量全局更新
|
||||
* @param { string } key 要获取的变量名
|
||||
* @param { Function } method 回调函数
|
||||
*/
|
||||
setWatching: function (key, method) {
|
||||
let obj = this.globalData;
|
||||
//加个前缀生成隐藏变量,防止死循环发生
|
||||
let ori = obj[key]; //obj[key]这个不能放在Object.defineProperty里
|
||||
|
||||
if (ori) { //处理已经声明的变量,绑定处理
|
||||
method(ori);
|
||||
}
|
||||
Object.defineProperty(obj, key, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
set: function (value) {
|
||||
this['__' + key] = value;
|
||||
method(value); //数据有变化的时候回调函数,实现同步功能
|
||||
},
|
||||
get: function () {
|
||||
if (typeof this['__' + key] == 'undefined') {
|
||||
if (ori) {
|
||||
//这里读取数据的时候隐藏变量和 globalData设置不一样,所以要做同步处理
|
||||
this['__' + key] = ori;
|
||||
return ori;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
return this['__' + key];
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
// 调用utils下的js
|
||||
loadUtils: function (name) {
|
||||
return require(`./utils/${name}.js`)
|
||||
},
|
||||
// 全局配置
|
||||
loadConfig: function () {
|
||||
return require("./config/config.js")
|
||||
},
|
||||
// 需要使用async时引入
|
||||
loadAsync: function () {
|
||||
const regeneratorRuntime = require("./utils/regenerator-runtime/runtime")
|
||||
return regeneratorRuntime
|
||||
},
|
||||
// 导出接口地址
|
||||
loadApi: function () {
|
||||
return require("./http/api")
|
||||
},
|
||||
// 导出接口地址
|
||||
loadHttp: function () {
|
||||
return require("./http/index")
|
||||
},
|
||||
// 导出model模块
|
||||
loadModel: function (name) {
|
||||
return require(`./model/${name}`)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user