index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <Container
  3. title="法规"
  4. :scrollY="maskStyle.height < 0"
  5. @onSafeAreaChange="onSafeAreaChange"
  6. >
  7. <uni-collapse
  8. ref="collapse"
  9. v-model="value"
  10. class="class-content"
  11. @change="onChnage"
  12. v-show="!showContainer"
  13. >
  14. <view class="free-content">
  15. <uni-collapse-item
  16. open
  17. :title="item.name"
  18. v-for="item in freeChaptersList"
  19. :key="item.id"
  20. class="text"
  21. >
  22. <view class="-mt-20">
  23. <Tree
  24. :chaptersList="item.children"
  25. @onChnage="onChnage"
  26. @onClickButton="onClickButton"
  27. />
  28. </view>
  29. </uni-collapse-item>
  30. </view>
  31. <!-- 付费功能 -->
  32. <view class="pay-content" v-if="chaptersList.length">
  33. <view
  34. class="modal-mask"
  35. :style="{
  36. height: `${maskStyle.height}px`,
  37. width: `${maskStyle.width}px`,
  38. }"
  39. v-if="maskStyle.height > 0"
  40. >
  41. <uni-icons type="locked" color="#fff" size="35"></uni-icons>
  42. <view class="modal-wrapper" @click="onClickMask">邀请好友可解锁</view>
  43. </view>
  44. <uni-collapse-item
  45. :title="item.name"
  46. v-for="item in chaptersList"
  47. :key="item.id"
  48. class="text"
  49. >
  50. <view class="-mt-20">
  51. <Tree
  52. :chaptersList="item.children"
  53. @onChnage="onChnage"
  54. @onClickButton="onClickButton"
  55. />
  56. </view>
  57. </uni-collapse-item>
  58. </view>
  59. </uni-collapse>
  60. <Modal
  61. ref="popup"
  62. background-color="#fff"
  63. v-model:open="showContainer"
  64. title="邀请新客户解锁课程"
  65. >
  66. <text class="unlock"
  67. >邀请一名新用户注册并完成第一章全部考点学习,可解锁新两章内容</text
  68. >
  69. <template #footer>
  70. <button>立即邀请</button>
  71. </template>
  72. </Modal>
  73. </Container>
  74. </template>
  75. <script setup name="regulations">
  76. import Tree from "../../components/Tree/Tree.vue";
  77. import Container from "../../components/Container/Container.vue";
  78. import Modal from "@/components/Modal/Modal.vue";
  79. import { ref, getCurrentInstance, onMounted } from "vue";
  80. import { getRect, arrayToTree } from "../../utils";
  81. import { getRoute, router } from "../../utils/router";
  82. import { request } from "../../utils/request";
  83. const collapse = ref(null);
  84. const popup = ref(null);
  85. const showContainer = ref(false);
  86. const value = ref("");
  87. const instance = getCurrentInstance();
  88. const safeArea = ref({});
  89. const maskStyle = ref({
  90. height: 0,
  91. width: 0,
  92. });
  93. const chaptersList = ref([]);
  94. const freeChaptersList = ref([]);
  95. // 点击学习按钮
  96. const onClickButton = (item) => {
  97. router.push({
  98. url: "/pages/regulations/learing",
  99. params: {
  100. id: item.id,
  101. parent_id: item.parent_id,
  102. name: item.name,
  103. },
  104. });
  105. };
  106. const resolveHeight = () =>
  107. setTimeout(() => {
  108. getRect({
  109. name: ".free-content",
  110. instance,
  111. onSuccess(res) {
  112. maskStyle.value.width = safeArea.value?.source?.width || 0;
  113. maskStyle.value.height = safeArea.value.height - res.height;
  114. },
  115. });
  116. // 动画300需要等待
  117. }, 800);
  118. const onSafeAreaChange = (s) => {
  119. safeArea.value = s;
  120. resolveHeight();
  121. };
  122. const onChnage = () => {
  123. resolveHeight();
  124. };
  125. const onClickMask = () => {
  126. showContainer.value = true;
  127. };
  128. onMounted(async () => {
  129. const id = getRoute().params.id;
  130. const res = await request(
  131. "api/question_bank/question_reception/chapter/get_all_chapter",
  132. {
  133. id,
  134. }
  135. );
  136. const list = arrayToTree({
  137. list: res.data,
  138. firstId: +id,
  139. });
  140. const freeList = list.filter((item) => !item.is_lock);
  141. const payList = list.filter((item) => item.is_lock);
  142. // 免费
  143. freeChaptersList.value = freeList;
  144. // 付费章节
  145. chaptersList.value = payList;
  146. });
  147. </script>
  148. <style scoped lang="scss">
  149. @import "@/uni.scss";
  150. .text {
  151. font-family: PingFang SC, PingFang SC;
  152. font-weight: 500;
  153. font-size: 28rpx;
  154. color: #000000;
  155. }
  156. .content {
  157. display: flex;
  158. justify-content: space-between;
  159. align-items: center;
  160. padding: 0 20rpx 10rpx 40rpx;
  161. .buttons {
  162. display: flex;
  163. gap: 10rpx;
  164. }
  165. .comment {
  166. width: 132rpx;
  167. height: 48rpx;
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. background-color: #fff;
  172. color: $primary;
  173. border: 1px solid $primary;
  174. font-family: "PingFang SC, PingFang SC";
  175. font-weight: 500;
  176. font-size: 28rpx;
  177. color: $primary;
  178. border-radius: 4rpx;
  179. }
  180. .comment.success {
  181. color: $success;
  182. border: 1px solid $success;
  183. }
  184. .comment.warning {
  185. color: $warning;
  186. border: 1px solid $warning;
  187. }
  188. }
  189. .unlock {
  190. font-family: PingFang SC, PingFang SC;
  191. font-weight: 500;
  192. font-size: 28rpx;
  193. color: #000000;
  194. margin: 100rpx 0;
  195. display: block;
  196. }
  197. .class-content {
  198. height: 100%;
  199. }
  200. .pay-content {
  201. flex: 1;
  202. position: relative;
  203. .modal-mask {
  204. background-color: rgba($color: #858585, $alpha: 0.8);
  205. position: absolute;
  206. height: 100%;
  207. z-index: 9999;
  208. left: -24rpx;
  209. display: flex;
  210. align-items: center;
  211. flex-direction: column;
  212. justify-content: center;
  213. gap: 34rpx;
  214. }
  215. }
  216. .modal-wrapper {
  217. width: 685rpx;
  218. height: 64rpx;
  219. background: #dfdfdf;
  220. font-family: PingFang SC, PingFang SC;
  221. font-weight: 500;
  222. font-size: 28rpx;
  223. color: #000000;
  224. display: flex;
  225. align-items: center;
  226. justify-content: center;
  227. }
  228. </style>