index.vue 6.2 KB

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