feat: Implement core e-learning features including course discovery, classroom components, user profile management, and internationalization for English and Thai.

This commit is contained in:
supalerk-ar66 2026-02-11 11:25:55 +07:00
parent e7a2ac8b5a
commit 7ead98375e
11 changed files with 107 additions and 43 deletions

View file

@ -15,14 +15,21 @@ const emit = defineEmits<{
(e: 'enroll', courseId: number): void;
}>();
const { locale, t } = useI18n();
const getLocalizedText = (text: any) => {
if (!text) return ''
if (typeof text === 'string') return text
return text.th || text.en || ''
const currentLocale = locale.value as 'th' | 'en'
return text[currentLocale] || text.th || text.en || ''
}
const formatPrice = (price: number) => {
return new Intl.NumberFormat('th-TH', { style: 'currency', currency: 'THB' }).format(price);
return new Intl.NumberFormat(locale.value === 'th' ? 'th-TH' : 'en-US', {
style: 'currency',
currency: 'THB'
}).format(price);
}
const enrollmentLoading = ref(false);
@ -43,7 +50,7 @@ const handleEnroll = () => {
<q-btn
flat
icon="arrow_back"
label="ย้อนกลับ"
:label="$t('common.back')"
class="mb-6 font-bold text-slate-500 hover:text-slate-800 dark:text-slate-400 dark:hover:text-white transition-colors"
@click="emit('back')"
/>
@ -72,7 +79,7 @@ const handleEnroll = () => {
/>
<div class="absolute inset-0 flex items-center justify-center">
<div class="w-16 h-16 bg-white/20 backdrop-blur-sm rounded-full flex items-center justify-center ring-1 ring-white/50">
<q-icon name="play_arrow" size="40px" class="text-white" />
<q-icon name="play_arrow" size="40px" class="text-white" />
</div>
</div>
</template>
@ -86,11 +93,11 @@ const handleEnroll = () => {
<div class="flex flex-wrap items-center gap-4 text-sm text-slate-500 dark:text-slate-400 mb-6">
<span class="flex items-center gap-1 bg-slate-100 dark:bg-slate-800 px-3 py-1 rounded-full text-slate-700 dark:text-slate-300 font-medium">
<q-icon name="category" size="16px" class="text-blue-500" />
{{ course.category?.name?.th || course.category?.name?.en || 'ทั่วไป' }}
{{ getLocalizedText(course.category?.name) }}
</span>
<span class="flex items-center gap-1">
<q-icon name="schedule" size="16px" />
{{ course.duration_minutes || 60 }} นาท
{{ course.duration_minutes || 60 }} {{ $t('course.minutes') }}
</span>
<span class="flex items-center gap-1">
<q-icon name="person" size="16px" />
@ -107,14 +114,14 @@ const handleEnroll = () => {
<div class="bg-slate-50 dark:bg-white/5 rounded-3xl p-6 md:p-8">
<h3 class="text-xl font-bold text-slate-900 dark:text-white mb-6 flex items-center gap-2">
<q-icon name="list_alt" class="text-blue-600 dark:text-blue-400" />
เนอหาบทเรยน
{{ $t('course.courseContent') }}
</h3>
<div class="space-y-4">
<div v-for="(chapter, idx) in course.chapters" :key="chapter.id" class="bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-slate-800 overflow-hidden">
<div class="px-6 py-4 bg-slate-100 dark:bg-white/5 font-bold text-slate-800 dark:text-white flex justify-between items-center">
<span>{{ idx + 1 }}. {{ getLocalizedText(chapter.title) }}</span>
<span class="text-xs text-slate-500 dark:text-slate-400 font-normal">{{ chapter.lessons?.length || 0 }} บทเรยน</span>
<span>{{ Number(idx) + 1 }}. {{ getLocalizedText(chapter.title) }}</span>
<span class="text-xs text-slate-500 dark:text-slate-400 font-normal">{{ chapter.lessons?.length || 0 }} {{ $t('course.lessonsUnit') }}</span>
</div>
<div class="divide-y divide-slate-100 dark:divide-slate-800">
<div v-for="lesson in chapter.lessons" :key="lesson.id" class="px-6 py-3 flex items-center gap-3 text-sm text-slate-600 dark:text-slate-400 hover:bg-slate-50 dark:hover:bg-white/5 transition-colors">
@ -124,13 +131,13 @@ const handleEnroll = () => {
size="18px"
/>
<span class="flex-1">{{ getLocalizedText(lesson.title) }}</span>
<span v-if="lesson.duration_minutes" class="text-slate-400 dark:text-slate-500 text-xs">{{ lesson.duration_minutes }} นาที</span>
<span v-if="lesson.duration_minutes" class="text-slate-400 dark:text-slate-500 text-xs">{{ lesson.duration_minutes }} {{ $t('course.minutes') }}</span>
<q-icon v-if="lesson.is_locked !== false" name="lock" size="14px" class="text-slate-300 dark:text-slate-600" />
</div>
</div>
</div>
<div v-if="!course.chapters || course.chapters.length === 0" class="text-center text-slate-400 dark:text-slate-600 py-8">
งไมเนอหาในขณะน
{{ $t('course.noContent') }}
</div>
</div>
</div>
@ -145,10 +152,10 @@ const handleEnroll = () => {
<div class="relative">
<div class="text-3xl font-black text-slate-900 dark:text-white mb-2 font-display">
{{ course.price > 0 ? formatPrice(course.price) : 'เรียนฟรี' }}
{{ course.price > 0 ? formatPrice(course.price) : $t('course.free') }}
</div>
<div v-if="course.price > 0" class="text-sm text-slate-500 dark:text-slate-400 mb-6 line-through">
{{ formatPrice(course.price * 2) }}
{{ formatPrice(Number(course.price) * 2) }}
</div>
<q-btn
@ -157,13 +164,13 @@ const handleEnroll = () => {
size="lg"
color="primary"
class="w-full mb-4 shadow-lg shadow-blue-600/30 font-bold"
:label="user ? (course.enrolled ? 'เข้าสู่บทเรียน' : (course.price > 0 ? 'ซื้อคอร์สเรียนนี้' : 'ลงทะเบียนเรียนฟรี')) : 'เข้าสู่ระบบเพื่อลงทะเบียน'"
:label="user ? (course.enrolled ? $t('course.startLearning') : (course.price > 0 ? $t('course.buyNow') : $t('course.enrollFree'))) : $t('course.loginToEnroll')"
:loading="enrollmentLoading"
@click="handleEnroll"
/>
<div class="text-xs text-center text-slate-400 dark:text-slate-500">
บประกนความพงพอใจ นเงนภายใน 7
{{ $t('course.satisfactionGuarantee') }}
</div>
<hr class="my-6 border-slate-100 dark:border-slate-800">
@ -171,15 +178,15 @@ const handleEnroll = () => {
<div class="space-y-3 block">
<div class="flex items-center gap-3 text-sm text-slate-600 dark:text-slate-400">
<q-icon name="check_circle" class="text-green-500" />
เขาเรยนไดตลอดช
{{ $t('course.lifetimeAccess') }}
</div>
<div class="flex items-center gap-3 text-sm text-slate-600 dark:text-slate-400">
<q-icon name="check_circle" class="text-green-500" />
ทำแบบทดสอบไมจำก
{{ $t('course.unlimitedQuizzes') }}
</div>
<div class="flex items-center gap-3 text-sm text-slate-600 dark:text-slate-400">
<q-icon name="check_circle" class="text-green-500" />
ใบประกาศนยบตรเมอเรยนจบ
{{ $t('course.certificate') }} ({{ $t('course.available') }})
</div>
</div>
</div>