ProgrammingCourset.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <!-- 编程课列表内容 -->
  2. <template>
  3. <div class="programming-content">
  4. <!-- 标题部分 -->
  5. <div class="upper-box">
  6. <!-- 返回按钮 -->
  7. <div class="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="middle-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="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. .upper-box {
  167. flex: 1;
  168. display: flex;
  169. justify-content: space-between;
  170. }
  171. .left-box, .middle-box, .right-box {
  172. flex: 1;
  173. margin: rpx(5);
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. }
  178. .top-center-inner-box{
  179. width: 100%;
  180. height: 100%;
  181. background-size: 100%;
  182. background-position: 50% 30%;
  183. background-repeat: no-repeat;
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. span{
  188. font-size: rpx(15);
  189. color: white;
  190. }
  191. }
  192. .top-left-inner-box{
  193. display: flex;
  194. align-items: center; /* 垂直居中对齐 */
  195. width: 100%;
  196. height: 100%;
  197. .left-icon{
  198. font-size: rpx(14);
  199. color: white;
  200. padding-left: rpx(20);
  201. cursor: pointer;
  202. }
  203. .left-text{
  204. font-size: rpx(14);
  205. color: white;
  206. padding-left: rpx(10);
  207. cursor: pointer;
  208. }
  209. }
  210. .top-right-inner-box {
  211. width: 100%;
  212. height: 100%;
  213. display: flex;
  214. justify-content: flex-end;
  215. align-items: center;
  216. padding-right: rpx(20);
  217. .course-info-box {
  218. width: rpx(60);
  219. height: rpx(20);
  220. background-color: rgb(255, 255, 255);
  221. border-radius: rpx(15);
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. color: #45300b;
  226. font-size: rpx(10);
  227. }
  228. }
  229. .lower-box {
  230. flex: 5;
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. width: 100%;
  235. height: 100%;
  236. }
  237. .content-box {
  238. width: 100%;
  239. height: 100%;
  240. background-image: url('@/assets/programming/track.png');
  241. background-size: cover;
  242. background-position: center;
  243. background-repeat: no-repeat;
  244. display: flex;
  245. justify-content: space-between;
  246. position: relative;
  247. }
  248. .left-content-box, .center-content-box, .right-content-box {
  249. flex: 1;
  250. height: 40%; /* 高度缩小 */
  251. margin: 0 rpx(10);
  252. border-radius: rpx(40);
  253. background-color: rgba(255, 255, 255);
  254. display: flex;
  255. align-items: center;
  256. justify-content: center;
  257. box-shadow: 0 rpx(5) rpx(10) rgba(0, 0, 0, 0.2);
  258. transition: transform 0.3s ease;
  259. cursor: pointer;
  260. }
  261. /* 位置调整 */
  262. .left-content-box {
  263. position: absolute;
  264. left: 5%;
  265. top: 10%; /* 偏上 */
  266. width: calc(20% - rpx(10));
  267. }
  268. .center-content-box {
  269. position: absolute;
  270. left: 48%;
  271. transform: translateX(-50%);
  272. bottom: 15%; /* 偏下 */
  273. width: calc(20% - rpx(10));
  274. }
  275. .right-content-box {
  276. position: absolute;
  277. right: 5%;
  278. top: 10%; /* 偏上 */
  279. width: calc(20% - rpx(10));
  280. }
  281. /* 内容样式 */
  282. .box-content {
  283. display: flex;
  284. flex-direction: column;
  285. align-items: center;
  286. justify-content: center;
  287. height: 100%;
  288. width: 100%;
  289. }
  290. /* 鼠标悬停放大效果 */
  291. .left-content-box:hover,
  292. .right-content-box:hover{
  293. transform: scale(1.1);
  294. }
  295. .center-content-box:hover {
  296. transform: translateX(-50%) scale(1.1);
  297. }
  298. .box-image {
  299. width: 100%;
  300. height: 90%;
  301. object-fit: contain;
  302. }
  303. .box-text {
  304. width: 100%;
  305. height: 20%;
  306. line-height: 20%;
  307. font-size: rpx(13);
  308. color: #333;
  309. text-align: center;
  310. }
  311. </style>