feat: add setting page loading

This commit is contained in:
tim
2025-07-08 14:32:40 +08:00
parent 6f4d6aa924
commit a1c96179ec
+9 -5
View File
@@ -125,6 +125,9 @@ export default {
} }
}, },
async save() { async save() {
this.isSaving = true
do {
const token = getToken() const token = getToken()
this.usernameError = '' this.usernameError = ''
if (!this.username) { if (!this.username) {
@@ -134,7 +137,7 @@ export default {
} }
if (this.usernameError) { if (this.usernameError) {
toast.error(this.usernameError) toast.error(this.usernameError)
return break
} }
if (this.avatarFile) { if (this.avatarFile) {
const form = new FormData() const form = new FormData()
@@ -149,20 +152,18 @@ export default {
this.avatar = data.url this.avatar = data.url
} else { } else {
toast.error(data.error || '上传失败') toast.error(data.error || '上传失败')
return break
} }
} }
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 || '保存失败')
return break
} }
if (this.role === 'ADMIN') { if (this.role === 'ADMIN') {
await fetch(`${API_BASE_URL}/api/admin/config`, { await fetch(`${API_BASE_URL}/api/admin/config`, {
@@ -172,6 +173,9 @@ export default {
}) })
} }
toast.success('保存成功') toast.success('保存成功')
} while (!this.isSaving)
this.isSaving = false
}, },
} }
} }