Преглед изворни кода

学员管理部分接口联调

zhangsq пре 7 месеци
родитељ
комит
6b39356c43

+ 9 - 1
src/api/courseCenter/studentDetails.js

@@ -17,6 +17,14 @@ export default {
 	},
 	// 学员导入
 	importStudents(data) {
-		return request('/disk/coursestudentrelate/import', data, 'post')
+		return request('disk/coursestudentrelate/import', data, 'post')
+	},
+	// 学员导入模版下载
+	downloadImportlate(data) {
+		return request('disk/coursestudentrelate/downloadImportlate', data, 'get', { responseType: 'blob' })
+	},
+	// 学员删除
+	delete(data) {
+		return request('disk/coursestudentrelate/delete', data, 'post')
 	}
 }

+ 75 - 25
src/views/courseAdd/components/StudentDetails.vue

@@ -36,6 +36,7 @@
 			>
 				<a-button>导入</a-button>
 			</a-upload>
+			<a-button style="margin-left: 10px" @click="downloadImport">下载导入模板</a-button>
 		</div>
 		<!-- 表格 -->
 		<a-table
@@ -66,7 +67,9 @@
 						<a-button size="small" @click="onDetail(record)">详情</a-button>
 						<!-- <a-button size="small" @click="onEdit(record)">编辑</a-button> -->
 						<!-- <a-button size="small" @click="onSetting(record)">设置</a-button> -->
-						<a-button size="small" danger @click="onDelete(record)">删除</a-button>
+						<a-popconfirm title="删除此短信?" @confirm="onDelete(record)">
+							<a-button size="small" danger>删除</a-button>
+						</a-popconfirm>
 					</a-space>
 				</template>
 			</template>
@@ -140,8 +143,8 @@
 						<th>性别</th>
 					</tr>
 					<tr>
-						<td>{{ detailData.id }}</td>
-						<td>{{ detailData.name }}</td>
+						<td>{{ detailData.ACCOUNT }}</td>
+						<td>{{ detailData.userIdName }}</td>
 						<td>{{ detailData.phone }}</td>
 						<td>{{ detailData.gender }}</td>
 					</tr>
@@ -152,9 +155,9 @@
 						<th>所在城市</th>
 					</tr>
 					<tr>
-						<td>{{ detailData.college }}</td>
+						<td>{{ detailData.orgIdName }}</td>
 						<td>{{ detailData.className }}</td>
-						<td>{{ detailData.birthday }}</td>
+						<td>{{ detailData.birth }}</td>
 						<td>{{ detailData.city }}</td>
 					</tr>
 					<tr>
@@ -164,10 +167,10 @@
 						<th>最后登录</th>
 					</tr>
 					<tr>
-						<td>{{ detailData.educationStatus }}</td>
-						<td>{{ detailData.onlineStatus }}</td>
-						<td>{{ detailData.registerTime }}</td>
-						<td>{{ detailData.lastLogin }}</td>
+						<td>{{ detailData.userStatus }}</td>
+						<td>{{ detailData.isLoginName }}</td>
+						<td>{{ detailData.createTime }}</td>
+						<td>{{ detailData.latestLoginTime }}</td>
 					</tr>
 				</table>
 				<div class="modal-btn-bar">
@@ -188,7 +191,14 @@
 	import { getStudentDetail } from '@/api/course/courseDetail'
 	import studentSelection from './studentSelection.vue'
 	import tool from '@/utils/tool'
-
+	const props = defineProps({
+		//课程id
+		courseInfoId: {
+			type: Number,
+			required: true,
+			default: null
+		}
+	})
 	// mock数据
 	const allStudents = ref([
 		// 生成20条mock数据
@@ -240,7 +250,7 @@
 	const detailVisible = ref(false)
 	const detailData = ref({})
 	const pagedDatas = ref([])
-	const rowKey = (record) => record.userId
+	const rowKey = (record) => record.relateId
 
 	const filteredData = computed(() => {
 		let data = allStudents.value
@@ -280,8 +290,8 @@
 		addStudentVisible.value = false
 		searchForm.StudentIds = StudentIds.join(',')
 		let params = {
-			userIds: searchForm.StudentIds
-			// courseId: pageSize.value
+			userIds: searchForm.StudentIds,
+			courseId: props.courseInfoId
 		}
 		studentDetailsApi
 			.add(params)
@@ -344,14 +354,11 @@
 		const { file, onSuccess, onError } = options
 		importLoading.value = true
 		try {
-			// const formData = new FormData()
-			// formData.append('file', file)
-			let params = {
-				courseId: courseId.value,
-				file
-			}
+			const formData = new FormData()
+			formData.append('file', file)
+			formData.append('courseId', props.courseInfoId)
 			// 调用API接口
-			const res = await studentDetailsApi.importStudents(params)
+			const res = await studentDetailsApi.importStudents(formData)
 			console.log(res)
 			message.success(`成功导入 ${res.data.count} 条数据`)
 			onSuccess(res, file)
@@ -382,10 +389,10 @@
 	}
 	function onSelectAll() {
 		console.log(pagedDatas.value)
-		selectedRowKeys.value = pagedDatas.value.map((item) => item.userId)
+		selectedRowKeys.value = pagedDatas.value.map((item) => item.relateId)
 	}
 	function onInvertSelect() {
-		const currentIds = pagedDatas.value.map((item) => item.userId)
+		const currentIds = pagedDatas.value.map((item) => item.relateId)
 		selectedRowKeys.value = currentIds.filter((id) => !selectedRowKeys.value.includes(id))
 	}
 	function onAddStudent() {
@@ -393,6 +400,36 @@
 		// 默认展开所有部门
 		// expandedDeptIds.value = departments.value.map((d) => d.id)
 	}
+	function downloadImport() {
+		studentDetailsApi
+			.downloadImportlate()
+			.then((res) => {
+				console.log(res.data, 'messagemessagemessage')
+				// 创建 blob 对象
+				const blob = new Blob([res.data], {
+					type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
+				})
+				// 创建下载链接
+				const downloadUrl = window.URL.createObjectURL(blob)
+				const link = document.createElement('a')
+				link.href = downloadUrl
+
+				// 设置下载文件名(可以从响应头获取或固定)
+				link.download = '学生导入模板.xlsx'
+
+				// 触发下载
+				document.body.appendChild(link)
+				link.click()
+
+				// 清理
+				window.URL.revokeObjectURL(downloadUrl)
+				document.body.removeChild(link)
+			})
+			.catch((err) => {
+				message.error('模板下载失败: ' + (err || err))
+				console.error(err)
+			})
+	}
 	function handleAddStudentCancel() {
 		addStudentVisible.value = false
 	}
@@ -462,13 +499,13 @@
 	function onDetail(record) {
 		detailVisible.value = true
 		let params = {
-			id: record.userId
+			id: record.relateId
 		}
 		studentDetailsApi
 			.detail(params)
 			.then((res) => {
 				console.log(res, '学员详情')
-				detailData.value = res.data.records
+				detailData.value = res.data
 			})
 			.catch((err) => {
 				console.log(err)
@@ -481,7 +518,20 @@
 		// TODO: 设置弹窗
 	}
 	function onDelete(record) {
-		// TODO: 删除确认
+		let params = [
+			{
+				id: record.relateId
+			}
+		]
+		studentDetailsApi
+			.delete(params)
+			.then((res) => {
+				console.log(res, '删除学员')
+				getList()
+			})
+			.catch((err) => {
+				console.log(err)
+			})
 	}
 </script>
 

+ 1 - 1
src/views/courseAdd/index.vue

@@ -12,7 +12,7 @@
 						<courseProduction :courseInfoId="courseInfoId" />
 					</a-tab-pane>
 					<a-tab-pane key="3" tab="学员管理" :disabled="courseInfoId==null">
-						<StudentDetails></StudentDetails>
+						<StudentDetails :courseInfoId="courseInfoId"></StudentDetails>
 					</a-tab-pane>
 					<a-tab-pane key="4" tab="作业布置" :disabled="courseInfoId==null">
 						<div>这里是作业布置的内容</div>