index.vue 6.1 KB

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