052ec8a54f
Shows the admin a summary of a user's sessions viewed, exam/homework performance, and current term status, with a PDF export action.
393 lines
10 KiB
Vue
393 lines
10 KiB
Vue
<template>
|
|
<div class="user-evaluation">
|
|
<div class="user-evaluation__header">
|
|
<LineTitleBlock
|
|
class="user-evaluation__title"
|
|
title="سیستم ارزیابی کاربر"
|
|
title-en="User Evaluation System"
|
|
/>
|
|
<BaseButton
|
|
text="دانلود PDF"
|
|
:loading="pdfLoading"
|
|
:disabled="isLoading || !evaluation"
|
|
custom-class="user-evaluation__pdf-btn"
|
|
data-pdf-ignore
|
|
@click="onSaveAsPdf"
|
|
>
|
|
<template #appendIcon>
|
|
<SvgIcon name="arrow-left" :size="16" color="#fff" />
|
|
</template>
|
|
</BaseButton>
|
|
</div>
|
|
|
|
<SkeletonLoaderBlock v-if="isLoading" :rows="2" :cols-per-row="3" />
|
|
|
|
<div v-else-if="evaluation" ref="pdfContent" class="user-evaluation__content">
|
|
<header class="user-evaluation__pdf-header">
|
|
<h1>سیستم ارزیابی کاربر</h1>
|
|
<p>{{ fullName }}</p>
|
|
</header>
|
|
|
|
<section class="user-evaluation__section">
|
|
<p class="user-evaluation__section-title">مشخصات هویتی</p>
|
|
<div class="user-evaluation__identity-grid">
|
|
<LineInfoBlock title="نام و نام خانوادگی" :numeric-desc="fullName" />
|
|
<LineInfoBlock title="شماره تماس" :numeric-desc="user?.phone || '—'" />
|
|
<LineInfoBlock title="کد ملی" :numeric-desc="user?.nationalCode || '—'" />
|
|
<LineInfoBlock title="نقش" :desc="roleText" />
|
|
<LineInfoBlock title="تاریخ عضویت" :numeric-desc="joinDateLabel" />
|
|
</div>
|
|
</section>
|
|
|
|
<section class="user-evaluation__section">
|
|
<p class="user-evaluation__section-title">خلاصه عملکرد</p>
|
|
<div class="user-evaluation__stats">
|
|
<div v-for="(stat, i) in stats" :key="i" class="user-evaluation__stat-card">
|
|
<div class="user-evaluation__stat-icon">
|
|
<SvgIcon :name="stat.icon" :size="20" color="var(--color-primary)" />
|
|
</div>
|
|
<div class="user-evaluation__stat-text">
|
|
<p class="user-evaluation__stat-label">{{ stat.label }}</p>
|
|
<p class="user-evaluation__stat-value">
|
|
{{ stat.value }}
|
|
<span v-if="stat.unit" class="user-evaluation__stat-unit">{{ stat.unit }}</span>
|
|
</p>
|
|
<p v-if="stat.subtitle" class="user-evaluation__stat-subtitle">
|
|
{{ stat.subtitle }}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<NoItems v-else title="موردی نیست" desc="اطلاعات ارزیابی این کاربر در دسترس نیست." />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed, ref } from 'vue'
|
|
import { toast } from 'vue3-toastify'
|
|
import { ROLE_LABELS } from '@/enums'
|
|
import BaseButton from '@/components/BaseButton.vue'
|
|
import SvgIcon from '@/components/icons/SvgIcon.vue'
|
|
import NoItems from '@/components/blocks/NoItems.vue'
|
|
import { formatJalaaliDate } from '@/utils/date-utils'
|
|
import LineTitleBlock from '@/components/LineTitleBlock.vue'
|
|
import LineInfoBlock from '@/components/blocks/LineInfoBlock.vue'
|
|
import { useAdminUserEvaluationQuery } from '@/services/query/admin-users'
|
|
import SkeletonLoaderBlock from '@/components/blocks/SkeletonLoaderBlock.vue'
|
|
|
|
const props = defineProps({
|
|
userId: { type: [Number, String], required: true },
|
|
user: { type: Object, default: null },
|
|
})
|
|
|
|
const userIdRef = computed(() => props.userId)
|
|
const { data: evaluation, isLoading } = useAdminUserEvaluationQuery(userIdRef, {
|
|
enabled: () => !!userIdRef.value,
|
|
})
|
|
|
|
const fullName = computed(() => props.user?.name || '—')
|
|
|
|
const roleText = computed(() => {
|
|
const names = (props.user?.roles || [])
|
|
.map((r) => (typeof r === 'string' ? r : r?.name))
|
|
.filter(Boolean)
|
|
if (names.length === 0) return 'بدون نقش'
|
|
return names.map((name) => ROLE_LABELS[name] || name).join('، ')
|
|
})
|
|
|
|
const joinDateLabel = computed(() => formatJalaaliDate(props.user?.createdAt) || '—')
|
|
|
|
const formatMembershipDuration = (days) => {
|
|
if (days == null) return '—'
|
|
if (days < 1) return 'کمتر از یک روز'
|
|
const years = Math.floor(days / 365)
|
|
const months = Math.floor((days % 365) / 30)
|
|
const remDays = Math.floor(days % 30)
|
|
const parts = []
|
|
if (years) parts.push(`${years} سال`)
|
|
if (months) parts.push(`${months} ماه`)
|
|
if (!years && !months) parts.push(`${remDays} روز`)
|
|
return parts.join(' و ')
|
|
}
|
|
|
|
const stats = computed(() => {
|
|
const e = evaluation.value || {}
|
|
const exams = e.exams || {}
|
|
const assignments = e.assignments || {}
|
|
|
|
return [
|
|
{
|
|
icon: 'video',
|
|
label: 'جلسات مشاهدهشده',
|
|
value: e.sessions_viewed ?? 0,
|
|
unit: 'جلسه',
|
|
},
|
|
{
|
|
icon: 'check-square',
|
|
label: 'آزمونهای شرکتکرده',
|
|
value: exams.taken ?? 0,
|
|
unit: 'آزمون',
|
|
subtitle: `قبولشده: ${exams.passed ?? 0}`,
|
|
},
|
|
{
|
|
icon: 'certificate',
|
|
label: 'میانگین امتیاز',
|
|
value: exams.average_score_percent ?? '—',
|
|
unit: exams.average_score_percent == null ? '' : '%',
|
|
},
|
|
{
|
|
icon: 'file',
|
|
label: 'تکالیف انجامشده',
|
|
value: assignments.completed ?? 0,
|
|
unit: 'تکلیف',
|
|
subtitle: `تاییدشده: ${assignments.accepted ?? 0}`,
|
|
},
|
|
{
|
|
icon: 'book',
|
|
label: 'ترم فعلی',
|
|
value: e.current_term?.title || 'بدون ترم',
|
|
unit: '',
|
|
},
|
|
{
|
|
icon: 'clock',
|
|
label: 'مدت عضویت',
|
|
value: formatMembershipDuration(e.member_since?.days),
|
|
unit: '',
|
|
},
|
|
]
|
|
})
|
|
|
|
const pdfContent = ref(null)
|
|
const pdfLoading = ref(false)
|
|
|
|
const onSaveAsPdf = async () => {
|
|
if (!pdfContent.value || isLoading.value || pdfLoading.value) return
|
|
|
|
pdfLoading.value = true
|
|
try {
|
|
await document.fonts?.ready
|
|
|
|
const pdfSource = pdfContent.value.cloneNode(true)
|
|
pdfSource.classList.add('user-evaluation__content--pdf')
|
|
pdfSource.querySelectorAll('[data-pdf-ignore]').forEach((element) => element.remove())
|
|
|
|
const html2pdfModule = await import('html2pdf.js')
|
|
const html2pdf = html2pdfModule.default || html2pdfModule
|
|
|
|
await html2pdf()
|
|
.set({
|
|
margin: [8, 8, 8, 8],
|
|
filename: `user-evaluation-${props.userId}.pdf`,
|
|
image: { type: 'jpeg', quality: 0.98 },
|
|
html2canvas: {
|
|
scale: 2,
|
|
useCORS: true,
|
|
backgroundColor: '#ffffff',
|
|
logging: false,
|
|
},
|
|
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' },
|
|
pagebreak: {
|
|
mode: ['css', 'legacy'],
|
|
avoid: ['.user-evaluation__section', '.user-evaluation__stat-card'],
|
|
},
|
|
})
|
|
.from(pdfSource)
|
|
.save()
|
|
} catch {
|
|
toast.error('ساخت فایل PDF با خطا مواجه شد.')
|
|
} finally {
|
|
pdfLoading.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.user-evaluation {
|
|
width: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.5rem;
|
|
text-align: start;
|
|
|
|
&__header {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 0.625rem;
|
|
}
|
|
|
|
&__title {
|
|
flex: 1;
|
|
min-width: 12rem;
|
|
padding: 0;
|
|
}
|
|
|
|
&__pdf-btn {
|
|
min-width: 9rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
&__pdf-header {
|
|
display: none;
|
|
}
|
|
|
|
&__section {
|
|
margin-bottom: 1.25rem;
|
|
|
|
&:last-child {
|
|
margin-bottom: 0;
|
|
}
|
|
}
|
|
|
|
&__section-title {
|
|
font-family: var(--font-family-fa);
|
|
font-weight: 500;
|
|
font-size: 0.8125rem;
|
|
color: #8a8a8a;
|
|
margin: 0 0 0.625rem;
|
|
}
|
|
|
|
&__identity-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr;
|
|
gap: 0.25rem;
|
|
|
|
@media (min-width: 640px) {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
|
|
@media (min-width: 1024px) {
|
|
grid-template-columns: repeat(3, 1fr);
|
|
}
|
|
}
|
|
|
|
&__stats {
|
|
display: grid;
|
|
grid-template-columns: 1fr;
|
|
gap: 0.75rem;
|
|
|
|
@media (min-width: 640px) {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
|
|
@media (min-width: 1024px) {
|
|
grid-template-columns: repeat(3, 1fr);
|
|
}
|
|
}
|
|
|
|
&__stat-card {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 0.625rem;
|
|
padding: 0.875rem;
|
|
background: rgba(255, 255, 255, 55%);
|
|
box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 8%);
|
|
border-radius: 0.875rem;
|
|
min-width: 0;
|
|
}
|
|
|
|
&__stat-icon {
|
|
flex-shrink: 0;
|
|
width: 2.5rem;
|
|
height: 2.5rem;
|
|
border-radius: 0.625rem;
|
|
background: rgba(243, 102, 117, 8%);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
&__stat-text {
|
|
min-width: 0;
|
|
flex: 1;
|
|
}
|
|
|
|
&__stat-label {
|
|
margin: 0 0 0.25rem;
|
|
font-family: var(--font-family-fa);
|
|
font-weight: 400;
|
|
font-size: 0.75rem;
|
|
line-height: 1.3;
|
|
color: #9a9a9a;
|
|
}
|
|
|
|
&__stat-value {
|
|
margin: 0;
|
|
font-family: var(--font-family-fa);
|
|
font-weight: 700;
|
|
font-size: 1.0625rem;
|
|
line-height: 1.4;
|
|
color: #4b4b4b;
|
|
word-break: break-word;
|
|
}
|
|
|
|
&__stat-unit {
|
|
font-family: var(--font-family-fa);
|
|
font-weight: 400;
|
|
font-size: 0.75rem;
|
|
color: #8a8a8a;
|
|
}
|
|
|
|
&__stat-subtitle {
|
|
margin: 0.25rem 0 0;
|
|
font-family: var(--font-family-fa);
|
|
font-size: 0.6875rem;
|
|
color: #9a9a9a;
|
|
}
|
|
|
|
&__content--pdf {
|
|
width: 100%;
|
|
padding: 0.25rem;
|
|
background: #fff;
|
|
box-sizing: border-box;
|
|
direction: rtl;
|
|
}
|
|
|
|
&__content--pdf &__pdf-header {
|
|
display: block;
|
|
margin-bottom: 1.5rem;
|
|
padding-bottom: 0.75rem;
|
|
border-bottom: 1px solid #eee;
|
|
text-align: right;
|
|
break-after: avoid;
|
|
|
|
h1 {
|
|
margin: 0;
|
|
font-family: var(--font-family-fa);
|
|
font-size: 1.25rem;
|
|
font-weight: 500;
|
|
color: #4b4b4b;
|
|
}
|
|
|
|
p {
|
|
margin: 0.25rem 0 0;
|
|
font-family: var(--font-family-fa);
|
|
font-size: 0.875rem;
|
|
color: #808080;
|
|
}
|
|
}
|
|
|
|
&__content--pdf &__section {
|
|
margin-bottom: 1rem;
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
}
|
|
|
|
&__content--pdf &__identity-grid {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
|
|
&__content--pdf &__stats {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
|
|
&__content--pdf &__stat-card {
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
}
|
|
}
|
|
</style>
|