catalogue.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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)" 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"></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. 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. /**
  88. * @summary 选中
  89. * @param({zhangId:string}) data
  90. */
  91. function handleSelectZhang(data) {
  92. $emit('change-zhang', Object.assign({}, data));
  93. handleClose();
  94. }
  95. function handleExpand() {
  96. console.log('zhankai')
  97. }
  98. defineExpose({
  99. showPopup
  100. })
  101. </script>