index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. init(options)
  67. })
  68. function init(options){
  69. if (cacheManager.get('auth')) {
  70. //会员 取auth
  71. selectZhang.value = cacheManager.get('auth');
  72. console.log(selectZhang.value);
  73. // 已登录
  74. // 选择年级进入调用此接口
  75. //options.flag == 'selectGrades'
  76. getZhangInfo()
  77. // 蛋
  78. // eggDialogRef.value.eggShow();
  79. } else {
  80. zhangId.value = options.zhangId
  81. nianji.value = options.nianji
  82. cardId.value = options.cardId
  83. // 未登录 游客
  84. getCommonZhang(options)
  85. }
  86. }
  87. function getZhangInfo(data) {
  88. let req = {
  89. nianji: selectZhang.value.nianji,
  90. cardId: selectZhang.value.cardId,
  91. zhangId: selectZhang.value.zhangId,
  92. }
  93. userZhangInfo(req).then(res => {
  94. cacheManager.set('zhangInfo', res.data)
  95. infoData.jieList = res.data.jieList
  96. infoData.haveFlag = res.data.haveFlag
  97. infoData.nianji = res.data.nianji
  98. infoData.number = res.data.number
  99. infoData.numberStr = res.data.numberStr
  100. infoData.cardId = res.data.cardId
  101. infoData.zhangId = res.data.zhangId
  102. infoData.zhangName = res.data.zhangName
  103. recordZhangJie()
  104. getNewData()
  105. // if (cacheManager.get('zhangInfo')) {
  106. // cacheManager.remove('zhangInfo')
  107. // cacheManager.set('zhangInfo', res.data)
  108. // } else {
  109. // cacheManager.set('zhangInfo', res.data)
  110. // }
  111. })
  112. }
  113. function getCommonZhang(data) {
  114. let req = {
  115. nianji: data.nianji,
  116. cardId: data.cardId,
  117. zhangId:data.zhangId,
  118. }
  119. getCommonZhangInfo(req).then(res => {
  120. infoData.jieList = res.data.jieList
  121. infoData.haveFlag = res.data.haveFlag
  122. infoData.nianji = res.data.nianji
  123. infoData.number = res.data.number
  124. infoData.numberStr = res.data.numberStr
  125. infoData.cardId = res.data.cardId
  126. infoData.zhangId = res.data.zhangId
  127. infoData.zhangName = res.data.zhangName
  128. //getNewData()
  129. })
  130. }
  131. function onLeft(event) {
  132. console.log('用户左滑了');
  133. let req = {
  134. nianji: selectZhang.value.nianji,
  135. zhangId: selectZhang.value.zhangId,
  136. cardId: selectZhang.value.cardId,
  137. }
  138. userZhangForntInfo(req).then(res => {
  139. cacheManager.set('zhangInfo', res.data)
  140. infoData.jieList = res.data.jieList
  141. infoData.haveFlag = res.data.haveFlag
  142. infoData.nianji = res.data.nianji
  143. infoData.number = res.data.number
  144. infoData.numberStr = res.data.numberStr
  145. infoData.cardId = res.data.cardId
  146. infoData.zhangId = res.data.zhangId
  147. infoData.zhangName = res.data.zhangName
  148. recordZhangJie()
  149. getNewData()
  150. })
  151. }
  152. function onRight(event) {
  153. console.log('用户又滑了');
  154. let req = {
  155. nianji: selectZhang.value.nianji,
  156. zhangId: selectZhang.value.zhangId,
  157. cardId: selectZhang.value.cardId,
  158. }
  159. userZhangNextInfo(req).then(res => {
  160. cacheManager.set('zhangInfo', res.data)
  161. infoData.jieList = res.data.jieList
  162. infoData.haveFlag = res.data.haveFlag
  163. infoData.nianji = res.data.nianji
  164. infoData.number = res.data.number
  165. infoData.numberStr = res.data.numberStr
  166. infoData.cardId = res.data.cardId
  167. infoData.zhangId = res.data.zhangId
  168. infoData.zhangName = res.data.zhangName
  169. recordZhangJie()
  170. getNewData()
  171. })
  172. }
  173. function getNewData() {
  174. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  175. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  176. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  177. cacheManager.updateObject('auth', {
  178. zhangId: selectZhang.value.zhangId,
  179. cardId: selectZhang.value.cardId,
  180. nianji: selectZhang.value.nianji,
  181. })
  182. }
  183. function recordZhangJie() {
  184. let req = {
  185. nianji: selectZhang.value.nianji,
  186. userId: cacheManager.get('auth').userId,
  187. zhangId: infoData.zhangId,
  188. cardId: selectZhang.value.cardId,
  189. }
  190. userLocate(req).then(res => {
  191. })
  192. }
  193. function handleChangeZhang(data) {
  194. selectZhang.value = data;
  195. const authCode = getUserIdentity();
  196. if (authCode !== 'Visitor') {
  197. cacheManager.updateObject('auth', {
  198. zhangId: data.zhangId
  199. })
  200. }
  201. init()
  202. }
  203. function goKaoshi(data) {
  204. let zhangId = selectZhang.value ? selectZhang.value.zhangId : infoData.zhangId;
  205. let nianji = selectZhang.value.nianji;
  206. let cardId = selectZhang.value.cardId;
  207. uni.navigateTo({
  208. url: `/pages/unitTest/index?jieId=${data.jieId}&zhangId=${zhangId}&nianji=${nianji}&cardId=${cardId}`
  209. })
  210. }
  211. function goLookShipin(data) {
  212. data.progressMarkers = [{
  213. offset: 30,
  214. isCustomized: true,
  215. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/9A3F562E595E4764AD1DD546FA52C6E5-6-2.png',
  216. title: '变式1',
  217. time: '00:00:30',
  218. describe: 'test string',
  219. }, {
  220. offset: 120,
  221. isCustomized: true,
  222. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/1E7F402241CD4C0F94AD2BBB5CCC3EC7-6-2.png',
  223. title: '变式2',
  224. time: '00:02:00',
  225. describe: 'test string',
  226. }, {
  227. offset: 300,
  228. isCustomized: true,
  229. coverUrl: 'https://alivc-demo-vod.aliyuncs.com/image/cover/553AEA01161342C8A2B1756E83B69B5B-6-2.png',
  230. title: '变式3',
  231. time: '00:05:00',
  232. describe: 'test string',
  233. }]
  234. data.zhangId = infoData.zhangId
  235. data.nianji = infoData.nianji
  236. data.cardId = infoData.cardId
  237. uni.navigateTo({
  238. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  239. url: '/pages/study/lookShipin?studyData=' + JSON.stringify(data)
  240. })
  241. }
  242. function listClick(data, index) {
  243. if (!cacheManager.get('auth')) {
  244. toast("当前为游客模式请登录!")
  245. uni.redirectTo({
  246. url: '/pages/login/index'
  247. })
  248. return;
  249. }
  250. const authCode = getUserIdentity();
  251. if (!(authCode=='VIP' || data.number == 1)) {
  252. goPayDialogRef.value.handleShow();
  253. return false
  254. }
  255. if (data.number == infoData.jieList.length) {
  256. // 最后一项
  257. goKaoshi(data)
  258. } else {
  259. goLookShipin(data)
  260. }
  261. }
  262. function handleCheckCatalogue() {
  263. catalogueRef.value.showPopup();
  264. }
  265. function clickGradeTerm() {
  266. uni.navigateTo({
  267. url: `/pages/selectGradesTerms/index`,
  268. })
  269. }
  270. function eggBtn() {
  271. console.log('点击:开启提分之旅');
  272. }
  273. </script>
  274. <style>
  275. </style>