catalogue.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  3. mask-background-color="rgba(255, 255, 255, 0.6);" :is-shadow="false">
  4. <view class="ezy-catalogue-dialog">
  5. <uni-icons @click="handleClose" class="catalogue-close-btn"></uni-icons>
  6. <!-- 目录区域 -->
  7. <uni-collapse v-model="activeCollapse" class="ezy-catalogue-collapse" accordion>
  8. <uni-collapse-item title-border="none" :border="false" :name="index+''" v-for="(item,index) in list"
  9. class="collapse-item-box" :class="{ 'collapse-active': activeCollapse === index+''}">
  10. <template v-slot:title>
  11. <view @click.stop="handleSelectZhang(item,index)" class="collapse-title">
  12. <view class="collapse-num-box">{{index+1}}</view>
  13. <!-- 章名 -->
  14. <text class="collapse-name">{{item.zhangName}}</text>
  15. <!-- 锁 -->
  16. <template>
  17. <view class="collapse-lock" v-if="index!=0"></view>
  18. </template>
  19. </view>
  20. </template>
  21. <view class="collapse-content-box">
  22. <view v-for="(jie,cindex) in item.jieList" class="collapse-content-item">
  23. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  24. <text class="text">{{jie.jieName}}</text>
  25. </view>
  26. </view>
  27. </uni-collapse-item>
  28. </uni-collapse>
  29. </view>
  30. </uni-popup>
  31. </template>
  32. <script setup>
  33. import {
  34. useCatalogue
  35. } from './useCatalogue';
  36. import {
  37. ref
  38. } from "vue";
  39. import {
  40. toast
  41. } from "@/utils/common.js"
  42. const $emit = defineEmits(['change-zhang'])
  43. const props = defineProps({
  44. nianji: {
  45. type: [String, Number],
  46. },
  47. xueke: {
  48. type: [String, Number],
  49. }
  50. })
  51. const {
  52. getCatalogue,
  53. } = useCatalogue(props);
  54. const popupRef = ref(null); // 索引
  55. const list = ref([]); // 章节
  56. const activeCollapse = ref('');
  57. /**
  58. * @summary 展示弹窗 暴露函数
  59. */
  60. async function showPopup() {
  61. const [err, data] = await getCatalogue();
  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. /**
  88. * @summary 选中
  89. * @param({zhangId:string}) data
  90. */
  91. function handleSelectZhang(data,index) {
  92. if(index!=0){
  93. toast("付费章节");
  94. return;
  95. }
  96. $emit('change-zhang', Object.assign({}, data));
  97. handleClose();
  98. }
  99. function handleExpand() {
  100. console.log('zhankai')
  101. }
  102. defineExpose({
  103. showPopup
  104. })
  105. </script>