|
|
@@ -1,47 +1,94 @@
|
|
|
<template>
|
|
|
- <div class="page-container">
|
|
|
- <div class="page-header">
|
|
|
- <h2 class="page-title">班级管理</h2>
|
|
|
- <el-button type="primary" icon="el-icon-plus" @click="showDialog = true">新建班级</el-button>
|
|
|
- </div>
|
|
|
+ <div class="page-container classes-page">
|
|
|
+ <div class="split-layout">
|
|
|
+ <!-- 左侧:课程列表 -->
|
|
|
+ <div class="sidebar">
|
|
|
+ <div class="sidebar-header">
|
|
|
+ <span class="sidebar-title">课程</span>
|
|
|
+ <router-link to="/courses" class="sidebar-link">管理课程</router-link>
|
|
|
+ </div>
|
|
|
+ <div v-loading="coursesLoading" class="course-list">
|
|
|
+ <div
|
|
|
+ v-for="c in courses"
|
|
|
+ :key="c.id"
|
|
|
+ class="course-item"
|
|
|
+ :class="{ active: selectedCourseId === c.id }"
|
|
|
+ @click="selectCourse(c.id)"
|
|
|
+ >
|
|
|
+ <span class="course-level">{{ c.level }}</span>
|
|
|
+ <span class="course-name">{{ c.name }}</span>
|
|
|
+ </div>
|
|
|
+ <div v-if="!coursesLoading && courses.length === 0" class="empty-hint">
|
|
|
+ 暂无课程,先去创建
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 右侧:班级管理 -->
|
|
|
+ <div class="main-content">
|
|
|
+ <div class="page-header">
|
|
|
+ <h2 class="page-title">
|
|
|
+ 班级管理
|
|
|
+ <span v-if="selectedCourse" class="breadcrumb-course">
|
|
|
+ > {{ selectedCourse.level }} · {{ selectedCourse.name }}
|
|
|
+ </span>
|
|
|
+ </h2>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ icon="el-icon-plus"
|
|
|
+ :disabled="!selectedCourse"
|
|
|
+ @click="showDialog = true"
|
|
|
+ >新建班级</el-button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div v-if="!selectedCourse" class="no-course-hint">
|
|
|
+ 请先选择左侧课程,或前往<a href="#/courses">课程管理</a>创建课程。
|
|
|
+ </div>
|
|
|
|
|
|
- <el-table :data="list" v-loading="loading" border stripe style="width:100%">
|
|
|
- <el-table-column prop="id" label="ID" width="80" />
|
|
|
- <el-table-column prop="name" label="班级名称" min-width="160" />
|
|
|
- <el-table-column label="所属课程" width="180">
|
|
|
- <template slot-scope="{ row }">{{ courseNameOf(row.courseId) }}</template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="time" label="时间" width="160" />
|
|
|
- <el-table-column prop="place" label="地点" width="160" />
|
|
|
- <el-table-column prop="capacity" label="容量" width="80" />
|
|
|
- <el-table-column prop="createdAt" label="创建时间" width="170" :formatter="formatTime" />
|
|
|
- </el-table>
|
|
|
+ <template v-else>
|
|
|
+ <el-table :data="list" v-loading="loading" border stripe style="width:100%">
|
|
|
+ <el-table-column prop="id" label="ID" width="80" />
|
|
|
+ <el-table-column prop="name" label="班级名称" min-width="160" />
|
|
|
+ <el-table-column prop="time" label="时间" width="160" />
|
|
|
+ <el-table-column prop="place" label="地点" width="160" />
|
|
|
+ <el-table-column prop="capacity" label="容量" width="80" />
|
|
|
+ <el-table-column label="状态" width="90">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-tag :type="row.status === 'active' ? 'success' : 'info'" size="small">{{ row.status || '-' }}</el-tag>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="createdAt" label="创建时间" width="170" :formatter="formatTime" />
|
|
|
+ </el-table>
|
|
|
|
|
|
- <el-dialog title="新建班级" :visible.sync="showDialog" width="500px" @close="resetForm">
|
|
|
- <el-form :model="form" :rules="rules" ref="form" label-width="80px">
|
|
|
- <el-form-item label="名称" prop="name">
|
|
|
- <el-input v-model="form.name" placeholder="如:AI 1期" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="所属课程" prop="courseId">
|
|
|
- <el-select v-model="form.courseId" placeholder="请选择课程">
|
|
|
- <el-option v-for="c in courses" :key="c.id" :label="c.level + ' ' + c.name" :value="c.id" />
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="时间">
|
|
|
- <el-input v-model="form.time" placeholder="如:周六10:00-17:00" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="地点">
|
|
|
- <el-input v-model="form.place" placeholder="如:北京会议室A" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="容量">
|
|
|
- <el-input-number v-model="form.capacity" :min="1" :max="9999" />
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <div slot="footer">
|
|
|
- <el-button @click="showDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="handleSubmit" :loading="submitting">确定</el-button>
|
|
|
+ <el-empty v-if="!loading && list.length === 0" description="该课程下暂无班级" />
|
|
|
+
|
|
|
+ <!-- 新建班级弹窗 -->
|
|
|
+ <el-dialog title="新建班级" :visible.sync="showDialog" width="500px" @close="resetForm">
|
|
|
+ <el-form :model="form" :rules="rules" ref="form" label-width="80px">
|
|
|
+ <el-form-item label="名称" prop="name">
|
|
|
+ <el-input v-model="form.name" placeholder="如:AI 1期" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="所属课程">
|
|
|
+ <span class="readonly-course">{{ selectedCourse ? selectedCourse.level + ' · ' + selectedCourse.name : '-' }}</span>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="时间">
|
|
|
+ <el-input v-model="form.time" placeholder="如:周六10:00-17:00" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="地点">
|
|
|
+ <el-input v-model="form.place" placeholder="如:北京会议室A" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="容量">
|
|
|
+ <el-input-number v-model="form.capacity" :min="1" :max="9999" />
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer">
|
|
|
+ <el-button @click="showDialog = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="handleSubmit" :loading="submitting">确定</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </template>
|
|
|
</div>
|
|
|
- </el-dialog>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
@@ -53,14 +100,16 @@ export default {
|
|
|
name: 'Classes',
|
|
|
data: function () {
|
|
|
return {
|
|
|
- list: [],
|
|
|
courses: [],
|
|
|
+ coursesLoading: false,
|
|
|
+ selectedCourseId: null,
|
|
|
+ list: [],
|
|
|
loading: false,
|
|
|
showDialog: false,
|
|
|
submitting: false,
|
|
|
form: {
|
|
|
name: '',
|
|
|
- courseId: '',
|
|
|
+ courseId: null,
|
|
|
time: '',
|
|
|
place: '',
|
|
|
capacity: 30
|
|
|
@@ -71,30 +120,43 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ selectedCourse: function () {
|
|
|
+ var self = this
|
|
|
+ return self.courses.find(function (c) { return c.id === self.selectedCourseId })
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted: function () {
|
|
|
- var self = this
|
|
|
- this.fetchList()
|
|
|
- courseList().then(function (res) {
|
|
|
- self.courses = res.data || []
|
|
|
- }).catch(function () {
|
|
|
- self.$message.error('获取课程列表失败')
|
|
|
- })
|
|
|
+ this.fetchCourses()
|
|
|
},
|
|
|
methods: {
|
|
|
- formatTime: function (row, col, val) {
|
|
|
- return val || '-'
|
|
|
- },
|
|
|
- courseNameOf: function (courseId) {
|
|
|
+ fetchCourses: function () {
|
|
|
var self = this
|
|
|
- var c = self.courses.find(function (item) {
|
|
|
- return item.id === courseId
|
|
|
+ self.coursesLoading = true
|
|
|
+ courseList().then(function (res) {
|
|
|
+ self.courses = res.data || []
|
|
|
+ // 自动选中第一个课程
|
|
|
+ if (self.courses.length > 0 && !self.selectedCourseId) {
|
|
|
+ self.selectCourse(self.courses[0].id)
|
|
|
+ }
|
|
|
+ }).catch(function () {
|
|
|
+ self.$message.error('获取课程列表失败')
|
|
|
+ }).finally(function () {
|
|
|
+ self.coursesLoading = false
|
|
|
})
|
|
|
- return c ? c.level + ' ' + c.name : '-'
|
|
|
+ },
|
|
|
+ selectCourse: function (courseId) {
|
|
|
+ this.selectedCourseId = courseId
|
|
|
+ this.fetchList()
|
|
|
+ },
|
|
|
+ formatTime: function (row, col, val) {
|
|
|
+ return val || '-'
|
|
|
},
|
|
|
fetchList: function () {
|
|
|
var self = this
|
|
|
+ if (!self.selectedCourseId) return
|
|
|
self.loading = true
|
|
|
- classList().then(function (res) {
|
|
|
+ classList(self.selectedCourseId).then(function (res) {
|
|
|
self.list = res.data || []
|
|
|
}).catch(function () {
|
|
|
self.$message.error('获取班级列表失败')
|
|
|
@@ -103,7 +165,7 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
resetForm: function () {
|
|
|
- this.form = { name: '', courseId: '', time: '', place: '', capacity: 30 }
|
|
|
+ this.form = { name: '', courseId: this.selectedCourseId, time: '', place: '', capacity: 30 }
|
|
|
},
|
|
|
handleSubmit: function () {
|
|
|
var self = this
|
|
|
@@ -111,12 +173,19 @@ export default {
|
|
|
self.$refs.form.validate(function (valid) {
|
|
|
if (!valid) return
|
|
|
self.submitting = true
|
|
|
- createClass(self.form).then(function () {
|
|
|
+ var payload = {
|
|
|
+ name: self.form.name,
|
|
|
+ courseId: self.form.courseId,
|
|
|
+ time: self.form.time,
|
|
|
+ place: self.form.place,
|
|
|
+ capacity: self.form.capacity
|
|
|
+ }
|
|
|
+ createClass(payload).then(function () {
|
|
|
self.$message.success('创建成功')
|
|
|
self.showDialog = false
|
|
|
self.fetchList()
|
|
|
- }).catch(function () {
|
|
|
- self.$message.error('创建失败')
|
|
|
+ }).catch(function (err) {
|
|
|
+ self.$message.error((err && err.message) || '创建失败')
|
|
|
}).finally(function () {
|
|
|
self.submitting = false
|
|
|
})
|
|
|
@@ -127,16 +196,129 @@ export default {
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
+.classes-page {
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+.split-layout {
|
|
|
+ display: flex;
|
|
|
+ gap: 20px;
|
|
|
+ height: calc(100vh - 120px);
|
|
|
+}
|
|
|
+
|
|
|
+/* 左侧课程列表 */
|
|
|
+.sidebar {
|
|
|
+ width: 260px;
|
|
|
+ flex-shrink: 0;
|
|
|
+ border: 1px solid #EBEEF5;
|
|
|
+ border-radius: 4px;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ overflow: hidden;
|
|
|
+}
|
|
|
+.sidebar-header {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ align-items: center;
|
|
|
+ padding: 12px 16px;
|
|
|
+ border-bottom: 1px solid #EBEEF5;
|
|
|
+ background: #F5F7FA;
|
|
|
+}
|
|
|
+.sidebar-title {
|
|
|
+ font-size: 14px;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #303133;
|
|
|
+}
|
|
|
+.sidebar-link {
|
|
|
+ font-size: 12px;
|
|
|
+ color: #409EFF;
|
|
|
+ text-decoration: none;
|
|
|
+}
|
|
|
+.sidebar-link:hover {
|
|
|
+ text-decoration: underline;
|
|
|
+}
|
|
|
+.course-list {
|
|
|
+ flex: 1;
|
|
|
+ overflow-y: auto;
|
|
|
+ padding: 8px 0;
|
|
|
+}
|
|
|
+.course-item {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ padding: 10px 16px;
|
|
|
+ cursor: pointer;
|
|
|
+ transition: background 0.15s;
|
|
|
+}
|
|
|
+.course-item:hover {
|
|
|
+ background: #F5F7FA;
|
|
|
+}
|
|
|
+.course-item.active {
|
|
|
+ background: #ECF5FF;
|
|
|
+ border-left: 3px solid #409EFF;
|
|
|
+ padding-left: 13px;
|
|
|
+}
|
|
|
+.course-level {
|
|
|
+ display: inline-block;
|
|
|
+ min-width: 36px;
|
|
|
+ font-size: 12px;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #409EFF;
|
|
|
+ background: #ECF5FF;
|
|
|
+ border-radius: 3px;
|
|
|
+ padding: 2px 6px;
|
|
|
+ margin-right: 8px;
|
|
|
+ flex-shrink: 0;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+.course-name {
|
|
|
+ font-size: 13px;
|
|
|
+ color: #303133;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ white-space: nowrap;
|
|
|
+}
|
|
|
+.empty-hint {
|
|
|
+ padding: 20px 16px;
|
|
|
+ font-size: 13px;
|
|
|
+ color: #909399;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+
|
|
|
+/* 右侧内容区 */
|
|
|
+.main-content {
|
|
|
+ flex: 1;
|
|
|
+ min-width: 0;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+}
|
|
|
.page-header {
|
|
|
display: flex;
|
|
|
justify-content: space-between;
|
|
|
align-items: center;
|
|
|
margin-bottom: 16px;
|
|
|
}
|
|
|
-
|
|
|
.page-title {
|
|
|
margin: 0;
|
|
|
font-size: 18px;
|
|
|
font-weight: 600;
|
|
|
+ color: #303133;
|
|
|
+}
|
|
|
+.breadcrumb-course {
|
|
|
+ font-size: 14px;
|
|
|
+ font-weight: 400;
|
|
|
+ color: #909399;
|
|
|
+ margin-left: 8px;
|
|
|
+}
|
|
|
+.no-course-hint {
|
|
|
+ padding: 40px;
|
|
|
+ text-align: center;
|
|
|
+ color: #909399;
|
|
|
+ font-size: 14px;
|
|
|
+}
|
|
|
+.no-course-hint a {
|
|
|
+ color: #409EFF;
|
|
|
+}
|
|
|
+.readonly-course {
|
|
|
+ line-height: 32px;
|
|
|
+ color: #606266;
|
|
|
}
|
|
|
</style>
|