index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. <tip-middle-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :content="YouKeContent"></tip-middle-dialog>
  14. </template>
  15. <script setup>
  16. import {
  17. userZhangInfo,
  18. userLocate,
  19. userZhangForntInfo,
  20. userZhangNextInfo,
  21. getCommonZhangInfo
  22. } from "@/api/learnPlan.js"
  23. import {
  24. reactive,
  25. ref,
  26. getCurrentInstance,
  27. onMounted
  28. } from "vue";
  29. import {
  30. onLoad
  31. } from '@dcloudio/uni-app';
  32. import catalogue from "@/components/catalogue/catalogue.vue";
  33. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  34. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  35. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.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,
  44. getUserIdentity
  45. } from "@/utils/common";
  46. import cacheManager from "@/utils/cacheManager.js";
  47. const tipContent = '付费章节,是否前往开通付费?'; //当前产品
  48. const goPayDialogRef = ref(null);
  49. const youkeDialogRef = ref(null);
  50. const eggDialogRef = ref(null);
  51. const YouKeContent = '您当前是游客身份,登录后才能浏览内容,现在去登录?';
  52. const zhangId = ref(null); //游客使用
  53. const nianji = ref(null); //游客使用
  54. const cardId = ref(null); //游客使用
  55. const catalogueRef = ref(null);
  56. const currentProduct = ref(null);
  57. const selectZhang = ref(null);
  58. let infoData = reactive({
  59. jieList: [],
  60. haveFlag: '',
  61. nianji: '',
  62. number: '',
  63. cardId: '',
  64. zhangId: '',
  65. zhangName: '',
  66. numberStr: '',
  67. });
  68. onLoad((options) => {
  69. init(options)
  70. })
  71. function init(options) {
  72. if (cacheManager.get('auth')) {
  73. currentProduct.value = cacheManager.get('auth').cardId;
  74. //会员 取auth
  75. selectZhang.value = cacheManager.get('auth');
  76. console.log(selectZhang.value);
  77. // 已登录
  78. // 选择年级进入调用此接口
  79. //options.flag == 'selectGrades'
  80. getZhangInfo()
  81. // 蛋
  82. // eggDialogRef.value.eggShow();
  83. } else {
  84. zhangId.value = options.zhangId
  85. nianji.value = options.nianji
  86. cardId.value = options.cardId
  87. currentProduct.value = options.cardId
  88. // 未登录 游客
  89. getCommonZhang(options)
  90. }
  91. }
  92. function getZhangInfo(data) {
  93. let req = {
  94. nianji: selectZhang.value.nianji,
  95. cardId: selectZhang.value.cardId,
  96. zhangId: selectZhang.value.zhangId,
  97. }
  98. userZhangInfo(req).then(res => {
  99. cacheManager.set('zhangInfo', res.data)
  100. infoData.jieList = res.data.jieList
  101. infoData.haveFlag = res.data.haveFlag
  102. infoData.nianji = res.data.nianji
  103. infoData.number = res.data.number
  104. infoData.numberStr = res.data.numberStr
  105. infoData.cardId = res.data.cardId
  106. infoData.zhangId = res.data.zhangId
  107. infoData.zhangName = res.data.zhangName
  108. recordZhangJie()
  109. getNewData()
  110. // if (cacheManager.get('zhangInfo')) {
  111. // cacheManager.remove('zhangInfo')
  112. // cacheManager.set('zhangInfo', res.data)
  113. // } else {
  114. // cacheManager.set('zhangInfo', res.data)
  115. // }
  116. })
  117. }
  118. function getCommonZhang(data) {
  119. let req = {
  120. nianji: data.nianji,
  121. cardId: data.cardId,
  122. zhangId: data.zhangId,
  123. }
  124. getCommonZhangInfo(req).then(res => {
  125. infoData.jieList = res.data.jieList
  126. infoData.haveFlag = res.data.haveFlag
  127. infoData.nianji = res.data.nianji
  128. infoData.number = res.data.number
  129. infoData.numberStr = res.data.numberStr
  130. infoData.cardId = res.data.cardId
  131. infoData.zhangId = res.data.zhangId
  132. infoData.zhangName = res.data.zhangName
  133. //getNewData()
  134. })
  135. }
  136. function onLeft(event) {
  137. console.log('用户左滑了');
  138. let req = {
  139. nianji: selectZhang.value.nianji,
  140. zhangId: selectZhang.value.zhangId,
  141. cardId: selectZhang.value.cardId,
  142. }
  143. userZhangForntInfo(req).then(res => {
  144. cacheManager.set('zhangInfo', res.data)
  145. infoData.jieList = res.data.jieList
  146. infoData.haveFlag = res.data.haveFlag
  147. infoData.nianji = res.data.nianji
  148. infoData.number = res.data.number
  149. infoData.numberStr = res.data.numberStr
  150. infoData.cardId = res.data.cardId
  151. infoData.zhangId = res.data.zhangId
  152. infoData.zhangName = res.data.zhangName
  153. recordZhangJie()
  154. getNewData()
  155. })
  156. }
  157. function onRight(event) {
  158. console.log('用户又滑了');
  159. let req = {
  160. nianji: selectZhang.value.nianji,
  161. zhangId: selectZhang.value.zhangId,
  162. cardId: selectZhang.value.cardId,
  163. }
  164. userZhangNextInfo(req).then(res => {
  165. cacheManager.set('zhangInfo', res.data)
  166. infoData.jieList = res.data.jieList
  167. infoData.haveFlag = res.data.haveFlag
  168. infoData.nianji = res.data.nianji
  169. infoData.number = res.data.number
  170. infoData.numberStr = res.data.numberStr
  171. infoData.cardId = res.data.cardId
  172. infoData.zhangId = res.data.zhangId
  173. infoData.zhangName = res.data.zhangName
  174. recordZhangJie()
  175. getNewData()
  176. })
  177. }
  178. function getNewData() {
  179. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  180. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  181. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  182. cacheManager.updateObject('auth', {
  183. zhangId: selectZhang.value.zhangId,
  184. cardId: selectZhang.value.cardId,
  185. nianji: selectZhang.value.nianji,
  186. })
  187. }
  188. function recordZhangJie() {
  189. let req = {
  190. nianji: selectZhang.value.nianji,
  191. userId: cacheManager.get('auth').userId,
  192. zhangId: infoData.zhangId,
  193. cardId: selectZhang.value.cardId,
  194. }
  195. userLocate(req).then(res => {
  196. })
  197. }
  198. function goPayPage() {
  199. }
  200. function handleChangeZhang(data) {
  201. selectZhang.value = data;
  202. const authCode = getUserIdentity();
  203. if (authCode !== 'Visitor') {
  204. cacheManager.updateObject('auth', {
  205. zhangId: data.zhangId
  206. })
  207. }
  208. init()
  209. }
  210. function goKaoshi(data) {
  211. uni.redirectTo({
  212. url: `/pages/unitTest/index?jieNumber=` + data.number
  213. })
  214. }
  215. function goLookShipin(data) {
  216. if (!cacheManager.get('auth')) {
  217. uni.redirectTo({
  218. url: '/pages/study/lookShipin?jieNumber=' + data.number + '&cardId=' + cardId.value + '&nianji=' +
  219. nianji.value + '&zhangId=' + zhangId.value + '&videoId=' + infoData.jieList[0].videoId
  220. })
  221. return;
  222. } else {
  223. uni.redirectTo({
  224. url: '/pages/study/lookShipin?jieNumber=' + data.number
  225. })
  226. }
  227. }
  228. function listClick(data, index) {
  229. if (!cacheManager.get('auth') && data.number != 1) {
  230. youkeDialogRef.value.handleShow();
  231. return;
  232. }
  233. const authCode = getUserIdentity();
  234. if (!(authCode == 'VIP' || data.number == 1)) {
  235. goPayDialogRef.value.handleShow();
  236. return false
  237. }
  238. if (data.number == infoData.jieList.length && data.jieName == '单元测试') {
  239. // 最后一项
  240. goKaoshi(data)
  241. } else {
  242. goLookShipin(data)
  243. }
  244. }
  245. function handleCheckCatalogue() {
  246. catalogueRef.value.showPopup();
  247. }
  248. function clickGradeTerm() {
  249. uni.navigateTo({
  250. url: `/pages/selectGradesTerms/index`,
  251. })
  252. }
  253. // 游客弹窗---确定
  254. function ykConfirm() {
  255. uni.redirectTo({
  256. url: '/pages/login/index'
  257. });
  258. }
  259. function eggBtn() {
  260. console.log('点击:开启提分之旅');
  261. }
  262. </script>
  263. <style>
  264. </style>