|
5 | 5 | <h2>修改密码</h2> |
6 | 6 | </template> |
7 | 7 | <div class="change-password-content"> |
| 8 | + <!-- 显示用户信息 --> |
| 9 | + <div v-if="authStore.user" class="user-info-section"> |
| 10 | + <a-descriptions :column="1" bordered size="small"> |
| 11 | + <a-descriptions-item label="用户名"> |
| 12 | + {{ authStore.user.username }} |
| 13 | + </a-descriptions-item> |
| 14 | + <a-descriptions-item v-if="authStore.user.nickname" label="昵称"> |
| 15 | + {{ authStore.user.nickname }} |
| 16 | + </a-descriptions-item> |
| 17 | + </a-descriptions> |
| 18 | + </div> |
8 | 19 | <a-alert |
9 | 20 | v-if="!hasPassword" |
10 | 21 | message="首次登录" |
|
66 | 77 | import { ref, onMounted } from 'vue' |
67 | 78 | import { useRouter } from 'vue-router' |
68 | 79 | import { message } from 'ant-design-vue' |
69 | | -import { changePassword, getUserInfo } from '@/api/auth' |
| 80 | +import { changePassword } from '@/api/auth' |
70 | 81 | import { useAuthStore } from '@/stores/auth' |
71 | 82 |
|
72 | 83 | const router = useRouter() |
@@ -138,7 +149,10 @@ const changePasswordRules = { |
138 | 149 | // 检查用户是否已有密码 |
139 | 150 | const checkUserPassword = async () => { |
140 | 151 | try { |
141 | | - await getUserInfo() // 验证用户已登录 |
| 152 | + // 如果 authStore 中没有用户信息,则加载 |
| 153 | + if (!authStore.user) { |
| 154 | + await authStore.loadUserInfo() |
| 155 | + } |
142 | 156 | // 如果用户有密码,后端会在GetUserInfo中返回相关信息 |
143 | 157 | // 这里我们通过尝试修改密码时的错误来判断 |
144 | 158 | // 但为了简化,我们可以假设首次登录的用户没有密码 |
@@ -217,5 +231,14 @@ onMounted(() => { |
217 | 231 | .change-password-content { |
218 | 232 | padding: 20px 0; |
219 | 233 | } |
| 234 | +
|
| 235 | +.user-info-section { |
| 236 | + margin-bottom: 24px; |
| 237 | +} |
| 238 | +
|
| 239 | +:deep(.ant-descriptions-item-label) { |
| 240 | + font-weight: 500; |
| 241 | + width: 80px; |
| 242 | +} |
220 | 243 | </style> |
221 | 244 |
|
0 commit comments