This commit is contained in:
owenchen committed 2026-10-17 13:22:10 +08:00
1 parent b5d2a2ede0
commit aff58692bb
17 files changed
+1851 -240

No files matched your search

@@ -0,0 +1,90 @@
<script setup lang="ts">
// 修改昵称页:复刻旧系统 WebVue views/login/changeLocalName.vue(旧为弹窗,本页改作「我的」跳入的独立页)
// 旧系统约定:昵称写在登录快照(LoginProfile.UserLocalName)里,改后无法即时刷新,
// 故 UpdateLocalName 成功后照旧退出登录并清档案,回登录页重登以拉取最新昵称
import { useLocale } from "uview-pro";
import { ref } from "vue";
import { useAuthGuard } from "@/composables";
import { pageUrl } from "@/router/routes";
import authService from "@/service/security/authService";
import securityUserService from "@/service/security/securityUserService";
import { useLoginProfileStore } from "@/stores";
const { t } = useLocale();
useAuthGuard();
const loginProfileStore = useLoginProfileStore();
// 预填当前昵称,便于在原值上微调
const localName = ref(loginProfileStore.userLocalName || "");
const loading = ref(false);
/** 退出登录并回登录页:改昵称 / 主动退出共用 */
async function doLogout(): Promise<void> {
try {
await authService.Logout();
}
catch {
// 后端退出失败也要清本地态,避免卡在已登录的假象
}
loginProfileStore.clearStorage();
uni.reLaunch({ url: pageUrl("login") });
}
async function handleSubmit() {
const name = localName.value.trim();
if (!name) {
uni.showToast({ title: t("ChangeLocalNamePage.nameRequired"), icon: "none" });
return;
}
if (name.length < 2) {
uni.showToast({ title: t("ChangeLocalNamePage.nameTooShort"), icon: "none" });
return;
}
loading.value = true;
try {
await securityUserService.UpdateLocalName(name);
uni.showToast({ title: t("ChangeLocalNamePage.success"), icon: "none" });
// 旧系统约定:改昵称后退出重登,刷新登录快照里的昵称
setTimeout(doLogout, 800);
}
catch {
// 错误提示已由 http.interceptor 统一处理
}
finally {
loading.value = false;
}
}
</script>
<template>
<app-page :nav-title="t('ChangeLocalNamePage.title')">
<view class="name-page">
<view class="name-card">
<u-input v-model="localName" :placeholder="t('ChangeLocalNamePage.nameLabel')" border clearable
maxlength="20" @confirm="handleSubmit" />
<u-button type="primary" shape="circle" :loading="loading" :text="t('ChangeLocalNamePage.submitBut')"
@click="handleSubmit" />
</view>
</view>
</app-page>
</template>
<style lang="scss" scoped>
.name-page {
box-sizing: border-box;
min-height: 100%;
padding: 40rpx 24rpx;
}
.name-card {
display: flex;
flex-direction: column;
gap: 40rpx;
padding: 48rpx 32rpx;
border-radius: 24rpx;
background-color: #ffffff;
box-shadow: 0 4rpx 16rpx rgba(31, 35, 41, 0.06);
}
</style>