catalogue.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 v-if="AuthCode !== 'VIP'">
  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. <tip-small-dialog ref="confirmDialogRef" @confirm-btn="handleConfirmPay" :content="Message"></tip-small-dialog>
  30. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :content="MESSAGE_VISITER_TO_LOGIN"></tip-middle-dialog>
  31. </view>
  32. </uni-popup>
  33. </template>
  34. <script setup>
  35. import {
  36. useCatalogue
  37. } from './useCatalogue';
  38. import {
  39. ref
  40. } from "vue";
  41. import {
  42. toast
  43. } from "@/utils/common.js"
  44. import {getUserIdentity} from "@/utils/common.js"
  45. import {MESSAGE_VISITER_TO_LOGIN,MESSAGE_BEFORE_PAY} from "@/utils/constant.js"
  46. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  47. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  48. const $emit = defineEmits(['change-zhang'])
  49. const { getCatalogue} = useCatalogue();
  50. const popupRef = ref(null); // 索引
  51. const confirmDialogRef = ref(null);
  52. const list = ref([]); // 章节
  53. const activeCollapse = ref('');
  54. const Message = MESSAGE_BEFORE_PAY;
  55. const AuthCode = getUserIdentity(); // 用户身份
  56. const youkeDialogRef = ref(null);
  57. function ykConfirm() {
  58. uni.redirectTo({
  59. url: '/pages/login/index'
  60. });
  61. }
  62. /**
  63. * @summary 展示弹窗 暴露函数
  64. */
  65. async function showPopup() {
  66. const [err, data] = await getCatalogue();
  67. if (err) {
  68. toast("章节目录数据获取失败");
  69. return;
  70. }
  71. refreshCatalogue(data);
  72. handleShow();
  73. }
  74. /**
  75. * @param([]) 章节赋值
  76. */
  77. function refreshCatalogue(data) {
  78. list.value = data;
  79. }
  80. /**
  81. * @summary 展示目录弹窗
  82. */
  83. function handleShow() {
  84. popupRef.value.open('center');
  85. }
  86. /**
  87. * @summary 关闭目录弹窗
  88. */
  89. function handleClose() {
  90. popupRef.value.close();
  91. }
  92. /**
  93. * @summary 选中
  94. * @param({zhangId:string}) data
  95. */
  96. function handleSelectZhang(data,index) {
  97. if(index !=0 && AuthCode == 'Visitor'){
  98. // 游客
  99. youkeDialogRef.value.handleShow();
  100. return;
  101. }
  102. if(index !=0 && AuthCode == 'Not-Vip'){
  103. // 非VIP
  104. popupRef.value.close();
  105. confirmDialogRef.value.handleShow();
  106. return;
  107. }
  108. $emit('change-zhang', Object.assign({}, data));
  109. handleClose();
  110. }
  111. function handleConfirmPay() {
  112. uni.redirectTo({ url: '/pages/pay/svip' })
  113. }
  114. defineExpose({
  115. showPopup
  116. })
  117. </script>