mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-08-14 23:31:01 +00:00
feat: add saving state
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="settings-page">
|
<div class="settings-page">
|
||||||
<div class="settings-title">设置</div>
|
<div class="settings-title">个人资料设置</div>
|
||||||
<div class="profile-section">
|
<div class="profile-section">
|
||||||
<div class="avatar-row">
|
<div class="avatar-row">
|
||||||
<!-- label 充当点击区域,内部隐藏 input -->
|
<!-- label 充当点击区域,内部隐藏 input -->
|
||||||
@@ -34,7 +34,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button @click="save">保存</button>
|
<div v-if="isSaving" class="save-button disabled">保存中...</div>
|
||||||
|
<div v-else @click="save" class="save-button">保存</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -44,6 +45,8 @@ import { API_BASE_URL, toast } from '../main'
|
|||||||
import { getToken, fetchCurrentUser } from '../utils/auth'
|
import { getToken, fetchCurrentUser } from '../utils/auth'
|
||||||
import BaseInput from '../components/BaseInput.vue'
|
import BaseInput from '../components/BaseInput.vue'
|
||||||
import Dropdown from '../components/Dropdown.vue'
|
import Dropdown from '../components/Dropdown.vue'
|
||||||
|
import { hatch } from 'ldrs'
|
||||||
|
hatch.register()
|
||||||
export default {
|
export default {
|
||||||
name: 'SettingsPageView',
|
name: 'SettingsPageView',
|
||||||
components: { BaseInput, Dropdown },
|
components: { BaseInput, Dropdown },
|
||||||
@@ -56,11 +59,15 @@ export default {
|
|||||||
avatarFile: null,
|
avatarFile: null,
|
||||||
role: '',
|
role: '',
|
||||||
publishMode: 'DIRECT',
|
publishMode: 'DIRECT',
|
||||||
passwordStrength: 'LOW'
|
passwordStrength: 'LOW',
|
||||||
|
isLoadingPage: false,
|
||||||
|
isSaving: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
|
this.isLoadingPage = true
|
||||||
const user = await fetchCurrentUser()
|
const user = await fetchCurrentUser()
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
this.username = user.username
|
this.username = user.username
|
||||||
this.introduction = user.introduction || ''
|
this.introduction = user.introduction || ''
|
||||||
@@ -70,6 +77,7 @@ export default {
|
|||||||
this.loadAdminConfig()
|
this.loadAdminConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.isLoadingPage = false
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onAvatarChange(e) {
|
onAvatarChange(e) {
|
||||||
@@ -131,11 +139,13 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.isSaving = true
|
||||||
const res = await fetch(`${API_BASE_URL}/api/users/me`, {
|
const res = await fetch(`${API_BASE_URL}/api/users/me`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||||
body: JSON.stringify({ username: this.username, introduction: this.introduction })
|
body: JSON.stringify({ username: this.username, introduction: this.introduction })
|
||||||
})
|
})
|
||||||
|
this.isSaving = false
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
toast.error(data.error || '保存失败')
|
toast.error(data.error || '保存失败')
|
||||||
@@ -261,4 +271,30 @@ export default {
|
|||||||
margin-top: -10px;
|
margin-top: -10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.save-button {
|
||||||
|
margin-top: 40px;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
color: white;
|
||||||
|
padding: 10px 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-button:hover {
|
||||||
|
background-color: var(--primary-color-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-button.disabled:hover {
|
||||||
|
background-color: var(--primary-color-disabled);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.save-button.disabled {
|
||||||
|
background-color: var(--primary-color-disabled);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user