index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. nextTick(() => {
  82. eggDialogRef.value.eggShow();
  83. })
  84. getZhangInfo()
  85. // 蛋
  86. // eggDialogRef.value.eggShow();
  87. } else {
  88. zhangId.value = options.zhangId
  89. nianji.value = options.nianji
  90. cardId.value = options.cardId
  91. currentProduct.value = options.cardId
  92. // 未登录 游客
  93. getCommonZhang(options)
  94. }
  95. }
  96. function getZhangInfo(data) {
  97. let req = {
  98. nianji: selectZhang.value.nianji,
  99. cardId: selectZhang.value.cardId,
  100. zhangId: selectZhang.value.zhangId,
  101. }
  102. userZhangInfo(req).then(res => {
  103. cacheManager.set('zhangInfo', res.data)
  104. infoData.jieList = res.data.jieList
  105. infoData.haveFlag = res.data.haveFlag
  106. infoData.nianji = res.data.nianji
  107. infoData.number = res.data.number
  108. infoData.numberStr = res.data.numberStr
  109. infoData.cardId = res.data.cardId
  110. infoData.zhangId = res.data.zhangId
  111. infoData.zhangName = res.data.zhangName
  112. recordZhangJie()
  113. getNewData()
  114. // if (cacheManager.get('zhangInfo')) {
  115. // cacheManager.remove('zhangInfo')
  116. // cacheManager.set('zhangInfo', res.data)
  117. // } else {
  118. // cacheManager.set('zhangInfo', res.data)
  119. // }
  120. })
  121. }
  122. function getCommonZhang(data) {
  123. let req = {
  124. nianji: data.nianji,
  125. cardId: data.cardId,
  126. zhangId: data.zhangId,
  127. }
  128. getCommonZhangInfo(req).then(res => {
  129. infoData.jieList = res.data.jieList
  130. infoData.haveFlag = res.data.haveFlag
  131. infoData.nianji = res.data.nianji
  132. infoData.number = res.data.number
  133. infoData.numberStr = res.data.numberStr
  134. infoData.cardId = res.data.cardId
  135. infoData.zhangId = res.data.zhangId
  136. infoData.zhangName = res.data.zhangName
  137. //getNewData()
  138. })
  139. }
  140. function onLeft(event) {
  141. const authCode = getUserIdentity();
  142. if (authCode !== 'VIP') {
  143. return false
  144. }
  145. console.log('用户左滑了');
  146. let req = {
  147. nianji: selectZhang.value.nianji,
  148. zhangId: selectZhang.value.zhangId,
  149. cardId: selectZhang.value.cardId,
  150. }
  151. userZhangForntInfo(req).then(res => {
  152. cacheManager.set('zhangInfo', res.data)
  153. infoData.jieList = res.data.jieList
  154. infoData.haveFlag = res.data.haveFlag
  155. infoData.nianji = res.data.nianji
  156. infoData.number = res.data.number
  157. infoData.numberStr = res.data.numberStr
  158. infoData.cardId = res.data.cardId
  159. infoData.zhangId = res.data.zhangId
  160. infoData.zhangName = res.data.zhangName
  161. recordZhangJie()
  162. getNewData()
  163. })
  164. }
  165. function onRight(event) {
  166. const authCode = getUserIdentity();
  167. if (authCode !== 'VIP') {
  168. return false
  169. }
  170. console.log('用户又滑了');
  171. let req = {
  172. nianji: selectZhang.value.nianji,
  173. zhangId: selectZhang.value.zhangId,
  174. cardId: selectZhang.value.cardId,
  175. }
  176. userZhangNextInfo(req).then(res => {
  177. cacheManager.set('zhangInfo', res.data)
  178. infoData.jieList = res.data.jieList
  179. infoData.haveFlag = res.data.haveFlag
  180. infoData.nianji = res.data.nianji
  181. infoData.number = res.data.number
  182. infoData.numberStr = res.data.numberStr
  183. infoData.cardId = res.data.cardId
  184. infoData.zhangId = res.data.zhangId
  185. infoData.zhangName = res.data.zhangName
  186. recordZhangJie()
  187. getNewData()
  188. })
  189. }
  190. function getNewData() {
  191. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  192. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  193. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  194. cacheManager.updateObject('auth', {
  195. zhangId: selectZhang.value.zhangId,
  196. cardId: selectZhang.value.cardId,
  197. nianji: selectZhang.value.nianji,
  198. })
  199. }
  200. function recordZhangJie() {
  201. let req = {
  202. nianji: selectZhang.value.nianji,
  203. userId: cacheManager.get('auth').userId,
  204. zhangId: infoData.zhangId,
  205. cardId: selectZhang.value.cardId,
  206. }
  207. userLocate(req).then(res => {
  208. })
  209. }
  210. function goPayPage() {
  211. }
  212. function handleChangeZhang(data) {
  213. selectZhang.value = data;
  214. const authCode = getUserIdentity();
  215. if (authCode !== 'Visitor') {
  216. cacheManager.updateObject('auth', {
  217. zhangId: data.zhangId
  218. })
  219. }
  220. init()
  221. }
  222. function goKaoshi(data) {
  223. uni.redirectTo({
  224. url: `/pages/unitTest/index?jieNumber=` + data.number
  225. })
  226. }
  227. function goLookShipin(data) {
  228. if (!cacheManager.get('auth')) {
  229. uni.redirectTo({
  230. url: '/pages/study/lookShipin?jieNumber=' + data.number + '&cardId=' + cardId.value + '&nianji=' +
  231. nianji.value + '&zhangId=' + zhangId.value + '&videoId=' + infoData.jieList[0].videoId
  232. })
  233. return;
  234. } else {
  235. uni.redirectTo({
  236. url: '/pages/study/lookShipin?jieNumber=' + data.number
  237. })
  238. }
  239. }
  240. function listClick(data, index) {
  241. if (!cacheManager.get('auth') && data.number != 1) {
  242. youkeDialogRef.value.handleShow();
  243. return;
  244. }
  245. const authCode = getUserIdentity();
  246. if (!(authCode == 'VIP' || data.number == 1)) {
  247. goPayDialogRef.value.handleShow();
  248. return false
  249. }
  250. if (data.number == infoData.jieList.length && data.jieName == '单元测试') {
  251. // 最后一项
  252. goKaoshi(data)
  253. } else {
  254. goLookShipin(data)
  255. }
  256. }
  257. function handleCheckCatalogue() {
  258. catalogueRef.value.showPopup();
  259. }
  260. function clickGradeTerm() {
  261. uni.navigateTo({
  262. url: `/pages/selectGradesTerms/index`,
  263. })
  264. }
  265. // 游客弹窗---确定
  266. function ykConfirm() {
  267. uni.redirectTo({
  268. url: '/pages/login/index'
  269. });
  270. }
  271. function eggBtn() {
  272. console.log('点击:开启提分之旅');
  273. }
  274. </script>
  275. <style>
  276. </style>