ReedawFoodApp/App.vue

161 lines
3.9 KiB
Vue
Raw Normal View History

2025-05-30 10:04:01 +08:00
<script>
2026-03-27 10:04:26 +08:00
let platform = ""
let SystemVersion = ""
2026-04-15 17:30:55 +08:00
import {
mapState
} from "vuex";
2026-04-11 11:37:58 +08:00
export default {
data() {
return {}
},
2026-04-15 17:30:55 +08:00
computed: {
...mapState(["user"]),
},
2026-04-11 11:37:58 +08:00
onLaunch: function() {
let that = this
// 返回的是apk包信息
// #ifdef APP-PLUS||APP
uni.getSystemInfo({
success(e) {
platform = e.platform
that.$store.commit('changePhoneInfo', {
platform: e.platform
})
}
})
if (platform === 'ios') { // ios首次安装没有网络
uni.onNetworkStatusChange(function(res) {
if (res.isConnected == true) {
that.handleoginversion()
2026-03-27 10:04:26 +08:00
}
2026-04-11 11:37:58 +08:00
});
}
plus.runtime.getProperty(plus.runtime.appid, function(info) {
uni.setStorageSync('VERSION', info.version)
SystemVersion = info.version
that.$store.commit('changePhoneInfo', {
info: info
2026-03-31 16:04:41 +08:00
})
2026-04-11 11:37:58 +08:00
})
// #endif
that.handleoginversion()
console.log('App Launch')
},
onShow: function() {
let that = this
that.handleTabBarItem()
uni.switchTab({
url: "/pages/index/index"
})
},
onHide: function() {
console.log('App Hide')
// #ifdef APP-PLUS||APP
uni.offNetworkStatusChange(function(res) {
console.log("取消网络监听")
})
// #endif
},
methods: {
// 公共信息
handleoginversion() {
let that = this
that.$model.getLoginVersion({}).then(res => {
2026-04-16 14:57:58 +08:00
console.log("版本", res.data)
2026-04-15 17:30:55 +08:00
let language = res.data.language == "zh" ? 'zh-Hans' : res.data.language
2026-04-11 11:37:58 +08:00
uni.setLocale(language)
that.$i18n.locale = language
2026-04-15 17:30:55 +08:00
that.$store.commit('changeLocale', res.data.language)
uni.setStorageSync('language', res.data.language)
2026-04-11 11:37:58 +08:00
that.$store.dispatch("getCardAllList") // 全部卡片
that.$store.dispatch("getPublicRecord") // 卡片手动记录配置
that.$store.dispatch("getHomeConfig") //配置接口信息
2026-04-15 17:30:55 +08:00
2026-04-11 11:37:58 +08:00
if (res.code == 0) {
that.$tools.handleUserList()
} else {
uni.setStorageSync('token', "")
uni.setStorageSync('aan_id', null)
setTimeout(() => {
uni.reLaunch({
url: '/body/login/login',
})
}, 500);
}
2026-04-16 15:20:06 +08:00
// #ifdef APP-PLUS||APP
2026-03-27 10:04:26 +08:00
that.$store.commit('changePhoneInfo', {
2026-04-11 11:37:58 +08:00
versionUrl: res.data
2025-05-30 11:14:38 +08:00
})
2026-04-15 17:30:55 +08:00
let versionPK = that.$tools.compareVersions(SystemVersion, res.data.version)
if (versionPK == -1) {
// 版本1小于版本2
return uni.showModal({
title: that.$t('newVersion'),
content: that.$t('newVersion') + res.data.version + that.$t('IsUpdate'),
cancelText: that.$t("btnSancellation"), //取消按钮文字
confirmText: that.$t("btnConfirm"), //确认按钮文字
success: (modalRes) => {
if (modalRes.confirm) { //确定更新
if (platform === 'android') { //安卓更新
uni.navigateTo({
url: "/body/my/about"
})
} else { //ios跳转
plus.runtime.launchApplication({
action: res.data.ios_address
})
}
} else {
that.$tools.msg(that.$t('UpdateProgram'))
}
}
});
}
2026-04-16 15:20:06 +08:00
// #endif
2026-04-11 11:37:58 +08:00
}).catch(error => {
// console.error('Error fetching data:', error);
});
2025-05-30 11:14:38 +08:00
},
2026-04-11 11:37:58 +08:00
handleTabBarItem() {
let that = this
uni.setTabBarItem({
index: 0,
text: that.$t('titleHealth')
2026-03-31 16:04:41 +08:00
})
2026-04-11 11:37:58 +08:00
uni.setTabBarItem({
index: 1,
text: that.$t('titleDiet')
})
uni.setTabBarItem({
index: 2,
text: that.$t('titleExercise')
})
uni.setTabBarItem({
index: 3,
text: that.$t('titleMe')
2025-05-30 11:14:38 +08:00
})
2026-03-31 16:04:41 +08:00
},
2025-05-30 10:04:01 +08:00
}
2026-04-11 11:37:58 +08:00
}
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>