From 9e094896bc65f3ada04a0b6c2dbb19ce82c23d86 Mon Sep 17 00:00:00 2001 From: Timothy Yin Date: Sun, 13 Apr 2025 16:29:06 +0800 Subject: [PATCH] refactor: enable eslint --- .vscode/settings.json | 7 +- api/course.ts | 328 ++++++++++++++-------------- api/file.ts | 30 +-- api/index.ts | 8 +- api/user.ts | 50 ++--- app.vue | 32 +-- components/CourseCard.vue | 32 ++- components/EmptyScreen.vue | 18 +- components/ResourceUploader.vue | 94 ++++---- components/app/NavMain.vue | 51 +++-- components/app/NavUser.vue | 42 ++-- components/app/PageWithSidebar.vue | 13 +- components/app/Sidebar.vue | 40 ++-- components/app/Topbar.vue | 53 +++-- components/course/Chapter.vue | 131 ++++++----- components/course/Resource.vue | 110 +++++----- components/course/Section.vue | 68 +++--- components/course/class/Card.vue | 131 ++++++----- components/course/team/Member.vue | 18 +- eslint.config.mjs | 17 +- layouts/no-sidebar.vue | 4 +- middleware/authMiddleware.global.ts | 12 +- nuxt.config.ts | 63 +++--- pages/course/[id].vue | 55 ++--- pages/course/[id]/chapters.vue | 121 +++++----- pages/course/[id]/classes.vue | 83 ++++--- pages/course/[id]/team.vue | 92 ++++---- pages/course/index.vue | 153 ++++++++----- pages/course/prepare/index.vue | 34 +-- pages/course/research/index.vue | 4 +- pages/course/resources/index.vue | 4 +- pages/index.vue | 23 +- pages/preview/[resource_url].vue | 49 +++-- pages/user/authenticate.client.vue | 107 +++++---- stores/loginState.ts | 67 +++--- tailwind.config.js | 76 +++---- types/course.ts | 68 +++--- types/index.ts | 6 +- types/user.ts | 136 ++++++------ utils/http.ts | 32 +-- 40 files changed, 1386 insertions(+), 1076 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 3dc7d64..e019176 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,8 @@ { - "eslint.useFlatConfig": true + "eslint.useFlatConfig": true, + "prettier.bracketSameLine": true, + "prettier.requireConfig": true, + "prettier.semi": false, + "prettier.singleAttributePerLine": true, + "prettier.singleQuote": true } \ No newline at end of file diff --git a/api/course.ts b/api/course.ts index ec9006c..ee5871d 100644 --- a/api/course.ts +++ b/api/course.ts @@ -1,293 +1,293 @@ +import type { IResponse } from '.' import type { ICourse, ICourseChapter, ICreateResource, IResource, -} from "~/types"; -import type { IResponse } from "."; +} from '~/types' export type IPerson = { - id: number; - courseId: number; - createTime: Date; - updateTime: Date; - createBy: number; - updateBy: number; - remark: string | null; + id: number + courseId: number + createTime: Date + updateTime: Date + createBy: number + updateBy: number + remark: string | null } & (T extends ITeacher - ? { teacher: ITeacher; teacherId: number } + ? { teacher: ITeacher, teacherId: number } : T extends IStudent - ? { student: IStudent; studentId: number } - : // eslint-disable-next-line @typescript-eslint/no-empty-object-type - {}); + ? { student: IStudent, studentId: number } + : // eslint-disable-next-line @typescript-eslint/no-empty-object-type + {}) export interface ITeacher { - id: number; - userName: string; - employeeId: string; - schoolId: number; - collegeId: number; - schoolName: string; - collegeName: string; - sex: number; - email: string; - phonenumber: string; - avatar: string; - status: number; - delFlag: number; - loginIp: string; - loginDate: Date; - createBy: number; - createTime: Date; - updateBy: number; - updateTime: Date; - remark: string | null; + id: number + userName: string + employeeId: string + schoolId: number + collegeId: number + schoolName: string + collegeName: string + sex: number + email: string + phonenumber: string + avatar: string + status: number + delFlag: number + loginIp: string + loginDate: Date + createBy: number + createTime: Date + updateBy: number + updateTime: Date + remark: string | null } export interface IStudent { - id: number; - userName: string; - studentId: string; - schoolId: number; - collegeId: number; - schoolName: string; - collegeName: string; - sex: number; - email: string; - phonenumber: string; - avatar: null | string; - status: number; - delFlag: null; - loginIp: null; - loginDate: null; - createBy: null; - createTime: null; - updateBy: null; - updateTime: null; - remark: null; + id: number + userName: string + studentId: string + schoolId: number + collegeId: number + schoolName: string + collegeName: string + sex: number + email: string + phonenumber: string + avatar: null | string + status: number + delFlag: null + loginIp: null + loginDate: null + createBy: null + createTime: null + updateBy: null + updateTime: null + remark: null } export interface ICourseClass { - id: number; - courseId: number; - classId: number; - className: string; - createBy: number; - createTime: Date; - updateBy: number; - updateTime: Date | null; - remark: string | null; - notes?: string | null; + id: number + courseId: number + classId: number + className: string + createBy: number + createTime: Date + updateBy: number + updateTime: Date | null + remark: string | null + notes?: string | null } export const listCourses = async () => { return await http< IResponse<{ - rows: ICourse[]; + rows: ICourse[] }> - >("/system/manage/list", { - method: "GET", - }); -}; + >('/system/manage/list', { + method: 'GET', + }) +} export const listUserCourses = async (userId: number) => { return await http< IResponse<{ - rows: ICourse[]; + rows: ICourse[] }> >(`/system/manage/leader/${userId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const getCourseDetail = async (courseId: string) => { return await http< IResponse<{ - data: ICourse; + data: ICourse }> >(`/system/manage/${courseId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const createCourse = async ( params: Pick< ICourse, - | "courseName" - | "profile" - | "schoolName" - | "teacherName" - | "semester" - | "previewUrl" - > + | 'courseName' + | 'profile' + | 'schoolName' + | 'teacherName' + | 'semester' + | 'previewUrl' + >, ) => { return await http(`/system/manage`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteCourse = async (courseId: number) => { return await http(`/system/manage/${courseId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const getCourseChatpers = async (courseId: number) => { return await http< IResponse<{ - total: number; - rows: ICourseChapter[]; + total: number + rows: ICourseChapter[] }> >(`/system/chapter/details/${courseId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const createCourseChatper = async (params: { - courseId: number; - title: string; + courseId: number + title: string }) => { return await http(`/system/chapter`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteCourseChatper = async (chapterId: number) => { return await http(`/system/chapter/${chapterId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const editCourseChapter = async (chapter: ICourseChapter) => { return await http(`/system/chapter`, { - method: "PUT", + method: 'PUT', body: chapter, - }); -}; + }) +} export const createCourseSection = async (params: { - chapterId: number; - title: string; + chapterId: number + title: string }) => { return await http(`/system/section`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteCourseSection = async (sectionId: number) => { return await http(`/system/section/${sectionId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const createResource = async (params: ICreateResource) => { return await http(`/system/resource`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteResource = async (resourceId: number) => { return await http(`/system/resource/${resourceId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const editResource = async (resource: IResource) => { return await http(`/system/resource`, { - method: "PUT", + method: 'PUT', body: resource, - }); -}; + }) +} export const addResourceToSection = async (params: { - sectionId: number; - resourceId: number; + sectionId: number + resourceId: number }) => { return await http(`/system/sectionResource`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const addTeacherToCourse = async (params: { - courseId: number; - teacherId: number; + courseId: number + teacherId: number }) => { return await http(`/system/teacherteam`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteTeacherTeamRecord = async (recordId: number) => { return await http(`/system/teacherteam/${recordId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const getTeacherTeamByCourse = async (courseId: number) => { return await http< IResponse<{ - data: IPerson[]; + data: IPerson[] }> >(`/system/teacherteam/course/${courseId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const createClass = async (params: { - className: string; - notes: string; - courseId: number; + className: string + notes: string + courseId: number }) => { return await http(`/system/course/class`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteClass = async (classId: number) => { return await http(`/system/course/class/${classId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} export const getClassListByCourse = async (courseId: number) => { return await http< IResponse<{ - data: ICourseClass[]; + data: ICourseClass[] }> >(`/system/course/class/${courseId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const getStudentListByClass = async (classId: number) => { return await http< IResponse<{ - data: IPerson[]; + data: IPerson[] }> >(`/system/student/class/${classId}`, { - method: "GET", - }); -}; + method: 'GET', + }) +} export const addStudentToClass = async (params: { - classId: number; - studentId: number; + classId: number + studentId: number }) => { return await http(`/system/student`, { - method: "POST", + method: 'POST', body: params, - }); -}; + }) +} export const deleteStudentClassRecord = async (recordId: number) => { return await http(`/system/student/${recordId}`, { - method: "DELETE", - }); -}; + method: 'DELETE', + }) +} diff --git a/api/file.ts b/api/file.ts index a772b98..531a21a 100644 --- a/api/file.ts +++ b/api/file.ts @@ -1,36 +1,36 @@ -import type { IResponse } from "."; +import type { IResponse } from '.' const putFile = (file: File, url: string): Promise => { return new Promise((resolve, reject) => { $fetch(url, { - method: "PUT", + method: 'PUT', body: file, headers: { - "Content-Type": file.type, + 'Content-Type': file.type, }, }) .then(() => { - resolve(url.split("?")[0]); + resolve(url.split('?')[0]) }) .catch(() => { - reject(new Error("File upload failed")); - }); - }); -}; + reject(new Error('File upload failed')) + }) + }) +} -export const uploadFile = async (file: File, type: "resource" | "temp") => { +export const uploadFile = async (file: File, type: 'resource' | 'temp') => { const signedUrl = await http>( `/common/oss/getSignUrl`, { - method: "POST", + method: 'POST', query: { fileName: encodeURI(file.name), fileType: type, fileSize: file.size, fileMime: file.type, }, - } - ); - const url = signedUrl.data; - return await putFile(file, url); -}; + }, + ) + const url = signedUrl.data + return await putFile(file, url) +} diff --git a/api/index.ts b/api/index.ts index 7482521..3616876 100644 --- a/api/index.ts +++ b/api/index.ts @@ -1,6 +1,6 @@ -export * from "./user"; +export * from './user' export type IResponse = { - msg: string; - code: number; -} & T; + msg: string + code: number +} & T diff --git a/api/user.ts b/api/user.ts index 7314232..811abe5 100644 --- a/api/user.ts +++ b/api/user.ts @@ -1,21 +1,21 @@ -import type { IUser, LoginType } from "~/types"; -import { http } from "~/utils/http"; -import type { IResponse } from "."; +import type { IResponse } from '.' +import type { IUser, LoginType } from '~/types' +import { http } from '~/utils/http' export interface LoginParams { - account: string; - password: string; - loginType: LoginType; + account: string + password: string + loginType: LoginType } export type LoginResponse = IResponse & { - loginType: LoginType; - token: string; -}; + loginType: LoginType + token: string +} export type UserProfileResponse = IResponse & { - user: IUser; -}; + user: IUser +} /** * 用户登录 @@ -24,28 +24,28 @@ export type UserProfileResponse = IResponse & { * @see {@link LoginParams} */ export const userLogin = async (params: LoginParams) => { - return await http("/login", { - method: "POST", + return await http('/login', { + method: 'POST', body: params, - }); -}; + }) +} export const userProfile = async () => { - return await http("/getInfo", { - method: "GET", - }); -}; + return await http('/getInfo', { + method: 'GET', + }) +} export const userSearch = async (pararms: { - searchType: "student" | "teacher"; - keyword: string; + searchType: 'student' | 'teacher' + keyword: string }) => { return await http< IResponse & { - data: IUser[]; + data: IUser[] } >(`/system/user/search`, { - method: "GET", + method: 'GET', query: pararms, - }); -}; + }) +} diff --git a/app.vue b/app.vue index 5b8b514..c20cfac 100644 --- a/app.vue +++ b/app.vue @@ -1,25 +1,25 @@