index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <shuxueZhangjie v-if="currentProduct ==1" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  3. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  4. </shuxueZhangjie>
  5. <yingyuZhangjie v-if="currentProduct ==2" @clickGradeTerm="clickGradeTerm" @onLeft="onLeft" @onRight="onRight"
  6. @handleCheckCatalogue="handleCheckCatalogue" @listClick="listClick" :options="infoData">
  7. </yingyuZhangjie>
  8. <!-- 蛋 -->
  9. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  10. <catalogue ref="catalogueRef" @change-zhang="handleChangeZhang"></catalogue>
  11. <CustomTabBar :cardId="cardId" :nianji="nianji" :zhangId="zhangId"></CustomTabBar>
  12. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  13. </template>
  14. <script setup>
  15. import {
  16. userZhangInfo,
  17. userLocate,
  18. userZhangForntInfo,
  19. userZhangNextInfo,
  20. getCommonZhangInfo
  21. } from "@/api/learnPlan.js"
  22. import {
  23. reactive,
  24. ref,
  25. getCurrentInstance,
  26. onMounted
  27. } from "vue";
  28. import {
  29. onLoad
  30. } from '@dcloudio/uni-app';
  31. import catalogue from "@/components/catalogue/catalogue.vue";
  32. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  33. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  34. import shuxueZhangjie from './product/shuxue.vue';
  35. import yingyuZhangjie from './product/yingyu.vue';
  36. import {
  37. useTabBarHistory
  38. } from '@/utils/emitEvents.js';
  39. import eggDialog from './eggDialog.vue'
  40. import {
  41. toast,getUserIdentity
  42. } from "@/utils/common";
  43. import cacheManager from "@/utils/cacheManager.js";
  44. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  45. const goPayDialogRef = ref(null);
  46. const eggDialogRef = ref(null);
  47. const zhangId = ref(null); //游客使用
  48. const nianji = ref(null);//游客使用
  49. const cardId = ref(null);//游客使用
  50. const catalogueRef = ref(null);
  51. const currentProduct = ref(null);
  52. const selectZhang = ref(null);
  53. let infoData = reactive({
  54. jieList: [],
  55. haveFlag: '',
  56. nianji: '',
  57. number: '',
  58. cardId: '',
  59. zhangId: '',
  60. zhangName: '',
  61. numberStr: '',
  62. });
  63. onLoad((options) => {
  64. init(options)
  65. })
  66. function init(options){
  67. if (cacheManager.get('auth')) {
  68. currentProduct.value = cacheManager.get('auth').cardId;
  69. //会员 取auth
  70. selectZhang.value = cacheManager.get('auth');
  71. console.log(selectZhang.value);
  72. // 已登录
  73. // 选择年级进入调用此接口
  74. //options.flag == 'selectGrades'
  75. getZhangInfo()
  76. // 蛋
  77. // eggDialogRef.value.eggShow();
  78. } else {
  79. zhangId.value = options.zhangId
  80. nianji.value = options.nianji
  81. cardId.value = options.cardId
  82. currentProduct.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 goPayPage(){
  194. }
  195. function handleChangeZhang(data) {
  196. selectZhang.value = data;
  197. const authCode = getUserIdentity();
  198. if (authCode !== 'Visitor') {
  199. cacheManager.updateObject('auth', {
  200. zhangId: data.zhangId
  201. })
  202. }
  203. init()
  204. }
  205. function goKaoshi(data) {
  206. uni.redirectTo({
  207. url: `/pages/unitTest/index?jieNumber=`+data.number
  208. })
  209. }
  210. function goLookShipin(data) {
  211. uni.redirectTo({
  212. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  213. url: '/pages/study/lookShipin?jieNumber='+data.number
  214. })
  215. }
  216. function listClick(data, index) {
  217. if (!cacheManager.get('auth')) {
  218. toast("当前为游客模式请登录!")
  219. uni.redirectTo({
  220. url: '/pages/login/index'
  221. })
  222. return;
  223. }
  224. const authCode = getUserIdentity();
  225. if (!(authCode=='VIP' || data.number == 1)) {
  226. goPayDialogRef.value.handleShow();
  227. return false
  228. }
  229. if (data.number == infoData.jieList.length &&data.jieName=='单元测试') {
  230. // 最后一项
  231. goKaoshi(data)
  232. } else {
  233. goLookShipin(data)
  234. }
  235. }
  236. function handleCheckCatalogue() {
  237. catalogueRef.value.showPopup();
  238. }
  239. function clickGradeTerm() {
  240. uni.navigateTo({
  241. url: `/pages/selectGradesTerms/index`,
  242. })
  243. }
  244. function eggBtn() {
  245. console.log('点击:开启提分之旅');
  246. }
  247. </script>
  248. <style>
  249. </style>