| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <script setup>
- import storage from "@/utils/storage.js";
- import { onLaunch, onShow, onHide } from '@dcloudio/uni-app';
- import { useStore } from 'vuex';
- import { getCurrentInstance } from 'vue';
- const store = useStore();
- const instance = getCurrentInstance();
- // 登录状态检查函数
- const 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;
- }
- });
- };
- // 初始化其他插件(uview-plus 已在 main.js 中注册)
- const initPlugins = async () => {
- try {
- // #ifdef H5
- // H5 环境加载 jessibuca 插件
- if (typeof window !== 'undefined') {
- const jessibucaModule = await import('./utils/jessibuca-plugin');
- if (instance && instance.appContext && instance.appContext.app) {
- instance.appContext.app.use(jessibucaModule.default);
- }
- }
- // #endif
- } catch (error) {
- console.error('插件初始化失败:', error);
- }
- };
- // uni-app 生命周期钩子 (保持原有命名)
- onLaunch(() => {
- console.log('App Launch');
- // 初始化插件
- initPlugins();
- // 初始化 store 状态
- store.dispatch('init');
- checkLoginStatus();
- });
- onShow(() => {
- console.log('App Show');
- });
- onHide(() => {
- console.log('App Hide');
- });
- </script>
- <!-- App.vue中不需要template,uni-app会自动处理页面跳转 -->
- <style lang="scss">
- /* 全局基础样式 */
- @import "uview-plus/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>
|