import App from './App' // ================== Vue2 逻辑 ================== // // #ifndef VUE3 import Vue from 'vue' import './uni.promisify.adaptor' // 初始化 Vue2 配置 Vue.config.productionTip = false App.mpType = 'app' // 创建 Vue 实例 const app = new Vue({ ...App }) app.$mount() // #endif // ================== Vue3 逻辑 ================== // // #ifdef VUE3 import { createSSRApp } from 'vue' export function createApp() { const app = createSSRApp(App) return { app } } // #endif // ================== 全局请求拦截器 ================== // // 在 main.js 中增强请求拦截器 uni.addInterceptor('request', { invoke(args) { const token = uni.getStorageSync('uni_id_token') console.log('[DEBUG] Current Token:', token) // 添加调试输出 args.header = { ...args.header, 'X-Cloud-Token': token, 'X-Device-Id': uni.getSystemInfoSync().deviceId // 追加设备指纹 } return args }, fail(err) { // 增加网络错误细分处理 if (err.errMsg.includes('timeout')) { uni.showToast({ title: '网络超时', icon: 'none' }) } else if (err.errMsg.includes('token')) { uni.removeStorageSync('uni_id_token') uni.redirectTo({ url: '/pages/login?err=TOKEN_EXPIRED' }) } } })