// 课程管理CRUDimport axios from'../axios.js'//获取分类信息const zx_basic ='http://localhost:9999/basic'//去后台,获取所有分类的三级树exportconstAllCategory=async()=>{const res =await axios.get(zx_basic+"/category/getTree")return res
}//去后台,获取一级分类exportconstLevel1Category=async()=>{const res =await axios.get(zx_basic+"/category/level1Category")return res
}//根据字典编号,获取字典信息exportconstGetDict=async(code)=>{const res =await axios.get(zx_basic+"/dictionary/getDicItems/"+code)return res
}//去后台//获取所有机构信息const zx_system ='http://localhost:8888/system'exportconstGetCompany=async()=>{const res =await axios.get(zx_system+"/company/selectAll")return res
}
5.4.4.7 修改course.vue
<template><el-cardshadow="always"><h3><el-icon><ElementPlus/></el-icon>课程管理</h3><el-rowstyle="padding:10px;"gutter="3"><el-colspan="8"><el-buttontype="primary"size="small"@click="toAdd"><el-icon><CirclePlus/></el-icon> 新增</el-button><el-buttonv-if="multipleSelection.length"type="danger"size="small"@click="handlerMuchDel">删除多条</el-button></el-col><el-colspan="16"><el-inputsize="small"v-model="searchName"placeholder="按课程名称搜索"><template#append><el-icon><Search/></el-icon></template></el-input></el-col></el-row><el-table:data="filterData"@selection-change="handleSelectionChange"border><el-table-columnprop="id"type="selection"width="55"></el-table-column><el-table-columnprop="planNum"label="计划数量"heder-align="center"></el-table-column><el-table-columnprop="companyName"label="公司名称"heder-align="center"></el-table-column><el-table-columnprop="name"label="课程名称"heder-align="center"></el-table-column><el-table-columnprop="tags"label="课程标签"heder-align="center"></el-table-column><el-table-columnprop="mtName"label="大分类名称"heder-align="center"></el-table-column><el-table-columnprop="stName"label="小分类名称"heder-align="center"></el-table-column><el-table-columnprop="grade"label="课程等级"heder-align="center"></el-table-column><el-table-columnprop="teachmode"label="教学模式"heder-align="center"></el-table-column><el-table-columnprop="auditStatus"label="审核状态"heder-align="center"></el-table-column><el-table-columnprop="coursePubId"label="发布标识"heder-align="center"></el-table-column><el-table-columnprop="price"label="课程单价"heder-align="center"></el-table-column><el-table-columnprop="createDate"label="创建时间":formatter="formatDate"align="center"/><el-table-columnprop="auditDate"label="审核时间":formatter="formatDate"align="center"/><el-table-columnlabel="操作"align="center"><template#default="scope"><el-button@click="toEdit(scope.$index)"type="success"size="small"><el-icon><EditPen/></el-icon>修改</el-button><el-button@click="handleDel(scope.row.id)"type="danger"size="small"><el-icon><Delete/></el-icon>删除</el-button><el-button@click="handlePub(scope.row.id)"type="danger"size="small"><el-icon><Delete/></el-icon>发布</el-button><el-button@click="handleDown(scope.row.id)"type="danger"size="small"><el-icon><Delete/></el-icon>下架</el-button></template></el-table-column></el-table><!-- 分页条 --><divstyle=""><el-pagination:current-page="page.pageNum":page-size="page.pageSize":page-sizes="[5,10,50,100]"layout="total,sizes,prev,pager,next,jumper":total="page.total"@size-change="handleSizeChange"@current-change="handleCurrentChange"></el-pagination></div></el-card><!-- 设置对话框 --><el-dialogv-model="dialogVisible"draggable><template#header><h4><el-icon><Brush/></el-icon> {{dialogType==='add'?'新增':'修改'}}课程管理</h4></template><el-form:model="form.data"label-position="left"label-width="120px"><el-form-itemlabel="机构名称"><el-selectv-model="form.data.companyId"placeholder="请选择"><el-optionv-for="item in companyOptions":key="item.id":label="item.name":value="item.id"></el-option></el-select></el-form-item><el-form-itemlabel="课程名称"><el-inputv-model="form.data.name"show-word-limitmaxlength="100"></el-input></el-form-item><el-form-itemlabel="适用人群"><el-inputv-model="form.data.users"type="textarea"show-word-limitmaxlength="500":autosize="{minRows:2,maxRows:4}"></el-input></el-form-item><el-form-itemlabel="课程标签"><el-inputv-model="form.data.tags"></el-input></el-form-item><!-- 4个下拉框 --><el-form-itemlabel="一级分类"><el-selectv-model="form.data.mt"placeholder="请选择"><el-optionv-for="item in mtOptions":key="item.id":label="item.name":value="item.id"></el-option></el-select></el-form-item><el-form-itemlabel="二级分类"><!-- 二级分类树 --><el-selectv-model="form.data.st"placeholder="请选择"><el-option:value="selectValue":label="selectValue"style="height: 200px;overflow: auto;"><el-tree:data="stOptions"@node-click="handleNodeClick"></el-tree></el-option></el-select></el-form-item><el-form-itemlabel="课程等级"><el-selectv-model="form.data.grade"placeholder="请选择"><!-- 遍历gradeOptions :key遍历的id :label要展示的数据 :value根据key获取到的value--><el-optionv-for="item in gradeOptions":key="item.code":label="item.desc":value="item.code"></el-option></el-select></el-form-item><el-form-itemlabel="教学模式"><el-selectv-model="form.data.teachmode"placeholder="请选择"><el-optionv-for="item in teachmodeOptions":key="item.code":label="item.desc":value="item.code"></el-option></el-select></el-form-item><el-form-itemlabel="课程介绍"><el-inputv-model="form.data.description"type="textarea"show-word-limitmaxlength="1000":autosize="{minRows:4,maxRows:10}"></el-input></el-form-item><el-form-itemlabel="课程图片"><el-inputv-model="form.data.pic"></el-input></el-form-item><el-form-itemlabel="课程单价"><el-inputv-model="form.data.price">(元)</el-input></el-form-item></el-form><divstyle=""><el-button@click="dialogSave"type="success">保存</el-button><el-button@click="dialogCancle"type="primary">取消</el-button></div></el-dialog></template><scriptsetup>// 一级分类:::: 1.引入jsimport{GetCompany,Level1Category,AllCategory,GetDict}from'../../api/basic.js'import{ ref, reactive }from'vue'import{ElMessageBox}from'element-plus'//导入消息提示框import{toast}from'../../tools/utils.js'import{CoursePage,CourseDel,CourseSave}from'../../api/course.js'const dialogVisible =ref(false)//对话框是否展示const dialogType =ref('add')//对话框新增还是修改const searchName =ref('')//按照课程名称查询//查后台数据,准备4个下拉框的值,value值是要传给后台的,label的值是要在页面展示的//:::: 一级分类:::: 2.使用1.引入js的结果,利用axios获取数据let mtOptions =ref([])//一级分类//响应式声明变量Level1Category().then(res=>{// console.log(res)mtOptions.value = res //给响应式变量赋值要用value属性}).catch(err=>{})//:::: 二级分类:::: let stOptions =ref([])AllCategory().then(res=>{stOptions=resconsole.log(res+'-'+stOptions)}).catch(err=>{console.log(err)})const selectValue=ref()consthandleNodeClick=(e,node)=>{selectValue.value=e.value+'->'+e.labelform.data.st=selectValue.value}let gradeOptions =ref([])//课程等级204,课程模式200GetDict(204).then((res=>{// console.log(res)gradeOptions.value=res})).catch(err=>{console.log(err)})let teachmodeOptions =ref([])//教学模式GetDict(200).then(res=>{teachmodeOptions=res}).catch(err=>{console.log(err)})//===============机构名称let companyOptions =ref([])GetCompany().then(res=>{companyOptions.value=res}).catch(err=>{console.log(err)})//多选const multipleSelection =ref([])//临时存放选中的数据,实际上就是多个rowconsthandleSelectionChange=(val)=>{//当点击多选按钮时就会触发multipleSelection.value = val}//准备表格数据,const state =reactive({tableDate:[]})//空数组consthandleDel=(id)=>{ElMessageBox.confirm('您是否确认删除此记录?','提示',{confirmButtonText:'确认',cancelButtonText:'取消',type:'warning'}).then(()=>{CourseDel(id).then(res=>{toast('删除记录成功!')loadingData(1,page.pageSize)//重新查询,默认展示第一页}).catch(err=>{console.log(err)})}).catch(()=>{})}//删除多条consthandlerMuchDel=()=>{ElMessageBox.confirm('您是否确认删除此记录?','提示',{confirmButtonText:'确认',cancelButtonText