<script setup>
|
import { onLaunch } from '@dcloudio/uni-app';
|
import { getToken } from '@/utils/auth';
|
import { useUserStore } from '@/stores/user';
|
|
// 定义页面白名单
|
const pageWhiteList = [
|
'pages/login/Login',
|
'pages/login/DingTalkLogin'
|
];
|
|
// 白名单检查
|
const isPageInWhiteList = (currentPage) => {
|
return pageWhiteList.some(path => currentPage.includes(path));
|
}
|
|
// 全局标记
|
let isProcessingSSO = false;
|
|
onLaunch(() => {
|
console.log('App Launch');
|
|
const launchOptions = uni.getLaunchOptionsSync();
|
const currentPage = launchOptions.path || '';
|
const query = launchOptions.query || {};
|
console.log('启动参数:', { currentPage, query, launchOptions });
|
|
// ✅ 第一步:检查是否SSO链接
|
if (query.userName && query.passWord) {
|
console.log('检测到SSO参数,处理中...');
|
|
// 如果已经在登录页,直接处理
|
if (currentPage.includes('login/Login')) {
|
console.log('当前已在登录页,等待login.vue处理SSO');
|
return;
|
}
|
|
// 防止重复处理
|
if (isProcessingSSO) {
|
console.log('正在处理SSO中,跳过');
|
return;
|
}
|
|
isProcessingSSO = true;
|
|
// ✅ 构建登录页URL,携带所有原始参数
|
const queryParams = [];
|
|
// 携带原始页面路径
|
if (currentPage) {
|
queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
|
}
|
|
// 携带所有查询参数
|
for (const key in query) {
|
if (query[key]) {
|
queryParams.push(`${key}=${encodeURIComponent(query[key])}`);
|
}
|
}
|
|
console.log('跳转到登录页,参数:', queryParams);
|
|
// 延迟跳转,避免冲突
|
setTimeout(() => {
|
uni.redirectTo({
|
url: `/pages/login/Login?${queryParams.join('&')}`,
|
success: () => {
|
console.log('SSO跳转成功');
|
isProcessingSSO = false;
|
},
|
fail: () => {
|
console.log('SSO跳转失败');
|
isProcessingSSO = false;
|
}
|
});
|
}, 200);
|
|
return;
|
}
|
|
// 第二步:正常token检查
|
handleTokenCheck();
|
});
|
|
// token检查函数
|
const handleTokenCheck = async () => {
|
const userStore = useUserStore();
|
const token = getToken();
|
const launchOptions = uni.getLaunchOptionsSync();
|
const currentPage = launchOptions.path || '';
|
const query = launchOptions.query || {};
|
|
console.log('token检查:', {
|
hasToken: !!token,
|
currentPage,
|
query
|
});
|
|
// 如果有SSO参数,已在上一步处理
|
if (query.userName && query.passWord) {
|
return;
|
}
|
|
if (!token) {
|
if (!isPageInWhiteList(currentPage)) {
|
console.log('无token且不在白名单,跳转登录页');
|
|
// 构建跳转URL,携带当前页面信息
|
let loginUrl = '/pages/login/Login';
|
if (currentPage) {
|
const queryParams = [];
|
queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
|
|
// 携带其他参数
|
for (const key in query) {
|
if (query[key]) {
|
queryParams.push(`${key}=${encodeURIComponent(query[key])}`);
|
}
|
}
|
|
if (queryParams.length > 0) {
|
loginUrl += `?${queryParams.join('&')}`;
|
}
|
}
|
|
setTimeout(() => {
|
uni.redirectTo({ url: loginUrl });
|
}, 100);
|
}
|
return;
|
}
|
|
try {
|
const current = await uni.$uapi.get("/getInfo");
|
|
if (current && current.user) {
|
userStore.setUserInfo(current.user);
|
if (current.roles) {
|
userStore.setroleKey(current.roles);
|
}
|
|
if (isPageInWhiteList(currentPage)) {
|
uni.switchTab({ url: '/pages/index/index' });
|
}
|
} else {
|
console.error('token无效');
|
userStore.clearUser();
|
if (!isPageInWhiteList(currentPage)) {
|
uni.redirectTo({ url: '/pages/login/Login' });
|
}
|
}
|
} catch (error) {
|
console.error('初始化失败:', error);
|
userStore.clearUser();
|
if (!isPageInWhiteList(currentPage)) {
|
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>
|