index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <view>
  3. <swiper :circular="true" @change="onChangeTab" :duration="currentDuration" :current="current"
  4. class="ezy-study-swiper" :class="'ezy-study-swiper'+ currentProduct">
  5. <swiper-item v-for="(item,index) in zhangList" :key="index">
  6. <shuxueZhangjie v-if="currentProduct ==1&&typeId==2" @clickGradeTerm="clickGradeTerm"
  7. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  8. :options="item" :youkeImage="youkeImage">
  9. </shuxueZhangjie>
  10. <yingyuZhangjie v-if="currentProduct ==2&&typeId==2" @clickGradeTerm="clickGradeTerm"
  11. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  12. :options="item" :youkeImage="youkeImage">
  13. </yingyuZhangjie>
  14. <shuxueNewZhangjie v-if="currentProduct ==1&&typeId==1" @clickGradeTerm="clickGradeTerm"
  15. @handleCheckCatalogue="handleCheckCatalogue(item)" @listClick="listClick" :gradeTerm='gradeTerm'
  16. :options="item" :youkeImage="youkeImage">
  17. </shuxueNewZhangjie>
  18. </swiper-item>
  19. </swiper>
  20. <!-- 蛋 -->
  21. <egg-dialog ref="eggDialogRef" @eggBtn="eggBtn"></egg-dialog>
  22. <catalogue ref="catalogueRef" :list=zhangList @change-zhang="handleChangeZhang"
  23. @listSelectJieClick="listSelectJieClick"></catalogue>
  24. <CustomTabBar :levelId="levelId" :currentTabNumber="0" :subjectId="subjectId" :typeId="typeId"
  25. :tipFlag="tipFlag">
  26. </CustomTabBar>
  27. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  28. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  29. <dao-tip-dialog ref="daoTipDialogRef" v-if="showDaoTip" :productTip="productTipImg"
  30. @dao-tip-close="daoTipClose"></dao-tip-dialog>
  31. <tip-dialog ref="tipDialogRef" :title="tipTitle" :content="tipContentVersion"></tip-dialog>
  32. </view>
  33. </template>
  34. <script setup>
  35. import daoTipDialog from './daoTipDialog.vue';
  36. import {
  37. userZhangInfo,
  38. userLocate,
  39. userZhangForntInfo,
  40. userZhangNextInfo,
  41. getCommonZhangInfo
  42. } from "@/api/learnPlan.js"
  43. import {
  44. getVersion
  45. } from "@/api/login.js"
  46. import {
  47. reactive,
  48. ref,
  49. nextTick,
  50. getCurrentInstance,
  51. onMounted
  52. } from "vue";
  53. import {
  54. onLoad
  55. } from '@dcloudio/uni-app';
  56. import catalogue from "@/components/catalogue/catalogue.vue";
  57. import CustomTabBar from '@/components/custom-tabbar/custom-tabbar.vue';
  58. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  59. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  60. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  61. import dSwiper from '@/components/wSwiper/DSwiper.vue';
  62. import shuxueZhangjie from './product/shuxue.vue';
  63. import shuxueNewZhangjie from './product/shuxueNew.vue';
  64. import yingyuZhangjie from './product/yingyu.vue';
  65. import {
  66. useTabBarHistory
  67. } from '@/utils/emitEvents.js';
  68. import eggDialog from './eggDialog.vue'
  69. import tipDialog from '@/components/dialog/tipDialog.vue';
  70. import config from '../../config.js'
  71. import {
  72. toast,
  73. getUserIdentity
  74. } from "@/utils/common";
  75. import cacheManager from "@/utils/cacheManager.js";
  76. const tipContent = '是否前往开通付费?'; //当前产品
  77. const goPayDialogRef = ref(null);
  78. const youkeDialogRef = ref(null);
  79. const dSwiperRef = ref(null);
  80. const eggDialogRef = ref(null);
  81. const current = ref(0);
  82. const currentDuration = ref(500)
  83. const YouKeContent = '您当前的身份是游客,想要体验完整内容需注册成用户!';
  84. const tipFlag = ref(null) //游客使用
  85. const catalogueRef = ref(null);
  86. const youkeImage = ref(null);
  87. const currentProduct = ref(null);
  88. const localAuth = ref(null);
  89. const levelId = ref(null); //游客使用
  90. const subjectId = ref(null); //游客使用
  91. const typeId = ref(null);
  92. const zhangList = ref(null);
  93. const gradeTerm = ref(null);
  94. let infoData = reactive({
  95. jieList: [],
  96. haveFlag: '',
  97. number: '',
  98. zhangId: '',
  99. zhangName: '',
  100. numberStr: '',
  101. });
  102. const termMapping = {
  103. 1: ' 数学',
  104. 2: ' 英语'
  105. };
  106. const daoTipDialogRef = ref(null);
  107. const showDaoTip = ref(true);
  108. const productTipImg = ref('');
  109. const version = config.appInfo.version;
  110. const tipDialogRef = ref(null);
  111. const tipTitle = '升级提醒';
  112. const tipContentVersion = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
  113. onLoad((options) => {
  114. init(options);
  115. getLoginInit()
  116. })
  117. function listSelectJieClick(item, data, index) {
  118. if (cacheManager.get('auth')) {
  119. cacheManager.updateObject('auth', {
  120. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == item.zhangId),
  121. zhangId: item.zhangId
  122. })
  123. }
  124. listClick(data, item, index);
  125. }
  126. function getLoginInit() {
  127. getVersion({}).then(res => {
  128. if (version != res.data.version) {
  129. tipDialogRef.value.handleShow();
  130. }
  131. })
  132. }
  133. function getProjectImg() {
  134. if (currentProduct.value == 1 && typeId.value == 2) {
  135. // 数学
  136. productTipImg.value = 'static/images/study/shuxue/shuxue-tip.gif';
  137. getBj('shuxue')
  138. } else if (currentProduct.value == 2 && typeId.value == 2) {
  139. // 英语
  140. productTipImg.value = 'static/images/study/yingyu/yingyu-tip.gif'
  141. getBj('yingyu');
  142. } else if (currentProduct.value == 1 && typeId.value == 1) {
  143. // 计算特训
  144. productTipImg.value = 'static/images/study/jstx/jstx-tip.gif'
  145. getBj('shuxueNew');
  146. }
  147. }
  148. function getBj(data) {
  149. let bjType = cacheManager.get('dao-tip')[data];
  150. if (cacheManager.get('auth')) {
  151. // 非游客
  152. if (bjType !== 'has') {
  153. nextTick(() => {
  154. daoTipDialogRef.value.handleShow();
  155. })
  156. }
  157. } else {
  158. // 游客
  159. if (tipFlag.value === '0') {
  160. nextTick(() => {
  161. daoTipDialogRef.value.handleShow();
  162. })
  163. }
  164. }
  165. }
  166. function daoTipClose() {
  167. if (cacheManager.get('auth')) {
  168. // 非游客 记缓存
  169. if (currentProduct.value == 1 && typeId.value == 2) {
  170. // 数学
  171. cacheManager.updateObject('dao-tip', {
  172. shuxue: 'has'
  173. })
  174. } else if (currentProduct.value == 2 && typeId.value == 2) {
  175. // 英语
  176. cacheManager.updateObject('dao-tip', {
  177. yingyu: 'has'
  178. })
  179. } else if (currentProduct.value == 1 && typeId.value == 1) {
  180. // 英语
  181. cacheManager.updateObject('dao-tip', {
  182. shuxueNew: 'has'
  183. })
  184. }
  185. } else {
  186. //游客
  187. tipFlag.value = '1';
  188. }
  189. }
  190. function onChangeTab(e) {
  191. console.log('e', e);
  192. console.log(e.detail.current);
  193. if (cacheManager.get('auth')) {
  194. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  195. cacheManager.updateObject('auth', {
  196. currentZhang: e.detail.current,
  197. zhangId: infoData.zhangId
  198. })
  199. }
  200. }
  201. function init(options) {
  202. if (cacheManager.get('auth')) {
  203. localAuth.value = cacheManager.get('auth');
  204. currentProduct.value = localAuth.value.subjectId;
  205. typeId.value = localAuth.value.typeId;
  206. console.log(localAuth.value);
  207. // 已登录
  208. if (localAuth.value.firstLogin) {
  209. nextTick(() => {
  210. eggDialogRef.value.eggShow();
  211. })
  212. }
  213. if (!cacheManager.get('daoPageCache').isCache) {
  214. console.log('不实用换葱');
  215. getZhangInfo()
  216. } else {
  217. console.log('shiyonghuancun');
  218. translateData(cacheManager.get('zhangInfo'))
  219. zhangList.value = cacheManager.get('zhangInfo').zhangList
  220. current.value = cacheManager.get('auth').currentZhang
  221. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[current.value].zhangId
  222. recordZhangJie()
  223. }
  224. // 已登录付费未支付选择返回 -> 恢复弹窗
  225. if (options.studyWithCatalgue) {
  226. // 展开弹窗
  227. nextTick(() => {
  228. catalogueRef.value.showPopup({
  229. zhangId: infoData.zhangId
  230. });
  231. })
  232. }
  233. } else {
  234. subjectId.value = options.subjectId
  235. typeId.value = options.typeId
  236. levelId.value = options.levelId
  237. tipFlag.value = options.tipFlag;
  238. currentProduct.value = options.subjectId
  239. // 未登录 游客
  240. getCommonZhang(options)
  241. getProjectImg()
  242. }
  243. }
  244. function getZhangInfo(data) {
  245. let req = {
  246. levelId: localAuth.value.levelId
  247. }
  248. userZhangInfo(req).then(res => {
  249. cacheManager.set('zhangInfo', res.data)
  250. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
  251. .value.zhangId);
  252. console.log('zhang', zhang);
  253. if (zhang != -1) {
  254. cacheManager.updateObject('auth', {
  255. currentZhang: zhang
  256. })
  257. } else {
  258. cacheManager.updateObject('auth', {
  259. currentZhang: 0
  260. })
  261. }
  262. cacheManager.set('daoPageCache', {
  263. isCache: true
  264. })
  265. nextTick(() => {
  266. translateData(res.data)
  267. zhangList.value = res.data.zhangList
  268. current.value = cacheManager.get('auth').currentZhang
  269. infoData.zhangId = res.data.zhangList[current.value].zhangId
  270. recordZhangJie()
  271. })
  272. }).catch((err) => {
  273. toast('数据异常,请重新登录!')
  274. cacheManager.clearAll();
  275. uni.reLaunch({
  276. url: '/pages/login/index'
  277. });
  278. })
  279. }
  280. function getCommonZhang(data) {
  281. let req = {
  282. levelId: data.levelId,
  283. }
  284. getCommonZhangInfo(req).then(res => {
  285. translateData(res.data)
  286. youkeImage.value = res.data.icon
  287. zhangList.value = res.data.zhangList
  288. current.value = 0
  289. }).catch((err) => {
  290. toast('数据异常,请重新登录!')
  291. cacheManager.clearAll();
  292. uni.reLaunch({
  293. url: '/pages/login/index'
  294. });
  295. })
  296. }
  297. function recordZhangJie() {
  298. let req = {
  299. levelId: localAuth.value.levelId,
  300. userId: localAuth.value.userId,
  301. zhangId: infoData.zhangId,
  302. subjectId: currentProduct.value
  303. }
  304. userLocate(req).then(res => {
  305. })
  306. }
  307. function goPayPage() {
  308. let zhangInfoLocal = cacheManager.get('zhangInfo')
  309. if (!zhangInfoLocal.cardId) {
  310. toast("cardId 丢失请重新选择学科LevelId");
  311. return false
  312. }
  313. uni.redirectTo({
  314. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  315. zhangInfoLocal.subjectId
  316. })
  317. }
  318. function handleChangeZhang(data) {
  319. console.log(data);
  320. const authCode = getUserIdentity();
  321. if (authCode !== 'Visitor') {
  322. cacheManager.updateObject('auth', {
  323. zhangId: data.zhangId,
  324. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  325. })
  326. }
  327. currentDuration.value = 0
  328. setTimeout(() => {
  329. current.value = data.number - 1
  330. nextTick(() => {
  331. currentDuration.value = 500
  332. })
  333. }, 100)
  334. // init()
  335. }
  336. function goKaoshi(data) {
  337. uni.redirectTo({
  338. // url: `/pages/unitTest/index?jieNumber=` + data.number
  339. url: `/pages/unitTest/index?jieId=` + data.jieId
  340. })
  341. }
  342. function goLookShipin(data, index) {
  343. if (!cacheManager.get('auth')) {
  344. console.log('zhangList.value[0].jieList', zhangList.value[0].jieList);
  345. console.log('zhangList.value[0].jieList.index', zhangList.value[0].jieList[index]);
  346. let youkeData = {
  347. levelId: levelId.value,
  348. typeId: typeId.value,
  349. subjectId: subjectId.value,
  350. tipFlag: tipFlag.value,
  351. jieList: zhangList.value[0].jieList[index],
  352. jieName: zhangList.value[0].jieList[index].jieName
  353. }
  354. if (youkeData.typeId == 1) {
  355. if (!data.videoId) {
  356. toast("videoId 丢失!");
  357. return false
  358. }
  359. uni.redirectTo({
  360. url: '/pages/study/lookShipinNew?youkePageData=' + JSON.stringify(youkeData)
  361. })
  362. } else {
  363. if (!data.videoId) {
  364. toast("videoId 丢失!");
  365. return false
  366. }
  367. uni.redirectTo({
  368. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  369. })
  370. }
  371. } else {
  372. if (typeId.value == 1) {
  373. // 1新 2旧
  374. if (!data.videoId) {
  375. toast("videoId 丢失!");
  376. return false
  377. }
  378. uni.redirectTo({
  379. url: '/pages/study/lookShipinNew?jieId=' + data.jieId
  380. })
  381. } else {
  382. if (!data.videoId) {
  383. toast("videoId 丢失!");
  384. return false
  385. }
  386. uni.redirectTo({
  387. url: '/pages/study/lookShipin?jieId=' + data.jieId
  388. })
  389. }
  390. }
  391. }
  392. function translateData(data) {
  393. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  394. gradeTerm.value = data.levelName
  395. }
  396. function listClick(data, data2, index) {
  397. console.log('data', data); // 节内容
  398. console.log('data2', data2); //章内容
  399. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  400. youkeDialogRef.value.handleShow();
  401. return;
  402. }
  403. const authCode = getUserIdentity();
  404. console.log('authCode', authCode);
  405. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  406. // debugger
  407. goPayDialogRef.value.handleShow();
  408. return false
  409. }
  410. if (data.type == 2) {
  411. // 最后一项
  412. goKaoshi(data, index)
  413. } else {
  414. goLookShipin(data, index)
  415. }
  416. }
  417. function handleCheckCatalogue(item) {
  418. catalogueRef.value.showPopup(item);
  419. }
  420. function clickGradeTerm() {
  421. // if(cacheManager.get('auth')){
  422. // cacheManager.updateObject('auth', {
  423. // currentZhang: 0
  424. // })
  425. // }
  426. uni.navigateTo({
  427. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}&from=daoPage&productId=${levelId.value}&xuekeId=${subjectId.value}`
  428. })
  429. }
  430. // 游客弹窗---确定
  431. function ykConfirm() {
  432. uni.redirectTo({
  433. url: '/pages/login/index'
  434. });
  435. }
  436. function eggBtn() {
  437. console.log('点击:开启提分之旅');
  438. getProjectImg();
  439. cacheManager.updateObject('auth', {
  440. firstLogin: false
  441. })
  442. }
  443. </script>
  444. <style>
  445. </style>