index.vue 8.4 KB

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