index.vue 16 KB

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