catalogue.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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>{{item.zhangName}}</text>
  15. </view>
  16. <!-- 锁 -->
  17. <view class="collapse-lock" v-if="index!=0"></view>
  18. </template>
  19. <view class="collapse-content-box">
  20. <view v-for="(jie,cindex) in item.jieList" class="collapse-content-item">
  21. <text class="jie-index">{{`${index+1}.${cindex+1}`}}</text>
  22. <text class="text">{{jie.jieName}}</text>
  23. </view>
  24. </view>
  25. </uni-collapse-item>
  26. </uni-collapse>
  27. </view>
  28. </uni-popup>
  29. </template>
  30. <script setup>
  31. import {
  32. useCatalogue
  33. } from './useCatalogue';
  34. import {
  35. ref
  36. } from "vue";
  37. import {
  38. toast
  39. } from "@/utils/common.js"
  40. const $emit = defineEmits(['change-zhang'])
  41. const props = defineProps({
  42. nianji: {
  43. type: [String, Number],
  44. },
  45. xueqi: {
  46. type: [String, Number],
  47. }
  48. })
  49. const {
  50. getCatalogue,
  51. } = useCatalogue(props);
  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. if (err) {
  62. toast("章节目录数据获取失败");
  63. return;
  64. }
  65. refreshCatalogue(data);
  66. handleShow();
  67. }
  68. /**
  69. * @param([]) 章节赋值
  70. */
  71. function refreshCatalogue(data) {
  72. list.value = data;
  73. }
  74. /**
  75. * @summary 展示目录弹窗
  76. */
  77. function handleShow() {
  78. popupRef.value.open('center');
  79. }
  80. /**
  81. * @summary 关闭目录弹窗
  82. */
  83. function handleClose() {
  84. popupRef.value.close();
  85. }
  86. /**
  87. * @summary 选中
  88. * @param({zhangId:string}) data
  89. */
  90. function handleSelectZhang(data,index) {
  91. if(index!=0){
  92. toast("付费章节");
  93. return;
  94. }
  95. $emit('change-zhang', Object.assign({}, data));
  96. handleClose();
  97. }
  98. function handleExpand() {
  99. console.log('zhankai')
  100. }
  101. defineExpose({
  102. showPopup
  103. })
  104. </script>