index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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">
  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 currentProduct = ref(null);
  97. const localAuth = ref(null);
  98. const levelId = ref(null); //游客使用
  99. const subjectId = ref(null); //游客使用
  100. const typeId = ref(null);
  101. const zhangList = ref(null);
  102. const gradeTerm = ref(null);
  103. let infoData = reactive({
  104. jieList: [],
  105. haveFlag: '',
  106. number: '',
  107. zhangId: '',
  108. zhangName: '',
  109. numberStr: '',
  110. });
  111. const termMapping = {
  112. 1: ' 数学',
  113. 2: ' 英语'
  114. };
  115. const daoTipDialogRef = ref(null);
  116. const showDaoTip = ref(true);
  117. const productTipImg = ref('');
  118. const version = config.appInfo.version;
  119. const tipDialogRef = ref(null);
  120. const tipTitle = '升级提醒';
  121. const tipContentVersion = '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!';
  122. onLoad((options) => {
  123. init(options);
  124. getLoginInit()
  125. })
  126. function listSelectJieClick(item, data, index) {
  127. if (cacheManager.get('auth')) {
  128. cacheManager.updateObject('auth', {
  129. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == item.zhangId),
  130. zhangId: item.zhangId
  131. })
  132. }
  133. listClick(data, item, index);
  134. }
  135. function getLoginInit() {
  136. getVersion({}).then(res => {
  137. if (version != res.data.version) {
  138. tipDialogRef.value.handleShow();
  139. }
  140. })
  141. }
  142. function getProjectImg() {
  143. if (currentProduct.value == 1 && typeId.value == 2) {
  144. // 数学
  145. productTipImg.value = 'static/images/study/shuxue/shuxue-tip.gif';
  146. getBj('shuxue')
  147. } else if (currentProduct.value == 2 && typeId.value == 2) {
  148. // 英语
  149. productTipImg.value = 'static/images/study/yingyu/yingyu-tip.gif'
  150. getBj('yingyu');
  151. } else if (currentProduct.value == 1 && typeId.value == 1) {
  152. // 计算特训
  153. productTipImg.value = 'static/images/study/jstx/jstx-tip.gif'
  154. getBj('shuxueNew');
  155. }
  156. }
  157. function getBj(data) {
  158. let bjType = cacheManager.get('dao-tip')[data];
  159. if (cacheManager.get('auth')) {
  160. // 非游客
  161. if (bjType !== 'has') {
  162. nextTick(() => {
  163. daoTipDialogRef.value.handleShow();
  164. })
  165. }
  166. } else {
  167. // 游客
  168. if (tipFlag.value === '0') {
  169. nextTick(() => {
  170. daoTipDialogRef.value.handleShow();
  171. })
  172. }
  173. }
  174. }
  175. function daoTipClose() {
  176. if (cacheManager.get('auth')) {
  177. // 非游客 记缓存
  178. if (currentProduct.value == 1 && typeId.value == 2) {
  179. // 数学
  180. cacheManager.updateObject('dao-tip', {
  181. shuxue: 'has'
  182. })
  183. } else if (currentProduct.value == 2 && typeId.value == 2) {
  184. // 英语
  185. cacheManager.updateObject('dao-tip', {
  186. yingyu: 'has'
  187. })
  188. } else if (currentProduct.value == 1 && typeId.value == 1) {
  189. // 英语
  190. cacheManager.updateObject('dao-tip', {
  191. shuxueNew: 'has'
  192. })
  193. }
  194. } else {
  195. //游客
  196. tipFlag.value = '1';
  197. }
  198. }
  199. function onChangeTab(e) {
  200. console.log('e', e);
  201. console.log(e.detail.current);
  202. if (cacheManager.get('auth')) {
  203. // 新的英语人教版
  204. if (currentProduct.value == 2 && typeId.value == 1) {
  205. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[0].zhangId
  206. cacheManager.updateObject('auth', {
  207. currentZhang: e.detail.current,
  208. zhangId: infoData.zhangId
  209. })
  210. } else {
  211. // 旧的数学 英语 新的数学
  212. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[e.detail.current].zhangId
  213. cacheManager.updateObject('auth', {
  214. currentZhang: e.detail.current,
  215. zhangId: infoData.zhangId
  216. })
  217. }
  218. }
  219. }
  220. function init(options) {
  221. if (cacheManager.get('auth')) {
  222. localAuth.value = cacheManager.get('auth');
  223. currentProduct.value = localAuth.value.subjectId;
  224. typeId.value = localAuth.value.typeId;
  225. console.log(localAuth.value);
  226. // 已登录
  227. if (localAuth.value.firstLogin) {
  228. nextTick(() => {
  229. eggDialogRef.value.eggShow();
  230. })
  231. }
  232. if (!cacheManager.get('daoPageCache').isCache) {
  233. console.log('不实用换葱');
  234. chooseMethodNoCache()
  235. } else {
  236. console.log('shiyonghuancun');
  237. chooseMethodUseCache()
  238. }
  239. // 已登录付费未支付选择返回 -> 恢复弹窗
  240. if (options.studyWithCatalgue) {
  241. // 展开弹窗
  242. nextTick(() => {
  243. catalogueRef.value.showPopup({
  244. zhangId: infoData.zhangId
  245. });
  246. })
  247. }
  248. } else {
  249. subjectId.value = options.subjectId
  250. typeId.value = options.typeId
  251. levelId.value = options.levelId
  252. tipFlag.value = options.tipFlag;
  253. currentProduct.value = options.subjectId
  254. // 未登录 游客
  255. getCommonZhang(options)
  256. getProjectImg()
  257. }
  258. }
  259. function chooseMethodNoCache() {
  260. // 新的英语 (人教版 之类的 新结构)
  261. if (currentProduct.value == 2 && typeId.value == 1) {
  262. getZhangInfoNewYingyu()
  263. } else {
  264. // 之前 旧的岛 数学英语 和新的数学
  265. getZhangInfoNewYingyu()
  266. // getZhangInfo()
  267. }
  268. }
  269. function chooseMethodUseCache() {
  270. // 新的英语 (人教版 之类的 新结构)
  271. if (currentProduct.value == 2 && typeId.value == 1) {
  272. translateData(cacheManager.get('zhangInfo'))
  273. zhangList.value = cacheManager.get('zhangInfo').zhangList[0].zList
  274. current.value = cacheManager.get('auth').currentZhang
  275. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[0].zhangId
  276. recordZhangJie()
  277. } else {
  278. // 之前 旧的岛 数学英语 和新的数学
  279. translateData(cacheManager.get('zhangInfo'))
  280. zhangList.value = cacheManager.get('zhangInfo').zhangList
  281. current.value = cacheManager.get('auth').currentZhang
  282. infoData.zhangId = cacheManager.get('zhangInfo').zhangList[current.value].zhangId
  283. recordZhangJie()
  284. }
  285. }
  286. // 新的英语 (人教版 之类的 新结构)
  287. function getZhangInfoNewYingyu(data) {
  288. let req = {
  289. levelId: localAuth.value.levelId,
  290. // levelId: 31,
  291. zhangId: localAuth.value.zhangId
  292. // zhangId: 195
  293. }
  294. userZhangInfo(req).then(res => {
  295. cacheManager.set('zhangInfo', res.data)
  296. let zhang = cacheManager.get('zhangInfo').zhangList[0].zList.findIndex(zhang => zhang.zid == localAuth
  297. .value.zhangId);
  298. console.log('zhang', zhang);
  299. if (zhang != -1) {
  300. cacheManager.updateObject('auth', {
  301. currentZhang: zhang
  302. })
  303. } else {
  304. cacheManager.updateObject('auth', {
  305. currentZhang: 0
  306. })
  307. }
  308. cacheManager.set('daoPageCache', {
  309. isCache: true
  310. })
  311. nextTick(() => {
  312. translateData(res.data)
  313. zhangList.value = res.data.zhangList[0].zList
  314. current.value = cacheManager.get('auth').currentZhang
  315. infoData.zhangId = res.data.zhangList[0].zhangId
  316. recordZhangJie()
  317. })
  318. }).catch((err) => {
  319. toast('数据异常,请重新登录!')
  320. cacheManager.clearAll();
  321. uni.reLaunch({
  322. url: '/pages/login/index'
  323. });
  324. })
  325. }
  326. //旧的岛 数学英语 和新的数学
  327. function getZhangInfo(data) {
  328. let req = {
  329. levelId: localAuth.value.levelId
  330. }
  331. userZhangInfo(req).then(res => {
  332. cacheManager.set('zhangInfo', res.data)
  333. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
  334. .value.zhangId);
  335. console.log('zhang', zhang);
  336. if (zhang != -1) {
  337. cacheManager.updateObject('auth', {
  338. currentZhang: zhang
  339. })
  340. } else {
  341. cacheManager.updateObject('auth', {
  342. currentZhang: 0
  343. })
  344. }
  345. cacheManager.set('daoPageCache', {
  346. isCache: true
  347. })
  348. nextTick(() => {
  349. translateData(res.data)
  350. zhangList.value = res.data.zhangList
  351. current.value = cacheManager.get('auth').currentZhang
  352. infoData.zhangId = res.data.zhangList[current.value].zhangId
  353. recordZhangJie()
  354. })
  355. }).catch((err) => {
  356. toast('数据异常,请重新登录!')
  357. cacheManager.clearAll();
  358. uni.reLaunch({
  359. url: '/pages/login/index'
  360. });
  361. })
  362. }
  363. function getCommonZhang(data) {
  364. let req = {
  365. levelId: data.levelId,
  366. }
  367. getCommonZhangInfo(req).then(res => {
  368. translateData(res.data)
  369. youkeImage.value = res.data.icon
  370. zhangList.value = res.data.zhangList
  371. current.value = 0
  372. }).catch((err) => {
  373. toast('数据异常,请重新登录!')
  374. cacheManager.clearAll();
  375. uni.reLaunch({
  376. url: '/pages/login/index'
  377. });
  378. })
  379. }
  380. function recordZhangJie() {
  381. let req = {
  382. levelId: localAuth.value.levelId,
  383. userId: localAuth.value.userId,
  384. zhangId: infoData.zhangId,
  385. subjectId: currentProduct.value
  386. }
  387. userLocate(req).then(res => {
  388. })
  389. }
  390. function goPayPage() {
  391. let zhangInfoLocal = cacheManager.get('zhangInfo')
  392. if (!zhangInfoLocal.cardId) {
  393. toast("cardId 丢失请重新选择学科LevelId");
  394. return false
  395. }
  396. uni.redirectTo({
  397. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  398. zhangInfoLocal.subjectId
  399. })
  400. }
  401. function handleChangeZhang(data) {
  402. console.log(data);
  403. const authCode = getUserIdentity();
  404. if (authCode !== 'Visitor') {
  405. cacheManager.updateObject('auth', {
  406. zhangId: data.zhangId,
  407. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  408. })
  409. }
  410. currentDuration.value = 0
  411. setTimeout(() => {
  412. current.value = data.number - 1
  413. nextTick(() => {
  414. currentDuration.value = 500
  415. })
  416. }, 100)
  417. // init()
  418. }
  419. function goKaoshi(data) {
  420. uni.redirectTo({
  421. // url: `/pages/unitTest/index?jieNumber=` + data.number
  422. url: `/pages/unitTest/index?jieId=` + data.jieId
  423. })
  424. }
  425. function goDanciList(data, index) {
  426. if (!cacheManager.get('auth')) {
  427. let youkeData = {
  428. }
  429. uni.redirectTo({
  430. url: '/pages/study/lookShipinNew?youkePageData=' + JSON.stringify(youkeData)
  431. })
  432. } else {
  433. uni.redirectTo({
  434. url: '/pages/wordList/wordList?jieId=' + data.jieId
  435. })
  436. }
  437. }
  438. function goLookShipin(data, index) {
  439. if (!cacheManager.get('auth')) {
  440. console.log('zhangList.value[0].jieList', zhangList.value[0].jieList);
  441. console.log('zhangList.value[0].jieList.index', zhangList.value[0].jieList[index]);
  442. let youkeData = {
  443. levelId: levelId.value,
  444. typeId: typeId.value,
  445. subjectId: subjectId.value,
  446. tipFlag: tipFlag.value,
  447. jieList: zhangList.value[0].jieList[index],
  448. jieName: zhangList.value[0].jieList[index].jieName
  449. }
  450. if (youkeData.typeId == 1) {
  451. if (!data.videoId) {
  452. toast("videoId 丢失!");
  453. return false
  454. }
  455. uni.redirectTo({
  456. url: '/pages/study/lookShipinNew?youkePageData=' + JSON.stringify(youkeData)
  457. })
  458. } else {
  459. if (!data.videoId) {
  460. toast("videoId 丢失!");
  461. return false
  462. }
  463. uni.redirectTo({
  464. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  465. })
  466. }
  467. } else {
  468. if (typeId.value == 1) {
  469. // 1新 2旧
  470. if (!data.videoId) {
  471. toast("videoId 丢失!");
  472. return false
  473. }
  474. uni.redirectTo({
  475. url: '/pages/study/lookShipinNew?jieId=' + data.jieId
  476. })
  477. } else {
  478. if (!data.videoId) {
  479. toast("videoId 丢失!");
  480. return false
  481. }
  482. uni.redirectTo({
  483. url: '/pages/study/lookShipin?jieId=' + data.jieId
  484. })
  485. }
  486. }
  487. }
  488. function translateData(data) {
  489. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  490. gradeTerm.value = data.levelName
  491. }
  492. function listClick(data, data2, index) {
  493. console.log('data', data); // 节内容
  494. console.log('data2', data2); //章内容
  495. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  496. youkeDialogRef.value.handleShow();
  497. return;
  498. }
  499. const authCode = getUserIdentity();
  500. console.log('authCode', authCode);
  501. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  502. // debugger
  503. goPayDialogRef.value.handleShow();
  504. return false
  505. }
  506. if (data.type == 2) {
  507. // 最后一项
  508. goKaoshi(data, index)
  509. } else {
  510. if (currentProduct.value == 2 && typeId.value == 1) {
  511. goDanciList(data, index)
  512. } else {
  513. goLookShipin(data, index)
  514. }
  515. }
  516. }
  517. function handleCheckCatalogue(item) {
  518. catalogueRef.value.showPopup(item);
  519. }
  520. function clickGradeTerm() {
  521. // if(cacheManager.get('auth')){
  522. // cacheManager.updateObject('auth', {
  523. // currentZhang: 0
  524. // })
  525. // }
  526. uni.navigateTo({
  527. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}&from=daoPage&productId=${levelId.value}&xuekeId=${subjectId.value}`
  528. })
  529. }
  530. // 游客弹窗---确定
  531. function ykConfirm() {
  532. uni.redirectTo({
  533. url: '/pages/login/index'
  534. });
  535. }
  536. function eggBtn() {
  537. console.log('点击:开启提分之旅');
  538. getProjectImg();
  539. cacheManager.updateObject('auth', {
  540. firstLogin: false
  541. })
  542. }
  543. </script>
  544. <style>
  545. </style>