ProgrammingCourset.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <!-- 编程课列表内容 -->
  2. <template>
  3. <div class="programming-content">
  4. <!-- 标题部分 -->
  5. <div class="top-box">
  6. <!-- 返回按钮 -->
  7. <div class="top-left-box">
  8. <div class="top-left-inner-box">
  9. <!-- 左侧返回图标 -->
  10. <el-icon class="left-icon" @click="goBackIndex"><ArrowLeftBold /></el-icon>
  11. <span class="left-text">返回</span>
  12. </div>
  13. </div>
  14. <!-- 标题 -->
  15. <div class="top-center-box">
  16. <div class="top-center-inner-box" style="background-image: url('./src/assets/programming/list_title.png');">
  17. <span>{{ pageTitle }}</span>
  18. </div>
  19. </div>
  20. <!-- 课程提示 -->
  21. <div class="top-right-box">
  22. <div class="top-right-inner-box">
  23. <div class="course-info-box">{{ originalCourseTitle }}</div>
  24. </div>
  25. </div>
  26. </div>
  27. <!-- 课程部分 -->
  28. <div class="lower-box">
  29. <div class="content-box">
  30. <!-- 动态渲染课程内容 -->
  31. <div
  32. v-for="item in courseItems"
  33. :key="item.id"
  34. :class="item.positionClass"
  35. @click="handleCourseItemClick(item)"
  36. >
  37. <div class="box-content">
  38. <img :src="item.image" :alt="item.title" class="box-image" />
  39. <div class="box-text">{{ item.title }}</div>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. <!-- 视频和编程界面 -->
  45. <Interface v-if="showVideo" :courseData="selectedCourseData" :courseList="resData" @closeVideo="showVideo = false" />
  46. </div>
  47. </template>
  48. <script setup>
  49. // 返回图标
  50. import { ArrowLeftBold } from '@element-plus/icons-vue';
  51. import { ref, onMounted } from 'vue';
  52. // 导入路由
  53. import { useRouter, useRoute } from 'vue-router';
  54. // 导入接口
  55. import { TopicType } from '@/api/programming/index.js'
  56. // 导入图片
  57. import explanation from '@/assets/programming/explanation.png'
  58. import practice from '@/assets/programming/practice.png'
  59. import summary from '@/assets/programming/summary.png'
  60. import Interface from './Interface.vue'
  61. // 获取路由实例
  62. const router = useRouter()
  63. const route = useRoute()
  64. // 页面标题
  65. const pageTitle = ref('')
  66. // 保存原始的课程ID和标题
  67. const originalCourseId = ref('')
  68. const originalCourseTitle = ref('')
  69. // 主题ID(从ProgrammingList页面传递过来)
  70. const topicId = ref('')
  71. // 控制视频界面显示
  72. const showVideo = ref(false)
  73. // 动态课程项数据
  74. const courseItems = ref([])
  75. // 当前选中的课程数据
  76. const selectedCourseData = ref(null)
  77. // 保存原始API返回的数据
  78. const resData = ref([])
  79. // 组件挂载时获取路由参数设置标题
  80. onMounted(() => {
  81. // 检查路由参数中是否有courseTitle
  82. const courseTitle = route.query.courseTitle
  83. if (courseTitle) {
  84. // 设置页面标题
  85. pageTitle.value = courseTitle
  86. }
  87. // 获取当前主题ID
  88. topicId.value = route.query.topicId
  89. // 保存原始的课程ID和标题,返回时使用
  90. originalCourseId.value = route.query.originalCourseId
  91. originalCourseTitle.value = route.query.originalCourseTitle
  92. // 获取到topicId后,再调用TopicType接口
  93. if (topicId.value) {
  94. TopicType(topicId.value).then(res => {
  95. console.log(topicId.value, res);
  96. if (res && res.data && Array.isArray(res.data)) {
  97. // 保存原始API返回的数据
  98. resData.value = res.data;
  99. // 创建映射,保持原有的图片和位置样式
  100. const positionMap = {
  101. 1: { image: explanation, positionClass: 'left-content-box' },
  102. 2: { image: practice, positionClass: 'center-content-box' },
  103. 3: { image: summary, positionClass: 'right-content-box' }
  104. }
  105. // 遍历接口返回的数据,设置课程项
  106. res.data.forEach((item, index) => {
  107. // 每个课程项都对应位置样式和图片
  108. const positionIndex = (index % 3) + 1
  109. const positionInfo = positionMap[positionIndex]
  110. courseItems.value.push({
  111. id: item.id,
  112. title: item.bcName,
  113. image: positionInfo.image,
  114. positionClass: positionInfo.positionClass,
  115. contentType: item.bcContentType
  116. })
  117. })
  118. }
  119. })
  120. }
  121. })
  122. // 处理课程项点击事件
  123. const handleCourseItemClick = (item) => {
  124. if (item.contentType === 'video' || item.contentType === 'blockly') {
  125. showVideo.value = true
  126. // 查找并保存完整的课程数据
  127. const fullCourseData = resData.value.find(course => course.id === item.id)
  128. if (fullCourseData) {
  129. selectedCourseData.value = fullCourseData
  130. }
  131. }
  132. }
  133. // 返回编程课列表
  134. const goBackIndex = () => {
  135. // 隐藏视频和游戏界面
  136. showVideo.value = false
  137. // 返回时携带原始的课程参数,使用categoryId保持与ProgrammingList.vue中参数名一致
  138. router.push({
  139. path: '/programminglist',
  140. query: {
  141. categoryId: originalCourseId.value,
  142. courseTitle: originalCourseTitle.value
  143. }
  144. })
  145. }
  146. </script>
  147. <style scoped lang="scss">
  148. @use 'sass:math';
  149. // 定义rpx转换函数
  150. @function rpx($px) {
  151. @return math.div($px, 750) * 100vw;
  152. }
  153. .programming-content{
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. right: 0;
  158. bottom: 0;
  159. background-image: url('@/assets/programming/list_bg03.png');
  160. background-size: cover;
  161. background-position: center;
  162. background-repeat: no-repeat;
  163. display: flex;
  164. flex-direction: column;
  165. }
  166. .top-box {
  167. height: 20%;
  168. display: flex;
  169. }
  170. .top-left-box,
  171. .top-right-box {
  172. flex: 1;
  173. height: 50%;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. .top-center-box {
  179. flex: 2;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. }
  184. .top-center-inner-box{
  185. width: 100%;
  186. height: 100%;
  187. background-size: 70%;
  188. background-position: 50% 80%;
  189. background-repeat: no-repeat;
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. span{
  194. font-size: rpx(15);
  195. color: white;
  196. }
  197. }
  198. .top-left-inner-box{
  199. display: flex;
  200. align-items: center; /* 垂直居中对齐 */
  201. width: 100%;
  202. height: 100%;
  203. .left-icon{
  204. font-size: rpx(14);
  205. color: white;
  206. padding-left: rpx(20);
  207. cursor: pointer;
  208. }
  209. .left-text{
  210. font-size: rpx(14);
  211. color: white;
  212. padding-left: rpx(10);
  213. cursor: pointer;
  214. }
  215. }
  216. .top-right-inner-box {
  217. width: 100%;
  218. height: 100%;
  219. display: flex;
  220. justify-content: flex-end;
  221. align-items: center;
  222. padding-right: rpx(20);
  223. .course-info-box {
  224. width: rpx(60);
  225. height: rpx(20);
  226. background-color: rgb(255, 255, 255);
  227. border-radius: rpx(15);
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. color: #45300b;
  232. font-size: rpx(10);
  233. }
  234. }
  235. .lower-box {
  236. flex: 1;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. width: 100%;
  241. height: 100%;
  242. }
  243. .content-box {
  244. width: 100%;
  245. height: 100%;
  246. background-image: url('@/assets/programming/track.png');
  247. background-size: cover;
  248. background-position: center;
  249. background-repeat: no-repeat;
  250. display: flex;
  251. justify-content: space-between;
  252. position: relative;
  253. }
  254. .left-content-box, .center-content-box, .right-content-box {
  255. flex: 1;
  256. height: 40%; /* 高度缩小 */
  257. margin: 0 rpx(10);
  258. border-radius: rpx(40);
  259. background-color: rgba(255, 255, 255);
  260. display: flex;
  261. align-items: center;
  262. justify-content: center;
  263. box-shadow: 0 rpx(5) rpx(10) rgba(0, 0, 0, 0.2);
  264. transition: transform 0.3s ease;
  265. cursor: pointer;
  266. }
  267. /* 位置调整 */
  268. .left-content-box {
  269. position: absolute;
  270. left: 5%;
  271. top: 10%; /* 偏上 */
  272. width: calc(20% - rpx(10));
  273. }
  274. .center-content-box {
  275. position: absolute;
  276. left: 48%;
  277. transform: translateX(-50%);
  278. bottom: 15%; /* 偏下 */
  279. width: calc(20% - rpx(10));
  280. }
  281. .right-content-box {
  282. position: absolute;
  283. right: 5%;
  284. top: 10%; /* 偏上 */
  285. width: calc(20% - rpx(10));
  286. }
  287. /* 内容样式 */
  288. .box-content {
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. justify-content: center;
  293. height: 100%;
  294. width: 100%;
  295. }
  296. /* 鼠标悬停放大效果 */
  297. .left-content-box:hover,
  298. .right-content-box:hover{
  299. transform: scale(1.1);
  300. }
  301. .center-content-box:hover {
  302. transform: translateX(-50%) scale(1.1);
  303. }
  304. .box-image {
  305. width: 100%;
  306. height: 90%;
  307. object-fit: contain;
  308. }
  309. .box-text {
  310. width: 100%;
  311. height: 20%;
  312. line-height: 20%;
  313. font-size: rpx(13);
  314. color: #333;
  315. text-align: center;
  316. }
  317. </style>