courseCollapse.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!--
  2. * @FileDescription: 折叠菜单
  3. * @Author: 黄琪勇
  4. * @Date:2024-04-01 18:40:50
  5. -->
  6. <template>
  7. <el-collapse class="courseCollapse" accordion v-model="activeCollapseId">
  8. <el-collapse-item v-for="item in props.courseList" :key="item.id" :name="item.id" :class="{ isChild: props.isChild }">
  9. <template #title>
  10. <div class="courseCollapseHead">
  11. <div class="courseCollapseHeadArrow">
  12. <div class="headArrow"></div>
  13. <div class="headArrowActive"></div>
  14. </div>
  15. <div class="courseCollapseHeadTit">
  16. <ellipsisScroll :title="item.name" />
  17. </div>
  18. </div>
  19. </template>
  20. <div class="courseCollapseCon" :class="{ courseListCon: item.materialList }">
  21. <template v-if="item.materialList">
  22. <div
  23. class="courseList"
  24. :class="{ isActive: activeCollapse?.id === i.id && activeCollapse?.knowledgePointId === i.knowledgePointId }"
  25. v-for="i in item.materialList"
  26. :key="i.id"
  27. @click="handleClick(i)"
  28. >
  29. <div class="courseTitleCon" :class="i.typeCode || i.type">
  30. <div class="imgIcon"></div>
  31. <div class="ellipsisBox">
  32. <!-- <ellipsisScroll :title="i.name" /> -->
  33. <span v-html="formatName(i.name)"></span>
  34. </div>
  35. </div>
  36. <div class="iconArrow">
  37. <img
  38. v-if="activeCollapse?.id === i.id && activeCollapse?.knowledgePointId === i.knowledgePointId"
  39. src="@/img/coursewarePlay/icon-load.gif"
  40. />
  41. </div>
  42. </div>
  43. </template>
  44. <courseCollapse
  45. v-else
  46. :isChild="true"
  47. :search="searchStr"
  48. :courseList="item.children || []"
  49. :activeCollapse="activeCollapse"
  50. @handleClick="handleClick"
  51. />
  52. </div>
  53. </el-collapse-item>
  54. </el-collapse>
  55. </template>
  56. <script setup lang="ts">
  57. import ellipsisScroll from "@/components/ellipsisScroll"
  58. import { ref, watch } from "vue"
  59. type materialListType = {
  60. id: string
  61. type: string
  62. typeCode?: string
  63. name: string
  64. knowledgePointId: string
  65. }
  66. type courseListType = {
  67. id: string
  68. name: string
  69. materialList: materialListType[] | null
  70. children: courseListType | null
  71. }[]
  72. const props = defineProps<{
  73. activeCollapse: undefined | Record<string, any>
  74. courseList: courseListType
  75. search?: string
  76. isChild?: boolean
  77. }>()
  78. const searchStr = ref(props.search)
  79. const emits = defineEmits<{
  80. (e: "handleClick", value: any): void
  81. }>()
  82. watch(
  83. () => props.activeCollapse,
  84. () => {
  85. activeCollapseId.value = filterActiveId()
  86. }
  87. )
  88. watch(
  89. () => props.search,
  90. () => {
  91. searchStr.value = props.search
  92. }
  93. )
  94. const activeCollapseId = ref(filterActiveId())
  95. function filterActiveId() {
  96. const course = props.courseList.find(item => {
  97. return (props.activeCollapse?.parentData.ids || []).includes(item.id)
  98. })
  99. return course?.id || ""
  100. }
  101. function handleClick(value: any) {
  102. emits("handleClick", value)
  103. }
  104. function formatName(name: string) {
  105. // console.log(name, searchStr.value, "searchStr")
  106. if (!name || !searchStr.value) return name
  107. const search: any = searchStr.value
  108. return name.replace(search, `<span style="color: #F67146;">${search}</span>`)
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .courseCollapse.el-collapse {
  113. --el-collapse-border-color: #f2f2f2;
  114. --el-collapse-header-height: 56px;
  115. border: none;
  116. & > :deep(.el-collapse-item) {
  117. > .el-collapse-item__wrap > .el-collapse-item__content {
  118. padding-bottom: 0px;
  119. }
  120. &:last-child {
  121. > .el-collapse-item__wrap {
  122. border-bottom: none;
  123. }
  124. > .el-collapse-item__header {
  125. border-bottom: none;
  126. }
  127. }
  128. .el-collapse-item__arrow {
  129. display: none;
  130. }
  131. &.is-active > .el-collapse-item__header {
  132. > .courseCollapseHead {
  133. .courseCollapseHeadTit {
  134. color: #333333;
  135. font-weight: 600;
  136. }
  137. .courseCollapseHeadArrow {
  138. > .headArrow {
  139. display: none;
  140. }
  141. > .headArrowActive {
  142. display: block;
  143. }
  144. }
  145. }
  146. }
  147. &.isChild {
  148. .el-collapse-item__wrap {
  149. border-bottom: none;
  150. }
  151. .el-collapse-item__header {
  152. border-bottom: none;
  153. }
  154. .courseCollapseHead {
  155. .courseCollapseHeadTit {
  156. color: #333333;
  157. font-size: 15px;
  158. }
  159. .courseCollapseHeadArrow {
  160. .headArrow {
  161. background: url("@/img/coursewarePlay/jtr1.png") no-repeat;
  162. background-size: 100% 100%;
  163. }
  164. }
  165. }
  166. }
  167. }
  168. .courseCollapseHead {
  169. width: 100%;
  170. height: 100%;
  171. display: flex;
  172. justify-content: space-between;
  173. align-items: center;
  174. .courseCollapseHeadTit {
  175. text-align: left;
  176. margin-left: 10px;
  177. flex-grow: 1;
  178. font-weight: 400;
  179. font-size: 16px;
  180. color: #777777;
  181. overflow: hidden;
  182. }
  183. .courseCollapseHeadArrow {
  184. flex-shrink: 0;
  185. .headArrow,
  186. .headArrowActive {
  187. width: 14px;
  188. height: 14px;
  189. }
  190. .headArrow {
  191. background: url("@/img/coursewarePlay/jtr.png") no-repeat;
  192. background-size: 100% 100%;
  193. }
  194. .headArrowActive {
  195. display: none;
  196. background: url("@/img/coursewarePlay/jtb.png") no-repeat;
  197. background-size: 100% 100%;
  198. }
  199. }
  200. }
  201. .courseCollapseCon {
  202. padding-left: 20px;
  203. &.courseListCon {
  204. padding-left: 0;
  205. }
  206. .courseList {
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. padding: 0 10px 0 24px;
  211. margin-bottom: 6px;
  212. cursor: pointer;
  213. &.isActive {
  214. background: #f0f0f0;
  215. border-radius: 7px;
  216. .courseTitleCon {
  217. color: #f67146;
  218. font-weight: 600;
  219. &.VIDEO .imgIcon {
  220. background: url("@/img/coursewarePlay/VIDEO.png") no-repeat;
  221. background-size: 100% 100%;
  222. }
  223. &.IMG .imgIcon {
  224. background: url("@/img/coursewarePlay/IMG.png") no-repeat;
  225. background-size: 100% 100%;
  226. }
  227. &.SONG .imgIcon {
  228. background: url("@/img/coursewarePlay/SONG.png") no-repeat;
  229. background-size: 100% 100%;
  230. }
  231. }
  232. }
  233. .courseTitleCon {
  234. padding: 6px 0;
  235. flex-grow: 1;
  236. overflow: hidden;
  237. margin-right: 8px;
  238. display: flex;
  239. align-items: center;
  240. font-weight: 400;
  241. font-size: 14px;
  242. color: #333333;
  243. > .ellipsisBox {
  244. flex-grow: 1;
  245. overflow: hidden;
  246. }
  247. > .imgIcon {
  248. flex-shrink: 0;
  249. width: 15px;
  250. height: 15px;
  251. margin-right: 10px;
  252. }
  253. &.VIDEO .imgIcon {
  254. background: url("@/img/coursewarePlay/VIDEO1.png") no-repeat;
  255. background-size: 100% 100%;
  256. }
  257. &.IMG .imgIcon {
  258. background: url("@/img/coursewarePlay/IMG1.png") no-repeat;
  259. background-size: 100% 100%;
  260. }
  261. &.SONG .imgIcon {
  262. background: url("@/img/coursewarePlay/SONG1.png") no-repeat;
  263. background-size: 100% 100%;
  264. }
  265. }
  266. .iconArrow {
  267. display: flex;
  268. flex-shrink: 0;
  269. width: 13px;
  270. height: 13px;
  271. > img {
  272. width: 100%;
  273. height: 100%;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. </style>