index.vue 5.8 KB

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