From 4000c97fa93065b59d7ccaefefb8977d2942ed2f Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期三, 04 二月 2026 08:58:28 +0800
Subject: [PATCH] feat(登录): 添加自动登录功能
---
src/pages/login/index.vue | 79 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 76 insertions(+), 3 deletions(-)
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index ffc4bf1..f88d79b 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -75,6 +75,11 @@
<text class="text">鍜�</text>
<text class="link" @click="navigateToPrivacy">銆婇殣绉佹斂绛栥��</text>
</view>
+
+ <!-- 鐗堟湰鍙� -->
+ <view class="version">
+ <text class="version-text">鐗堟湰鍙凤細{{ versionName }}</text>
+ </view>
</view>
</view>
@@ -86,19 +91,51 @@
import { onLoad } from "@dcloudio/uni-app";
import { type LoginFormData } from "@/api/auth";
import { useUserStore } from "@/store/modules/user";
+import { getToken } from "@/utils/cache";
import { useToast } from "wot-design-uni";
-import { ref } from "vue";
+import { ref, onMounted } from "vue";
const loginFormRef = ref();
const toast = useToast();
const loading = ref(false);
const userStore = useUserStore();
+// 鐗堟湰鍙�
+const versionName = ref("1.0.16");
+
+// 鑾峰彇鐗堟湰鍙�
+onMounted(() => {
+ // #ifdef MP-WEIXIN
+ try {
+ const accountInfo = uni.getAccountInfoSync();
+ if (accountInfo?.miniProgram?.version) {
+ versionName.value = accountInfo.miniProgram.version;
+ }
+ } catch (e) {
+ // 鑾峰彇澶辫触鏃朵娇鐢ㄩ粯璁ゅ��
+ }
+ // #endif
+
+ // #ifdef APP-PLUS
+ try {
+ // @ts-ignore
+ if (plus?.runtime?.version) {
+ // @ts-ignore
+ versionName.value = plus.runtime.version;
+ }
+ } catch (e) {
+ // 鑾峰彇澶辫触鏃朵娇鐢ㄩ粯璁ゅ��
+ }
+ // #endif
+});
+
// 鐧诲綍琛ㄥ崟鏁版嵁
const loginFormData = ref<LoginFormData>({
- username: "32408083",
+ username: "",
+ password: "",
+ // username: "32408083",
// username: "32308027",
- password: "cxjt1234",
+ // password: "cxjt1234",
});
// 鑾峰彇閲嶅畾鍚戝弬鏁�
@@ -109,7 +146,31 @@
} else {
redirect.value = "/pages/index/index";
}
+ tryAutoLogin();
});
+
+const tryAutoLogin = async () => {
+ const token = getToken();
+ if (!token || loading.value) return;
+ loading.value = true;
+ try {
+ if (!userStore.userInfo) {
+ await userStore.getInfo();
+ }
+ if (!userStore.userInfo) return;
+ if (!userStore.isUserInfoComplete()) {
+ uni.navigateTo({
+ url: `/pages/login/complete-profile?redirect=${encodeURIComponent(redirect.value)}`,
+ });
+ } else {
+ uni.reLaunch({
+ url: redirect.value,
+ });
+ }
+ } finally {
+ loading.value = false;
+ }
+};
// 鐧诲綍澶勭悊
const handleLogin = () => {
@@ -382,4 +443,16 @@
.agreement .link {
color: #165dff;
}
+
+.version {
+ display: flex;
+ justify-content: center;
+ margin-top: 20rpx;
+ margin-bottom: 20rpx;
+}
+
+.version-text {
+ font-size: 22rpx;
+ color: #9ca3af;
+}
</style>
--
Gitblit v1.9.3