55 lines
1.3 KiB
Vue
55 lines
1.3 KiB
Vue
<script>
|
|
// #ifdef APP-PLUS
|
|
import update from "@/uni_modules/uni-upgrade-center-app/utils/check-update";
|
|
|
|
// #endif
|
|
import { useUserStore } from '@/stores/user'
|
|
export default {
|
|
onLaunch: function() {
|
|
const userStore = useUserStore()
|
|
console.log('App Launch')
|
|
// 保存原生 switchTab 方法
|
|
const originalSwitchTab = uni.switchTab;
|
|
uni.switchTab = (options) => {
|
|
if (options.url.includes('/pages/book/index') && !uni.getStorageSync('token')) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: '请先登录后访问该页面',
|
|
confirmText: '去登录',
|
|
success: (res) => {
|
|
console.log(res, 'res');
|
|
if (res.confirm) uni.navigateTo({
|
|
url: '/pages/login/login'
|
|
});
|
|
}
|
|
});
|
|
return; // 拦截跳转
|
|
}
|
|
// 已登录/非拦截页 → 执行原生跳转
|
|
originalSwitchTab.call(uni, options);
|
|
}
|
|
// 检测自动更新
|
|
// #ifdef APP-PLUS
|
|
update();
|
|
// #endif
|
|
},
|
|
onShow: function() {
|
|
console.log('App Show')
|
|
},
|
|
onHide: function() {
|
|
console.log('App Hide')
|
|
},
|
|
onTabItemTap: function() {
|
|
console.log('点击了');
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
@import "@/style/tailwind.css";
|
|
@import "@/style/ui.scss";
|
|
|
|
.container {
|
|
padding: 15px;
|
|
}
|
|
</style> |