<script setup>
|
import { onLaunch } from '@dcloudio/uni-app'
|
import { getToken } from '@/utils/auth'
|
import { useUserStore } from '@/stores/user'
|
|
// 定义页面白名单 - 这些页面不需要token校验
|
const pageWhiteList = [
|
'pages/login/Login',
|
'pages/login/DingTalkLogin'
|
]
|
|
// 改进的白名单检查方法
|
const isPageInWhiteList = (currentPage) => {
|
return pageWhiteList.some(path => currentPage.includes(path))
|
}
|
|
onLaunch(async () => {
|
console.log('App Launch')
|
|
const userStore = useUserStore()
|
|
try {
|
const token = getToken()
|
const launchOptions = uni.getLaunchOptionsSync()
|
const currentPage = launchOptions.path || ''
|
console.log(launchOptions);
|
console.log(launchOptions.path);
|
|
if (!token) {
|
if (!isPageInWhiteList(currentPage)) {
|
console.log('未通过白名单跳转登录页')
|
return uni.redirectTo({ url: '/pages/login/Login' })
|
}
|
return
|
}
|
|
// 校验token有效性:通过调用/current/user/current_roles接口
|
const current = await uni.$uapi.get("/getInfo");
|
|
// 如果接口返回成功,说明token有效,继续获取用户信息
|
if (current) {
|
// const resuser = await uni.$uapi.get("/system/user/profile");
|
userStore.setUserInfo(current.user);
|
userStore.setroleKey(current.roles);
|
|
// 如果当前是登录页,跳转首页
|
if (isPageInWhiteList(currentPage)) {
|
uni.switchTab({ url: '/pages/index/index' })
|
}
|
} else {
|
// 接口返回但角色信息为空,视为token无效
|
console.error('角色信息获取失败,token可能无效')
|
userStore.clearUser() // 清除本地用户信息
|
uni.redirectTo({ url: '/pages/login/Login' })
|
}
|
|
} catch (error) {
|
console.error('初始化失败:', error)
|
// token无效或其他错误,清除本地用户信息并跳转登录页
|
userStore.clearUser()
|
uni.redirectTo({ url: '/pages/login/Login' })
|
}
|
})
|
</script>
|
|
<style lang="scss">
|
@import "@/uni_modules/uview-plus/index.scss";
|
// 主题颜色
|
$primary-color: #67AFAB;
|
$primary-light: rgba($primary-color, 0.1);
|
$primary-gradient: linear-gradient(135deg, #67AFAB, #89C4C1);
|
|
// 文字颜色
|
$text-primary: #333333;
|
$text-regular: #666666;
|
$text-secondary: #999999;
|
|
// 背景颜色
|
$bg-color: #F5F6FA;
|
$card-bg: #FFFFFF;
|
|
// 功能色
|
$success: #67C23A;
|
$warning: #E6A23C;
|
$danger: #F56C6C;
|
$info: #909399;
|
|
// 圆角
|
$radius-sm: 4rpx;
|
$radius-md: 12rpx;
|
$radius-lg: 24rpx;
|
$radius-xl: 36rpx;
|
|
// 阴影
|
$shadow-sm: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
|
$shadow-md: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
|
$shadow-lg: 0 8rpx 24rpx rgba(0, 0, 0, 0.12);
|
|
// 混入
|
@mixin flex-center {
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
}
|
|
@mixin text-ellipsis {
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
@mixin multi-ellipsis($line: 2) {
|
display: -webkit-box;
|
-webkit-box-orient: vertical;
|
-webkit-line-clamp: $line;
|
overflow: hidden;
|
}
|
|
// 通用样式类
|
.primary-btn {
|
background: $primary-gradient;
|
color: #fff;
|
border-radius: $radius-xl;
|
font-size: 28rpx;
|
height: 80rpx;
|
line-height: 80rpx;
|
text-align: center;
|
box-shadow: 0 4rpx 12rpx rgba($primary-color, 0.3);
|
|
&[disabled] {
|
opacity: 0.6;
|
}
|
|
&:active {
|
transform: scale(0.95);
|
}
|
}
|
|
.card {
|
background: $card-bg;
|
border-radius: $radius-md;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
box-shadow: $shadow-sm;
|
}
|
|
.tag {
|
display: inline-block;
|
font-size: 22rpx;
|
color: $primary-color;
|
background: $primary-light;
|
padding: 4rpx 12rpx;
|
border-radius: $radius-sm;
|
margin-right: 10rpx;
|
}
|
|
.section-title {
|
font-size: 34rpx;
|
font-weight: bold;
|
color: $text-primary;
|
position: relative;
|
padding-left: 20rpx;
|
margin-bottom: 30rpx;
|
|
&::before {
|
content: '';
|
position: absolute;
|
left: 0;
|
top: 50%;
|
transform: translateY(-50%);
|
width: 6rpx;
|
height: 30rpx;
|
background: $primary-color;
|
border-radius: 3rpx;
|
}
|
}
|
|
.price {
|
font-size: 32rpx;
|
color: $danger;
|
font-weight: bold;
|
|
&.free {
|
color: $success;
|
}
|
|
&.original {
|
font-size: 24rpx;
|
color: $text-secondary;
|
text-decoration: line-through;
|
margin-left: 10rpx;
|
}
|
}
|
|
.search-box {
|
@include flex-center;
|
height: 72rpx;
|
background: $card-bg;
|
border-radius: $radius-xl;
|
padding: 0 30rpx;
|
box-shadow: $shadow-md;
|
|
.icon-search {
|
width: 32rpx;
|
height: 32rpx;
|
margin-right: 20rpx;
|
color: $primary-color;
|
}
|
|
input {
|
flex: 1;
|
font-size: 28rpx;
|
color: $text-primary;
|
&::placeholder {
|
color: $text-secondary;
|
}
|
}
|
}
|
|
@import '@/static/style/iconfont.scss';
|
|
page {
|
background-color: $bg-color;
|
}
|
</style>
|