This commit is contained in:
zpc 2026-03-19 05:48:36 +08:00
parent 2f75cc611b
commit 01efec146c
3 changed files with 93 additions and 1 deletions

View File

@ -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)

View File

@ -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()

View 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)
}