catalogue.vue 3.1 KB

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