Files
root 50f8a89d51 fix: 云函数鉴权加固与投票数据防护
- follow/cms-vote/cms-articles-like/cms-articles-collect 云对象写操作强制 checkToken,uid 以服务端令牌为准,杜绝客户端伪造身份
- user-info.getIP 仅允许查询本人登录 IP(get_user_info 公开资料保持不变)
- ext-storage-co 上传凭证需登录,删除文件仅限 admin 角色(原为完全裸奔)
- cms-vote/cms-vote-info/user_select_vote 三表 schema 写权限全部关闭(投票读写均走云对象)
- 修复 follow.reFollow 中 total<0 永假导致的逻辑错误
- 各云对象 package.json 补 uni-id-common 依赖声明
- main.js 登录过期跳转修正为实际页面路径 /pages/login/login
2026-09-10 21:31:25 +08:00

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/login' })
}
})
}