WXL
11 小时以前 05c363fdd7ab04e3bd9a753e2c5d5bfff04d681c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<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) =>
  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 });
 
  // ✅ 改为检测 code 参数
  if (query.code) {
    console.log('检测到免登码(code),准备跳转登录页');
    if (currentPage.includes('login/Login')) {
      console.log('当前已在登录页,等待login.vue处理');
      return;
    }
    if (isProcessingSSO) return;
    isProcessingSSO = true;
    uni.__isSSOHandling = true;
 
    const queryParams = [];
    if (currentPage) {
      queryParams.push(`redirect=${encodeURIComponent('/' + currentPage)}`);
    }
    // 携带 code 参数
    queryParams.push(`code=${encodeURIComponent(query.code)}`);
    // 注意:其他业务参数(如 fcid)已不在 URL 上,不需要携带
 
    console.log('跳转到登录页,参数:', queryParams);
    setTimeout(() => {
      uni.redirectTo({
        url: `/pages/login/Login?${queryParams.join('&')}`,
        success: () => {
          setTimeout(() => {
            uni.__isSSOHandling = false;
            isProcessingSSO = false;
          }, 500);
        },
        fail: () => {
          uni.__isSSOHandling = false;
          isProcessingSSO = false;
        }
      });
    }, 200);
    return;
  }
 
  // 原有 token 检查逻辑不变(但注意去掉 SSO 参数判断)
  handleTokenCheck();
});
 
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 });
 
 
  if (!token) {
    if (!isPageInWhiteList(currentPage)) {
      console.log("无token且不在白名单,跳转登录页");
      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>