2026-01-20 16:36:20 +07:00
|
|
|
# 🛠️ Web Development Documentation: e-Learning Platform (Frontend)
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
เอกสารฉบับนี้สรุปรายละเอียดทางเทคนิค โครงสร้างโค้ด และการทำงานของระบบ **Frontend-Learner** (อัปเดตล่าสุด)
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-01-20 16:36:20 +07:00
|
|
|
---
|
|
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
## 🏗️ 1. Technical Foundation (รากฐานทางเทคนิค)
|
2026-01-20 16:36:20 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
รวมข้อมูลเครื่องมือ, ระบบความปลอดภัย และประสิทธิภาพการทำงานไว้ด้วยกัน
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
### 1.1 Tech Stack
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
- **Core:** [Nuxt 3](https://nuxt.com) (Vue 3 Composition API), TypeScript `^5.0`
|
2026-02-02 15:45:09 +07:00
|
|
|
- **UI Framework:** Quasar Framework (via `nuxt-quasar-ui`)
|
|
|
|
|
- **Styling:** Tailwind CSS (Utility) + Vanilla CSS Variables (Theming/Dark Mode)
|
|
|
|
|
- **State Management:** `ref`/`reactive` (Local) + `useState` (Global/Shared State)
|
|
|
|
|
- **Localization:** `@nuxtjs/i18n` (Supports JSON locales in `i18n/locales/`)
|
|
|
|
|
- **Media Control:** `useMediaPrefs` (Command Pattern for global volume/mute state)
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
### 1.2 Core Systems & Security
|
2026-01-23 10:11:30 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
- **Authentication:**
|
|
|
|
|
- ใช้ **JWT** (Access Token 1 วัน, Refresh Token 7 วัน)
|
|
|
|
|
- เก็บ Token ใน `useCookie` (Secure, SameSite)
|
|
|
|
|
- Middleware (`middleware/auth.ts`) ป้องกัน Route ตามสถานะ
|
|
|
|
|
- **API Handling:**
|
|
|
|
|
- ใช้ `runtimeConfig.public.apiBase` เชื่องโยง Backend
|
|
|
|
|
- Auto-attach Bearer Token ใน `useAuth` และ `useCourse`
|
2026-01-27 14:34:39 +07:00
|
|
|
- **Performance:**
|
2026-02-02 15:45:09 +07:00
|
|
|
- **Hybrid Progress Saving:** บันทึกเวลาเรียนลง LocalStorage (ถี่) และ Server (Throttle 15s) เพื่อความแม่นยำสูงสุด
|
|
|
|
|
- **Caching:** ใช้ `useState` จำข้อมูล Profile และ Categories ลด request
|
2026-01-23 10:11:30 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
---
|
2026-01-23 10:11:30 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
## 📂 2. Frontend Structure (โครงสร้างหน้าเว็บและ UI)
|
2026-01-23 10:11:30 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
### 2.1 Application Routes (`pages/`)
|
2026-01-23 10:11:30 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
| Module | ไฟล์ | Path | หน้าที่ |
|
|
|
|
|
| :---------- | :------------------------- | :---------------------- | :------------------------------------------- |
|
|
|
|
|
| **Public** | `index.vue` | `/` | หน้าแรก Landing Page |
|
|
|
|
|
| | `browse/discovery.vue` | `/browse/discovery` | **ระบบค้นหาและ Filter คอร์ส** (Catalog) |
|
|
|
|
|
| | `course/[id].vue` | `/course/:id` | **หน้ารายละเอียดคอร์ส** (Course Detail) |
|
|
|
|
|
| **Auth** | `auth/login.vue` | `/auth/login` | เข้าสู่ระบบ (รองรับ Remember Me) |
|
|
|
|
|
| | `auth/register.vue` | `/auth/register` | สมัครสมาชิกผู้เรียน |
|
|
|
|
|
| | `auth/reset-password.vue` | `/auth/reset-password` | ตั้งรหัสผ่านใหม่ (Reset Flow) |
|
|
|
|
|
| **Student** | `dashboard/index.vue` | `/dashboard` | แดชบอร์ดภาพรวมผู้เรียน |
|
|
|
|
|
| | `dashboard/my-courses.vue` | `/dashboard/my-courses` | **คอร์สของฉัน** และดาวน์โหลดใบประกาศฯ |
|
|
|
|
|
| | `dashboard/profile.vue` | `/dashboard/profile` | จัดการโปรไฟล์, รูปภาพ, เปลี่ยนรหัสผ่าน |
|
|
|
|
|
| | `classroom/learning.vue` | `/classroom/learning` | **ห้องเรียน (Video Player)** & Announcements |
|
|
|
|
|
| | `classroom/quiz.vue` | `/classroom/quiz` | การสอบวัดผล (Quiz System) |
|
|
|
|
|
|
|
|
|
|
### 2.2 Key Components (`components/`)
|
|
|
|
|
|
|
|
|
|
- **Common (`components/common/`):**
|
|
|
|
|
- `GlobalLoader.vue`: Loading indicator ทั่วทั้งแอป
|
|
|
|
|
- `LanguageSwitcher.vue`: ปุ่มเปลี่ยนภาษา (TH/EN)
|
|
|
|
|
- `AppHeader.vue`, `MobileNav.vue`: Navigation หลัก
|
|
|
|
|
- `FormInput.vue`: Input field มาตรฐาน
|
|
|
|
|
- **Course (`components/course/`):**
|
|
|
|
|
- `CourseCard.vue`: การ์ดแสดงผลคอร์ส (ใช้ซ้ำหลายหน้า)
|
|
|
|
|
- **User (`components/user/`):**
|
|
|
|
|
- `UserAvatar.vue`: แสดงรูปโปรไฟล์ (รองรับ Fallback)
|
2026-01-13 10:46:40 +07:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
## 🧠 3. Logic & Data Layer (Composables)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
รวบรวม Logic หลักแยกส่วนตามหน้าที่ (Separation of Concerns)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
### 3.1 `useAuth.ts` (Authentication & User)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
จัดการสถานะผู้ใช้, ล็อกอิน, และความปลอดภัย
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
- **Key Functions:** `login`, `register`, `fetchUserProfile`, `uploadAvatar`, `sendVerifyEmail`
|
|
|
|
|
- **Features:** Refresh Token อัตโนมัติ, ตรวจสอบ Role
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
### 3.2 `useCourse.ts` (Course & Classroom)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
หัวใจหลักของการเรียนการสอน
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
- **Catalog:** `fetchCourses`, `fetchCourseById`, `enrollCourse`
|
|
|
|
|
- **Classroom:**
|
|
|
|
|
- `fetchCourseLearningInfo`: โครงสร้างบทเรียน (Chapters/Lessons)
|
|
|
|
|
- `fetchLessonContent`: เนื้อหาวิดีโอ/Quiz/Attachments
|
|
|
|
|
- `saveVideoProgress`: บันทึกเวลาเรียน (Sync Server)
|
|
|
|
|
- `fetchCourseAnnouncements`: ดึงประกาศในคอร์สเรียน
|
|
|
|
|
- `getCertificate` / `generateCertificate`: ออกใบประกาศนียบัตร
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
### 3.3 `useMediaPrefs.ts` (Media Control)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
จัดการการตั้งค่า Media Player
|
|
|
|
|
|
|
|
|
|
- **State:** `volume` (0-1), `muted` (boolean)
|
|
|
|
|
- **Functions:** `setVolume`, `setMuted`, `applyTo` (apply state to video element)
|
2026-01-27 11:31:08 +07:00
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
## 🎨 4. Design System & Theming
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
### 4.1 Theme Strategy
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
- **Framework:** Tailwind CSS + Quasar UI
|
|
|
|
|
- **Dark Mode:** รองรับ Class-based Dark Mode (`.dark`)
|
|
|
|
|
- **Fonts:**
|
|
|
|
|
- **Heading:** Prompt, Sarabun (TH), Inter (EN)
|
|
|
|
|
- **Body:** Sarabun (TH), Inter (EN)
|
|
|
|
|
- **Handwriting:** (Optional) Dancing Script
|
2026-01-13 10:46:40 +07:00
|
|
|
|
2026-01-27 14:34:39 +07:00
|
|
|
---
|
2026-01-23 10:08:07 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
## 📊 5. Dependency Map (ความสัมพันธ์ไฟล์)
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
| หน้าเว็บ (Page) | Components หลัก | Composables หลัก |
|
|
|
|
|
| :----------------------- | :--------------------------- | :----------------------------------------------------- |
|
|
|
|
|
| **Login / Register** | `FormInput` | `useAuth`, `useFormValidation` |
|
|
|
|
|
| **Discovery (Browse)** | `CourseCard` | `useCourse` (Search/Filter), `useCategory` |
|
|
|
|
|
| **My Courses** | `CourseCard` (with Progress) | `useCourse` (Certificates) |
|
|
|
|
|
| **Classroom (Learning)** | Video Player, Sidebar | `useCourse` (Progress, Announcements), `useMediaPrefs` |
|
|
|
|
|
| **Profile** | `UserAvatar`, `FormInput` | `useAuth` (Upload Avatar, Verify Email) |
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
---
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
## ✅ 6. Project Status (สถานะล่าสุด)
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
### ✨ Recent Updates (อัปเดตล่าสุด)
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
1. **Code Optimization (Clean Code):**
|
|
|
|
|
- **ลบ Mock Data ทั้งหมด:** หน้า `quiz`, `classroom`, `discovery` ใช้ข้อมูลจริงจาก API 100%
|
|
|
|
|
- **ลบ Dead Code:** กำจัดตัวแปรที่ไม่ได้ใช้ (`currentUser` ซ้ำซ้อน, `unused intervals`) และ `console.log`
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
2. **Robust Learning System (Classroom):**
|
|
|
|
|
- **Hybrid Progress Saving:** ระบบบันทึกเวลาเรียนแบบลูกผสม (Local + Server) ป้องกันเวลาหายเมื่อเน็ตหลุดหรือปิดแท็บ
|
|
|
|
|
- **Announcements:** เพิ่มแท็บประกาศใน Sidebar ห้องเรียน เชื่อมต่อ API `course-announcements` พร้อมแจ้งเตือน "New"
|
|
|
|
|
- **Video Player:** ปรับปรุง UI Player, Volume Persistence (`useMediaPrefs`)
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
3. **i18n & Configuration:**
|
|
|
|
|
- **Path Correction:** แก้ไข `nuxt.config.ts` ให้เรียกไฟล์ภาษาจาก `i18n/locales/` ได้ถูกต้อง
|
|
|
|
|
- **Consistency:** เพิ่มคีย์ภาษาที่ขาดหาย (เช่น `common.close`) ใน `en.json`
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
4. **Enrollment & User Experience:**
|
|
|
|
|
- **Smart Enrolled Filter:** หน้า "คอร์สของฉัน" Tab "กำลังเรียน" แสดงทั้งคอร์สที่เพิ่งลงทะเบียน (`ENROLLED`) และกำลังเรียน (`IN_PROGRESS`)
|
|
|
|
|
- **Certificate System:** ระบบดาวน์โหลด/สร้างใบประกาศฯ อัตโนมัติเมื่อเรียนจบ
|
2026-01-28 09:55:21 +07:00
|
|
|
|
2026-02-02 15:45:09 +07:00
|
|
|
5. **Profile & Security:**
|
|
|
|
|
- **Email Verification:** ปุ่มยืนยันอีเมลและสถานะในหน้าโปรไฟล์
|
|
|
|
|
- **Avatar Upload:** อัปโหลดรูปภาพพร้อม Preview และ Validation (Size/Type)
|