catalogue.vue 4.6 KB

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