catalogue.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <uni-popup ref="popupRef" :mask-background-color="popup_background_color">
  3. <uni-card :is-shadow="false" class="card-container">
  4. <template #title>
  5. <!-- 章节目录区域 -->
  6. <view class="catalogue-custom-title">
  7. <!-- 自定义标题区域 -->
  8. <text></text>
  9. <uni-icons type="closeempty" size="16" @click="handleClose"></uni-icons>
  10. </view>
  11. </template>
  12. <!-- 目录区域 -->
  13. <uni-collapse v-model="activeCollapse" class="collapse-container" accordion>
  14. <uni-collapse-item title-border="none" :border="false" v-for="(item,index) in list">
  15. <template v-slot:title>
  16. <view class="title-layout">
  17. <view @click.stop="handleSelectZhang(item)" class="text-container">
  18. <uni-badge class="uni-badge-left-margin" :text="index+1" type="primary" />
  19. <!-- 章名 -->
  20. <text class="text-white">{{item.zhangName}}</text>
  21. </view>
  22. <uni-icons :class="['right-icon']" @click="handleExpand" type="locked-filled" size="16" style="justify-self: flex-end;"></uni-icons>
  23. </view>
  24. </template>
  25. <view class="content">
  26. <view v-for="(jie,cindex) in item.jieList">
  27. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  28. <text class="text">{{jie.jieName}}</text>
  29. </view>
  30. </view>
  31. </uni-collapse-item>
  32. </uni-collapse>
  33. </uni-card>
  34. </uni-popup>
  35. </template>
  36. <script setup>
  37. import {
  38. useCatalogue
  39. } from './useCatalogue';
  40. import {
  41. ref
  42. } from "vue";
  43. import {toast} from "@/utils/common.js"
  44. const $emit = defineEmits(['change-zhang'])
  45. const {
  46. getCatalogue,
  47. } = useCatalogue();
  48. const popupRef = ref(null); // 索引
  49. const list = ref([]); // 章节
  50. const activeCollapse = ref('');
  51. const popup_background_color = `rgba(0,0,0,0.2)`; // 【弹出框模态层背景颜色】
  52. /**
  53. * @summary 展示弹窗 暴露函数
  54. */
  55. async function showPopup() {
  56. const [err, data] = await getCatalogue();
  57. console.log('ddd',data);
  58. if (err) {
  59. toast("章节目录数据获取失败");
  60. return;
  61. }
  62. refreshCatalogue(data);
  63. handleShow();
  64. }
  65. /**
  66. * @param([]) 章节赋值
  67. */
  68. function refreshCatalogue(data) {
  69. list.value = data;
  70. }
  71. /**
  72. * @summary 展示目录弹窗
  73. */
  74. function handleShow() {
  75. popupRef.value.open('center');
  76. }
  77. /**
  78. * @summary 关闭目录弹窗
  79. */
  80. function handleClose() {
  81. popupRef.value.close();
  82. }
  83. /**
  84. * @summary 选中
  85. * @param({zhangId:string}) data
  86. */
  87. function handleSelectZhang(data) {
  88. $emit('change-zhang', Object.assign({},data));
  89. handleClose();
  90. }
  91. function handleExpand() {
  92. console.log('zhankai')
  93. }
  94. defineExpose({
  95. showPopup
  96. })
  97. </script>
  98. <style lang="scss" scoped>
  99. .title-layout {
  100. display: flex;
  101. justify-content: space-between;
  102. align-items: center;
  103. padding: 10px
  104. }
  105. .child-item {
  106. padding: 10px;
  107. }
  108. // 章节目录Card
  109. .card-container {
  110. background-color: rgba(0, 0, 0, 0.2); // 【弹出框 背景颜色】
  111. min-width: 300px;
  112. }
  113. // 目录区域
  114. ::v-deep .uni-card__content {
  115. padding: 0 !important;
  116. margin: 10px 0;
  117. background-color: rgba(0, 0, 0, 0.5); // 【弹出框 内容区域背景颜色】
  118. border-radius: 4px;
  119. }
  120. // 目录文字 颜色调整
  121. .text-white {
  122. color: #fff; // 【课件 章文字颜色】
  123. }
  124. // 章节目录区域 标题
  125. .catalogue-custom-title {
  126. display: flex;
  127. justify-content: space-between;
  128. height: 40px;
  129. line-height: 40px;
  130. margin-top: 10px;
  131. background-color: #fff; // 【弹出 框 标题背景 待替换成背景图】
  132. border-top-left-radius: 4px;
  133. border-top-right-radius: 4px;
  134. }
  135. // 章文本区域
  136. .text-container {
  137. width: 100%;
  138. }
  139. .collapse-container {
  140. background-color: transparent; // 【弹出框 内容区域背景颜色】
  141. }
  142. ::v-deep .uni-collapse-item__wrap {
  143. background-color: transparent; // 【弹出框 内容区域背景颜色】
  144. }
  145. ::v-deep .uni-collapse-item__wrap-content {
  146. color: #fff; // 【课件 章文字颜色】
  147. line-height: 1.5;
  148. padding: 5px 10px;
  149. }
  150. .jie-index {
  151. margin-right: 5px;
  152. }
  153. </style>