LearningSystem.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="LearningSystem container-height">
  3. <div v-if="!isChildRoute">
  4. <div :style="{height: carouselHeight}">
  5. <div style="width:100%;position: absolute;top: 60px;left: 0;">
  6. <el-carousel :height="carouselHeight" style="width: 100%;">
  7. <el-carousel-item v-for="(item,index) in 3" :key="index">
  8. <img
  9. :src="`https://baomiai.oss-cn-shanghai.aliyuncs.com/static/learn-0${index+1}.png`"
  10. style="width:100%"
  11. @load="onImageLoad"
  12. />
  13. </el-carousel-item>
  14. <!-- <el-carousel-item>
  15. <img
  16. :src="learnIcon"
  17. style="width:100%"
  18. @load="onImageLoad"
  19. />
  20. </el-carousel-item> -->
  21. </el-carousel>
  22. </div>
  23. </div>
  24. <Breadcrumb />
  25. <div class="padding12 bg_color_fff border_radius_16 box_shadow_card">
  26. <div class="typeList flex-between typeborder" :class="{isShow:isShowStudyStage}">
  27. <div class="gray font_size14 typeName">{{$t('common.studyStage')}}:</div>
  28. <div class="flex_1 gap10">
  29. <div class="font_size14 typeItem" :class="{'active':searchFom.studyStage === ''}"
  30. @click="searchFom.studyStage = '';getList('init');"
  31. :key="-1">
  32. {{$t('common.all')}}
  33. </div>
  34. <div class="font_size14 typeItem"
  35. v-for="item in bus_study_stage" :key="item.dictValue"
  36. :class="{'active':searchFom.studyStage === item.dictValue}"
  37. @click="searchFom.studyStage = item.dictValue;getList('init');">
  38. {{item.dictLabel}}
  39. </div>
  40. </div>
  41. <div>
  42. <el-link type="primary" v-if="!isShowStudyStage" @click="isShowStudyStage = true;">
  43. {{$t('common.expand')}}<el-icon><ArrowDown /></el-icon>
  44. </el-link>
  45. <el-link type="primary" v-else @click="isShowStudyStage = false;">
  46. {{$t('common.collapse')}}<el-icon><ArrowDown /></el-icon>
  47. </el-link>
  48. </div>
  49. </div>
  50. <div class="typeList flex-between typeborder" :class="{isShow:isShowCourseCategory}">
  51. <div class="gray font_size14 typeName">{{$t('common.courseCategory')}}:</div>
  52. <div class="flex_1 gap10">
  53. <div class="font_size14 typeItem" :class="{'active':searchFom.courseCategory === ''}"
  54. @click="searchFom.courseCategory = '';getList('init');"
  55. :key="-1">
  56. {{$t('common.all')}}
  57. </div>
  58. <div class="font_size14 typeItem"
  59. v-for="item in bus_course_category" :key="item.dictValue"
  60. :class="{'active':searchFom.courseCategory === item.dictValue}"
  61. @click="searchFom.courseCategory = item.dictValue;getList('init');">
  62. {{item.dictLabel}}
  63. </div>
  64. </div>
  65. <div>
  66. <el-link type="primary" v-if="!isShowCourseCategory" @click="isShowCourseCategory = true;">
  67. {{$t('common.expand')}}<el-icon><ArrowDown /></el-icon>
  68. </el-link>
  69. <el-link type="primary" v-else @click="isShowCourseCategory = false;">
  70. {{$t('common.collapse')}}<el-icon><ArrowDown /></el-icon>
  71. </el-link>
  72. </div>
  73. </div>
  74. <div class="typeList flex-between" :class="{isShow:isShowSkillTag}">
  75. <div class="gray font_size14 typeName">{{$t('common.skillTag')}}:</div>
  76. <div class="flex_1 gap10">
  77. <div class="font_size14 typeItem" :class="{'active':searchFom.skillTag === ''}"
  78. @click="searchFom.skillTag = ''; getList('init');"
  79. :key="-1">
  80. {{$t('common.all')}}
  81. </div>
  82. <div class="font_size14 typeItem"
  83. v-for="item in bus_skill_tag" :key="item.dictValue"
  84. :class="{'active':searchFom.skillTag === item.dictValue}"
  85. @click="searchFom.skillTag = item.dictValue; getList('init');">
  86. {{item.dictLabel}}
  87. </div>
  88. </div>
  89. <div>
  90. <el-link type="primary" v-if="!isShowSkillTag" @click="isShowSkillTag = true;">
  91. {{$t('common.expand')}}<el-icon><ArrowDown /></el-icon>
  92. </el-link>
  93. <el-link type="primary" v-else @click="isShowSkillTag = false;">
  94. {{$t('common.collapse')}}<el-icon><ArrowDown /></el-icon>
  95. </el-link>
  96. </div>
  97. </div>
  98. </div>
  99. <!-- 列表 -->
  100. <div class="course-list mt20">
  101. <div class="course-grid">
  102. <div v-for="(item, index) in list" :key="index" class="course-item list_item_animation box_shadow_card">
  103. <div class="bg_color_f5 coverImg" @click.stop.prevent="goDetail(item)" >
  104. <img :src="item.coverImageUrl" alt="" class="coverImg" />
  105. </div>
  106. <div class="padding16">
  107. <div class="font_size18 bold">
  108. {{item.courseTitle}}
  109. </div>
  110. <div class="mt10 line1 gray font_size13">
  111. {{item.courseIntro}}
  112. </div>
  113. <div class="flex-center-between mt10">
  114. <div class="gap5">
  115. <img :src="viewIcon" alt="" style="width:16px;height:16px">
  116. <div>{{item.viewCount}} {{ $t('common.renkanguo') }}</div>
  117. </div>
  118. <div class="gap5 gradient border_radius_4 cursor-pointer xuexi" @click.stop.prevent="goDetail(item)">
  119. <img :src="playIcon" alt="" style="width:13px;height:15px">
  120. <div>{{$t('common.lijixuexi')}}</div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <!-- 分页 -->
  128. <!-- 替换原有的分页代码 -->
  129. <Pagination
  130. :total="listTotal"
  131. :page-size="searchFom.pageSize"
  132. :current-page="searchFom.pageNum"
  133. @page-change="handlePageChange"
  134. />
  135. </div>
  136. <router-view />
  137. </div>
  138. </template>
  139. <script setup>
  140. import viewIcon from '@/assets/imgs/view.png'
  141. import playIcon from '@/assets/imgs/bofang.png'
  142. import CourseCard from '@/components/course-card.vue'
  143. import Pagination from '@/components/Pagination.vue'
  144. import { getCategoryListTree } from '@/api/category.js'
  145. import { getCourseList } from '@/api/course.js'
  146. import { getDictType } from '@/api/common.js'
  147. import { isLogin,openFullScreenLoading } from '@/utils/util.js'
  148. import { useI18n } from 'vue-i18n'
  149. const { t } = useI18n()
  150. import { useRouter, useRoute } from 'vue-router'
  151. const router = useRouter();
  152. const route = useRoute();
  153. import { ref, computed, reactive, onMounted, inject } from 'vue'
  154. //获取参数
  155. const query = route.query
  156. const categoryId = ref(query.categoryId || '');
  157. const activePlatform = ref(query.activePlatform || '');
  158. //获取当前路由路径
  159. // const currentPath = ref(router.currentRoute.value.path)
  160. const isChildRoute = computed(() => {
  161. return route.matched.length > 1
  162. });
  163. // 监听图片加载完成,动态设置轮播图高度
  164. const carouselHeight = ref('auto')
  165. const onImageLoad = (event) => {
  166. const img = event.target
  167. const aspectRatio = img.naturalWidth / img.naturalHeight
  168. const containerWidth = img.offsetWidth
  169. const calculatedHeight = containerWidth / aspectRatio
  170. carouselHeight.value = calculatedHeight + 'px'
  171. }
  172. const openLoginDialog = inject('openLoginDialog')
  173. // 学习阶段
  174. const isShowStudyStage = ref(false);
  175. // 课程分类
  176. const isShowCourseCategory = ref(false);
  177. // 技能标签
  178. const isShowSkillTag = ref(false);
  179. // 一级分类列表
  180. const bus_study_stage = ref([]);
  181. const bus_course_category = ref([]);
  182. const bus_skill_tag = ref([]);
  183. // 活动平台
  184. // 添加分页相关数据
  185. const list = ref([]);
  186. const listTotal = ref(0);
  187. const searchFom = reactive({
  188. studyStage: '',
  189. courseCategory: '',
  190. skillTag: '',
  191. pageNum: 1,
  192. pageSize: 10,
  193. orderByColumn: 'courseId',
  194. isAsc: 'desc'
  195. })
  196. onMounted(() => {
  197. getList();
  198. getDictTypeFn('bus_study_stage');
  199. getDictTypeFn('bus_course_category');
  200. getDictTypeFn('bus_skill_tag');
  201. })
  202. // 列表
  203. const getList = async (type) => {
  204. if(type === 'init'){
  205. searchFom.pageNum = 1
  206. }
  207. // 打开loading
  208. const loading = openFullScreenLoading();
  209. const res = await getCourseList(searchFom)
  210. // 关闭loading
  211. loading.close();
  212. if(res.code === 200){
  213. list.value = res.rows || [];
  214. listTotal.value = res.total || 0;
  215. }
  216. }
  217. const handlePageChange = (page) => {
  218. searchFom.pageNum = page
  219. // 这里可以添加获取数据的逻辑
  220. console.log('当前页:', page)
  221. getList();
  222. }
  223. const goDetail = (item) => {
  224. //判断是否登录
  225. if(!isLogin({callback: openLoginDialog,t})){
  226. return;
  227. }
  228. //增加参数名称
  229. router.push({
  230. path: `/learning-system/detail/${item.courseId}`,
  231. query: {
  232. courseId: item.courseId,
  233. metaTitle: item.courseTitle || '课程详情'
  234. }
  235. })
  236. };
  237. // 获取课程标签
  238. //学习阶段 bus_study_stage
  239. //教程分类 bus_course_category
  240. //技能标签 bus_skill_tag
  241. const getDictTypeFn = (dictType) => {
  242. getDictType({dictType}).then(res => {
  243. switch (dictType) {
  244. case 'bus_study_stage':
  245. bus_study_stage.value = res.rows || [];
  246. break;
  247. case 'bus_course_category':
  248. bus_course_category.value = res.rows || [];
  249. break;
  250. case 'bus_skill_tag':
  251. bus_skill_tag.value = res.rows || [];
  252. break;
  253. }
  254. })
  255. };
  256. </script>
  257. <style scoped lang="scss">
  258. .LearningSystem {
  259. .typeList{
  260. padding: 20px 0;
  261. height: 70px;
  262. overflow: hidden;
  263. &.isShow{
  264. height: auto;
  265. }
  266. &.typeborder{
  267. border-bottom: 1px dashed #DCDFE6;
  268. }
  269. .typeName{
  270. margin-top: 6px;
  271. min-width: 80px;
  272. white-space: nowrap;
  273. }
  274. .typeItem{
  275. margin: 4px 8px;
  276. cursor: pointer;
  277. padding: 4px 8px;
  278. &.active{
  279. background: rgba(45,113,255,0.1);
  280. border-radius: 4px 4px 4px 4px;
  281. color: $primary-color;
  282. font-weight: 600;
  283. }
  284. }
  285. }
  286. .course-item{
  287. width: 345.5px;
  288. background-color: #ffffff;
  289. border-radius: 8px;
  290. overflow: hidden;
  291. cursor: pointer;
  292. .coverImg{
  293. width: 100%;
  294. height: 204px;
  295. }
  296. }
  297. .xuexi{
  298. color: #ffffff;
  299. padding: 10px 20px;
  300. border-radius: 10px;
  301. font-size: 14px;
  302. }
  303. }
  304. </style>