list.vue 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" @submit.native.prevent>
  6. <el-form-item label="课程分类">
  7. <el-select v-model="categoryValue" placeholder="请选择" clearable @change="searchList" size="small">
  8. <el-option v-for="item in categoryOptions" :key="item.value" :label="item.label" :value="item.value">
  9. </el-option>
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item label="课程名称">
  13. <el-input v-model="keyword" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
  14. </el-form-item>
  15. <el-form-item label="讲师">
  16. <el-input v-model="instructor" placeholder="请输入" clearable @change="searchList" size="small"></el-input>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" @click="addCourse" size="small" >添加课程</el-button>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" @click="batchManage" size="small">分类管理</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </el-col>
  26. <!--列表-->
  27. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  28. <el-table-column type="index" width="50" align="center" label="#"></el-table-column>
  29. <el-table-column label="封面" width="120" align="center">
  30. <template slot-scope="scope">
  31. <img v-if="scope.row.coverImage" :src="scope.row.coverImage" class="course-cover-image" />
  32. <span v-else>无封面</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="courseTypeName" label="课程分类" min-width="120" align="center"></el-table-column>
  36. <el-table-column prop="courseName" label="课程名称" min-width="180" align="center"></el-table-column>
  37. <el-table-column prop="courseInstructor" label="讲师" min-width="120" align="center"></el-table-column>
  38. <el-table-column prop="coursePrice" label="价格" min-width="100" align="center">
  39. <template slot-scope="scope">
  40. <span>¥{{ scope.row.coursePrice }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="courseDuration" label="课程时间" min-width="120" align="center">
  44. <template slot-scope="scope">
  45. <span>{{ scope.row.courseDuration ? scope.row.courseDuration + '分钟' : '' }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="视频" min-width="100" align="center">
  49. <template slot-scope="scope">
  50. <span v-if="!scope.row.courseUrl">无</span>
  51. <el-button v-else type="text" @click="playVideo(scope.row)">
  52. <i class="el-icon-video-play" style="font-size: 20px; color: #409EFF;"></i>
  53. </el-button>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="操作" width="250" class-name="btns" header-align="center" fixed="right">
  57. <template slot-scope="scope">
  58. <el-button size="small" type="danger" @click="deleteItem(scope.row)">删除</el-button>
  59. <el-button size="small" type="primary" @click="editItem(scope.row)">编辑</el-button>
  60. <el-button size="small" :type="scope.row.courseStatus === 1 ? 'warning' : 'success'" @click="uploadItem(scope.row)">{{scope.row.courseStatus === 1 ? '下架' : '上架'}}</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <!--工具条-->
  65. <el-col :span="24" class="toolbar">
  66. <el-pagination
  67. @size-change="handleSizeChange"
  68. @current-change="handleCurrentChange"
  69. :page-sizes="[10, 20, 50, 100]"
  70. :page-size="size"
  71. layout="total, sizes, prev, pager, next, jumper"
  72. :total="total"
  73. style="float:right;"
  74. ></el-pagination>
  75. </el-col>
  76. <!-- 新增/编辑课程 -->
  77. <el-dialog :visible.sync="addDialogVisible" :title="newCourse.id ? '编辑课程' : '添加课程'" width="900px" :close-on-click-modal="false" @close="stopCourseVideo">
  78. <el-form :model="newCourse" ref="newCourseForm" label-width="100px" :rules="courseRules">
  79. <el-form-item label="课程分类" prop="categoryValue">
  80. <el-select v-model="newCourse.categoryValue" placeholder="请选择" style="width: 100%">
  81. <el-option v-for="item in categoryOptions" :key="item.value" :label="item.label" :value="item.value">
  82. </el-option>
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="课程名称" prop="courseName">
  86. <el-input v-model="newCourse.courseName" placeholder="请输入"></el-input>
  87. </el-form-item>
  88. <el-form-item label="课程介绍" prop="courseDesc">
  89. <el-input
  90. v-model="newCourse.courseDesc"
  91. type="textarea"
  92. :rows="5"
  93. placeholder="请输入课程介绍"
  94. />
  95. </el-form-item>
  96. <el-form-item label="讲师" prop="instructor">
  97. <el-input v-model="newCourse.instructor" placeholder="请输入讲师姓名"></el-input>
  98. </el-form-item>
  99. <el-form-item label="讲师介绍" prop="instructorDesc">
  100. <el-input
  101. v-model="newCourse.instructorDesc"
  102. type="textarea"
  103. :rows="5"
  104. placeholder="请输入讲师介绍"
  105. />
  106. </el-form-item>
  107. <el-form-item label="课程价格" prop="price">
  108. <el-input v-model="newCourse.price" placeholder="请输入"></el-input>
  109. </el-form-item>
  110. <el-form-item label="课程时间" prop="duration">
  111. <el-input v-model="newCourse.duration" placeholder="请输入"></el-input>
  112. </el-form-item>
  113. <el-form-item label="课程封面">
  114. <el-upload
  115. class="cover-uploader"
  116. action="#"
  117. :show-file-list="false"
  118. :on-change="handleCoverImageChange"
  119. :auto-upload="false"
  120. :before-upload="beforeImageUpload">
  121. <img v-if="newCourse.coverImageUrl" :src="newCourse.coverImageUrl" class="cover-image" />
  122. <i v-else class="el-icon-plus cover-uploader-icon"></i>
  123. </el-upload>
  124. <div class="upload-tip">请上传课程封面图片,建议尺寸 16:9</div>
  125. </el-form-item>
  126. <el-form-item label="讲师照片" prop="instructorImg">
  127. <el-upload
  128. class="instructor-uploader"
  129. action="#"
  130. :show-file-list="false"
  131. :on-change="handleInstructorImageChange"
  132. :auto-upload="false"
  133. :before-upload="beforeImageUpload">
  134. <img v-if="newCourse.instructorImageUrl" :src="newCourse.instructorImageUrl" class="instructor-image" />
  135. <i v-else class="el-icon-plus instructor-uploader-icon"></i>
  136. </el-upload>
  137. <div class="upload-tip">请上传讲师照片,建议尺寸 1:1</div>
  138. </el-form-item>
  139. <el-form-item label="课程视频">
  140. <el-upload
  141. action="#"
  142. :auto-upload="false"
  143. :limit="1"
  144. :on-exceed="handleExceed"
  145. :file-list="newCourse.videoFiles"
  146. :on-change="handleVideoChange"
  147. :before-upload="beforeVideoUpload"
  148. accept="video/mp4,video/avi,video/x-msvideo">
  149. <el-button size="small" type="primary">点击上传</el-button>
  150. <div slot="tip" class="el-upload__tip">只能上传单个mp4/avi文件</div>
  151. </el-upload>
  152. <div v-if="newCourse.courseUrl" class="video-preview">
  153. <div class="video-header">
  154. <span class="video-title">视频预览</span>
  155. <el-button
  156. type="text"
  157. class="delete-video-btn"
  158. @click="deleteVideo">
  159. <i class="el-icon-delete"></i> 删除视频
  160. </el-button>
  161. </div>
  162. <video
  163. controls
  164. width="300"
  165. ref="courseVideoPlayer"
  166. :src="newCourse.courseUrl"
  167. style="margin-top: 10px; max-width: 100%">
  168. 您的浏览器不支持视频播放
  169. </video>
  170. <div class="video-name" v-if="newCourse.videoFiles && newCourse.videoFiles.length > 0">
  171. {{ newCourse.videoFiles[0].name }}
  172. </div>
  173. </div>
  174. </el-form-item>
  175. </el-form>
  176. <span slot="footer" class="dialog-footer">
  177. <el-button @click="addDialogVisible = false">取消</el-button>
  178. <el-button type="primary" @click="submitNewCourse('newCourseForm')">{{newCourse.id ? '保存' : '添加'}}</el-button>
  179. </span>
  180. </el-dialog>
  181. <!-- 分类管理 -->
  182. <el-dialog :visible.sync="categoryManageVisible" title="分类管理" width="600px">
  183. <el-table :data="categoryList" style="width: 100%" max-height="400">
  184. <el-table-column prop="label" label="分类名称" width="180"></el-table-column>
  185. <el-table-column label="封面" width="180">
  186. <template slot-scope="scope">
  187. <img v-if="scope.row.coverImage" :src="scope.row.coverImage" class="category-cover-image" />
  188. <span v-else>无封面</span>
  189. </template>
  190. </el-table-column>
  191. <el-table-column label="操作" width="180">
  192. <template slot-scope="scope">
  193. <el-button size="mini" type="primary" @click="setCategoryCover(scope.$index, scope.row)">设置封面</el-button>
  194. <el-button size="mini" type="danger" @click="deleteCategory(scope.$index, scope.row)">删除</el-button>
  195. </template>
  196. </el-table-column>
  197. </el-table>
  198. <div style="margin-top: 20px;">
  199. <el-form :inline="true" :model="newCategory" class="demo-form-inline">
  200. <el-form-item label="分类名称">
  201. <el-input v-model="newCategory.label" placeholder="请输入分类名称"></el-input>
  202. </el-form-item>
  203. <el-form-item>
  204. <el-button type="primary" @click="addCategory">添加</el-button>
  205. </el-form-item>
  206. </el-form>
  207. </div>
  208. <span slot="footer" class="dialog-dialog">
  209. <el-button @click="categoryManageVisible = false">关 闭</el-button>
  210. </span>
  211. </el-dialog>
  212. <!-- 设置分类封面 -->
  213. <el-dialog :visible.sync="coverDialogVisible" title="设置分类封面" width="500px">
  214. <div class="cover-upload-container">
  215. <el-upload
  216. class="cover-uploader"
  217. action="#"
  218. :show-file-list="false"
  219. :on-change="handleCoverChange"
  220. :auto-upload="false"
  221. :before-upload="beforeCoverUpload">
  222. <img v-if="coverImageUrl" :src="coverImageUrl" class="cover-image" />
  223. <i v-else class="el-icon-plus cover-uploader-icon"></i>
  224. </el-upload>
  225. <div class="cover-tip">请上传分类封面图片,建议尺寸 16:9</div>
  226. </div>
  227. <span slot="footer" class="dialog-footer">
  228. <el-button @click="coverDialogVisible = false">取 消</el-button>
  229. <el-button type="primary" @click="saveCategoryCover">确 定</el-button>
  230. </span>
  231. </el-dialog>
  232. <!-- 视频播放对话框 -->
  233. <el-dialog :visible.sync="videoDialogVisible" title="视频播放" width="800px" center @close="stopVideo">
  234. <div class="video-player-container">
  235. <video
  236. v-if="currentVideoUrl"
  237. controls
  238. autoplay
  239. ref="videoPlayer"
  240. class="video-player"
  241. :src="currentVideoUrl">
  242. 您的浏览器不支持视频播放
  243. </video>
  244. </div>
  245. <span slot="footer" class="dialog-footer">
  246. <el-button @click="closeVideoDialog">关 闭</el-button>
  247. </span>
  248. </el-dialog>
  249. <!-- 新增飞书企业 -->
  250. <el-dialog v-if="addFeishuDig" :visible.sync="addFeishuDig" title="新增飞书客户">
  251. <el-form :model="feishuInfo" :rules="feishuInfoRules" ref="feishuInfo" label-width="100px" class="demo-ruleForm">
  252. <el-form-item label="公司名称" prop="companyName">
  253. <el-input v-model="feishuInfo.companyName"></el-input>
  254. </el-form-item>
  255. <el-form-item label="corpId" prop="corpId">
  256. <el-input v-model="feishuInfo.corpId"></el-input>
  257. </el-form-item>
  258. <el-form-item label="appId" prop="appId">
  259. <el-input v-model="feishuInfo.appId"></el-input>
  260. </el-form-item>
  261. <el-form-item label="appSecret" prop="appSecret">
  262. <el-input v-model="feishuInfo.appSecret"></el-input>
  263. </el-form-item>
  264. <el-form-item label="管理员" prop="managerName">
  265. <el-input v-model="feishuInfo.managerName"></el-input>
  266. </el-form-item>
  267. </el-form>
  268. <span slot="footer" class="dialog-footer">
  269. <el-button @click="addFeishuDig = false">取 消</el-button>
  270. <el-button type="primary" @click="addFeishuInfo('feishuInfo')">确 定</el-button>
  271. </span>
  272. </el-dialog>
  273. </section>
  274. </template>
  275. <script>
  276. import App from '../../App.vue';
  277. export default {
  278. components: { App },
  279. data() {
  280. return {
  281. // 课程分类选择
  282. categoryValue: '',
  283. categoryOptions: [],
  284. // 搜索条件
  285. keyword: null, // 课程名称
  286. instructor: null, // 讲师
  287. // 表格相关
  288. tableHeight: 0,
  289. listLoading: false,
  290. total: 0,
  291. page: 1,
  292. size: 20,
  293. list: [],
  294. // 对话框控制
  295. editDialogVisible: false,
  296. addDialogVisible: false,
  297. categoryManageVisible: false,
  298. videoDialogVisible: false, // 视频播放对话框
  299. currentVideoUrl: '', // 当前播放的视频URL
  300. // 当前编辑的课程数据
  301. currentCourse: null,
  302. // 新增课程数据
  303. newCourse: {
  304. categoryValue: '',
  305. courseName: '',
  306. courseDesc: '',
  307. instructor: '',
  308. instructorDesc: '',
  309. price: '',
  310. duration: '',
  311. coverImage: '',
  312. instructorImg: '',
  313. courseUrl: '',
  314. // 图片和文件上传
  315. coverImageUrl: '',
  316. coverImageFile: null,
  317. instructorImageUrl: '',
  318. instructorImageFile: null,
  319. videoFiles: []
  320. },
  321. // 表单验证规则
  322. courseRules: {
  323. categoryValue: [
  324. { required: true, message: '请选择课程分类', trigger: 'change' }
  325. ],
  326. courseName: [
  327. { required: true, message: '请输入课程名称', trigger: 'blur' }
  328. ],
  329. instructor: [
  330. { required: true, message: '请输入讲师姓名', trigger: 'blur' }
  331. ],
  332. price: [
  333. { required: true, message: '请输入课程价格', trigger: 'blur' },
  334. {
  335. pattern: /^\d+(\.\d{1,1})?$/,
  336. message: '请输入正确的价格格式(整数或最多1位小数)',
  337. trigger: 'blur'
  338. }
  339. ],
  340. duration: [
  341. { required: true, message: '请输入课程时长', trigger: 'blur' },
  342. {
  343. pattern: /^[1-9]\d*$/,
  344. message: '请输入整数分钟数',
  345. trigger: 'blur'
  346. }
  347. ]
  348. },
  349. // 文件上传
  350. videoFiles: [],
  351. attachmentFiles: [],
  352. // 分类管理
  353. categoryList: [],
  354. newCategory: {
  355. label: '',
  356. value: '',
  357. coverImage: ''
  358. },
  359. // 分类封面设置
  360. coverDialogVisible: false,
  361. currentCategoryIndex: -1,
  362. coverImageUrl: '',
  363. coverImageFile: null,
  364. // 用户信息
  365. user: sessionStorage.user ? JSON.parse(sessionStorage.user) : {},
  366. // 保留原有的一些变量,以防其他功能依赖
  367. dialogData: null,
  368. editDialogA: false,
  369. editDialogB: false,
  370. editDialogC: false,
  371. editDialogD: false,
  372. editDialogF: false,
  373. editDialogG: false,
  374. editDialogH: false,
  375. dingdingSync: false,
  376. isMeal: 0,
  377. addStaffCountMaxNum: 0,
  378. expirationNewDate: null,
  379. reportFormList: [],
  380. roleList: [],
  381. roleIdArr: [],
  382. onlyContract: false,
  383. addFeishuDig: false,
  384. feishuInfo: {
  385. companyName: '',
  386. corpId: '',
  387. appId: '',
  388. appSecret: '',
  389. managerName: '',
  390. },
  391. feishuInfoRules: {
  392. companyName: [
  393. { required: true, message: '请输入客户名称', trigger: 'blur' },
  394. ],
  395. corpId: [
  396. { required: true, message: '请输入corpId', trigger: 'blur' },
  397. ],
  398. appId: [
  399. { required: true, message: '请输入appId', trigger: 'blur' },
  400. ],
  401. appSecret: [
  402. { required: true, message: '请输入appSecret', trigger: 'blur' },
  403. ],
  404. managerName: [
  405. { required: true, message: '请输入管理员名称', trigger: 'blur' },
  406. ],
  407. }
  408. };
  409. },
  410. // 过滤器
  411. filters: {
  412. },
  413. methods: {
  414. // 播放视频
  415. playVideo(row) {
  416. if (row.courseUrl) {
  417. this.currentVideoUrl = row.courseUrl;
  418. this.videoDialogVisible = true;
  419. } else {
  420. this.$message.warning('该课程没有视频');
  421. }
  422. },
  423. // 停止视频播放
  424. stopVideo() {
  425. if (this.$refs.videoPlayer) {
  426. const videoElement = this.$refs.videoPlayer;
  427. videoElement.pause();
  428. videoElement.currentTime = 0;
  429. videoElement.src = '';
  430. }
  431. this.currentVideoUrl = '';
  432. },
  433. // 关闭视频对话框
  434. closeVideoDialog() {
  435. this.stopVideo();
  436. this.videoDialogVisible = false;
  437. },
  438. // 停止课程视频播放
  439. stopCourseVideo() {
  440. if (this.$refs.courseVideoPlayer) {
  441. const videoElement = this.$refs.courseVideoPlayer;
  442. videoElement.pause();
  443. videoElement.currentTime = 0;
  444. // 不清除视频源,只暂停播放
  445. }
  446. },
  447. // 删除视频
  448. deleteVideo() {
  449. this.$confirm('确认删除该视频?', '提示', {
  450. confirmButtonText: '确定',
  451. cancelButtonText: '取消',
  452. type: 'warning'
  453. }).then(() => {
  454. // 清空视频相关数据
  455. this.newCourse.courseUrl = '';
  456. this.newCourse.videoFiles = [];
  457. this.$message({
  458. type: 'success',
  459. message: '视频已删除!'
  460. });
  461. }).catch(() => {
  462. this.$message({
  463. type: 'info',
  464. message: '已取消删除'
  465. });
  466. });
  467. },
  468. // 搜索课程列表
  469. searchList() {
  470. this.page = 1;
  471. this.getList();
  472. },
  473. // 添加课程
  474. addCourse() {
  475. this.addDialogVisible = true;
  476. // 这里可以初始化新课程数据
  477. this.newCourse = {
  478. categoryValue: '',
  479. courseName: '',
  480. courseDesc: '',
  481. instructor: '',
  482. instructorDesc: '',
  483. price: '',
  484. duration: '',
  485. coverImage: '',
  486. instructorImg: '',
  487. courseUrl: '',
  488. // 图片和文件上传
  489. coverImageUrl: '',
  490. coverImageFile: null,
  491. instructorImageUrl: '',
  492. instructorImageFile: null,
  493. videoFiles: []
  494. };
  495. // 使用 $nextTick 确保表单已经渲染完成后再重置验证状态
  496. this.$nextTick(() => {
  497. if (this.$refs.newCourseForm) {
  498. this.$refs.newCourseForm.clearValidate();
  499. }
  500. });
  501. },
  502. // 分类管理
  503. batchManage() {
  504. this.categoryManageVisible = true;
  505. // 加载分类数据
  506. this.http.post('/course-type/list', {}, res => {
  507. if (res.code == "ok") {
  508. // 将后端返回的数据转换为前端需要的格式
  509. this.categoryList = res.data.map(item => ({
  510. label: item.typeName,
  511. value: item.id,
  512. coverImage: item.coverImage || ''
  513. }));
  514. // 同步更新下拉选项
  515. this.categoryOptions = [...this.categoryList];
  516. } else {
  517. this.$message({
  518. message: res.msg || '获取分类列表失败',
  519. type: 'error'
  520. });
  521. }
  522. }, error => {
  523. this.$message({
  524. message: error || '获取分类列表失败',
  525. type: 'error'
  526. });
  527. });
  528. },
  529. // 删除课程
  530. deleteItem(row) {
  531. this.$confirm('确认删除该课程?', '提示', {
  532. confirmButtonText: '确定',
  533. cancelButtonText: '取消',
  534. type: 'warning'
  535. }).then(() => {
  536. // 调用后端API删除课程
  537. this.http.post('/course-info/deleteCourse', {
  538. id: row.id
  539. }, res => {
  540. if (res.code == "ok") {
  541. this.$message({
  542. type: 'success',
  543. message: '删除成功!'
  544. });
  545. this.getList();
  546. } else {
  547. this.$message({
  548. message: res.msg || '删除课程失败',
  549. type: 'error'
  550. });
  551. }
  552. }, error => {
  553. this.$message({
  554. message: error || '删除课程失败',
  555. type: 'error'
  556. });
  557. });
  558. }).catch(() => {
  559. this.$message({
  560. type: 'info',
  561. message: '已取消删除'
  562. });
  563. });
  564. },
  565. // 编辑课程
  566. editItem(row) {
  567. // 显示加载状态
  568. this.listLoading = true;
  569. // 调用API获取课程详情
  570. this.http.post('/course-info/getDetail', {
  571. id: row.id
  572. }, res => {
  573. this.listLoading = false;
  574. if (res.code == "ok") {
  575. // 使用API返回的详细数据
  576. const courseDetail = res.data;
  577. // 重置新增课程表单,用于编辑
  578. this.newCourse = {
  579. id: courseDetail.id,
  580. categoryValue: courseDetail.courseTypeId,
  581. courseName: courseDetail.courseName,
  582. courseDesc: courseDetail.courseDesc || '',
  583. instructor: courseDetail.courseInstructor,
  584. instructorDesc: courseDetail.instructorDesc || '',
  585. price: courseDetail.coursePrice,
  586. duration: courseDetail.courseDuration || '',
  587. instructorImg: courseDetail.instructorImg || '',
  588. coverImage: courseDetail.coverImage || '',
  589. courseUrl: courseDetail.courseUrl || ''
  590. };
  591. // 设置课程封面和讲师照片URL(如果有)
  592. this.newCourse.coverImageUrl = courseDetail.coverImage ? courseDetail.coverImage : '';
  593. this.newCourse.instructorImageUrl = courseDetail.instructorImg ? courseDetail.instructorImg : '';
  594. this.newCourse.videoFiles = courseDetail.courseUrl ? [{
  595. name: '已上传视频',
  596. url: courseDetail.courseUrl
  597. }] : [];
  598. // 打开添加课程对话框(用于编辑)
  599. this.addDialogVisible = true;
  600. // 修改对话框标题为"编辑课程"
  601. setTimeout(() => {
  602. const dialogTitle = document.querySelector('.el-dialog__title');
  603. if (dialogTitle) {
  604. dialogTitle.textContent = '编辑课程';
  605. }
  606. }, 100);
  607. } else {
  608. // 如果API调用失败,使用表格行数据
  609. this.currentCourse = JSON.parse(JSON.stringify(row));
  610. this.editDialogVisible = true;
  611. this.$message({
  612. message: res.msg || '获取课程详情失败',
  613. type: 'warning'
  614. });
  615. }
  616. }, error => {
  617. this.listLoading = false;
  618. // 如果API调用出错,使用表格行数据
  619. this.currentCourse = JSON.parse(JSON.stringify(row));
  620. this.editDialogVisible = true;
  621. this.$message({
  622. message: error || '获取课程详情失败',
  623. type: 'error'
  624. });
  625. });
  626. },
  627. // 上架/下架课程
  628. uploadItem(row) {
  629. const action = row.courseStatus === 1 ? '下架' : '上架';
  630. this.$confirm(`确认${action}该课程?`, '提示', {
  631. confirmButtonText: '确定',
  632. cancelButtonText: '取消',
  633. type: 'warning'
  634. }).then(() => {
  635. // 调用后端API上架/下架课程
  636. this.http.post('/course-info/saveOrUpdate', {
  637. id: row.id,
  638. courseStatus: row.courseStatus === 1 ? 0 : 1 // 0: 下架, 1: 上架
  639. }, res => {
  640. if (res.code == "ok") {
  641. row.courseStatus = row.courseStatus === 1 ? 0 : 1;
  642. this.$message({
  643. type: 'success',
  644. message: `${action}成功!`
  645. });
  646. } else {
  647. this.$message({
  648. message: res.msg || `${action}失败`,
  649. type: 'error'
  650. });
  651. }
  652. }, error => {
  653. this.$message({
  654. message: error || `${action}失败`,
  655. type: 'error'
  656. });
  657. });
  658. }).catch(() => {
  659. this.$message({
  660. type: 'info',
  661. message: `已取消${action}`
  662. });
  663. });
  664. },
  665. // 处理视频文件上传前的验证
  666. beforeVideoUpload(file) {
  667. const isVideo = file.type === 'video/mp4' || file.type === 'video/avi' || file.type === 'video/x-msvideo';
  668. const isLt100M = file.size / 1024 / 1024 < 100;
  669. if (!isVideo) {
  670. this.$message.error('只能上传 MP4 或 AVI 格式的视频文件!');
  671. }
  672. if (!isLt100M) {
  673. this.$message.error('视频文件大小不能超过 100MB!');
  674. }
  675. return isVideo && isLt100M;
  676. },
  677. // 处理超出上传数量限制
  678. handleExceed(files, fileList) {
  679. this.$message.warning('只能上传单个视频文件,请先删除已有视频再上传新的!');
  680. },
  681. // 处理视频文件上传
  682. handleVideoChange(file, fileList) {
  683. // 限制只保留最新的一个文件
  684. if (fileList.length > 1) {
  685. fileList = [fileList[fileList.length - 1]];
  686. }
  687. this.newCourse.videoFiles = fileList;
  688. // 立即上传视频文件
  689. if (file && file.raw) {
  690. this.listLoading = true;
  691. this.uploadFile(file.raw, fileName => {
  692. this.listLoading = false;
  693. if (fileName) {
  694. // 如果是添加课程,更新newCourse对象
  695. if (this.addDialogVisible) {
  696. this.newCourse.courseUrl = fileName;
  697. }
  698. // 如果是编辑课程,更新currentCourse对象
  699. else if (this.editDialogVisible && this.currentCourse) {
  700. this.currentCourse.courseUrl = fileName;
  701. }
  702. this.$message({
  703. type: 'success',
  704. message: '视频上传成功!'
  705. });
  706. }
  707. });
  708. }
  709. },
  710. // 处理附件上传
  711. handleAttachmentChange(file, fileList) {
  712. this.attachmentFiles = fileList;
  713. // 立即上传附件文件
  714. if (file && file.raw) {
  715. this.listLoading = true;
  716. this.uploadFile(file.raw, fileName => {
  717. this.listLoading = false;
  718. if (fileName) {
  719. // 如果是添加课程,更新newCourse对象
  720. if (this.addDialogVisible) {
  721. this.newCourse.attachmentUrl = fileName;
  722. }
  723. // 如果是编辑课程,更新currentCourse对象
  724. else if (this.editDialogVisible && this.currentCourse) {
  725. this.currentCourse.attachmentUrl = fileName;
  726. }
  727. this.$message({
  728. type: 'success',
  729. message: '附件上传成功!'
  730. });
  731. }
  732. });
  733. }
  734. },
  735. // 处理讲师照片上传前的验证
  736. beforeImageUpload(file) {
  737. const isImage = file.type.indexOf('image/') === 0;
  738. const isLt2M = file.size / 1024 / 1024 < 2;
  739. if (!isImage) {
  740. this.$message.error('上传图片只能是图片格式!');
  741. }
  742. if (!isLt2M) {
  743. this.$message.error('上传图片大小不能超过 2MB!');
  744. }
  745. return isImage && isLt2M;
  746. },
  747. // 处理课程封面变更
  748. handleCoverImageChange(file) {
  749. this.newCourse.coverImageFile = file.raw;
  750. if (this.newCourse.coverImageFile) {
  751. this.newCourse.coverImageUrl = URL.createObjectURL(this.newCourse.coverImageFile);
  752. // 立即上传课程封面
  753. this.listLoading = true;
  754. this.uploadFile(this.newCourse.coverImageFile, fileName => {
  755. this.listLoading = false;
  756. if (fileName) {
  757. this.newCourse.coverImage = fileName;
  758. this.$message({
  759. type: 'success',
  760. message: '课程封面上传成功!'
  761. });
  762. }
  763. });
  764. }
  765. },
  766. // 处理讲师照片变更
  767. handleInstructorImageChange(file) {
  768. this.newCourse.instructorImageFile = file.raw;
  769. if (this.newCourse.instructorImageFile) {
  770. this.newCourse.instructorImageUrl = URL.createObjectURL(this.newCourse.instructorImageFile);
  771. // 立即上传讲师照片
  772. this.listLoading = true;
  773. this.uploadFile(this.newCourse.instructorImageFile, fileName => {
  774. this.listLoading = false;
  775. if (fileName) {
  776. this.newCourse.instructorImg = fileName;
  777. this.$message({
  778. type: 'success',
  779. message: '讲师照片上传成功!'
  780. });
  781. }
  782. });
  783. }
  784. },
  785. // 上传文件到服务器
  786. uploadFile(file, callback) {
  787. if (!file) {
  788. callback(null);
  789. return;
  790. }
  791. const formData = new FormData();
  792. formData.append('multipartFile', file);
  793. this.http.uploadFile('/common/uploadFile', formData, res => {
  794. if (res.code == "ok") {
  795. callback(res.data);
  796. } else {
  797. this.$message({
  798. message: res.msg || '文件上传失败',
  799. type: 'error'
  800. });
  801. callback(null);
  802. }
  803. }, error => {
  804. this.$message({
  805. message: error || '文件上传失败',
  806. type: 'error'
  807. });
  808. callback(null);
  809. });
  810. },
  811. // 提交课程(新增或编辑)
  812. submitNewCourse(formName) {
  813. this.$refs[formName].validate((valid) => {
  814. if (valid) {
  815. // 显示加载状态
  816. this.listLoading = true;
  817. // 准备课程数据
  818. let categoryOption = this.categoryOptions.find(
  819. option => option.value === this.newCourse.categoryValue
  820. );
  821. // 准备API请求参数
  822. const params = {
  823. courseTypeId: this.newCourse.categoryValue,
  824. courseName: this.newCourse.courseName,
  825. courseDesc: this.newCourse.courseDesc,
  826. courseInstructor: this.newCourse.instructor,
  827. instructorDesc: this.newCourse.instructorDesc,
  828. coursePrice: this.newCourse.price,
  829. instructorImg: this.newCourse.instructorImg,
  830. coverImage: this.newCourse.coverImage,
  831. courseUrl: this.newCourse.courseUrl,
  832. courseDuration: this.newCourse.duration
  833. };
  834. // 如果是编辑模式,添加课程ID
  835. if (this.newCourse.id) {
  836. params.id = this.newCourse.id;
  837. } else {
  838. // 新增课程默认为未上架状态
  839. params.courseStatus = 0;
  840. }
  841. // 调用后端API保存课程数据
  842. this.http.post('/course-info/saveOrUpdate', params, res => {
  843. this.listLoading = false;
  844. if (res.code == "ok") {
  845. // 清空表单
  846. this.newCourse = {
  847. categoryValue: '',
  848. courseName: '',
  849. courseDesc: '',
  850. instructor: '',
  851. instructorDesc: '',
  852. price: '',
  853. duration: '',
  854. coverImage: '',
  855. instructorImg: '',
  856. courseUrl: '',
  857. // 图片和文件上传
  858. coverImageUrl: '',
  859. coverImageFile: null,
  860. instructorImageUrl: '',
  861. instructorImageFile: null,
  862. videoFiles: []
  863. };
  864. this.addDialogVisible = false;
  865. this.$message({
  866. type: 'success',
  867. message: params.id ? '更新课程成功!' : '添加课程成功!'
  868. });
  869. // 刷新列表
  870. this.getList();
  871. } else {
  872. this.$message({
  873. message: res.msg || (params.id ? '更新课程失败' : '添加课程失败'),
  874. type: 'error'
  875. });
  876. }
  877. }, error => {
  878. this.listLoading = false;
  879. this.$message({
  880. message: error || (params.id ? '更新课程失败' : '添加课程失败'),
  881. type: 'error'
  882. });
  883. });
  884. } else {
  885. return false;
  886. }
  887. });
  888. },
  889. // 更新课程
  890. updateCourse(formName) {
  891. this.$refs[formName].validate((valid) => {
  892. if (valid) {
  893. // 显示加载状态
  894. this.listLoading = true;
  895. // 准备课程数据
  896. let categoryOption = this.categoryOptions.find(
  897. option => option.value === this.currentCourse.categoryValue
  898. );
  899. // 调用后端API更新课程数据
  900. this.http.post('/course-info/saveOrUpdate', {
  901. id: this.currentCourse.id,
  902. courseTypeId: this.currentCourse.categoryValue,
  903. courseName: this.currentCourse.courseName,
  904. courseInstructor: this.currentCourse.instructor,
  905. coursePrice: this.currentCourse.price.replace(/¥/g, ''),
  906. courseUrl: this.currentCourse.courseUrl,
  907. attachmentUrl: this.currentCourse.attachmentUrl
  908. }, res => {
  909. this.listLoading = false;
  910. if (res.code == "ok") {
  911. // 更新课程对象
  912. const categoryName = categoryOption ? categoryOption.label : this.currentCourse.category;
  913. this.currentCourse.category = categoryName;
  914. this.currentCourse.videos = this.videoFiles.length + '个';
  915. this.currentCourse.attachments = this.attachmentFiles.length + '个';
  916. this.editDialogVisible = false;
  917. this.$message({
  918. type: 'success',
  919. message: '更新课程成功!'
  920. });
  921. // 刷新列表
  922. this.getList();
  923. } else {
  924. this.$message({
  925. message: res.msg || '更新课程失败',
  926. type: 'error'
  927. });
  928. }
  929. }, error => {
  930. this.listLoading = false;
  931. this.$message({
  932. message: error || '更新课程失败',
  933. type: 'error'
  934. });
  935. });
  936. } else {
  937. return false;
  938. }
  939. });
  940. },
  941. // 添加分类
  942. addCategory() {
  943. if (!this.newCategory.label || !this.newCategory.label.trim()) {
  944. this.$message({
  945. type: 'warning',
  946. message: '请输入分类名称!'
  947. });
  948. return;
  949. }
  950. // 调用后端API保存课程分类
  951. this.http.post('/course-type/saveOrUpdate', {
  952. typeName: this.newCategory.label
  953. }, res => {
  954. if (res.code == "ok") {
  955. // 生成唯一ID作为value,实际项目中应该使用后端返回的ID
  956. const categoryId = res.data && res.data.id ? res.data.id : 'category_' + Date.now();
  957. this.newCategory.value = categoryId;
  958. // 添加到分类列表
  959. this.categoryList.push({...this.newCategory});
  960. this.categoryOptions.push({...this.newCategory});
  961. // 清空输入
  962. this.newCategory.label = '';
  963. this.newCategory.value = '';
  964. this.$message({
  965. type: 'success',
  966. message: '添加分类成功!'
  967. });
  968. } else {
  969. this.$message({
  970. message: res.msg || '添加分类失败',
  971. type: 'error'
  972. });
  973. }
  974. }, error => {
  975. this.$message({
  976. message: error || '添加分类失败',
  977. type: 'error'
  978. });
  979. });
  980. },
  981. // 删除分类
  982. deleteCategory(index, row) {
  983. this.$confirm('确认删除该分类?', '提示', {
  984. confirmButtonText: '确定',
  985. cancelButtonText: '取消',
  986. type: 'warning'
  987. }).then(() => {
  988. // 调用后端API删除课程分类
  989. this.http.post('/course-type/delete', {
  990. id: row.value
  991. }, res => {
  992. if (res.code == "ok") {
  993. // 从分类列表中删除
  994. this.categoryList.splice(index, 1);
  995. // 从下拉选项中删除
  996. const optionIndex = this.categoryOptions.findIndex(item => item.value === row.value);
  997. if (optionIndex !== -1) {
  998. this.categoryOptions.splice(optionIndex, 1);
  999. }
  1000. this.$message({
  1001. type: 'success',
  1002. message: '删除分类成功!'
  1003. });
  1004. } else {
  1005. this.$message({
  1006. message: res.msg || '删除分类失败',
  1007. type: 'error'
  1008. });
  1009. }
  1010. }, error => {
  1011. this.$message({
  1012. message: error || '删除分类失败',
  1013. type: 'error'
  1014. });
  1015. });
  1016. }).catch(() => {
  1017. this.$message({
  1018. type: 'info',
  1019. message: '已取消删除'
  1020. });
  1021. });
  1022. },
  1023. // 设置分类封面
  1024. setCategoryCover(index, row) {
  1025. this.currentCategoryIndex = index;
  1026. this.coverImageUrl = row.coverImage || '';
  1027. this.coverDialogVisible = true;
  1028. },
  1029. // 处理封面图片上传前的验证
  1030. beforeCoverUpload(file) {
  1031. const isImage = file.type.indexOf('image/') === 0;
  1032. const isLt2M = file.size / 1024 / 1024 < 2;
  1033. if (!isImage) {
  1034. this.$message.error('上传封面图片只能是图片格式!');
  1035. }
  1036. if (!isLt2M) {
  1037. this.$message.error('上传封面图片大小不能超过 2MB!');
  1038. }
  1039. return isImage && isLt2M;
  1040. },
  1041. // 处理封面图片变更
  1042. handleCoverChange(file) {
  1043. this.coverImageFile = file.raw;
  1044. if (this.coverImageFile) {
  1045. this.coverImageUrl = URL.createObjectURL(this.coverImageFile);
  1046. // 获取当前分类的ID
  1047. if (this.currentCategoryIndex >= 0) {
  1048. const categoryId = this.categoryList[this.currentCategoryIndex].value;
  1049. // 立即上传封面图片
  1050. this.listLoading = true;
  1051. // 创建FormData对象用于上传文件
  1052. const formData = new FormData();
  1053. formData.append('id', categoryId);
  1054. formData.append('coverImage', this.coverImageFile);
  1055. // 调用上传图片的API
  1056. this.http.uploadFile('/course-type/uploadCover', formData, res => {
  1057. this.listLoading = false;
  1058. if (res.code == "ok") {
  1059. // 上传成功后,获取返回的图片URL
  1060. const imageUrl = res.data && res.data.url ? res.data.url : this.coverImageUrl;
  1061. // 更新本地数据
  1062. this.categoryList[this.currentCategoryIndex].coverImage = imageUrl;
  1063. // 同步更新到分类选项中
  1064. const optionIndex = this.categoryOptions.findIndex(item => item.value === categoryId);
  1065. if (optionIndex !== -1) {
  1066. this.categoryOptions[optionIndex].coverImage = imageUrl;
  1067. }
  1068. this.$message({
  1069. type: 'success',
  1070. message: '封面图片上传成功!'
  1071. });
  1072. } else {
  1073. this.$message({
  1074. message: res.msg || '上传封面图片失败',
  1075. type: 'error'
  1076. });
  1077. }
  1078. }, error => {
  1079. this.listLoading = false;
  1080. this.$message({
  1081. message: error || '上传封面图片失败',
  1082. type: 'error'
  1083. });
  1084. });
  1085. }
  1086. }
  1087. },
  1088. // 保存分类封面
  1089. saveCategoryCover() {
  1090. if (!this.coverImageUrl) {
  1091. this.$message.warning('请先上传封面图片!');
  1092. return;
  1093. }
  1094. // 关闭对话框
  1095. this.coverDialogVisible = false;
  1096. this.$message({
  1097. type: 'success',
  1098. message: '设置封面成功!'
  1099. });
  1100. },
  1101. // 添加飞书信息
  1102. addFeishuInfo(formName) {
  1103. this.$refs[formName].validate((valid) => {
  1104. if (valid) {
  1105. this.http.post('/company/addFeiShuInfo', {
  1106. companyName: this.feishuInfo.companyName,
  1107. corpId: this.feishuInfo.corpId,
  1108. appId: this.feishuInfo.appId,
  1109. appSecret: this.feishuInfo.appSecret,
  1110. managerName: this.feishuInfo.managerName,
  1111. }, res => {
  1112. if (res.code == 'ok') {
  1113. this.addFeishuDig = false;
  1114. this.feishuInfo = {};
  1115. this.$message({
  1116. message: '新增飞书客户初始化成功',
  1117. type: 'success'
  1118. });
  1119. } else {
  1120. this.$message({
  1121. message: res.msg,
  1122. type: 'error'
  1123. });
  1124. }
  1125. }, err => {
  1126. this.$message({
  1127. message: err,
  1128. type: 'error'
  1129. });
  1130. });
  1131. } else {
  1132. return false;
  1133. }
  1134. });
  1135. },
  1136. // 分页相关
  1137. handleCurrentChange(val) {
  1138. this.page = val;
  1139. this.getList();
  1140. },
  1141. handleSizeChange(val) {
  1142. this.size = val;
  1143. this.getList();
  1144. },
  1145. // 获取课程列表
  1146. getList() {
  1147. this.listLoading = true;
  1148. // 调用后端API获取课程列表
  1149. this.http.post('/course-info/list', {
  1150. page: this.page,
  1151. size: this.size,
  1152. courseType: this.categoryValue,
  1153. courseName: this.keyword,
  1154. courseInstructor: this.instructor
  1155. }, res => {
  1156. this.listLoading = false;
  1157. if (res.code == "ok") {
  1158. this.list = res.data.records;
  1159. this.total = res.data.total;
  1160. } else {
  1161. // 如果API调用失败,使用模拟数据(实际项目中可以移除这部分)
  1162. this.useMockData();
  1163. this.$message({
  1164. message: res.msg || '获取课程列表失败',
  1165. type: 'error'
  1166. });
  1167. }
  1168. }, error => {
  1169. // 如果API调用出错,使用模拟数据(实际项目中可以移除这部分)
  1170. this.useMockData();
  1171. this.listLoading = false;
  1172. this.$message({
  1173. message: error || '获取课程列表失败',
  1174. type: 'error'
  1175. });
  1176. });
  1177. },
  1178. // 使用模拟数据(实际项目中可以移除这个方法)
  1179. useMockData() {
  1180. // 模拟数据
  1181. const mockData = [
  1182. {
  1183. id: 1,
  1184. category: '考试认证流程介绍',
  1185. courseName: '考试认证流程详解',
  1186. instructor: '张老师',
  1187. price: '¥299',
  1188. duration: '2小时',
  1189. videos: '5个',
  1190. attachments: '3个',
  1191. isUploaded: true
  1192. },
  1193. {
  1194. id: 2,
  1195. category: '线下研修班',
  1196. courseName: '线下实战培训',
  1197. instructor: '李老师',
  1198. price: '¥599',
  1199. duration: '8小时',
  1200. videos: '0个',
  1201. attachments: '5个',
  1202. isUploaded: true
  1203. },
  1204. {
  1205. id: 3,
  1206. category: '基础法规班',
  1207. courseName: '法规基础知识',
  1208. instructor: '王老师',
  1209. price: '¥199',
  1210. duration: '3小时',
  1211. videos: '10个',
  1212. attachments: '2个',
  1213. isUploaded: false
  1214. },
  1215. {
  1216. id: 4,
  1217. category: '高级培训班',
  1218. courseName: '高级实战技巧',
  1219. instructor: '赵老师',
  1220. price: '¥899',
  1221. duration: '12小时',
  1222. videos: '15个',
  1223. attachments: '8个',
  1224. isUploaded: true
  1225. }
  1226. ];
  1227. // 过滤数据
  1228. let filteredData = [...mockData];
  1229. if (this.categoryValue) {
  1230. let categoryOption = this.categoryOptions.find(option => option.value === this.categoryValue);
  1231. const categoryName = categoryOption ? categoryOption.label : '';
  1232. filteredData = filteredData.filter(item => item.category === categoryName);
  1233. }
  1234. if (this.keyword) {
  1235. filteredData = filteredData.filter(item =>
  1236. item.courseName.toLowerCase().includes(this.keyword.toLowerCase())
  1237. );
  1238. }
  1239. if (this.instructor) {
  1240. filteredData = filteredData.filter(item =>
  1241. item.instructor.toLowerCase().includes(this.instructor.toLowerCase())
  1242. );
  1243. }
  1244. this.total = filteredData.length;
  1245. // 分页
  1246. const start = (this.page - 1) * this.size;
  1247. const end = start + this.size;
  1248. this.list = filteredData.slice(start, end);
  1249. }
  1250. },
  1251. created() {
  1252. let height = window.innerHeight;
  1253. this.tableHeight = height - 195;
  1254. const that = this;
  1255. window.onresize = function temp() {
  1256. that.tableHeight = window.innerHeight - 195;
  1257. };
  1258. // 初始化分类列表
  1259. this.categoryList = [...this.categoryOptions];
  1260. },
  1261. mounted() {
  1262. // 获取课程分类数据
  1263. this.http.post('/course-type/list', {}, res => {
  1264. if (res.code == "ok") {
  1265. // 将后端返回的数据转换为前端需要的格式
  1266. this.categoryList = res.data.map(item => ({
  1267. label: item.typeName,
  1268. value: item.id,
  1269. coverImage: item.coverImage || ''
  1270. }));
  1271. // 同步更新下拉选项
  1272. this.categoryOptions = [...this.categoryList];
  1273. } else {
  1274. this.$message({
  1275. message: res.msg || '获取分类列表失败',
  1276. type: 'error'
  1277. });
  1278. }
  1279. }, error => {
  1280. this.$message({
  1281. message: error || '获取分类列表失败',
  1282. type: 'error'
  1283. });
  1284. });
  1285. // 获取课程列表
  1286. this.getList();
  1287. }
  1288. };
  1289. </script>
  1290. <style lang="scss" scoped>
  1291. .rg_span{
  1292. display: inline-block;
  1293. }
  1294. .rg_span span {
  1295. text-align: right;
  1296. box-sizing: border-box;
  1297. padding-right: 10px;
  1298. }
  1299. .el-dialog__title {
  1300. display: inline-table;
  1301. margin-top: 20px;
  1302. }
  1303. .btns .el-button{
  1304. margin-left: 10px;
  1305. margin-bottom: 5px;
  1306. }
  1307. </style>
  1308. <style>
  1309. .course-cover-image {
  1310. width: 100px;
  1311. height: 100px;
  1312. object-fit: cover;
  1313. border-radius: 4px;
  1314. }
  1315. .otherForm .el-form-item{
  1316. float: left;
  1317. width: 50%;
  1318. margin: 0;
  1319. }
  1320. /* 视频播放器样式 */
  1321. .video-player-container {
  1322. display: flex;
  1323. justify-content: center;
  1324. align-items: center;
  1325. width: 100%;
  1326. }
  1327. .video-player {
  1328. max-width: 100%;
  1329. max-height: 500px;
  1330. }
  1331. .video-preview {
  1332. margin-top: 10px;
  1333. border: 1px solid #ebeef5;
  1334. border-radius: 4px;
  1335. padding: 10px;
  1336. background-color: #f9f9f9;
  1337. }
  1338. .video-header {
  1339. display: flex;
  1340. justify-content: space-between;
  1341. align-items: center;
  1342. margin-bottom: 10px;
  1343. padding-bottom: 8px;
  1344. border-bottom: 1px solid #ebeef5;
  1345. }
  1346. .video-title {
  1347. font-weight: bold;
  1348. color: #303133;
  1349. }
  1350. .delete-video-btn {
  1351. color: #f56c6c;
  1352. padding: 0;
  1353. }
  1354. .delete-video-btn:hover {
  1355. color: #f78989;
  1356. }
  1357. .video-name {
  1358. margin-top: 5px;
  1359. color: #606266;
  1360. font-size: 14px;
  1361. }
  1362. /* 编辑器样式 */
  1363. .editor-container {
  1364. border: 1px solid #dcdfe6;
  1365. border-radius: 4px;
  1366. overflow: hidden;
  1367. }
  1368. .editor-toolbar {
  1369. background-color: #f5f7fa;
  1370. padding: 5px;
  1371. border-bottom: 1px solid #dcdfe6;
  1372. display: flex;
  1373. align-items: center;
  1374. }
  1375. .editor-btn {
  1376. background: none;
  1377. border: none;
  1378. padding: 5px 8px;
  1379. margin: 0 2px;
  1380. cursor: pointer;
  1381. border-radius: 3px;
  1382. }
  1383. .editor-btn:hover {
  1384. background-color: #e4e7ed;
  1385. }
  1386. .editor-separator {
  1387. width: 1px;
  1388. height: 16px;
  1389. background-color: #dcdfe6;
  1390. margin: 0 5px;
  1391. }
  1392. .editor-select {
  1393. height: 24px;
  1394. border: 1px solid #dcdfe6;
  1395. border-radius: 3px;
  1396. margin: 0 5px;
  1397. }
  1398. .editor-content {
  1399. width: 100%;
  1400. min-height: 120px;
  1401. padding: 10px;
  1402. border: none;
  1403. resize: vertical;
  1404. outline: none;
  1405. font-family: Arial, sans-serif;
  1406. font-size: 14px;
  1407. }
  1408. /* 上传链接样式 */
  1409. .upload-item {
  1410. margin-bottom: 20px;
  1411. }
  1412. .upload-link {
  1413. color: #409eff;
  1414. cursor: pointer;
  1415. font-size: 14px;
  1416. }
  1417. .upload-link:hover {
  1418. text-decoration: underline;
  1419. }
  1420. /* 分类封面图片样式 */
  1421. .category-cover-image {
  1422. width: 100px;
  1423. height: 56px;
  1424. object-fit: cover;
  1425. border-radius: 4px;
  1426. }
  1427. .cover-upload-container {
  1428. display: flex;
  1429. flex-direction: column;
  1430. align-items: center;
  1431. padding: 20px 0;
  1432. }
  1433. .cover-uploader {
  1434. border: 1px dashed #d9d9d9;
  1435. border-radius: 6px;
  1436. cursor: pointer;
  1437. position: relative;
  1438. overflow: hidden;
  1439. width: 178px;
  1440. height: 100px;
  1441. margin-bottom: 10px;
  1442. }
  1443. .cover-uploader:hover {
  1444. border-color: #409EFF;
  1445. }
  1446. .cover-uploader-icon {
  1447. font-size: 28px;
  1448. color: #8c939d;
  1449. width: 178px;
  1450. height: 100px;
  1451. line-height: 100px;
  1452. text-align: center;
  1453. }
  1454. .cover-image {
  1455. width: 178px;
  1456. height: 100px;
  1457. display: block;
  1458. object-fit: cover;
  1459. }
  1460. .cover-tip {
  1461. color: #909399;
  1462. font-size: 12px;
  1463. margin-top: 10px;
  1464. }
  1465. /* 讲师照片上传样式 */
  1466. .instructor-uploader {
  1467. border: 1px dashed #d9d9d9;
  1468. border-radius: 6px;
  1469. cursor: pointer;
  1470. position: relative;
  1471. overflow: hidden;
  1472. width: 100px;
  1473. height: 100px;
  1474. margin-bottom: 10px;
  1475. }
  1476. .instructor-uploader:hover {
  1477. border-color: #409EFF;
  1478. }
  1479. .instructor-uploader-icon {
  1480. font-size: 28px;
  1481. color: #8c939d;
  1482. width: 100px;
  1483. height: 100px;
  1484. line-height: 100px;
  1485. text-align: center;
  1486. }
  1487. .instructor-image {
  1488. width: 100px;
  1489. height: 100px;
  1490. display: block;
  1491. object-fit: cover;
  1492. }
  1493. .upload-tip {
  1494. color: #909399;
  1495. font-size: 12px;
  1496. margin-top: 5px;
  1497. }
  1498. </style>