diff --git a/src/api/user/object.js b/src/api/user/object.js index 8f065b2..80d6fa5 100644 --- a/src/api/user/object.js +++ b/src/api/user/object.js @@ -12,3 +12,15 @@ export const getObjectList = (params) => { params, }) } +// 删除课程目标 +export const delObjectContents = (id) => { + return request.delete(`/api/objective_contents/${id}`) +} +// 添加课程目标 +export const addObjectContents = (params) => { + return request.post(`/api/objective_contents/addcontent`, params) +} +// 查询目标内容 +export const getObjectContent = (id) => { + return request.get(`/api/objective_contents/${id}`) +} diff --git a/src/views/course/components/chapters-details.vue b/src/views/course/components/chapters-details.vue index 4642407..6b6fde2 100644 --- a/src/views/course/components/chapters-details.vue +++ b/src/views/course/components/chapters-details.vue @@ -28,7 +28,9 @@ padding: 20px; p { - margin: 10px; + margin-bottom: 5px; + line-height: 1.5; + letter-spacing: 1px; } } } diff --git a/src/views/course/components/course-chapters.vue b/src/views/course/components/course-chapters.vue index 017dc8a..78fb2b0 100644 --- a/src/views/course/components/course-chapters.vue +++ b/src/views/course/components/course-chapters.vue @@ -140,8 +140,16 @@ const dataSource = ref([ {{ data.name }} - 添加 - 删除 + + + + + + + + + + diff --git a/src/views/course/components/course-object.vue b/src/views/course/components/course-object.vue index 1e0bbe7..28375a8 100644 --- a/src/views/course/components/course-object.vue +++ b/src/views/course/components/course-object.vue @@ -2,8 +2,15 @@ import { ref, onMounted } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import { Edit, Delete } from '@element-plus/icons-vue' -import { getObjectType, updateContents, getObjectList } from '@/api/user/object' +import { + updateContents, + getObjectList, + delObjectContents, + addObjectContents, + getObjectContent, +} from '@/api/user/object' import { useRoute } from 'vue-router' +import { ITEM_RENDER_EVT } from 'element-plus/es/components/virtual-list/src/defaults.mjs' const route = useRoute() // const router = useRouter() const courseId = ref(0) @@ -15,7 +22,7 @@ const params = ref({ id: '', objectiveId: '', }) -// 获取课程知识点列表 +// 获取目标列表 const getObject = async () => { const res = await getObjectList({ id: courseId.value }) console.log(res, 'objectres') @@ -26,21 +33,21 @@ const getObject = async () => { console.log(data.value, 'data.value') // content.value = res.data[0].contents[0].content } + // 获取目标类型 -const type = ref({ - id: '', - typeName: '', -}) -const getType = async () => { - const res = await getObjectType() - type.value = res.data.slice(1, 5) - console.log(type.value, 'typeres') -} +// const type = ref({ +// id: '', +// typeName: '', +// }) +// const getType = async () => { +// const res = await getObjectType() +// type.value = res.data.slice(1, 5) +// console.log(type.value, 'typeres') +// } onMounted(() => { courseId.value = route.query.id console.log(courseId.value, 'courseid.vlue') getObject() - getType() }) // 修改目标内容 const isEditing = ref(false) @@ -84,6 +91,81 @@ const saveContent = async () => { const cancelEdit = () => { isEditing.value = false } +// 删除目标 +const delObject = async (id: any) => { + await ElMessageBox.confirm('你确认要删除该课程目标吗', '温馨提示', { + type: 'warning', + confirmButtonText: '确认', + cancelButtonText: '取消', + }) + await delObjectContents(id).then(() => { + ElMessage.success('删除成功') + getObject() + }) +} +// 添加目标 +// 内容 +const formData = ref({ + description: '', +}) +// 弹窗 +const dialogVisible = ref(false) +// 关闭弹窗 +const handleClose = () => { + dialogVisible.value = false +} +const close = () => { + formData.value = { + description: '', + } + dialogVisible.value = false +} +// 编辑 +const flog = ref() +const objectiveIds = ref(0) +const addObject = (item: any) => { + // console.log(id, 'id') + dialogVisible.value = true + flog.value = false + formData.value.description = '' + // updateDisabledStatus() + objectiveIds.value = item.id +} +const editdata = ref({ id: '', objectiveId: '' }) +const updateObjectContent = async (id: any) => { + dialogVisible.value = true + flog.value = true + const res = await getObjectContent(id) + formData.value.description = res.data.content + console.log(res, '回显res') + editdata.value.id = res.data.id + editdata.value.objectiveId = res.data.objectiveId +} +// 弹窗提交事件 +const submit = async () => { + if (formData.value.description === '') { + // 显示错误提示 + await ElMessage.error('内容不能为空') + return + } + if (flog.value) { + await updateContents({ + ...editdata.value, + content: formData.value.description, + }) + ElMessage.success('编辑成功') + } else { + console.log(objectiveIds, 'objectiveIds') + await addObjectContents({ + objectiveId: objectiveIds.value, + content: formData.value.description, + }) + ElMessage.success('添加成功') + } + getObject() + dialogVisible.value = false + formData.value.description = '' +}