frontend
This commit is contained in:
261
frontend/src/views/dashboard/Settings.vue
Normal file
261
frontend/src/views/dashboard/Settings.vue
Normal file
@@ -0,0 +1,261 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-base-100 p-4 md:p-6">
|
||||
<BreadcrumbHeader title="User Details" />
|
||||
|
||||
<div class="max-w-3xl mx-auto">
|
||||
<div class="card card-bordered bg-base-100 shadow-sm" v-if="user">
|
||||
<div class="card-body space-y-5">
|
||||
<div class="flex flex-col md:flex-row items-center gap-6">
|
||||
<div class="avatar placeholder" v-if="!user?.avatar_url">
|
||||
<div class="glass bg-neutral text-neutral-content rounded-full w-16 sm:w-20">
|
||||
<span class="text-2xl sm:text-3xl">{{ user?.username?.[0]?.toUpperCase() }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="avatar" v-else>
|
||||
<div class="w-16 sm:w-20 rounded-full ring ring-primary ring-offset-base-100 ring-offset-2">
|
||||
<img :src="user?.avatar_url" :alt="user?.name" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex-grow text-center md:text-left">
|
||||
<h2 class="text-2xl font-semibold text-base-content">
|
||||
{{ user?.name || user?.username }}
|
||||
</h2>
|
||||
<div class="flex items-center justify-center md:justify-start gap-2 mt-2">
|
||||
<span class="badge border-none px-0">
|
||||
<CircleCheckBig v-if="user.active" class="h-5 w-5 bg-green-300 rounded-full" />
|
||||
<CircleX v-else class="h-5 w-5 bg-rose-300 rounded-full" />
|
||||
</span>
|
||||
<span class="badge badge-outline"
|
||||
:class="user.role > 0 ? 'badge-warning' : 'badge-success'">{{
|
||||
formatRole(user?.role) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2 mt-4 md:mt-0">
|
||||
<input type="checkbox" class="toggle toggle-md"
|
||||
:class="user.active ? 'toggle-success' : 'toggle-error'" v-model="user.active"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="divider mt-1 mb-0"></div>
|
||||
|
||||
<form @submit.prevent="updateUser" class="space-y-4">
|
||||
|
||||
<div class="space-y-3">
|
||||
<h3 class="text-base font-medium text-base-content mb-3">
|
||||
Basic Information
|
||||
</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-3">
|
||||
<div class="form-control w-full">
|
||||
<label for="name" class="label pb-1">
|
||||
<span class="label-text text-sm font-medium text-base-content/80">Name</span>
|
||||
</label>
|
||||
<input id="name" type="text" v-model="user.name" placeholder="Full name"
|
||||
class="input input-bordered input-sm w-full" />
|
||||
</div>
|
||||
|
||||
<div class="form-control w-full">
|
||||
<label for="username" class="label pb-1">
|
||||
<span class="label-text text-sm font-medium text-base-content/80">
|
||||
Username <span class="text-red-500">*</span>
|
||||
</span>
|
||||
</label>
|
||||
<input id="username" type="text" v-model="user.username"
|
||||
placeholder="Select a username" class="input input-bordered input-sm w-full"
|
||||
required />
|
||||
</div>
|
||||
|
||||
<div class="form-control w-full">
|
||||
<label for="email" class="label pb-1">
|
||||
<span class="label-text text-sm font-medium text-base-content/80">Email
|
||||
Address</span>
|
||||
</label>
|
||||
<div class="relative">
|
||||
<input id="email" type="email" v-model="user.email"
|
||||
placeholder="email@example.com"
|
||||
class="input input-bordered input-sm w-full" />
|
||||
<button type="button" @click="toggleEmailVerify"
|
||||
class="absolute inset-y-0 right-0 px-3 flex items-center text-base-content/60 hover:text-base-content focus:outline-none rounded-r-md"
|
||||
aria-label="Toggle password visibility">
|
||||
<BadgeCheck v-if="user.email_verified"
|
||||
class="w-4 h-4 bg-green-300 rounded-full" />
|
||||
<div v-else class="tooltip tooltip-top" data-tip="Send verification email">
|
||||
<Send class="w-4 h-4" />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-control w-full">
|
||||
<label for="password" class="label pb-1">
|
||||
<span class="label-text text-sm font-medium text-base-content/80">
|
||||
Password <span class="text-xs text-base-content/60">(Leave blank to keep
|
||||
unchanged)</span>
|
||||
</span>
|
||||
</label>
|
||||
<div class="relative">
|
||||
<input id="password" :type="isPasswordVisible ? 'text' : 'password'"
|
||||
v-model="user.password" placeholder="Enter new password"
|
||||
class="input input-bordered input-sm w-full pr-10" />
|
||||
<button type="button" @click="togglePasswordVisibility"
|
||||
class="absolute inset-y-0 right-0 px-3 flex items-center text-base-content/60 hover:text-base-content focus:outline-none rounded-r-md"
|
||||
aria-label="Toggle password visibility">
|
||||
<EyeOff v-if="!isPasswordVisible" class="w-4 h-4" />
|
||||
<Eye v-else class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="collapse collapse-arrow border border-base-300/30 rounded-md mt-4">
|
||||
<input type="checkbox" class="min-h-0 py-2" checked />
|
||||
<div class="collapse-title text-base font-medium min-h-0 py-2">
|
||||
Advanced Options
|
||||
</div>
|
||||
<div class="collapse-content">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-3 pt-2">
|
||||
<div class="form-control w-full">
|
||||
<label for="role" class="label pb-1">
|
||||
<span
|
||||
class="label-text text-sm font-medium text-base-content/80">Role</span>
|
||||
</label>
|
||||
<select id="role" v-model="user.role"
|
||||
class="select select-bordered select-sm w-full">
|
||||
<option :value="0">User</option>
|
||||
<option :value="10">Admin</option>
|
||||
<option v-if="user.role > 10" :value="20">Root</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-control w-full">
|
||||
<label for="language" class="label pb-1">
|
||||
<span
|
||||
class="label-text text-sm font-medium text-base-content/80">Language</span>
|
||||
</label>
|
||||
<select id="language" v-model="user.language"
|
||||
class="select select-bordered select-sm w-full">
|
||||
<option value="en">English</option>
|
||||
<option value="zh">中文</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="md:col-span-2 form-control w-full">
|
||||
<label for="quota" class="label pb-1">
|
||||
<span
|
||||
class="label-text text-sm font-medium text-base-content/80">Quota</span>
|
||||
</label>
|
||||
<div class="flex items-center space-x-3">
|
||||
<input id="quota" type="number" v-model="user.quota"
|
||||
placeholder="Enter quota amount"
|
||||
class="input input-bordered input-sm flex-grow"
|
||||
:disabled="user.unlimited_quota" />
|
||||
<label class="label cursor-pointer space-x-2 p-0">
|
||||
<input type="checkbox" v-model="user.unlimited_quota"
|
||||
class="checkbox checkbox-sm" />
|
||||
<span class="label-text text-sm text-base-content/90">Unlimited</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-actions justify-end pt-4">
|
||||
<button type="submit" class="btn btn-outline btn-success btn-sm">
|
||||
Update
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="max-w-3xl mx-auto">
|
||||
<div class="card card-bordered bg-base-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="flex justify-center items-center py-10">
|
||||
<span class="loading loading-spinner loading-lg"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, inject } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { Eye, EyeOff, BadgeCheck, Send, CircleX, CircleCheckBig, TrashIcon, Infinity } from 'lucide-vue-next'; // Ensure lucide-vue-next is installed
|
||||
import { useAuthStore } from '../../stores/auth';
|
||||
import BreadcrumbHeader from '@/components/dashboard/BreadcrumbHeader.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const authStore = useAuthStore();
|
||||
const { setToast } = inject('toast');
|
||||
|
||||
const loading = computed(() => authStore.loading);
|
||||
const user = computed(() => authStore.user);
|
||||
|
||||
onMounted(async () => {
|
||||
await authStore.refreshProfile()
|
||||
});
|
||||
|
||||
const updateUser = async () => {
|
||||
if (!user.value) return;
|
||||
try {
|
||||
const payload = {
|
||||
name: user.value.name,
|
||||
username: user.value.username,
|
||||
email: user.value.email,
|
||||
language: user.value.language,
|
||||
};
|
||||
if (user.value.password) {
|
||||
payload.password = user.value.password;
|
||||
}
|
||||
const res = await userStore.editUser(userId.value, payload);
|
||||
console.log('updateUser', res)
|
||||
if (res.data?.code == 200) {
|
||||
setToast(`User ${userId.value} updated`, 'success');
|
||||
}
|
||||
await userStore.refreshUser(userId.value);
|
||||
} catch (err) {
|
||||
console.error('Error updating user:', err.response?.data?.data?.error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//显示密码
|
||||
const isPasswordVisible = ref(false);
|
||||
const togglePasswordVisibility = () => {
|
||||
isPasswordVisible.value = !isPasswordVisible.value;
|
||||
};
|
||||
|
||||
// 格式化角色
|
||||
const formatRole = (role) => {
|
||||
switch (true) {
|
||||
case role > 10:
|
||||
return 'Root';
|
||||
case role > 0:
|
||||
return 'Admin';
|
||||
default:
|
||||
return 'U';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const toggleEmailVerify = () => {
|
||||
if (user.value && !user.value.email_verified) {
|
||||
// todo
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user