index.vue 7.3 KB

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