index.vue 5.3 KB

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