index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="ezy-study-page">
  3. <shuxueZhangjie v-if="currentProduct ==1" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  4. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  5. </shuxueZhangjie>
  6. <yingyuZhangjie v-if="currentProduct ==2" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  7. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  8. </yingyuZhangjie>
  9. <!-- 蛋 -->
  10. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  11. <catalogue ref="catalogueRef" @change-zhang="handleChangeZhang"></catalogue>
  12. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  13. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPay" :content="tipContent"></tip-small-dialog>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. userZhangInfo,
  19. userLocate,
  20. userZhangForntInfo,
  21. userZhangNextInfo,
  22. getCommonZhangInfo
  23. } from "@/api/learnPlan.js"
  24. import {
  25. reactive,
  26. ref,
  27. getCurrentInstance,
  28. onMounted
  29. } from "vue";
  30. import {
  31. onLoad
  32. } from '@dcloudio/uni-app';
  33. import catalogue from "@/components/catalogue/catalogue.vue";
  34. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  35. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  36. import shuxueZhangjie from './product/shuxue.vue';
  37. import yingyuZhangjie from './product/yingyu.vue';
  38. import {
  39. useTabBarHistory
  40. } from '@/utils/emitEvents.js';
  41. import eggDialog from './eggDialog.vue'
  42. import {
  43. toast,getUserIdentity
  44. } from "@/utils/common";
  45. import cacheManager from "@/utils/cacheManager.js";
  46. const tipContent = '付费章节,是否前往开通付费?';
  47. const currentProduct = cacheManager.get('auth').cardId; //当前产品
  48. const goPayDialogRef = ref(null);
  49. const eggDialogRef = ref(null);
  50. const zhangId = ref(null); //游客使用
  51. const nianji = ref(null);//游客使用
  52. const cardId = ref(null);//游客使用
  53. const catalogueRef = ref(null);
  54. const selectZhang = ref(null);
  55. let infoData = reactive({
  56. jieList: [],
  57. haveFlag: '',
  58. nianji: '',
  59. number: '',
  60. cardId: '',
  61. zhangId: '',
  62. zhangName: '',
  63. numberStr: '',
  64. });
  65. onLoad((options) => {
  66. // 获取路由参数
  67. if(options){
  68. zhangId.value = options.zhangId
  69. nianji.value = options.nianji
  70. cardId.value = options.cardId
  71. }
  72. init(options)
  73. })
  74. function init(options){
  75. if (cacheManager.get('auth')) {
  76. //会员 取auth
  77. selectZhang.value = cacheManager.get('auth');
  78. console.log(selectZhang.value);
  79. // 已登录
  80. // 选择年级进入调用此接口
  81. //options.flag == 'selectGrades'
  82. getZhangInfo()
  83. // 蛋
  84. // eggDialogRef.value.eggShow();
  85. } else {
  86. console.log(options);
  87. // 未登录 游客
  88. getCommonZhang(options)
  89. }
  90. }
  91. function getZhangInfo(data) {
  92. let req = {
  93. nianji: selectZhang.value.nianji,
  94. cardId: selectZhang.value.cardId,
  95. zhangId: selectZhang.value.zhangId,
  96. }
  97. userZhangInfo(req).then(res => {
  98. cacheManager.set('zhangInfo', res.data)
  99. infoData.jieList = res.data.jieList
  100. infoData.haveFlag = res.data.haveFlag
  101. infoData.nianji = res.data.nianji
  102. infoData.number = res.data.number
  103. infoData.numberStr = res.data.numberStr
  104. infoData.cardId = res.data.cardId
  105. infoData.zhangId = res.data.zhangId
  106. infoData.zhangName = res.data.zhangName
  107. recordZhangJie()
  108. getNewData()
  109. // if (cacheManager.get('zhangInfo')) {
  110. // cacheManager.remove('zhangInfo')
  111. // cacheManager.set('zhangInfo', res.data)
  112. // } else {
  113. // cacheManager.set('zhangInfo', res.data)
  114. // }
  115. })
  116. }
  117. function getCommonZhang(data) {
  118. let req = {
  119. nianji: data.nianji,
  120. cardId: data.cardId,
  121. zhangId:data.zhangId,
  122. }
  123. getCommonZhangInfo(req).then(res => {
  124. infoData.jieList = res.data.jieList
  125. infoData.haveFlag = res.data.haveFlag
  126. infoData.nianji = res.data.nianji
  127. infoData.number = res.data.number
  128. infoData.numberStr = res.data.numberStr
  129. infoData.cardId = res.data.cardId
  130. infoData.zhangId = res.data.zhangId
  131. infoData.zhangName = res.data.zhangName
  132. //getNewData()
  133. })
  134. }
  135. function onLeft(event) {
  136. console.log('用户左滑了');
  137. let req = {
  138. nianji: selectZhang.value.nianji,
  139. zhangId: selectZhang.value.zhangId,
  140. cardId: selectZhang.value.cardId,
  141. }
  142. userZhangForntInfo(req).then(res => {
  143. cacheManager.set('zhangInfo', res.data)
  144. infoData.jieList = res.data.jieList
  145. infoData.haveFlag = res.data.haveFlag
  146. infoData.nianji = res.data.nianji
  147. infoData.number = res.data.number
  148. infoData.numberStr = res.data.numberStr
  149. infoData.cardId = res.data.cardId
  150. infoData.zhangId = res.data.zhangId
  151. infoData.zhangName = res.data.zhangName
  152. recordZhangJie()
  153. getNewData()
  154. })
  155. }
  156. function onRight(event) {
  157. console.log('用户又滑了');
  158. let req = {
  159. nianji: selectZhang.value.nianji,
  160. zhangId: selectZhang.value.zhangId,
  161. cardId: selectZhang.value.cardId,
  162. }
  163. userZhangNextInfo(req).then(res => {
  164. cacheManager.set('zhangInfo', res.data)
  165. infoData.jieList = res.data.jieList
  166. infoData.haveFlag = res.data.haveFlag
  167. infoData.nianji = res.data.nianji
  168. infoData.number = res.data.number
  169. infoData.numberStr = res.data.numberStr
  170. infoData.cardId = res.data.cardId
  171. infoData.zhangId = res.data.zhangId
  172. infoData.zhangName = res.data.zhangName
  173. recordZhangJie()
  174. getNewData()
  175. })
  176. }
  177. function getNewData() {
  178. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  179. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  180. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  181. }
  182. function recordZhangJie() {
  183. let req = {
  184. nianji: selectZhang.value.nianji,
  185. userId: cacheManager.get('auth').userId,
  186. zhangId: infoData.zhangId,
  187. cardId: selectZhang.value.cardId,
  188. }
  189. userLocate(req).then(res => {
  190. })
  191. }
  192. function handleChangeZhang(data) {
  193. selectZhang.value = data;
  194. const authCode = getUserIdentity();
  195. if (authCode !== 'Visitor') {
  196. cacheManager.updateObject('auth', {
  197. zhangId: data.zhangId
  198. })
  199. }
  200. init()
  201. }
  202. function goKaoshi(data) {
  203. let zhangId = selectZhang.value ? selectZhang.value.zhangId : infoData.zhangId;
  204. let nianji = selectZhang.value.nianji;
  205. let cardId = selectZhang.value.cardId;
  206. uni.navigateTo({
  207. url: `/pages/unitTest/index?jieId=${data.jieId}&zhangId=${zhangId}&nianji=${nianji}&cardId=${cardId}`
  208. })
  209. }
  210. function goLookShipin(data) {
  211. data.progressMarkers = [{
  212. offset: 30,
  213. isCustomized: true,
  214. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
  215. title: '变式1',
  216. time: '00:00:30',
  217. describe: 'test string',
  218. }, {
  219. offset: 120,
  220. isCustomized: true,
  221. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
  222. title: '变式2',
  223. time: '00:02:00',
  224. describe: 'test string',
  225. }, {
  226. offset: 300,
  227. isCustomized: true,
  228. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  229. title: '变式3',
  230. time: '00:05:00',
  231. describe: 'test string',
  232. }]
  233. data.zhangId = infoData.zhangId
  234. data.nianji = infoData.nianji
  235. data.cardId = infoData.cardId
  236. uni.navigateTo({
  237. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  238. url: '/pages/study/lookShipin?studyData=' + JSON.stringify(data)
  239. })
  240. }
  241. function listClick(data, index) {
  242. if (!cacheManager.get('auth')) {
  243. toast("当前为游客模式请登录!")
  244. uni.redirectTo({
  245. url: '/pages/login/index'
  246. })
  247. return;
  248. }
  249. const authCode = getUserIdentity();
  250. if (!(authCode=='VIP' || data.number == 1)) {
  251. goPayDialogRef.value.handleShow();
  252. return false
  253. }
  254. if (data.number == infoData.jieList.length) {
  255. // 最后一项
  256. goKaoshi(data)
  257. } else {
  258. goLookShipin(data)
  259. }
  260. }
  261. function handleCheckCatalogue() {
  262. catalogueRef.value.showPopup();
  263. }
  264. function clickGradeTerm() {
  265. uni.navigateTo({
  266. url: `/pages/selectGradesTerms/index`,
  267. })
  268. }
  269. function eggBtn() {
  270. console.log('点击:开启提分之旅');
  271. }
  272. </script>
  273. <style>
  274. </style>