index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. const authCode = getUserIdentity();
  138. if (authCode !== 'VIP') {
  139. return false
  140. }
  141. console.log('用户左滑了');
  142. let req = {
  143. nianji: selectZhang.value.nianji,
  144. zhangId: selectZhang.value.zhangId,
  145. cardId: selectZhang.value.cardId,
  146. }
  147. userZhangForntInfo(req).then(res => {
  148. cacheManager.set('zhangInfo', res.data)
  149. infoData.jieList = res.data.jieList
  150. infoData.haveFlag = res.data.haveFlag
  151. infoData.nianji = res.data.nianji
  152. infoData.number = res.data.number
  153. infoData.numberStr = res.data.numberStr
  154. infoData.cardId = res.data.cardId
  155. infoData.zhangId = res.data.zhangId
  156. infoData.zhangName = res.data.zhangName
  157. recordZhangJie()
  158. getNewData()
  159. })
  160. }
  161. function onRight(event) {
  162. const authCode = getUserIdentity();
  163. if (authCode !== 'VIP') {
  164. return false
  165. }
  166. console.log('用户又滑了');
  167. let req = {
  168. nianji: selectZhang.value.nianji,
  169. zhangId: selectZhang.value.zhangId,
  170. cardId: selectZhang.value.cardId,
  171. }
  172. userZhangNextInfo(req).then(res => {
  173. cacheManager.set('zhangInfo', res.data)
  174. infoData.jieList = res.data.jieList
  175. infoData.haveFlag = res.data.haveFlag
  176. infoData.nianji = res.data.nianji
  177. infoData.number = res.data.number
  178. infoData.numberStr = res.data.numberStr
  179. infoData.cardId = res.data.cardId
  180. infoData.zhangId = res.data.zhangId
  181. infoData.zhangName = res.data.zhangName
  182. recordZhangJie()
  183. getNewData()
  184. })
  185. }
  186. function getNewData() {
  187. selectZhang.value.zhangId = cacheManager.get('zhangInfo').zhangId;
  188. selectZhang.value.cardId = cacheManager.get('zhangInfo').cardId;
  189. selectZhang.value.nianji = cacheManager.get('zhangInfo').nianji;
  190. cacheManager.updateObject('auth', {
  191. zhangId: selectZhang.value.zhangId,
  192. cardId: selectZhang.value.cardId,
  193. nianji: selectZhang.value.nianji,
  194. })
  195. }
  196. function recordZhangJie() {
  197. let req = {
  198. nianji: selectZhang.value.nianji,
  199. userId: cacheManager.get('auth').userId,
  200. zhangId: infoData.zhangId,
  201. cardId: selectZhang.value.cardId,
  202. }
  203. userLocate(req).then(res => {
  204. })
  205. }
  206. function goPayPage() {
  207. }
  208. function handleChangeZhang(data) {
  209. selectZhang.value = data;
  210. const authCode = getUserIdentity();
  211. if (authCode !== 'Visitor') {
  212. cacheManager.updateObject('auth', {
  213. zhangId: data.zhangId
  214. })
  215. }
  216. init()
  217. }
  218. function goKaoshi(data) {
  219. uni.redirectTo({
  220. url: `/pages/unitTest/index?jieNumber=` + data.number
  221. })
  222. }
  223. function goLookShipin(data) {
  224. if (!cacheManager.get('auth')) {
  225. uni.redirectTo({
  226. url: '/pages/study/lookShipin?jieNumber=' + data.number + '&cardId=' + cardId.value + '&nianji=' +
  227. nianji.value + '&zhangId=' + zhangId.value + '&videoId=' + infoData.jieList[0].videoId
  228. })
  229. return;
  230. } else {
  231. uni.redirectTo({
  232. url: '/pages/study/lookShipin?jieNumber=' + data.number
  233. })
  234. }
  235. }
  236. function listClick(data, index) {
  237. if (!cacheManager.get('auth') && data.number != 1) {
  238. youkeDialogRef.value.handleShow();
  239. return;
  240. }
  241. const authCode = getUserIdentity();
  242. if (!(authCode == 'VIP' || data.number == 1)) {
  243. goPayDialogRef.value.handleShow();
  244. return false
  245. }
  246. if (data.number == infoData.jieList.length && data.jieName == '单元测试') {
  247. // 最后一项
  248. goKaoshi(data)
  249. } else {
  250. goLookShipin(data)
  251. }
  252. }
  253. function handleCheckCatalogue() {
  254. catalogueRef.value.showPopup();
  255. }
  256. function clickGradeTerm() {
  257. uni.navigateTo({
  258. url: `/pages/selectGradesTerms/index`,
  259. })
  260. }
  261. // 游客弹窗---确定
  262. function ykConfirm() {
  263. uni.redirectTo({
  264. url: '/pages/login/index'
  265. });
  266. }
  267. function eggBtn() {
  268. console.log('点击:开启提分之旅');
  269. }
  270. </script>
  271. <style>
  272. </style>