init frontend_management
This commit is contained in:
parent
af58550f7f
commit
62812f2090
23 changed files with 13174 additions and 0 deletions
77
frontend_management/stores/auth.ts
Normal file
77
frontend_management/stores/auth.ts
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import { defineStore } from 'pinia';
|
||||
|
||||
interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
fullName: string;
|
||||
role: 'INSTRUCTOR' | 'ADMIN' | 'STUDENT';
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
state: () => ({
|
||||
user: null as User | null,
|
||||
token: null as string | null,
|
||||
isAuthenticated: false
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isInstructor: (state) => state.user?.role === 'INSTRUCTOR',
|
||||
isAdmin: (state) => state.user?.role === 'ADMIN',
|
||||
isStudent: (state) => state.user?.role === 'STUDENT'
|
||||
},
|
||||
|
||||
actions: {
|
||||
async login(email: string, password: string) {
|
||||
// TODO: Replace with real API call
|
||||
// const { $api } = useNuxtApp();
|
||||
// const response = await $api('/auth/login', {
|
||||
// method: 'POST',
|
||||
// body: { email, password }
|
||||
// });
|
||||
|
||||
// Mock login for development
|
||||
const mockUser: User = {
|
||||
id: '1',
|
||||
email: email,
|
||||
fullName: 'อาจารย์ทดสอบ',
|
||||
role: 'INSTRUCTOR'
|
||||
};
|
||||
|
||||
this.token = 'mock-jwt-token';
|
||||
this.user = mockUser;
|
||||
this.isAuthenticated = true;
|
||||
|
||||
// Save to localStorage
|
||||
if (process.client) {
|
||||
localStorage.setItem('token', this.token);
|
||||
localStorage.setItem('user', JSON.stringify(this.user));
|
||||
}
|
||||
|
||||
return { token: this.token, user: this.user };
|
||||
},
|
||||
|
||||
logout() {
|
||||
this.user = null;
|
||||
this.token = null;
|
||||
this.isAuthenticated = false;
|
||||
|
||||
if (process.client) {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
}
|
||||
},
|
||||
|
||||
checkAuth() {
|
||||
if (process.client) {
|
||||
const token = localStorage.getItem('token');
|
||||
const user = localStorage.getItem('user');
|
||||
|
||||
if (token && user) {
|
||||
this.token = token;
|
||||
this.user = JSON.parse(user);
|
||||
this.isAuthenticated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
60
frontend_management/stores/instructor.ts
Normal file
60
frontend_management/stores/instructor.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { defineStore } from 'pinia';
|
||||
|
||||
interface Course {
|
||||
id: string;
|
||||
title: string;
|
||||
students: number;
|
||||
lessons: number;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
interface DashboardStats {
|
||||
totalCourses: number;
|
||||
totalStudents: number;
|
||||
completedStudents: number;
|
||||
}
|
||||
|
||||
export const useInstructorStore = defineStore('instructor', {
|
||||
state: () => ({
|
||||
stats: {
|
||||
totalCourses: 5,
|
||||
totalStudents: 125,
|
||||
completedStudents: 45
|
||||
} as DashboardStats,
|
||||
|
||||
recentCourses: [
|
||||
{
|
||||
id: '1',
|
||||
title: 'Python เบื้องต้น',
|
||||
students: 45,
|
||||
lessons: 8,
|
||||
icon: '📘'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'JavaScript สำหรับเว็บ',
|
||||
students: 32,
|
||||
lessons: 12,
|
||||
icon: '📗'
|
||||
}
|
||||
] as Course[]
|
||||
}),
|
||||
|
||||
getters: {
|
||||
getDashboardStats: (state) => state.stats,
|
||||
getRecentCourses: (state) => state.recentCourses
|
||||
},
|
||||
|
||||
actions: {
|
||||
async fetchDashboardData() {
|
||||
// TODO: Replace with real API call
|
||||
// const { $api } = useNuxtApp();
|
||||
// const data = await $api('/instructor/dashboard');
|
||||
// this.stats = data.stats;
|
||||
// this.recentCourses = data.recentCourses;
|
||||
|
||||
// Using mock data for now
|
||||
console.log('Using mock data for instructor dashboard');
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue