index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. })
  273. }
  274. function getCommonZhang(data) {
  275. let req = {
  276. levelId: data.levelId,
  277. }
  278. getCommonZhangInfo(req).then(res => {
  279. translateData(res.data)
  280. youkeImage.value = res.data.icon
  281. zhangList.value = res.data.zhangList
  282. current.value = 0
  283. })
  284. }
  285. function recordZhangJie() {
  286. let req = {
  287. levelId: localAuth.value.levelId,
  288. userId: localAuth.value.userId,
  289. zhangId: infoData.zhangId,
  290. subjectId: currentProduct.value
  291. }
  292. userLocate(req).then(res => {
  293. })
  294. }
  295. function goPayPage() {
  296. let zhangInfoLocal = cacheManager.get('zhangInfo')
  297. if (!zhangInfoLocal.cardId) {
  298. toast("cardId 丢失请重新选择学科LevelId");
  299. return false
  300. }
  301. uni.redirectTo({
  302. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  303. zhangInfoLocal.subjectId
  304. })
  305. }
  306. function handleChangeZhang(data) {
  307. console.log(data);
  308. const authCode = getUserIdentity();
  309. if (authCode !== 'Visitor') {
  310. cacheManager.updateObject('auth', {
  311. zhangId: data.zhangId,
  312. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  313. })
  314. }
  315. currentDuration.value = 0
  316. setTimeout(() => {
  317. current.value = data.number - 1
  318. nextTick(() => {
  319. currentDuration.value = 500
  320. })
  321. }, 100)
  322. // init()
  323. }
  324. function goKaoshi(data) {
  325. uni.redirectTo({
  326. // url: `/pages/unitTest/index?jieNumber=` + data.number
  327. url: `/pages/unitTest/index?jieId=` + data.jieId
  328. })
  329. }
  330. function goLookShipin(data, index) {
  331. if (!cacheManager.get('auth')) {
  332. console.log('zhangList.value[0].jieList', zhangList.value[0].jieList);
  333. console.log('zhangList.value[0].jieList.index', zhangList.value[0].jieList[index]);
  334. let youkeData = {
  335. levelId: levelId.value,
  336. typeId: typeId.value,
  337. subjectId: subjectId.value,
  338. tipFlag: tipFlag.value,
  339. jieList: zhangList.value[0].jieList[index],
  340. jieName: zhangList.value[0].jieList[index].jieName
  341. }
  342. if (youkeData.typeId == 1) {
  343. if (!data.videoId) {
  344. toast("videoId 丢失!");
  345. return false
  346. }
  347. uni.redirectTo({
  348. url: '/pages/study/lookShipinNew?youkePageData=' + JSON.stringify(youkeData)
  349. })
  350. } else {
  351. if (!data.videoId) {
  352. toast("videoId 丢失!");
  353. return false
  354. }
  355. uni.redirectTo({
  356. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  357. })
  358. }
  359. } else {
  360. if (typeId.value == 1) {
  361. // 1新 2旧
  362. if (!data.videoId) {
  363. toast("videoId 丢失!");
  364. return false
  365. }
  366. uni.redirectTo({
  367. url: '/pages/study/lookShipinNew?jieId=' + data.jieId
  368. })
  369. } else {
  370. if (!data.videoId) {
  371. toast("videoId 丢失!");
  372. return false
  373. }
  374. uni.redirectTo({
  375. url: '/pages/study/lookShipin?jieId=' + data.jieId
  376. })
  377. }
  378. }
  379. }
  380. function translateData(data) {
  381. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  382. gradeTerm.value = data.levelName
  383. }
  384. function listClick(data, data2, index) {
  385. console.log('data', data); // 节内容
  386. console.log('data2', data2); //章内容
  387. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  388. youkeDialogRef.value.handleShow();
  389. return;
  390. }
  391. const authCode = getUserIdentity();
  392. console.log('authCode', authCode);
  393. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  394. // debugger
  395. goPayDialogRef.value.handleShow();
  396. return false
  397. }
  398. if (data.type == 2) {
  399. // 最后一项
  400. goKaoshi(data, index)
  401. } else {
  402. goLookShipin(data, index)
  403. }
  404. }
  405. function handleCheckCatalogue(item) {
  406. catalogueRef.value.showPopup(item);
  407. }
  408. function clickGradeTerm() {
  409. // if(cacheManager.get('auth')){
  410. // cacheManager.updateObject('auth', {
  411. // currentZhang: 0
  412. // })
  413. // }
  414. uni.navigateTo({
  415. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}&from=daoPage&productId=${levelId.value}&xuekeId=${subjectId.value}`
  416. })
  417. }
  418. // 游客弹窗---确定
  419. function ykConfirm() {
  420. uni.redirectTo({
  421. url: '/pages/login/index'
  422. });
  423. }
  424. function eggBtn() {
  425. console.log('点击:开启提分之旅');
  426. getProjectImg();
  427. cacheManager.updateObject('auth', {
  428. firstLogin: false
  429. })
  430. }
  431. </script>
  432. <style>
  433. </style>