index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. >
  13. <view class="free-content">
  14. <uni-collapse-item
  15. :open="index <= 1"
  16. :title="`第${numberConvertToUppercase(index + 1)}章 ${item.title}`"
  17. v-for="(item, index) in chaptersList.slice(0, 2)"
  18. :key="item.id"
  19. class="text"
  20. >
  21. <view class="-mt-20">
  22. <view class="content" v-for="(i, ind) in item.children" :key="i.id">
  23. <view class="text"
  24. >{{ `第${numberConvertToUppercase(ind + 1)}节` }}
  25. {{ i.title }}</view
  26. >
  27. <view class="buttons">
  28. <view
  29. @click="onClickButton(i.isStudied)"
  30. class="comment"
  31. v-if="i.isStudied === 0"
  32. >开始学习</view
  33. >
  34. <view
  35. @click="onClickButton(i.isStudied)"
  36. class="comment warning"
  37. v-if="i.isStudied > 0 && i.isStudied < 100"
  38. >继续学习</view
  39. >
  40. <view
  41. @click="onClickButton(i.isStudied)"
  42. class="comment"
  43. v-if="i.isStudied === 100"
  44. >去练习</view
  45. >
  46. <view
  47. @click="onClickButton(i.isStudied)"
  48. class="comment success"
  49. v-if="i.isStudied === 100"
  50. >已学习</view
  51. >
  52. </view>
  53. </view>
  54. </view>
  55. </uni-collapse-item>
  56. </view>
  57. <!-- 付费功能 -->
  58. <view class="pay-content">
  59. <view
  60. class="modal-mask"
  61. :style="{
  62. height: `${maskStyle.height}px`,
  63. width: `${maskStyle.width}px`,
  64. }"
  65. >
  66. <uni-icons type="locked" color="#fff" size="35"></uni-icons>
  67. <view class="modal-wrapper">邀请好友可解锁</view>
  68. </view>
  69. <uni-collapse-item
  70. :title="`第${numberConvertToUppercase(index + 3)}章 ${item.title}`"
  71. v-for="(item, index) in chaptersList.slice(2)"
  72. :key="item.id"
  73. class="text"
  74. >
  75. <view class="-mt-20">
  76. <view class="content" v-for="(i, ind) in item.children" :key="i.id">
  77. <view class="text"
  78. >{{ `第${numberConvertToUppercase(ind + 1)}节` }}
  79. {{ i.title }}</view
  80. >
  81. <view class="buttons">
  82. <view
  83. @click="onClickButton(i.isStudied)"
  84. class="comment"
  85. v-if="i.isStudied === 0"
  86. >开始学习</view
  87. >
  88. <view
  89. @click="onClickButton(i.isStudied)"
  90. class="comment warning"
  91. v-if="i.isStudied > 0 && i.isStudied < 100"
  92. >继续学习</view
  93. >
  94. <view
  95. @click="onClickButton(i.isStudied)"
  96. class="comment"
  97. v-if="i.isStudied === 100"
  98. >去练习</view
  99. >
  100. <view
  101. @click="onClickButton(i.isStudied)"
  102. class="comment success"
  103. v-if="i.isStudied === 100"
  104. >已学习</view
  105. >
  106. </view>
  107. </view>
  108. </view>
  109. </uni-collapse-item>
  110. </view>
  111. </uni-collapse>
  112. </Container>
  113. </template>
  114. <script setup name="regulations">
  115. import Container from "../../components/Container/Container.vue";
  116. import { ref, getCurrentInstance } from "vue";
  117. import { numberConvertToUppercase, getRect } from "../../utils";
  118. const collapse = ref(null);
  119. const value = ref("");
  120. const instance = getCurrentInstance();
  121. const safeArea = ref({});
  122. const maskStyle = ref({
  123. height: 0,
  124. width: 0,
  125. });
  126. const chaptersList = ref(
  127. new Array(10)
  128. .fill({
  129. title: "测试1",
  130. id: 1,
  131. children: new Array(5)
  132. .fill({
  133. id: 11,
  134. })
  135. .map((item, index) => {
  136. return {
  137. title: `测试1-${index + 1}`,
  138. id: index + item.id,
  139. isStudied: index === 1 ? 0 : index === 2 ? 20 : 100,
  140. };
  141. }),
  142. })
  143. .map((iten, index) => {
  144. return {
  145. ...iten,
  146. title: `测试${index + 1}`,
  147. id: index + 1,
  148. };
  149. })
  150. );
  151. const onClickButton = (isStudied) => {
  152. console.log(isStudied);
  153. };
  154. const resolveHeight = () =>
  155. setTimeout(() => {
  156. getRect({
  157. name: ".free-content",
  158. instance,
  159. onSuccess(res) {
  160. maskStyle.value.width = safeArea.value?.source?.width || 0;
  161. maskStyle.value.height = safeArea.value.height - res.height;
  162. },
  163. });
  164. // 动画300需要等待
  165. }, 300);
  166. const onSafeAreaChange = (s) => {
  167. safeArea.value = s;
  168. resolveHeight();
  169. };
  170. const onChnage = () => {
  171. resolveHeight();
  172. };
  173. </script>
  174. <style scoped lang="scss">
  175. @import "@/uni.scss";
  176. .text {
  177. font-family: PingFang SC, PingFang SC;
  178. font-weight: 500;
  179. font-size: 28rpx;
  180. color: #000000;
  181. }
  182. .content {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. padding: 0 20rpx 4rpx 40rpx;
  187. .buttons {
  188. display: flex;
  189. gap: 10rpx;
  190. }
  191. .comment {
  192. width: 132rpx;
  193. height: 48rpx;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. background-color: #fff;
  198. color: $primary;
  199. border: 1px solid $primary;
  200. font-family: "PingFang SC, PingFang SC";
  201. font-weight: 500;
  202. font-size: 28rpx;
  203. color: #002fa7;
  204. border-radius: 4rpx;
  205. }
  206. .comment.success {
  207. color: $success;
  208. border: 1px solid $success;
  209. }
  210. .comment.warning {
  211. color: $warning;
  212. border: 1px solid $warning;
  213. }
  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>