添加课程模块和章节;
This commit is contained in:
241
src/view/course/addCourse/index.vue
Normal file
241
src/view/course/addCourse/index.vue
Normal file
@@ -0,0 +1,241 @@
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
import com_api from '@/api/common'
|
||||
import custom from '@/utils/custom'
|
||||
// import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
import {ref,onMounted,provide } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
import { useUserStore } from '@/pinia/modules/user'
|
||||
const userStore = useUserStore()
|
||||
import chapterCom from '../components/chapter.vue'
|
||||
// 变量
|
||||
const path = ref(import.meta.env.VITE_BASE_API)
|
||||
const course_id = ref(0)
|
||||
const active = ref(0)
|
||||
const form = ref({status:1})
|
||||
const subjectParams = ref({
|
||||
pageIndex:1,
|
||||
pageSize:100,
|
||||
})
|
||||
const subjectList = ref([])
|
||||
const rules = ref({
|
||||
name: [{ required: true, message: '请输入课程名称', trigger: 'blur' }],
|
||||
subject: [{ required: true, message: '请选择课程科目', trigger: 'change' }],
|
||||
price: [{ required: true, message: '请输入课程价格', trigger: 'blur' }]
|
||||
})
|
||||
const ruleFormRef = ref(null)
|
||||
const chapter_info = ref([])
|
||||
const current_subject = ref('')
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
course_id.value = route.params.course_id || 0
|
||||
if(course_id.value) {
|
||||
getCourseInfo()
|
||||
}
|
||||
getSubject()
|
||||
})
|
||||
provide('subjectList', subjectList)
|
||||
provide('current_subject', current_subject)
|
||||
async function getCourseInfo() { // 获取课程信息
|
||||
const res = await api.getCourse({id:course_id.value})
|
||||
if(res.code === 0) {
|
||||
chapter_info.value = res.data.course_ware_json
|
||||
form.value = res.data
|
||||
console.log(form.value)
|
||||
}
|
||||
}
|
||||
// 方法
|
||||
function stepChangeFunc(type) {
|
||||
switch (type) {
|
||||
case 1: // 上一步
|
||||
active.value -=1
|
||||
break;
|
||||
case 2: // 下一步
|
||||
if(active.value == 0) { // 保存第一步的信息
|
||||
submitForm(ruleFormRef.value)
|
||||
}
|
||||
else{
|
||||
active.value +=1
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
const submitForm = async (formEl) => {
|
||||
if (!formEl) return
|
||||
await formEl.validate((valid, fields) => {
|
||||
if (valid) {
|
||||
console.log('submit!')
|
||||
saveStep1()
|
||||
} else {
|
||||
// console.log('error submit!', fields)
|
||||
}
|
||||
})
|
||||
}
|
||||
async function saveStep1() {
|
||||
let params = {
|
||||
step1:{
|
||||
...form.value
|
||||
}
|
||||
}
|
||||
params.step1.price = parseInt(params.step1.price)
|
||||
let func_name =''
|
||||
if(course_id.value) { // 编辑
|
||||
params.course_id = parseInt(course_id.value)
|
||||
func_name = 'editCourse'
|
||||
}
|
||||
else{ // 新增
|
||||
func_name = 'addCourse'
|
||||
}
|
||||
const res = await api[func_name](params)
|
||||
if(res.code === 0) {
|
||||
active.value += 1
|
||||
course_id.value = res.data
|
||||
current_subject.value = form.value.subject
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '操作成功!'
|
||||
})
|
||||
}
|
||||
}
|
||||
async function getSubject(){ // 获取课程分类
|
||||
const res = await api.getSubjectList(subjectParams.value)
|
||||
if(res.code === 0) {
|
||||
subjectList.value = custom.getStdSubject(res.data.records)
|
||||
}
|
||||
}
|
||||
async function uploadAction(file){//图片上传 非oss
|
||||
file.status = 'uploading';
|
||||
file.message = '上传中...';
|
||||
//开始上传
|
||||
const content = new FormData();
|
||||
//上传图片需要转换二进制这里要用到FormData
|
||||
content.append("file", file.file);
|
||||
content.append("type", '1');
|
||||
const res=await com_api.upload(content);
|
||||
if(res.code==200){
|
||||
file.status = 'done';
|
||||
file.message = '上传成功';
|
||||
file.url = res.data.full_path;
|
||||
this.courseForm.cover = file.url
|
||||
}
|
||||
else{
|
||||
file.status = 'failed';
|
||||
file.message = '上传失败';
|
||||
}
|
||||
//重新赋值 img/视频
|
||||
|
||||
// var val_arr = []
|
||||
// for(let item of topicInfo.value[topic_index.value].answer_img_arr){
|
||||
// if(item.uid==file.file.uid){
|
||||
// item.url=file.url
|
||||
// }
|
||||
// val_arr.push(item.url)
|
||||
// }
|
||||
// topicInfo.value[topic_index.value].answer_img = val_arr.join(",")
|
||||
// const exercises_info = {
|
||||
// ...topicInfo.value[topic_index.value],
|
||||
// answer_img: topicInfo.value[topic_index.value].answer_img
|
||||
// }
|
||||
// card_submit_data(exercises_info)
|
||||
}
|
||||
function handleAvatarSuccess(res) {
|
||||
form.value.cover = res.data.file.url
|
||||
}
|
||||
function beforeAvatarUpload(file) {
|
||||
const isLt05M = file.size / 1024 / 1024 < 5
|
||||
const isJPG = file.type.indexOf('image/') === -1
|
||||
if (isJPG) {
|
||||
ElMessage.error('文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件')
|
||||
}
|
||||
if (!isLt05M) {
|
||||
ElMessage.error('上传头像图片大小不能超过 2M!')
|
||||
}
|
||||
return !isJPG && isLt05M
|
||||
}
|
||||
function onSubmit() {
|
||||
router.push({name:'courseManage'})
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<!-- 步骤条-->
|
||||
<div class="gva-search-box">
|
||||
<el-steps :active="active" finish-status="success" simple style="margin-bottom: 20px">
|
||||
<el-step title="课程信息" />
|
||||
<el-step title="添加章节" />
|
||||
</el-steps>
|
||||
</div>
|
||||
<!-- 表单区域-->
|
||||
<div class="gva-table-box">
|
||||
<!-- step1-->
|
||||
<el-form ref="ruleFormRef" v-if="active == 0" :model="form" :rules="rules" label-width="120px" style="width: 50%">
|
||||
<el-form-item label="课程名称" prop="name">
|
||||
<el-input placeholder="请输入课程名称" v-model="form.name" />
|
||||
</el-form-item>
|
||||
<el-form-item label="课程分类" prop="subject">
|
||||
<el-select v-model="form.subject" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="item in subjectList"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.name"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="封面">
|
||||
<el-upload
|
||||
class="avatar-uploader"
|
||||
:action="`${path}/fileUploadAndDownload/upload`"
|
||||
:headers="{ 'x-token': userStore.token }"
|
||||
:show-file-list="false"
|
||||
:on-success="handleAvatarSuccess"
|
||||
:before-upload="beforeAvatarUpload"
|
||||
>
|
||||
<img v-if="form.cover" :src="form.cover" class="avatar" />
|
||||
<el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
<el-form-item label="价格" prop="price">
|
||||
<el-input placeholder="请输入课程价格" type="number" v-model="form.price" />
|
||||
</el-form-item>
|
||||
<el-form-item label="课程简介">
|
||||
<el-input v-model="form.introduction" type="textarea" />
|
||||
</el-form-item>
|
||||
<el-form-item label="包含试听">
|
||||
<el-switch v-model="form.is_audition" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设置精品">
|
||||
<el-switch v-model="form.is_boutique" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="课程状态">
|
||||
<el-switch v-model="form.status" active-text="上架" inactive-text="下架" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
<el-form-item style="display: none">
|
||||
<el-button type="primary" @click="submitForm(ruleFormRef)">
|
||||
Create
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<!-- step2-->
|
||||
<div class="chapter-part" v-if="active == 1">
|
||||
<chapter-com @reload="getCourseInfo" :chapter_info="chapter_info" :course_id="course_id"/>
|
||||
</div>
|
||||
<div class="btn-box" style="text-align: right">
|
||||
<el-button v-if="active>0" @click="stepChangeFunc(1)">上一步</el-button>
|
||||
<el-button v-if="active<1" type="primary" @click="stepChangeFunc(2)">下一步</el-button>
|
||||
<el-button v-else type="primary" @click="onSubmit">完成</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.avatar-uploader .avatar {
|
||||
width: 178px;
|
||||
height: 178px;
|
||||
display: block;
|
||||
}
|
||||
</style>
|
315
src/view/course/components/chapter.vue
Normal file
315
src/view/course/components/chapter.vue
Normal file
@@ -0,0 +1,315 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'chapterCom',
|
||||
methods: {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
// import com_api from '@/api/common'
|
||||
// import custom from '@/utils/custom'
|
||||
// import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
import {ref,onMounted,watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
import { useUserStore } from '@/pinia/modules/user'
|
||||
const userStore = useUserStore()
|
||||
import exercisesCom from '../components/mediaPool.vue'
|
||||
const props = defineProps(['course_id','chapter_info'])
|
||||
const emit = defineEmits(['reload'])
|
||||
import UploadCommon from '@/components/upload/common.vue'
|
||||
// 变量
|
||||
const dialogChapterVisible = ref(false)
|
||||
// const dialogChapterTitle = ref('')
|
||||
const chapterForm = ref({pid:0})
|
||||
const chapterRules = ref({
|
||||
name: [{ required: true, message: '请输入章节名称', trigger: 'blur' }]
|
||||
})
|
||||
const chapter_data = ref([])
|
||||
const dialogChapterChildVisible = ref(false)
|
||||
const chapterChildForm = ref({})
|
||||
const chapterChildRules = ref({
|
||||
name: [{ required: true, message: '请输入章节名称', trigger: 'blur' }]
|
||||
})
|
||||
const dialogChapterTitle = ref('')
|
||||
const dialogChapterChildTitle = ref('')
|
||||
// const path = ref(import.meta.env.VITE_BASE_API)
|
||||
const imageCommon = ref('')
|
||||
// const current_chapter = ref({}) // 当前操作的大章节
|
||||
// const current_chapter_child = ref({}) // 当前操作的子章节
|
||||
// const chapter_index = ref(0)
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
chapter_data.value = props.chapter_info
|
||||
})
|
||||
watch(props,(old, newProps) => {
|
||||
chapter_data.value = props.chapter_info
|
||||
})
|
||||
// 方法
|
||||
function addChapterFunc() { // 添加大章节
|
||||
chapterForm.value = {pid:0}
|
||||
dialogChapterVisible.value = true
|
||||
dialogChapterTitle.value = '添加大章节'
|
||||
}
|
||||
async function deleteChapterFunc(item) { //删除大章节
|
||||
delFunc(item.id)
|
||||
}
|
||||
function delFunc(id) {
|
||||
ElMessageBox.confirm('此操作将永久删除该数据, 是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(async() => {
|
||||
const res = await api.delChapter({
|
||||
ids:[id]
|
||||
})
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '删除成功!'
|
||||
})
|
||||
emit('reload')
|
||||
}
|
||||
},() => {
|
||||
})
|
||||
}
|
||||
function editChapterFunc(item) { //编辑大章节
|
||||
chapterForm.value = item
|
||||
dialogChapterVisible.value = true
|
||||
dialogChapterTitle.value = '编辑大章节'
|
||||
}
|
||||
function closeChapterDialog() {
|
||||
dialogChapterVisible.value = false
|
||||
}
|
||||
function closeChapterChildDialog() {
|
||||
dialogChapterChildVisible.value = false
|
||||
}
|
||||
async function enterChapterDialog() { // 提交大章节
|
||||
// console.log(chapterForm.value)
|
||||
// return
|
||||
chapterForm.value.sort = parseInt(chapterForm.value.sort)
|
||||
const params = {
|
||||
...chapterForm.value
|
||||
}
|
||||
let func_name = ''
|
||||
if(chapterForm.value.id) { // 编辑
|
||||
func_name = 'editChapter'
|
||||
}
|
||||
else{ // 新增
|
||||
func_name = 'addChapter'
|
||||
params.course_id = props.course_id
|
||||
}
|
||||
const res = await api[func_name](params)
|
||||
if(res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '操作成功!'
|
||||
})
|
||||
closeChapterDialog()
|
||||
emit('reload')
|
||||
}
|
||||
}
|
||||
function addChapterchildFunc(item) { // 打开新增子章节窗口
|
||||
dialogChapterChildTitle.value = '新增子章节'
|
||||
// current_chapter.value = item
|
||||
chapterChildForm.value = {pid:item.id}
|
||||
dialogChapterChildVisible.value = true
|
||||
}
|
||||
function editChapterChildFunc(item,main_index) { // 打开编辑子章节窗口
|
||||
dialogChapterChildTitle.value = '编辑子章节'
|
||||
// current_chapter.value = chapter_data.value[main_index]
|
||||
chapterChildForm.value = item
|
||||
dialogChapterChildVisible.value = true
|
||||
}
|
||||
function deleteChapterChildFunc(item) { // 删除子章节
|
||||
delFunc(item.id)
|
||||
}
|
||||
async function enterChapterChildDialog() { // 提交小章节
|
||||
chapterChildForm.value.sort = parseInt(chapterChildForm.value.sort)
|
||||
const params = {
|
||||
...chapterChildForm.value
|
||||
}
|
||||
let func_name = ''
|
||||
// console.log(params)
|
||||
// return
|
||||
if(chapterChildForm.value.id){ // 编辑
|
||||
func_name = 'editChapter'
|
||||
}
|
||||
else{ // 新增
|
||||
func_name = 'addChapter'
|
||||
params.course_id = props.course_id
|
||||
}
|
||||
const res = await api[func_name](params)
|
||||
if(res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '操作成功!'
|
||||
})
|
||||
closeChapterChildDialog()
|
||||
emit('reload')
|
||||
}
|
||||
}
|
||||
function getFilePath(file) { // 获取上传文件之后的地址
|
||||
|
||||
}
|
||||
function chooseChapterChildExercises() { // 打开选择习题窗口
|
||||
|
||||
}
|
||||
function openExercisesWinFunc() { // 打开媒体库
|
||||
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<div class="btn-box" style="text-align: right;margin: 10px 0 20px;">
|
||||
<el-button type="primary" icon="plus" @click="addChapterFunc">添加章节</el-button>
|
||||
</div>
|
||||
<div class="list-box">
|
||||
<div class="lb-card" v-for="(item,i) in chapter_data">
|
||||
<!--大章节标题-->
|
||||
<div class="lb-title-part">
|
||||
<div class="lbt-title">{{item.name}}</div>
|
||||
<div class="lbt-btn-box">
|
||||
<el-button
|
||||
icon="edit"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="editChapterFunc(item)"
|
||||
/>
|
||||
<el-button
|
||||
icon="plus"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="addChapterchildFunc(item)"
|
||||
/>
|
||||
<el-button
|
||||
icon="delete"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="deleteChapterFunc(item)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<!--表格数据-->
|
||||
<div class="lb-table-part" style="margin-bottom: 20px">
|
||||
<el-table :data="item.children" >
|
||||
<el-table-column align="left" label="id" width="60" prop="id" />
|
||||
<el-table-column align="left" label="子章节名称" min-width="60" prop="name" />
|
||||
<el-table-column align="left" label="课件名称" min-width="60" prop="url_name" />
|
||||
<el-table-column align="left" label="章节习题" min-width="60" prop="is_contain_exercise">
|
||||
<template #default="scope">
|
||||
{{scope.row.is_contain_exercise === 0?'未添加习题':scope.row.is_contain_exercise}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="是否免费" min-width="60">
|
||||
<template #default="scope">
|
||||
{{scope.row.is_free === 1? '是':'否'}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="是否展示" min-width="60">
|
||||
<template #default="scope">
|
||||
{{scope.row.is_show === 1? '是':'否'}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="left" label="操作" min-width="60">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
icon="edit"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="editChapterChildFunc(scope.row)"
|
||||
>编辑</el-button>
|
||||
<el-button
|
||||
icon="delete"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="deleteChapterChildFunc(scope.row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 添加/编辑 大章节窗口-->
|
||||
<el-dialog v-model="dialogChapterVisible" :before-close="closeChapterDialog" :title="dialogChapterTitle">
|
||||
<el-form ref="apiForm" :model="chapterForm" :rules="chapterRules" label-width="80px">
|
||||
<el-form-item label="章节名称" prop="name">
|
||||
<el-input v-model="chapterForm.name" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="章节排序" prop="sort">
|
||||
<el-input v-model="chapterForm.sort" placeholder="输入整数,排序越小越靠前展示" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否免费" prop="is_free">
|
||||
<el-switch v-model="chapterForm.is_free" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否展示" prop="is_show">
|
||||
<el-switch v-model="chapterForm.is_show" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button size="small" @click="closeChapterDialog">取 消</el-button>
|
||||
<el-button size="small" type="primary" @click="enterChapterDialog">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!-- 添加小章节窗口-->
|
||||
<el-dialog v-model="dialogChapterChildVisible" :before-close="closeChapterChildDialog" :title="dialogChapterChildTitle">
|
||||
<el-form ref="apiForm" :model="chapterChildForm" :rules="chapterChildRules" label-width="80px">
|
||||
<el-form-item label="章节名称" prop="name">
|
||||
<el-input v-model="chapterChildForm.name" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="上传课件">
|
||||
<!-- <upload-common-->
|
||||
<!-- v-model:imageCommon="imageCommon"-->
|
||||
<!-- class="upload-btn"-->
|
||||
<!-- @on-success="getFilePath"-->
|
||||
<!-- />-->
|
||||
<exercises-com @on-success="getFilePath" />
|
||||
<!-- <el-button size="small" type="primary" @click="openExercisesWinFunc">点击上传</el-button>-->
|
||||
</el-form-item>
|
||||
<el-form-item label="习题管理">
|
||||
<el-button size="small" @click="chooseChapterChildExercises">添加习题</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="章节排序" prop="sort">
|
||||
<el-input v-model="chapterChildForm.sort" placeholder="输入整数,排序越小越靠前展示" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否免费" prop="is_free">
|
||||
<el-switch v-model="chapterChildForm.is_free" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
<el-form-item label="是否展示" prop="is_show">
|
||||
<el-switch v-model="chapterChildForm.is_show" active-text="是" inactive-text="否" :active-value="1" :inactive-value="-1" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button size="small" @click="closeChapterChildDialog">取 消</el-button>
|
||||
<el-button size="small" type="primary" @click="enterChapterChildDialog">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.lbt-title{
|
||||
margin-right: 20px;
|
||||
font-size: 18px;
|
||||
}
|
||||
.lb-title-part{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
141
src/view/course/components/mediaPool.vue
Normal file
141
src/view/course/components/mediaPool.vue
Normal file
@@ -0,0 +1,141 @@
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
// import com_api from '@/api/common'
|
||||
// import custom from '@/utils/custom'
|
||||
// import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
import {ref,onMounted,watch,inject } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
import { useUserStore } from '@/pinia/modules/user'
|
||||
const userStore = useUserStore()
|
||||
// import chapterCom from '../components/chapter.vue'
|
||||
const props = defineProps(['course_id','chapter_info'])
|
||||
const emit = defineEmits(['on-success'])
|
||||
import { clients, getNowDate } from '@/utils'
|
||||
import { getToken } from '@/utils/auth'
|
||||
// 变量
|
||||
const headers = ref({ Authorization: 'Bearer ' + getToken() })
|
||||
const drawer = ref(false)
|
||||
const queryParams =ref({
|
||||
pageIndex:1,
|
||||
pageSize:10,
|
||||
name:''
|
||||
})
|
||||
// 生命周期
|
||||
const subjectList = inject('subjectList')
|
||||
const current_subject = inject('current_subject')
|
||||
onMounted(() => {
|
||||
// console.log(headers.value)
|
||||
})
|
||||
|
||||
// 方法
|
||||
function openExercisesWinFunc() {
|
||||
drawer.value = true
|
||||
}
|
||||
function onSubmit() {
|
||||
|
||||
}
|
||||
function onReset() {
|
||||
queryParams.value = {
|
||||
pageIndex:1,
|
||||
pageSize:10,
|
||||
name:''
|
||||
}
|
||||
}
|
||||
async function httpUpload(file) { // 上传oss
|
||||
console.log(file)
|
||||
// this.$set(this.chapterTable.sel, 'percentage', 0)
|
||||
// this.$set(this.chapterTable.sel, 'loading', true)
|
||||
const client = clients()
|
||||
// 判断扩展名
|
||||
const tmpcnt = file.file.name.lastIndexOf('.')
|
||||
const exname = file.file.name.substring(tmpcnt + 1)
|
||||
const imgUrl = 'http://gwjxb.oss-cn-chengdu.aliyuncs.com'
|
||||
const fileName = `static/uploadfile/${getNowDate()}/${file.file.uid}.${exname}`
|
||||
await client.multipartUpload(fileName, file.file, {
|
||||
progress: (p, cpt, res) => {
|
||||
// 获取分片上传进度、断点和返回值。
|
||||
// this.$set(
|
||||
// this.chapterTable.sel,
|
||||
// 'percentage',
|
||||
// (Math.floor(p * 100) / 100) * 100
|
||||
// )
|
||||
// if (p === 1) {
|
||||
// this.$set(this.chapterTable.sel, 'loading', false)
|
||||
// }
|
||||
},
|
||||
parallel: 5, // 并发上传的分片数量
|
||||
partSize: 1024 * 1024 * 20,
|
||||
// headers,
|
||||
// 指定meta参数,自定义Object的元信息。通过head接口可以获取到Object的meta数据。
|
||||
meta: {
|
||||
year: 2020,
|
||||
people: 'test'
|
||||
},
|
||||
mime: file.type // 上传文件类型
|
||||
})
|
||||
// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。
|
||||
const head = await client.head(fileName)
|
||||
if (head.status === 200) {
|
||||
// 上传成功之后添加媒体库
|
||||
// this.addDepotFun(`${imgUrl}/${fileName}`, file.file.name)
|
||||
// 数据赋值
|
||||
// this.$set(this.chapterTable.sel, 'url', `${imgUrl}/${fileName}`)
|
||||
// this.$set(this.chapterTable.sel, 'url_name', file.file.name)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<el-button size="small" type="primary" @click="openExercisesWinFunc">点击上传</el-button>
|
||||
<el-drawer v-model="drawer" title="媒体库" size="50%">
|
||||
<div class="drawer-section">
|
||||
<!-- 搜索框-->
|
||||
<div class="search-box">
|
||||
<el-form ref="searchForm" :inline="true" :model="queryParams">
|
||||
<el-form-item label="课程名称">
|
||||
<el-input v-model="queryParams.name" placeholder="根据课程名称进行查询" />
|
||||
</el-form-item>
|
||||
<el-form-item label="课程分类">
|
||||
<el-select v-model="queryParams.subject" clearable placeholder="请选择">
|
||||
<el-option
|
||||
v-for="item in subjectList"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button size="small" type="primary" icon="search" @click="onSubmit">查询</el-button>
|
||||
<el-button size="small" icon="refresh" @click="onReset">重置</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-upload
|
||||
class="upload-demo"
|
||||
action
|
||||
:http-request="httpUpload"
|
||||
:show-file-list="false"
|
||||
>
|
||||
<el-button
|
||||
size="small"
|
||||
type="text"
|
||||
>普通上传</el-button>
|
||||
</el-upload>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<!-- 数据列表-->
|
||||
<div class="list-box"></div>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.drawer-section{
|
||||
padding: 10px;
|
||||
}
|
||||
</style>
|
@@ -1,9 +1,9 @@
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
import custom from '@/utils/custom'
|
||||
import { toSQLLine } from '@/utils/stringFun'
|
||||
import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
// import custom from '@/utils/custom'
|
||||
// import { toSQLLine } from '@/utils/stringFun'
|
||||
// import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
import {ref,onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
// 变量
|
||||
@@ -12,9 +12,9 @@ const queryParams = ref({
|
||||
pageSize:10,
|
||||
keyword:''
|
||||
})
|
||||
const total = ref(0)
|
||||
// const dataList = ref([])
|
||||
const subjectList = ref([])
|
||||
const deleteVisible = ref(false)
|
||||
const dialogFormVisible = ref(false)
|
||||
const tableData =ref([])
|
||||
const dialogTitle = ref('')
|
||||
@@ -43,6 +43,7 @@ async function getSubjectList() {
|
||||
subjectList.value = res.data.records
|
||||
if(res.code == 0) {
|
||||
subjectList.value = res.data.records
|
||||
total.value = res.data.total
|
||||
subjectList.value = addTreeFormatSubject(subjectList.value)
|
||||
console.log(subjectList.value)
|
||||
}
|
||||
@@ -64,16 +65,16 @@ function onSubmit() {
|
||||
getSubjectList()
|
||||
}
|
||||
// 排序
|
||||
const sortChange = ({ prop, order }) => {
|
||||
if (prop) {
|
||||
if (prop === 'ID') {
|
||||
prop = 'id'
|
||||
}
|
||||
queryParams.value.orderKey = toSQLLine(prop)
|
||||
queryParams.value.desc = order === 'descending'
|
||||
}
|
||||
getSubjectList()
|
||||
}
|
||||
// const sortChange = ({ prop, order }) => {
|
||||
// if (prop) {
|
||||
// if (prop === 'ID') {
|
||||
// prop = 'id'
|
||||
// }
|
||||
// queryParams.value.orderKey = toSQLLine(prop)
|
||||
// queryParams.value.desc = order === 'descending'
|
||||
// }
|
||||
// getSubjectList()
|
||||
// }
|
||||
// 批量操作
|
||||
const handleSelectionChange = (val) => {
|
||||
apis.value = val
|
||||
@@ -188,6 +189,14 @@ const onReset = () => {
|
||||
keyword:''
|
||||
}
|
||||
}
|
||||
function handleCurrentChange(val) {
|
||||
queryParams.value.pageIndex = val
|
||||
getSubjectList()
|
||||
}
|
||||
function handleSizeChange(val) {
|
||||
queryParams.value.pageSize = val
|
||||
getSubjectList()
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
@@ -242,8 +251,19 @@ const onReset = () => {
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="gva-pagination">
|
||||
<el-pagination
|
||||
:current-page="queryParams.pageIndex"
|
||||
:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 30, 50, 100]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@current-change="handleCurrentChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<!--新增、编辑-->
|
||||
<!--新增、编辑 窗口-->
|
||||
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="dialogTitle">
|
||||
<!-- <warning-bar title="新增API,需要在角色管理内配置权限才可使用" />-->
|
||||
<el-form ref="categoryForm" :model="form" :rules="rules" label-width="80px">
|
||||
|
@@ -1,10 +1,14 @@
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
import custom from '@/utils/custom'
|
||||
// import { toSQLLine } from '@/utils/stringFun'
|
||||
import WarningBar from '@/components/warningBar/warningBar.vue'
|
||||
import {ref,onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
// 变量
|
||||
const queryParams = ref({
|
||||
pageIndex:1,
|
||||
@@ -17,42 +21,140 @@ const subjectParams = ref({
|
||||
pageIndex:1,
|
||||
pageSize:100,
|
||||
})
|
||||
const dataList = ref([])
|
||||
const tableData = ref([])
|
||||
const subjectList = ref([])
|
||||
const deleteVisible = ref(false)
|
||||
const course_ids = ref([])
|
||||
const total = ref(0)
|
||||
const dialogFormVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const form =ref({})
|
||||
const rules = ref({
|
||||
name: [{ required: true, message: '请输入课程名称', trigger: 'blur' }]
|
||||
})
|
||||
const course_id = ref(0)
|
||||
// 生命周期
|
||||
getCourseList()
|
||||
// getSubject()
|
||||
onMounted(() => {
|
||||
getCourseList()
|
||||
getSubject()
|
||||
})
|
||||
// 方法
|
||||
async function getCourseList() {
|
||||
const res = await api.getCourseList(queryParams.value)
|
||||
if(res.code === 200) {
|
||||
dataList.value = res.data.list
|
||||
if(res.code === 0) {
|
||||
tableData.value = res.data.records
|
||||
}
|
||||
}
|
||||
async function getSubject(){ // 获取课程分类
|
||||
const res = await api.getSubjectList(subjectParams.value)
|
||||
if(res.code === 0) {
|
||||
subjectList.value = custom.getStdSubject(res.data.records)
|
||||
// console.log(subjectList.value)
|
||||
}
|
||||
}
|
||||
function onSubmit() {
|
||||
getCourseList()
|
||||
}
|
||||
async function getSubject(){
|
||||
const res = await api.getSubject()
|
||||
if(res.code == 200) {
|
||||
subjectList.value = res.data.list
|
||||
const onReset = () => {
|
||||
queryParams.value = {
|
||||
pageIndex:1,
|
||||
pageSize:10,
|
||||
name:'',
|
||||
status:'',
|
||||
subject:''
|
||||
}
|
||||
}
|
||||
function openDialog(type) {
|
||||
let params = {}
|
||||
switch (type){
|
||||
case 'add':
|
||||
dialogTitle.value = '新增课程'
|
||||
break;
|
||||
case 'edit':
|
||||
params.course_id = course_id.value
|
||||
dialogTitle.value = '编辑课程'
|
||||
break;
|
||||
}
|
||||
router.push({name:'addCourse',params})
|
||||
}
|
||||
async function onDelete() {
|
||||
console.log(course_ids.value)
|
||||
const ids = course_ids.value.map(item => item.course_id)
|
||||
const res = await api.delCourse({ ids })
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: res.msg
|
||||
})
|
||||
// if (tableData.value.length === ids.length && page.value > 1) {
|
||||
// page.value--
|
||||
// }
|
||||
deleteVisible.value = false
|
||||
getCourseList()
|
||||
}
|
||||
}
|
||||
const handleSelectionChange = (val) => {
|
||||
// console.log(val)
|
||||
course_ids.value = val
|
||||
}
|
||||
function editCourseFunc(row) {
|
||||
course_id.value = row.course_id
|
||||
openDialog('edit')
|
||||
}
|
||||
function deleteCourseFunc(row) {
|
||||
ElMessageBox.confirm('此操作将永久删除该数据, 是否继续?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(async() => {
|
||||
const res = await api.delCourse({
|
||||
ids:[row.course_id]
|
||||
})
|
||||
if (res.code === 0) {
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '删除成功!'
|
||||
})
|
||||
// if (tableData.value.length === 1 && page.value > 1) {
|
||||
// page.value--
|
||||
// }
|
||||
getCourseList()
|
||||
}
|
||||
},() => {
|
||||
})
|
||||
}
|
||||
function handleCurrentChange() {
|
||||
|
||||
}
|
||||
function handleSizeChange() {
|
||||
|
||||
}
|
||||
function closeDialog(){
|
||||
dialogFormVisible.value = false
|
||||
}
|
||||
function enterDialog() {
|
||||
|
||||
}
|
||||
function viewCourseFunc(row) { // 查看课程
|
||||
router.push({name:'viewCourse',params:{course_id:row.course_id}})
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<!-- 搜索框-->
|
||||
<div class="gva-search-box">
|
||||
<el-form ref="searchForm" :inline="true" :model="queryParams">
|
||||
<el-form-item label="课程名称">
|
||||
<el-input v-model="queryParams.name" placeholder="课程名称" />
|
||||
<el-input v-model="queryParams.name" placeholder="根据课程名称进行查询" />
|
||||
</el-form-item>
|
||||
<el-form-item label="课程状态">
|
||||
<el-select v-model="queryParams.method" clearable placeholder="请选择">
|
||||
<el-form-item label="课程分类">
|
||||
<el-select v-model="queryParams.subject" clearable placeholder="请选择">
|
||||
<el-option
|
||||
v-for="item in subjectList"
|
||||
:key="item.value"
|
||||
:label="`${item.label}(${item.value})`"
|
||||
:value="item.value"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -62,9 +164,11 @@ async function getSubject(){
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<!-- 表格数据-->
|
||||
<div class="gva-table-box">
|
||||
<!-- 批量操作-->
|
||||
<div class="gva-btn-list">
|
||||
<el-button size="small" type="primary" icon="plus" @click="openDialog('addApi')">新增</el-button>
|
||||
<el-button size="small" type="primary" icon="plus" @click="openDialog('add')">新增</el-button>
|
||||
<el-popover v-model="deleteVisible" placement="top" width="160">
|
||||
<p>确定要删除吗?</p>
|
||||
<div style="text-align: right; margin-top: 8px;">
|
||||
@@ -72,50 +176,52 @@ async function getSubject(){
|
||||
<el-button size="small" type="primary" @click="onDelete">确定</el-button>
|
||||
</div>
|
||||
<template #reference>
|
||||
<el-button icon="delete" size="small" :disabled="!apis.length" style="margin-left: 10px;" @click="deleteVisible = true">删除</el-button>
|
||||
<el-button icon="delete" size="small" type="danger" :disabled="!course_ids.length" style="margin-left: 10px;" @click="deleteVisible = true">删除</el-button>
|
||||
</template>
|
||||
</el-popover>
|
||||
</div>
|
||||
<el-table :data="tableData" @sort-change="sortChange" @selection-change="handleSelectionChange">
|
||||
<!-- 数据列表-->
|
||||
<el-table :data="tableData" @selection-change="handleSelectionChange">
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="55"
|
||||
/>
|
||||
<el-table-column align="left" label="id" min-width="60" prop="ID" sortable="custom" />
|
||||
<el-table-column align="left" label="API路径" min-width="150" prop="path" sortable="custom" />
|
||||
<el-table-column align="left" label="API分组" min-width="150" prop="apiGroup" sortable="custom" />
|
||||
<el-table-column align="left" label="API简介" min-width="150" prop="description" sortable="custom" />
|
||||
<el-table-column align="left" label="请求" min-width="150" prop="method" sortable="custom">
|
||||
<template #default="scope">
|
||||
<div>
|
||||
{{ scope.row.method }} / {{ methodFilter(scope.row.method) }}
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column align="left" label="id" min-width="60" prop="id" sortable="custom" />
|
||||
<el-table-column align="left" label="名称" min-width="150" prop="name" />
|
||||
<el-table-column align="left" label="科目" min-width="150" prop="subject" />
|
||||
<el-table-column align="left" label="价格" min-width="150" prop="price" />
|
||||
<el-table-column align="left" label="状态" min-width="150" prop="status" />
|
||||
<el-table-column align="left" label="是否精品" min-width="150" prop="is_boutique" />
|
||||
<el-table-column align="left" fixed="right" label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
icon="view"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="viewCourseFunc(scope.row)"
|
||||
>查看</el-button>
|
||||
<el-button
|
||||
icon="edit"
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
@click="editApiFunc(scope.row)"
|
||||
@click="editCourseFunc(scope.row)"
|
||||
>编辑</el-button>
|
||||
<el-button
|
||||
icon="delete"
|
||||
size="small"
|
||||
type="primary"
|
||||
type="danger"
|
||||
link
|
||||
@click="deleteApiFunc(scope.row)"
|
||||
@click="deleteCourseFunc(scope.row)"
|
||||
>删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="gva-pagination">
|
||||
<el-pagination
|
||||
:current-page="page"
|
||||
:page-size="pageSize"
|
||||
:current-page="queryParams.pageIndex"
|
||||
:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 30, 50, 100]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@@ -127,26 +233,12 @@ async function getSubject(){
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="dialogTitle">
|
||||
<warning-bar title="新增API,需要在角色管理内配置权限才可使用" />
|
||||
<el-form ref="apiForm" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="路径" prop="path">
|
||||
<el-input v-model="form.path" autocomplete="off" />
|
||||
<el-form-item label="课程名称" prop="name">
|
||||
<el-input v-model="form.name" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="请求" prop="method">
|
||||
<el-select v-model="form.method" placeholder="请选择" style="width:100%">
|
||||
<el-option
|
||||
v-for="item in methodOptions"
|
||||
:key="item.value"
|
||||
:label="`${item.label}(${item.value})`"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="api分组" prop="apiGroup">
|
||||
<el-input v-model="form.apiGroup" autocomplete="off" />
|
||||
</el-form-item>
|
||||
<el-form-item label="api简介" prop="description">
|
||||
<el-input v-model="form.description" autocomplete="off" />
|
||||
<el-form-item label="课程简介" prop="introduction">
|
||||
<el-input v-model="form.introduction" autocomplete="off" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
|
79
src/view/course/viewCourse/index.vue
Normal file
79
src/view/course/viewCourse/index.vue
Normal file
@@ -0,0 +1,79 @@
|
||||
<script setup>
|
||||
// 引入依赖
|
||||
import api from '@/api/course'
|
||||
import {ref,onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
// 变量
|
||||
const course_id = ref(0)
|
||||
const courseData = ref({})
|
||||
// 生命周期
|
||||
onMounted(() => {
|
||||
course_id.value = route.params.course_id
|
||||
getCourse()
|
||||
})
|
||||
//方法
|
||||
async function getCourse() { // 获取课程信息
|
||||
const res = await api.getCourse({id:course_id.value})
|
||||
if(res.code === 0) {
|
||||
courseData.value = res.data
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<!-- 基本信息-->
|
||||
<div class="gva-search-box">
|
||||
<div class="baseinfoBox">
|
||||
<div class="base-card course-name">
|
||||
<div class="bc-left">课程名称:</div>
|
||||
<div class="bc-right">{{courseData.step1.name}}</div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">课程名称:</div>
|
||||
<div class="bc-right">{{courseData.step1.name}}</div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">课程科目:</div>
|
||||
<div class="bc-right">{{courseData.step1.subject}}</div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">课程状态:</div>
|
||||
<div class="bc-right">{{courseData.step1.status === 1?'上架':'下架'}}</div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">课程价格:</div>
|
||||
<div class="bc-right">{{courseData.step1.price}}</div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">教师姓名:</div>
|
||||
<div class="bc-right"></div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">创建时间:</div>
|
||||
<div class="bc-right"></div>
|
||||
</div>
|
||||
<div class="base-card">
|
||||
<div class="bc-left">课程简介:</div>
|
||||
<div class="bc-right">{{courseData.step1.introduction}}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 章节信息-->
|
||||
<div class="gva-table-box">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.course-name{
|
||||
font-weight: 900;
|
||||
font-size: 18px;
|
||||
width: 100%;
|
||||
}
|
||||
.baseinfoBox{
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user