feature:添加变更用户名功能

This commit is contained in:
cloudy2331
2026-03-27 00:52:59 +08:00
parent 439a8e70de
commit 2c09fd1e1b
2 changed files with 22 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ const activeNav = ref('profile');
var bearer = localStorage.getItem('bearer'); var bearer = localStorage.getItem('bearer');
const loginClientUrl = 'https://www.cloudy233.top/UniAuth'; const loginClientUrl = 'https://www.cloudy233.top/UniAuth';
const loginServerUrl = 'https://www.cloudy233.top:6699'; const loginServerUrl = 'https://www.cloudy233.top:6699';
localStorage.setItem('loginServerUrl', loginServerUrl);
onMounted(() => { onMounted(() => {
BearerVerify(); BearerVerify();

View File

@@ -1,8 +1,28 @@
<script setup> <script setup>
import { ref } from 'vue';
const props = defineProps({ const props = defineProps({
UserName: String, UserName: String,
Email: String, Email: String,
}) })
function ChangeUserName() {
let newUserName = prompt('请输入新的用户名');
if (newUserName !== null && newUserName !== props.UserName && newUserName.length > 0) {
const loginServerUrl = localStorage.getItem('loginServerUrl');
const formData = new FormData();
formData.append('name', newUserName);
fetch(loginServerUrl + '/changename', {
method: 'POST',
headers: {
Authorization: `Bearer ${window.localStorage.getItem('bearer')}`
},
body: formData
}).then(res => {
location.reload(true);
})
}
}
</script> </script>
<template> <template>
@@ -21,7 +41,7 @@ const props = defineProps({
<label class="form-label">用户名</label> <label class="form-label">用户名</label>
<div class="form-row"> <div class="form-row">
<div class="form-value">{{ props.UserName }}</div> <div class="form-value">{{ props.UserName }}</div>
<button class="edit-btn" disabled>编辑</button> <button class="edit-btn" @click="ChangeUserName()">编辑</button>
</div> </div>
</div> </div>