catalogue.vue 4.4 KB

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