index.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { NCollapse, NCollapseItem } from 'naive-ui';
  2. import { computed, defineComponent, ref, watch } from 'vue';
  3. import CardType from '/src/components/card-type';
  4. import styles from './index.module.less';
  5. export default defineComponent({
  6. name: 'source-list',
  7. props: {
  8. knowledgePointList: {
  9. type: Array,
  10. default: () => []
  11. },
  12. activeItem: {
  13. type: Object,
  14. default: () => ({})
  15. },
  16. /** 当前播放的是第几个知识点组 */
  17. courseActiveIndex: {
  18. type: Number,
  19. default: 0
  20. }
  21. },
  22. emits: ['confirm'],
  23. setup(props, { emit }) {
  24. const parentIndex = ref(props.courseActiveIndex);
  25. watch(
  26. () => props.courseActiveIndex,
  27. () => {
  28. parentIndex.value = props.courseActiveIndex;
  29. }
  30. );
  31. const childIndex = computed(() => {
  32. let index = 0;
  33. props.knowledgePointList.forEach((item: any) => {
  34. item.list.forEach((child: any, j: number) => {
  35. if (child.id === props.activeItem.id) {
  36. index = j;
  37. }
  38. });
  39. });
  40. return index;
  41. });
  42. return () => (
  43. <div class={[styles.listSection]} id="drawerCardRef">
  44. {props.knowledgePointList.map((item: any, index: number) => (
  45. <div class={styles.treeParent} key={'parent' + index}>
  46. <div
  47. class={[styles.treeItem, styles.parentItem]}
  48. onClick={() => {
  49. if (parentIndex.value === index) {
  50. parentIndex.value = -1;
  51. } else {
  52. parentIndex.value = index;
  53. }
  54. }}>
  55. <span
  56. class={[
  57. styles.arrow,
  58. parentIndex.value === index ? styles.arrowSelect : ''
  59. ]}></span>
  60. <p
  61. class={[
  62. styles.title,
  63. parentIndex.value === index ? styles.titleSelect : ''
  64. ]}>
  65. {item.title}
  66. </p>
  67. </div>
  68. {parentIndex.value === index &&
  69. item.list &&
  70. item.list.map((child: any, j: number) => (
  71. <div class={[styles.cardContainer, 'drawerCardItemRef']}>
  72. <CardType
  73. item={child}
  74. isActive={
  75. childIndex.value === j &&
  76. parentIndex.value === props.courseActiveIndex
  77. }
  78. isCollect={false}
  79. isShowCollect={false}
  80. onClick={() => {
  81. emit('confirm', child);
  82. }}
  83. />
  84. </div>
  85. ))}
  86. </div>
  87. ))}
  88. </div>
  89. );
  90. }
  91. });