21
This commit is contained in:
parent
2f75cc611b
commit
01efec146c
|
|
@ -53,9 +53,10 @@ public class OrderService : IOrderService
|
|||
if (pageSize > 100) pageSize = 100;
|
||||
|
||||
// 构建查询 - 用户数据隔离(Requirements 7.1)
|
||||
// 只展示已支付或退款的订单,排除待支付(1)和已取消(6)(Requirements 9)
|
||||
var query = _dbContext.Orders
|
||||
.AsNoTracking()
|
||||
.Where(o => o.UserId == userId && !o.IsDeleted);
|
||||
.Where(o => o.UserId == userId && !o.IsDeleted && o.Status != 1 && o.Status != 6);
|
||||
|
||||
// 支持按订单类型筛选(Requirements 7.1)
|
||||
if (orderType.HasValue)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
<script>
|
||||
import { useUserStore } from './store/user.js'
|
||||
import { useAppStore } from './store/app.js'
|
||||
import { setupRouteGuard } from './utils/routeGuard.js'
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
console.log('App Launch')
|
||||
// 初始化路由守卫(未登录跳转登录页)
|
||||
setupRouteGuard()
|
||||
|
||||
// 初始化系统信息
|
||||
const appStore = useAppStore()
|
||||
appStore.initSystemInfo()
|
||||
|
|
|
|||
87
uniapp/utils/routeGuard.js
Normal file
87
uniapp/utils/routeGuard.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* 路由守卫模块
|
||||
* 拦截页面跳转,未登录时自动重定向到登录页
|
||||
*/
|
||||
|
||||
import { getToken } from './storage.js'
|
||||
|
||||
/**
|
||||
* 不需要登录即可访问的页面白名单
|
||||
* 包含:TabBar 页面、登录页、协议页
|
||||
*/
|
||||
const WHITE_LIST = [
|
||||
'pages/index/index',
|
||||
'pages/team/index',
|
||||
'pages/mine/index',
|
||||
'pages/login/index',
|
||||
'pages/agreement/user/index',
|
||||
'pages/agreement/privacy/index'
|
||||
]
|
||||
|
||||
/**
|
||||
* 从跳转 url 中提取页面路径(去掉前导 / 和查询参数)
|
||||
* @param {string} url - 跳转地址
|
||||
* @returns {string} 页面路径
|
||||
*/
|
||||
function extractPath(url) {
|
||||
if (!url) return ''
|
||||
// 去掉前导 /
|
||||
let path = url.startsWith('/') ? url.substring(1) : url
|
||||
// 去掉查询参数
|
||||
const queryIndex = path.indexOf('?')
|
||||
if (queryIndex > -1) {
|
||||
path = path.substring(0, queryIndex)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断页面是否在白名单中
|
||||
* @param {string} path - 页面路径
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isWhiteListed(path) {
|
||||
return WHITE_LIST.includes(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建拦截器回调
|
||||
* @returns {Object} 拦截器配置
|
||||
*/
|
||||
function createInterceptor() {
|
||||
return {
|
||||
invoke(args) {
|
||||
const path = extractPath(args.url)
|
||||
|
||||
// 白名单页面直接放行
|
||||
if (isWhiteListed(path)) {
|
||||
return args
|
||||
}
|
||||
|
||||
// 已登录放行
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
return args
|
||||
}
|
||||
|
||||
// 未登录,重定向到登录页,携带原目标地址
|
||||
const redirectUrl = encodeURIComponent(args.url)
|
||||
uni.navigateTo({
|
||||
url: `/pages/login/index?redirect=${redirectUrl}`
|
||||
})
|
||||
|
||||
// 返回 false 阻止原始跳转
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化路由守卫
|
||||
* 拦截 navigateTo 和 redirectTo
|
||||
*/
|
||||
export function setupRouteGuard() {
|
||||
const interceptor = createInterceptor()
|
||||
uni.addInterceptor('navigateTo', interceptor)
|
||||
uni.addInterceptor('redirectTo', interceptor)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user