| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <script>
- import storage from "@/utils/storage.js";
- export default {
- onLaunch: function() {
- console.log('App Launch');
- this.checkLoginStatus();
- // 添加全局页面生命周期监听
- // uni.onPageNotFound(function(e) {
- // console.error('页面不存在:', e);
- // uni.navigateTo({
- // url: '/pages/dashboard/index'
- // });
- // });
- },
- onShow: function() {
- console.log('App Show');
- },
- onHide: function() {
- console.log('App Hide');
- },
- methods: {
- checkLoginStatus() {
- // 登录状态检查,对敏感页面进行拦截
- const pages = ['pages/device/index'];
-
- uni.addInterceptor('navigateTo', {
- invoke(e) {
- const url = e.url;
- // 检查是否属于需要登录的页面
- const needLogin = pages.some(page => url.indexOf(page) > -1);
-
- if (needLogin && !storage.isLoggedIn()) {
- uni.navigateTo({
- url: '/pages/login/index'
- });
- return false;
- }
- return true;
- }
- });
-
- uni.addInterceptor('switchTab', {
- invoke(e) {
- const url = e.url;
- // 检查是否属于需要登录的页面
- const needLogin = pages.some(page => url.indexOf(page) > -1);
-
- if (needLogin && !storage.isLoggedIn()) {
- uni.navigateTo({
- url: '/pages/login/index'
- });
- return false;
- }
- return true;
- }
- });
- }
- }
- }
- </script>
- <!-- App.vue中不需要template,uni-app会自动处理页面跳转 -->
- <style lang="scss">
- /* 全局基础样式 */
- @import "uview-ui/index.scss";
- page {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
- font-size: 28rpx;
- line-height: 1.5;
- color: #333;
- background-color: #f5f5f5;
- }
- /* 去除按钮默认边框 */
- button::after {
- border: none;
- }
- /* 隐藏滚动条 */
- ::-webkit-scrollbar {
- width: 0;
- height: 0;
- color: transparent;
- }
- /* H5环境特殊样式 */
- /* #ifdef H5 */
- html, body {
- height: 100%;
- width: 100%;
- overflow-x: hidden;
- }
- .uni-page-head {
- display: flex !important;
- }
- /* #endif */
- </style>
|