catalogue.vue 4.8 KB

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