255 lines
6.7 KiB
Vue
255 lines
6.7 KiB
Vue
<script>
|
||
let platform = ""
|
||
let SystemVersion = ""
|
||
export default {
|
||
data() {
|
||
return {
|
||
list: [{
|
||
key: "en",
|
||
value: "en"
|
||
},
|
||
{
|
||
key: "zh",
|
||
value: "zh-Hans"
|
||
}
|
||
]
|
||
}
|
||
},
|
||
onLaunch: function() {
|
||
let that = this
|
||
// #ifdef APP-PLUS
|
||
// 获取设备信息
|
||
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()
|
||
}
|
||
});
|
||
}
|
||
plus.runtime.getProperty(plus.runtime.appid, function(info) {
|
||
uni.setStorageSync('VERSION', info.version)
|
||
SystemVersion = info.version
|
||
that.$store.commit('changePhoneInfo', {
|
||
info: info
|
||
})
|
||
})
|
||
// #endif
|
||
// #ifdef MP-WEIXIN
|
||
that.updataWeiXin() //小程序版本更新
|
||
// #endif
|
||
//订阅登录成功事件
|
||
uni.$on('login-sucesss', function() {
|
||
console.log('on login-sucesss')
|
||
that.handleUserList()
|
||
that.handleBannerList()
|
||
that.handleTabBarItem()
|
||
setTimeout(() => {
|
||
uni.reLaunch({
|
||
url: '/pages/home/home'
|
||
})
|
||
}, 500)
|
||
})
|
||
//订阅需要登录事件
|
||
uni.$on('need-login', function() {
|
||
uni.setStorageSync('token', null)
|
||
uni.setStorageSync('aan_id', null)
|
||
setTimeout(() => {
|
||
uni.reLaunch({
|
||
url: '/pageTwo/login/login'
|
||
})
|
||
}, 500);
|
||
})
|
||
that.handleoginversion()
|
||
that.handleCityList()
|
||
|
||
},
|
||
onShow: function() {
|
||
let that = this
|
||
that.handleTabBarItem()
|
||
},
|
||
onHide: function() {
|
||
// #ifdef APP-PLUS
|
||
uni.offNetworkStatusChange(function(res) {
|
||
console.log("取消网络监听")
|
||
})
|
||
// #endif
|
||
},
|
||
methods: {
|
||
// 版本信息
|
||
handleoginversion() {
|
||
let that = this
|
||
that.$model.getloginversion({
|
||
is_wechat: uni.getSystemInfoSync().uniPlatform == 'app' ? false : true
|
||
}).then(res => {
|
||
that.$store.commit('changeLanguage', res.data.language_arr)
|
||
if (res.code == 0) {
|
||
that.$i18n.locale = res.data.language
|
||
uni.setStorageSync('language', res.data.language)
|
||
that.$store.commit('changeLocale', res.data.language)
|
||
uni.$emit('login-sucesss');
|
||
console.log("已登录手机语言", res.data.language)
|
||
} else {
|
||
uni.getSystemInfo({
|
||
success(e) {
|
||
let locale = ""
|
||
that.list.forEach(ite => {
|
||
if (e.language.indexOf(ite.key) != -1) {
|
||
locale = ite.value
|
||
}
|
||
})
|
||
let language = uni.getStorageSync('language') ? uni.getStorageSync(
|
||
'language') : locale
|
||
that.$i18n.locale = language
|
||
uni.setStorageSync('language', language)
|
||
that.$store.commit('changeLocale', language)
|
||
uni.$emit('need-login');
|
||
console.log("未登录手机语言", language, uni.getStorageSync('language'), locale)
|
||
}
|
||
})
|
||
|
||
}
|
||
// #ifdef APP-PLUS||APP
|
||
that.$store.commit('changePhoneInfo', {
|
||
versionUrl: res.data
|
||
})
|
||
// 比对版本号
|
||
let version = that.$tools.compareVersions(SystemVersion, res.data.version)
|
||
console.log("是否登录及版本号", res.data.version, SystemVersion, version)
|
||
if (version == -1) { // 0版本号相通,1,:第一个版本号大于第二个版本号,-1:第一个版本号小于第二个版本号
|
||
uni.showModal({
|
||
title: '发现新版本',
|
||
content: '检查到新版本' + res.data.version + ',是否更新?',
|
||
cancelText: that.$t('tips.btnSancellation'),
|
||
confirmText: that.$t('tips.btnConfirm'),
|
||
success: (modalRes) => {
|
||
if (modalRes.confirm) { //确定更新
|
||
if (platform === 'android') { //安卓更新
|
||
uni.setStorageSync('VERSION', res.data.version)
|
||
uni.navigateTo({
|
||
url: "/pageTwo/my/about"
|
||
})
|
||
} else { //ios跳转
|
||
plus.runtime.launchApplication({
|
||
action: `itms-apps://itunes.apple.com/cn/app/id6654906497?mt=8`
|
||
})
|
||
}
|
||
} else {
|
||
that.$tools.msg("稍后可在'关于我们'内更新程序!")
|
||
}
|
||
}
|
||
});
|
||
}
|
||
// #endif
|
||
})
|
||
},
|
||
// 成员列表
|
||
handleUserList() {
|
||
let that = this
|
||
that.$model.getUserList({
|
||
type: 2
|
||
}).then(res => {
|
||
if (res.code != 0) {
|
||
that.$tools.msg(res.msg)
|
||
return
|
||
}
|
||
that.$store.commit('changeFamilay', res.data)
|
||
if (res.data.length) {
|
||
let userid = ""
|
||
if (uni.getStorageSync('userid')) {
|
||
let found = res.data.find(e => e.id == uni.getStorageSync('userid'));
|
||
if (found !== undefined) {
|
||
userid = found.id
|
||
} else {
|
||
userid = res.data[0].id
|
||
uni.setStorageSync('userid', res.data[0].id)
|
||
}
|
||
} else {
|
||
userid = res.data[0].id
|
||
uni.setStorageSync('userid', res.data[0].id)
|
||
}
|
||
that.$store.dispatch('getUserInfo', {
|
||
aud_id: userid
|
||
})
|
||
that.$store.dispatch("getResult", {
|
||
aud_id: userid
|
||
})
|
||
}
|
||
})
|
||
},
|
||
// banner
|
||
handleBannerList() {
|
||
let that = this
|
||
that.$model.getBannerList({}).then(res => {
|
||
if (res.code == 0) {
|
||
that.$store.commit('changeBannerAll', res.data)
|
||
}
|
||
})
|
||
},
|
||
// 微信小程序更新
|
||
updataWeiXin() {
|
||
let that = this
|
||
const updateManager = uni.getUpdateManager()
|
||
updateManager.onUpdateReady(function() {
|
||
uni.showModal({
|
||
title: '更新提示',
|
||
content: '新版本已经准备好,是否重启应用?',
|
||
cancelText: that.$t('tips.btnSancellation'),
|
||
confirmText: that.$t('tips.btnConfirm'),
|
||
success: function(res) {
|
||
if (res.confirm) {
|
||
updateManager.applyUpdate()
|
||
}
|
||
}
|
||
})
|
||
})
|
||
updateManager.onUpdateFailed(function() {
|
||
uni.showModal({
|
||
title: '新版本更新失败',
|
||
content: '请退出并移除小程序,重新打开...',
|
||
})
|
||
})
|
||
},
|
||
// 地区
|
||
handleCityList() {
|
||
let that = this
|
||
that.$model.getGradeList({}).then((res) => {
|
||
// console.log("|全部地区", res.data)
|
||
if (res.code != 0) return
|
||
that.$store.commit('changeCityList', res.data.area_list)
|
||
that.$store.commit('changeGradeList', res.data.grade_list)
|
||
that.$store.commit('changeIdentityList', res.data.identity_list)
|
||
})
|
||
},
|
||
handleTabBarItem() {
|
||
let that = this
|
||
uni.setTabBarItem({
|
||
index: 0,
|
||
text: that.$t('common.titleHome')
|
||
})
|
||
uni.setTabBarItem({
|
||
index: 1,
|
||
text: that.$t('common.titleMe')
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
/*每个页面公共css */
|
||
/* #ifndef APP-NVUE */
|
||
@import "/uni.scss";
|
||
@import "/scss/common.scss";
|
||
@import "/scss/iconfont.css";
|
||
@import "/scss/iconfont-weapp-icon.css";
|
||
|
||
/* #endif*/
|
||
</style> |