index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <view class="container">
  3. <view class="sticky-title">
  4. 学习
  5. </view>
  6. <view>
  7. <view class="arrow-nav">
  8. <view class="arrow" :class="{ 'disabled': currentIndex == 0 }" @click="prev">
  9. 左箭头
  10. </view>
  11. <view class="arrow" :class="{ 'disabled': currentIndex == list.length - 1 }" @click="next">
  12. 右箭头
  13. </view>
  14. </view>
  15. <!-- 显示内容 -->
  16. <view class="current-content">
  17. <text>{{ danyuanInfo.danyuanName }}</text>
  18. <text>{{ danyuanInfo.danyuanIntro }}</text>
  19. </view>
  20. </view>
  21. <scroll-view scroll-y class="scroll-view" :scroll-top="scrollTop" @scroll="onScroll">
  22. <view>
  23. <progress :percent="20" class="exam-progress-box" stroke-width="10" backgroundColor="#3c7dfd"
  24. activeColor="#ffd11c" />
  25. <text class="course-name" @click="handlePlay(subjectDetail,'jixu')">继续学习</text>
  26. <view>单元大纲</view>
  27. <view>单元目录</view>
  28. </view>
  29. <view v-for="section in dagangList" :key="section.jieId" class="section-item">
  30. <view class="status" :class="section.wanchengFlag === 1 ? 'completed' : 'uncompleted'">
  31. {{ section.wanchengFlag === 1 ? '已完成' : '未开始' }}
  32. </view>
  33. <view class="section-left">
  34. <image class="section-cover" :src="section.cover" mode="aspectFill"></image>
  35. <view class="section-info">
  36. <text class="section-name">{{ section.jieName }}</text>
  37. <text class="section-desc">{{ section.jieIntro }}</text>
  38. </view>
  39. </view>
  40. <view class="section-right">
  41. <text class="section-number">第{{ section.number }}节</text>
  42. <text @click="handlePlay(section,'play')">播放按钮</text>
  43. </view>
  44. </view>
  45. <!-- 底部占位 -->
  46. <view style="height: 100px; text-align: center;">学习下一单元</view>
  47. </scroll-view>
  48. <danyuanInfoVue ref="dyRef" v-if="isShow" @close="isShow= false"></danyuanInfoVue>
  49. <CustomTabBar :currentTabNumber="1"></CustomTabBar>
  50. </view>
  51. </template>
  52. <script>
  53. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  54. import {
  55. shuxueChanpinDanyuanInfo
  56. } from "@/api/chanpinneirong.js"
  57. import danyuanInfoVue from '@/pages/xinshuxue/components/danyuanInfo.vue';
  58. export default {
  59. data() {
  60. return {
  61. dagangList: [],
  62. currentUnitName: "",
  63. isShow: true,
  64. currentIndex: 0,
  65. danyuanInfo:{}
  66. }
  67. },
  68. components: {
  69. CustomTabBar,
  70. danyuanInfoVue,
  71. },
  72. onShow() {
  73. console.log('学习页面显示,尝试恢复滚动位置')
  74. },
  75. onHide() {
  76. console.log('学习页面隐藏,保存滚动位置')
  77. },
  78. onLoad() {
  79. this.loadDataFromApi()
  80. },
  81. methods: {
  82. prev() {
  83. if (this.currentIndex > 0) {
  84. this.currentIndex--
  85. }
  86. },
  87. next() {
  88. if (this.currentIndex < this.list.length - 1) {
  89. this.currentIndex++
  90. }
  91. },
  92. handlePlay(da, code) {
  93. let jieId = null;
  94. if (code == 'jixu') {
  95. jieId = da.curJieId;
  96. uni.navigateTo({
  97. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  98. })
  99. } else {
  100. jieId = da.jieId;
  101. if (da.type == 1) {
  102. uni.navigateTo({
  103. url: `/pages/xinshuxue/lookShipin?jieId=${jieId}`
  104. })
  105. } else {
  106. uni.navigateTo({
  107. url: `/pages/xinshuxue/unitTest?jieId=${jieId}`
  108. })
  109. }
  110. }
  111. },
  112. handleClickDanyuan(item) {
  113. console.log('item', item)
  114. this.isShow = true;
  115. setTimeout(() => {
  116. this.$refs.dyRef.handleShow(item.danyuanId)
  117. }, 100)
  118. },
  119. loadDataFromApi() {
  120. const req = {
  121. banbenId: 7,
  122. danyuanId:2
  123. }
  124. shuxueChanpinDanyuanInfo(req).then(res => {
  125. this.danyuanInfo = res.data
  126. this.dagangList = res.data.dagangList || []
  127. // 初始化当前单元
  128. // if (this.danyuanList.length > 0) {
  129. // this.currentUnitName = this.danyuanList[0].danyuanName
  130. // }
  131. })
  132. },
  133. // 滚动事件处理
  134. onScroll(e) {
  135. const scrollTop = e.detail.scrollTop;
  136. // 更新滚动位置
  137. this.scrollTop = scrollTop;
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped>
  143. .container {
  144. height: 100vh;
  145. background-color: #f5f5f5;
  146. }
  147. /* 吸顶标题 */
  148. .sticky-title {
  149. position: fixed;
  150. top: 0;
  151. left: 0;
  152. right: 0;
  153. z-index: 100;
  154. background-color: #1890ff;
  155. color: white;
  156. padding: 12px 16px;
  157. font-size: 16px;
  158. font-weight: bold;
  159. text-align: center;
  160. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  161. }
  162. /* 返回顶部按钮 */
  163. .back-top {
  164. position: fixed;
  165. right: 16px;
  166. bottom: 100px;
  167. z-index: 99;
  168. width: 44px;
  169. height: 44px;
  170. background-color: #1890ff;
  171. border-radius: 50%;
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. color: white;
  176. font-size: 20px;
  177. box-shadow: 0 2px 8px rgba(24, 144, 255, 0.4);
  178. }
  179. .back-top:active {
  180. background-color: #096dd9;
  181. transform: scale(0.95);
  182. }
  183. /* 滚动区域 */
  184. .scroll-view {
  185. height: 100%;
  186. padding-top: 50px;
  187. /* 给吸顶标题留出空间 */
  188. box-sizing: border-box;
  189. }
  190. /* 单元样式 */
  191. .unit-item {
  192. margin: 12px;
  193. background: white;
  194. border-radius: 8px;
  195. overflow: hidden;
  196. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  197. }
  198. .unit-title {
  199. padding: 16px;
  200. background: linear-gradient(135deg, #1890ff, #36cfc9);
  201. color: white;
  202. }
  203. .unit-name {
  204. font-size: 18px;
  205. font-weight: bold;
  206. display: block;
  207. margin-bottom: 4px;
  208. }
  209. .unit-intro {
  210. font-size: 14px;
  211. opacity: 0.9;
  212. }
  213. /* 节样式 */
  214. .section-item {
  215. padding: 12px 16px;
  216. border-bottom: 1px solid #f0f0f0;
  217. display: flex;
  218. justify-content: space-between;
  219. align-items: center;
  220. }
  221. .section-item:last-child {
  222. border-bottom: none;
  223. }
  224. .section-left {
  225. display: flex;
  226. align-items: center;
  227. flex: 1;
  228. }
  229. .section-cover {
  230. width: 60px;
  231. height: 60px;
  232. border-radius: 6px;
  233. margin-right: 12px;
  234. }
  235. .section-info {
  236. flex: 1;
  237. }
  238. .section-name {
  239. font-size: 16px;
  240. color: #333;
  241. display: block;
  242. margin-bottom: 4px;
  243. font-weight: 500;
  244. }
  245. .section-desc {
  246. font-size: 13px;
  247. color: #666;
  248. }
  249. .section-right {
  250. display: flex;
  251. flex-direction: column;
  252. align-items: flex-end;
  253. margin-left: 12px;
  254. }
  255. .section-number {
  256. font-size: 12px;
  257. color: #999;
  258. margin-bottom: 4px;
  259. }
  260. .status {
  261. font-size: 12px;
  262. padding: 2px 8px;
  263. border-radius: 10px;
  264. }
  265. .status.completed {
  266. background-color: #f6ffed;
  267. color: #52c41a;
  268. border: 1px solid #b7eb8f;
  269. }
  270. .status.uncompleted {
  271. background-color: #fff7e6;
  272. color: #fa8c16;
  273. border: 1px solid #ffd591;
  274. }
  275. </style>