- 修复 uni-popup-dialog/uni-data-picker keypress.js 中 $once 在 H5 端报错(改用生命周期钩子清理监听) - main.js 补 $delete globalProperties polyfill(z-paging 自动高度逻辑依赖) - App.vue onLaunch 补设备信息初始化,修复 X-Device-Id 恒为 unknown - 68 处 ::v-deep、/deep/ 旧深度选择器替换为 :deep()(含 login-page.scss) - zetank-personalpage 组件 .sync 修饰符改为 v-model:xxx(Vue3 已移除 .sync) - vite.config.js HBuilderX 路径支持 HBUILDERX_HOME 环境变量覆盖 - 根 package.json 清理 image-grid 插件遗留元数据 - 收录此前未提交的 uView Vue3 兜底补丁(common/uview-init.js 及各组件 props.js)
101 lines
2.5 KiB
JavaScript
101 lines
2.5 KiB
JavaScript
// 优先初始化 uView 全局配置(uni.$u),避免页面组件先于其加载
|
|
import '@/uni_modules/uview-ui'
|
|
import App from './App'
|
|
|
|
// ================== Vue2 逻辑 ================== //
|
|
// #ifndef VUE3
|
|
import Vue from 'vue'
|
|
import './uni.promisify.adaptor'
|
|
import uView from '@/uni_modules/uview-ui'
|
|
Vue.use(uView)
|
|
|
|
// 初始化 Vue2 配置
|
|
Vue.config.productionTip = false
|
|
App.mpType = 'app'
|
|
|
|
// 创建 Vue 实例
|
|
const app = new Vue({ ...App })
|
|
app.$mount()
|
|
// #endif
|
|
|
|
// ================== Vue3 逻辑 ================== //
|
|
// #ifdef VUE3
|
|
import { createSSRApp } from 'vue'
|
|
import uView from '@/uni_modules/uview-ui'
|
|
|
|
export function createApp() {
|
|
const app = createSSRApp(App)
|
|
app.use(uView)
|
|
|
|
// Vue3 已移除 $delete,补齐以兼容依赖该 API 的旧组件(如 z-paging 自动高度逻辑)
|
|
app.config.globalProperties.$delete = function $delete(target, key) {
|
|
if (target && typeof target === 'object') {
|
|
delete target[key]
|
|
}
|
|
}
|
|
|
|
return { app }
|
|
}
|
|
// #endif
|
|
|
|
|
|
// ================== 全局请求拦截器 ================== //
|
|
uni.addInterceptor('request', {
|
|
invoke(args) {
|
|
// 1. 添加认证信息
|
|
const token = uni.getStorageSync('uni_id_token')
|
|
if (token) {
|
|
args.header = {
|
|
...args.header,
|
|
'X-Cloud-Token': token,
|
|
// 异步获取设备信息(避免阻塞)
|
|
'X-Device-Id': getApp().globalData.deviceId || 'unknown'
|
|
}
|
|
}
|
|
|
|
// 2. 添加请求超时配置
|
|
if (!args.timeout) {
|
|
args.timeout = 10000 // 默认10秒超时
|
|
}
|
|
|
|
// 3. 生产环境移除调试输出
|
|
if (process.env.NODE_ENV === 'development') {
|
|
console.log('[请求拦截]', args.url, args.header)
|
|
}
|
|
|
|
return args
|
|
},
|
|
|
|
fail(err) {
|
|
// 1. 网络错误处理
|
|
if (err.errMsg.includes('fail abort')) {
|
|
uni.showToast({ title: '请求取消', icon: 'none' })
|
|
}
|
|
// 2. 超时处理
|
|
else if (err.errMsg.includes('timeout')) {
|
|
uni.showToast({ title: '网络超时,请重试', icon: 'none' })
|
|
}
|
|
// 3. Token失效处理
|
|
else if (err.errMsg.includes('401') || err.errMsg.includes('TOKEN')) {
|
|
handleTokenExpired()
|
|
}
|
|
// 4. 其他错误
|
|
else {
|
|
uni.showToast({ title: '网络异常', icon: 'none' })
|
|
}
|
|
}
|
|
})
|
|
|
|
// 独立处理Token过期的函数
|
|
function handleTokenExpired() {
|
|
uni.showModal({
|
|
title: '登录过期',
|
|
content: '请重新登录',
|
|
showCancel: false,
|
|
success: () => {
|
|
uni.removeStorageSync('uni_id_token')
|
|
uni.reLaunch({ url: '/pages/login' })
|
|
}
|
|
})
|
|
}
|