index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <Container
  3. :title="title"
  4. :scrollY="maskStyle.height < 0"
  5. @onSafeAreaChange="onSafeAreaChange"
  6. bgColor="#f8f8f8"
  7. >
  8. <div class="vip" v-if="isVip">
  9. <span>您已解锁本科目所有内容(科目{{ day.time }}天会员)</span>
  10. <span>有效期至:{{ day.timeStr }}</span>
  11. </div>
  12. <uni-collapse
  13. ref="collapse"
  14. v-model="value"
  15. class="class-content"
  16. @change="onChnage"
  17. v-show="!showContainer"
  18. >
  19. <view class="free-content">
  20. <Tree
  21. :chaptersList="freeChaptersList"
  22. @onChnage="onChnage"
  23. @onClickButton="onClickButton"
  24. />
  25. </view>
  26. <!-- 付费功能 -->
  27. <view class="pay-content" v-if="chaptersList.length">
  28. <view
  29. class="modal-mask"
  30. :style="{
  31. height: `${maskStyle.height}px`,
  32. width: `100vw`,
  33. }"
  34. v-if="maskStyle.height > 0"
  35. >
  36. <view class="locked">
  37. <uni-icons type="locked" color="#fff" size="35"></uni-icons>
  38. </view>
  39. <view class="modal-wrapper" @click="onClickMask">邀请好友可解锁</view>
  40. </view>
  41. <Tree
  42. :chaptersList="chaptersList"
  43. @onChnage="onChnage"
  44. @onClickButton="onClickButton"
  45. />
  46. </view>
  47. </uni-collapse>
  48. <Modal
  49. ref="popup"
  50. background-color="#fff"
  51. v-model:open="showContainer"
  52. title="邀请新客户解锁课程"
  53. >
  54. <text class="unlock"
  55. >邀请一名新用户注册并完成第一章全部考点学习,可解锁新两章内容</text
  56. >
  57. <template #footer>
  58. <button>立即邀请</button>
  59. </template>
  60. </Modal>
  61. </Container>
  62. </template>
  63. <script setup name="regulations">
  64. import Tree from "../../components/Tree/Tree.vue";
  65. import Container from "../../components/Container/Container.vue";
  66. import Modal from "@/components/Modal/Modal.vue";
  67. import { ref, getCurrentInstance } from "vue";
  68. import { getRect, arrayToTree } from "../../utils";
  69. import { getRoute, router } from "../../utils/router";
  70. import { request } from "../../utils/request";
  71. import { onShow } from "@dcloudio/uni-app";
  72. const title = ref("");
  73. const collapse = ref(null);
  74. const popup = ref(null);
  75. const showContainer = ref(false);
  76. const value = ref("");
  77. const instance = getCurrentInstance();
  78. const safeArea = ref({});
  79. const maskStyle = ref({
  80. height: 0,
  81. width: 0,
  82. });
  83. const isVip = ref(0);
  84. const chaptersList = ref([]);
  85. const freeChaptersList = ref([]);
  86. const day = ref({
  87. time: 0,
  88. timeStr: "",
  89. });
  90. // 点击学习按钮
  91. const onClickButton = (item) => {
  92. router.push({
  93. url: item.practice
  94. ? "/pages/regulations/practice"
  95. : "/pages/regulations/learing",
  96. params: {
  97. id: item.id,
  98. parent_id: item.parent_id,
  99. name: item.name,
  100. title: item.name,
  101. },
  102. });
  103. };
  104. const resolveHeight = () =>
  105. setTimeout(() => {
  106. getRect({
  107. name: ".free-content",
  108. instance,
  109. onSuccess(res) {
  110. maskStyle.value.height = safeArea.value.height - res.height;
  111. },
  112. });
  113. // 动画300需要等待
  114. }, 800);
  115. const onSafeAreaChange = (s) => {
  116. safeArea.value = s;
  117. resolveHeight();
  118. };
  119. const onChnage = () => {
  120. resolveHeight();
  121. };
  122. const onClickMask = () => {
  123. router.push({
  124. url: "/pages/user/share",
  125. });
  126. };
  127. onShow(async () => {
  128. const id = getRoute().params.id;
  129. request("api/question_bank/question_reception/share_subject_vip/info", {
  130. subject_id: id,
  131. }).then((res) => {
  132. isVip.value = res.data.is_vip;
  133. const { vip_end_time, vip_start_time } = res.data;
  134. day.value = {
  135. // 计算有多少天
  136. time: (vip_end_time - vip_start_time) / 60 / 60 / 24,
  137. // 格式化 'yyyy-dd-mm'
  138. timeStr: new Date(vip_end_time * 1000)
  139. .toLocaleDateString()
  140. .replace(/\//g, "-"),
  141. };
  142. });
  143. const res = await request(
  144. "api/question_bank/question_reception/chapter/get_all_chapter",
  145. {
  146. id,
  147. }
  148. );
  149. const list = arrayToTree({
  150. list: res.data,
  151. firstId: +id,
  152. });
  153. const freeList = list.filter((item) => !item.is_lock);
  154. const payList = list.filter((item) => item.is_lock);
  155. // 免费
  156. freeChaptersList.value = freeList;
  157. // 付费章节
  158. chaptersList.value = payList;
  159. title.value = getRoute().params.title;
  160. });
  161. </script>
  162. <style scoped lang="scss">
  163. @import "@/uni.scss";
  164. .text {
  165. font-family: PingFang SC, PingFang SC;
  166. font-weight: 500;
  167. font-size: 28rpx;
  168. color: #000000;
  169. }
  170. .vip {
  171. width: 100%;
  172. box-sizing: border-box;
  173. border-radius: 10rpx;
  174. background: url(https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/06/CAQLLie6UhF9ti3PEzDc1EYlP27oUJpBsY5aTDDe.png);
  175. margin-bottom: 16px;
  176. padding: 8rpx 16rpx;
  177. display: flex;
  178. flex-direction: column;
  179. gap: 5rpx;
  180. font-weight: bold;
  181. font-size: 28rpx;
  182. color: #ffffff;
  183. background-size: 100% 100%;
  184. }
  185. .content {
  186. display: flex;
  187. justify-content: space-between;
  188. align-items: center;
  189. padding: 8rpx 20rpx 10rpx 40rpx;
  190. .buttons {
  191. display: flex;
  192. gap: 10rpx;
  193. }
  194. .comment {
  195. width: 132rpx;
  196. height: 48rpx;
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. background-color: #fff;
  201. color: $primary;
  202. border: 1px solid $primary;
  203. font-family: "PingFang SC, PingFang SC";
  204. font-weight: 500;
  205. font-size: 28rpx;
  206. color: $primary;
  207. border-radius: 4rpx;
  208. }
  209. .comment.success {
  210. color: $success;
  211. border: 1px solid $success;
  212. }
  213. .comment.warning {
  214. color: $warning;
  215. border: 1px solid $warning;
  216. }
  217. }
  218. .unlock {
  219. font-family: PingFang SC, PingFang SC;
  220. font-weight: 500;
  221. font-size: 28rpx;
  222. color: #000000;
  223. margin: 100rpx 0;
  224. display: block;
  225. }
  226. .class-content {
  227. height: 100%;
  228. }
  229. .pay-content {
  230. flex: 1;
  231. position: relative;
  232. .modal-mask {
  233. background-color: rgba($color: #333333, $alpha: 0.8);
  234. position: absolute;
  235. height: 100%;
  236. z-index: 9999;
  237. left: -24rpx;
  238. display: flex;
  239. align-items: center;
  240. flex-direction: column;
  241. justify-content: center;
  242. gap: 34rpx;
  243. }
  244. }
  245. .modal-wrapper {
  246. width: 685rpx;
  247. height: 64rpx;
  248. background: $primary;
  249. font-family: PingFang SC, PingFang SC;
  250. font-weight: 500;
  251. font-size: 28rpx;
  252. color: #fff;
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. }
  257. .locked {
  258. width: 96rpx;
  259. height: 96rpx;
  260. background: linear-gradient(159deg, #00d0ff 0%, #008cff 100%);
  261. border-radius: 50%;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. }
  266. </style>