index.vue 18 KB

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