buhuazhen
3 天以前 4000c97fa93065b59d7ccaefefb8977d2942ed2f
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: "31601016",
  username: "32308027",
  password: "cxjt1234",
  username: "",
  password: "",
  // username: "32408083",
  // username: "32308027",
  // 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>