96 lines
3.1 KiB
Vue
96 lines
3.1 KiB
Vue
<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() {
|
|
// 已认证用户昵称锁定为身份证姓名,禁止再改(冷启动直达本页时的兜底)
|
|
if (loginProfileStore.userType === "N") {
|
|
uni.showToast({ title: t("MinePage.verifiedNoRename"), icon: "none" });
|
|
return;
|
|
}
|
|
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>
|