ReedawFoodApp/App.vue

154 lines
4.0 KiB
Vue
Raw Permalink Normal View History

2025-05-30 10:04:01 +08:00
<script>
2026-03-27 10:04:26 +08:00
let platform = ""
let SystemVersion = ""
2025-05-30 10:04:01 +08:00
export default {
2025-05-30 11:14:38 +08:00
data() {
return {}
},
2025-05-30 10:04:01 +08:00
onLaunch: function() {
2025-05-30 11:14:38 +08:00
let that = this
// 返回的是apk包信息
2026-03-31 13:51:12 +08:00
// #ifdef APP-PLUS||APP
2026-03-27 10:04:26 +08:00
uni.getSystemInfo({
success(e) {
platform = e.platform
that.$store.commit('changePhoneInfo', {
platform: e.platform
})
}
})
if (platform === 'ios') { // ios首次安装没有网络
2025-05-30 11:14:38 +08:00
uni.onNetworkStatusChange(function(res) {
if (res.isConnected == true) {
2026-03-27 10:04:26 +08:00
that.handleoginversion()
2025-05-30 11:14:38 +08:00
}
});
}
2026-03-27 10:04:26 +08:00
plus.runtime.getProperty(plus.runtime.appid, function(info) {
uni.setStorageSync('VERSION', info.version)
SystemVersion = info.version
that.$store.commit('changePhoneInfo', {
info: info
})
})
2025-05-30 11:14:38 +08:00
// #endif
2026-03-27 10:04:26 +08:00
that.handleoginversion()
2025-05-30 10:04:01 +08:00
console.log('App Launch')
},
onShow: function() {
2026-03-30 10:02:10 +08:00
uni.switchTab({
2026-03-31 13:51:12 +08:00
url: "/pages/index/index"
2026-03-30 10:02:10 +08:00
})
2025-05-30 10:04:01 +08:00
},
onHide: function() {
console.log('App Hide')
2026-03-31 13:51:12 +08:00
// #ifdef APP-PLUS||APP
2025-05-30 11:14:38 +08:00
uni.offNetworkStatusChange(function(res) {
console.log("取消网络监听")
})
// #endif
},
methods: {
2026-03-23 09:50:49 +08:00
// 公共信息
2026-03-27 10:04:26 +08:00
handleoginversion() {
2025-05-30 11:14:38 +08:00
let that = this
2026-03-27 10:04:26 +08:00
that.$model.getLoginVersion({}).then(res => {
that.$store.dispatch("getHomeConfig") //配置接口信息
if (res.code == 0) {
2026-03-27 10:56:18 +08:00
that.$tools.handleUserList()
2026-03-27 10:04:26 +08:00
} else {
2026-03-31 13:51:12 +08:00
uni.setStorageSync('token', "")
2026-03-27 10:04:26 +08:00
uni.setStorageSync('aan_id', null)
2026-03-27 10:56:18 +08:00
// #ifdef APP-PLUS||APP
2026-03-27 10:04:26 +08:00
setTimeout(() => {
uni.reLaunch({
url: '/body/login/login',
})
}, 500);
2026-03-27 10:56:18 +08:00
// #endif
2026-03-27 10:04:26 +08:00
}
// #ifdef APP-PLUS||APP
that.$store.commit('changePhoneInfo', {
versionUrl: res.data
2025-05-30 11:14:38 +08:00
})
2026-03-27 10:04:26 +08:00
// 比对版本号
let version = that.$tools.compareVersions(SystemVersion, res.data.version)
console.log("是否登录及版本号", res, res.data.version, SystemVersion, version)
if (version == -1) { // 0版本号相通1第一个版本号大于第二个版本号-1第一个版本号小于第二个版本号
uni.showModal({
title: '发现新版本',
content: '检查到新版本' + res.data.version + ',是否更新?',
success: (modalRes) => {
if (modalRes.confirm) { //确定更新
if (platform === 'android') { //安卓更新
uni.setStorageSync('VERSION', res.data.version)
uni.navigateTo({
url: "/body/me/about"
})
} else { //ios跳转
plus.runtime.launchApplication({
action: `itms-apps://itunes.apple.com/cn/app/id6654906497?mt=8`
})
}
} else {
that.$tools.msg("稍后可在'关于我们'内更新程序!")
}
}
});
}
2025-05-30 11:14:38 +08:00
// #endif
2026-03-23 09:50:49 +08:00
2026-03-31 13:51:12 +08:00
}).catch(error => {
// console.error('Error fetching data:', error);
});
2025-05-30 11:14:38 +08:00
},
// 微信小程序更新
updataWeiXin() {
let that = this
const updateManager = uni.getUpdateManager()
// 请求完新版本信息的回调
updateManager.onCheckForUpdate(function(res) {
// console.log("是否有新版本", res.hasUpdate)
})
updateManager.onUpdateReady(function() {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function() {
uni.showModal({
title: '新版本更新失败',
content: '请退出并移除小程序,重新打开...',
})
})
}
2025-05-30 10:04:01 +08:00
}
}
</script>
2025-05-30 11:14:38 +08:00
<style lang="scss">
2025-05-30 10:04:01 +08:00
/*每个页面公共css */
2025-05-30 11:14:38 +08:00
/* #ifndef APP-NVUE */
@import "/uni.scss";
2026-03-23 09:50:49 +08:00
@import "/scss/food.scss";
2025-05-30 11:14:38 +08:00
@import "/scss/common.scss";
@import "/scss/iconfont.css";
@import "/scss/iconfont-weapp-icon.css";
/* #endif*/
2026-03-23 09:50:49 +08:00
.content {
display: flex;
flex-direction: column;
align-items: center;
background-color: #f7f7f7;
min-height: 100vh;
}
2025-05-30 11:14:38 +08:00
</style>