110 lines
2.0 KiB
Vue
110 lines
2.0 KiB
Vue
<script>
|
|
export default {
|
|
globalData: {
|
|
token: '',
|
|
user: null,
|
|
shouldRefresh: false,
|
|
loginTime: 0
|
|
},
|
|
onLaunch: function() {
|
|
console.log('App Launch')
|
|
|
|
// 初始化全局数据
|
|
this.initGlobalData()
|
|
|
|
this.setTabBarText()
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
this.setTabBarText()
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
methods: {
|
|
/**
|
|
* 初始化全局数据
|
|
*/
|
|
initGlobalData() {
|
|
try {
|
|
// 从本地存储恢复 token
|
|
const token = uni.getStorageSync('token')
|
|
if (token) {
|
|
this.globalData.token = token
|
|
}
|
|
|
|
// 从本地存储恢复用户信息
|
|
const userStr = uni.getStorageSync('user')
|
|
if (userStr) {
|
|
try {
|
|
this.globalData.user = JSON.parse(userStr)
|
|
} catch (e) {
|
|
console.error('解析用户信息失败:', e)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error('初始化全局数据失败:', e)
|
|
}
|
|
},
|
|
|
|
setTabBarText() {
|
|
// 动态设置 TabBar 文本
|
|
const pages = getCurrentPages()
|
|
if (pages.length > 0) {
|
|
const currentPage = pages[pages.length - 1]
|
|
if (currentPage.$vm && currentPage.$vm.$t) {
|
|
uni.setTabBarItem({
|
|
index: 0,
|
|
text: currentPage.$vm.$t('tabbar.home')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 1,
|
|
text: currentPage.$vm.$t('tabbar.appointment')
|
|
})
|
|
uni.setTabBarItem({
|
|
index: 2,
|
|
text: currentPage.$vm.$t('tabbar.me')
|
|
})
|
|
}
|
|
}
|
|
}
|
|
},
|
|
watch: {
|
|
'$i18n.locale'() {
|
|
this.setTabBarText()
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
/*每个页面公共css */
|
|
.bg {
|
|
background-size: cover;
|
|
background-repeat: no-repeat;
|
|
background-position: center;
|
|
}
|
|
|
|
.column {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.row {
|
|
display: flex;
|
|
flex-direction: row;
|
|
}
|
|
|
|
.center {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.single-overflow {
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
display: inline-block;
|
|
}
|
|
</style> |