@liujitcn/kratos-uni-app-core 0.0.81 → 0.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,13 +2,13 @@
2
2
  import { useSettingStore, useThemeStore, useUserStore } from '../../../stores'
3
3
  import type { LoginRequest } from '../../../rpc/base/v1/login'
4
4
  import { LoginStatus, type LoginResponse } from '../../../rpc/base/v1/login'
5
- import { onLoad, onUnload } from '@dcloudio/uni-app'
5
+ import { onLoad, onShow, onUnload } from '@dcloudio/uni-app'
6
6
  import { computed, defineAsyncComponent, nextTick, reactive, ref, watch } from 'vue'
7
7
  import { defLoginService } from '../../../api/base/v1/login'
8
8
  import { defMfaService } from '../../../api/base/v1/mfa'
9
9
  import defaultLogo from '../../../static/images/logo_icon.png'
10
10
  import { formatSrc } from '../../../utils'
11
- import { homeTabPage } from '../../../utils/navigation'
11
+ import { prepareLoginPage, restoreLoginRedirect, returnFromLogin } from '../../../utils/navigation'
12
12
  import { encryptPassword } from '../../../utils/secretCrypto'
13
13
  import { createWebAuthnCredential, getWebAuthnAssertion } from '../../../utils/webauthn'
14
14
  import { navigateAppRoute } from '../../../navigation'
@@ -600,11 +600,9 @@ const refreshCaptcha = async () => {
600
600
  }
601
601
  }
602
602
 
603
- /** 返回上一页;登录页可能是冷启动首页,无上级页面时回主页。 */
603
+ /** 返回首页并结束本次登录回跳,避免上一页再次要求登录。 */
604
604
  const goBack = () => {
605
- uni.navigateBack({
606
- fail: () => uni.reLaunch({ url: homeTabPage }),
607
- })
605
+ void returnFromLogin()
608
606
  }
609
607
 
610
608
  // 页面加载或普通表单刷新验证码,行为验证码延迟到登录弹窗打开时再请求。
@@ -786,6 +784,7 @@ const onSubmit = async () => {
786
784
  }
787
785
  }
788
786
  // #endif
787
+ /** 完成用户资料加载并替换到本次登录目标,直接登录默认进入首页。 */
789
788
  const loginSuccess = async () => {
790
789
  await userStore.getUserProfile()
791
790
  // 成功提示
@@ -793,13 +792,7 @@ const loginSuccess = async () => {
793
792
  if (loginSuccessTimer) clearTimeout(loginSuccessTimer)
794
793
  loginSuccessTimer = setTimeout(() => {
795
794
  loginSuccessTimer = undefined
796
- const lastRoute = uni.getStorageSync('lastRoute') || homeTabPage
797
- if (lastRoute.startsWith(homeTabPage)) {
798
- uni.setStorageSync('SwitchTabIndex', true)
799
- }
800
- uni.removeStorageSync('lastRoute')
801
-
802
- uni.reLaunch({ url: lastRoute })
795
+ void restoreLoginRedirect()
803
796
  }, 500)
804
797
  }
805
798
 
@@ -882,8 +875,13 @@ const loadLoginSettings = () => {
882
875
  /** 确保登录前已完成移动端配置加载。 */
883
876
  const ensureLoginSettings = () => loadLoginSettings()
884
877
 
885
- // 获取 code 登录凭证
886
- onLoad(() => {
878
+ let loginRedirect: string | undefined
879
+ onLoad((options) => {
880
+ loginRedirect = options?.redirect
881
+ })
882
+
883
+ onShow(() => {
884
+ if (!prepareLoginPage(loginRedirect)) return
887
885
  void loadLoginSettings()
888
886
  })
889
887
 
@@ -918,10 +916,6 @@ onUnload(() => {
918
916
  </view>
919
917
  </view>
920
918
  <view class="k-glass k-glass--lit login-panel">
921
- <view class="k-cnr k-cnr--tl" aria-hidden="true"></view>
922
- <view class="k-cnr k-cnr--tr" aria-hidden="true"></view>
923
- <view class="k-cnr k-cnr--bl" aria-hidden="true"></view>
924
- <view class="k-cnr k-cnr--br" aria-hidden="true"></view>
925
919
  <view class="login-form">
926
920
  <!-- 网页端表单登录 -->
927
921
  <!-- #ifdef H5 -->