index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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('zhangInfo')) {
  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 findZhangindex(data) {
  245. console.log('data', data);
  246. for (let zhangIndex = 0; zhangIndex < data.zhangList.length; zhangIndex++) {
  247. const zhang = data.zhangList[zhangIndex];
  248. for (let jieIndex = 0; jieIndex < zhang.jieList.length; jieIndex++) {
  249. if (zhang.jieList[jieIndex].studyFlag == 0) {
  250. return zhangIndex; // 返回所在zhang的索引
  251. }
  252. }
  253. }
  254. return -1; // 如果没有找到
  255. }
  256. function getZhangInfo(data) {
  257. let req = {
  258. levelId: localAuth.value.levelId
  259. }
  260. userZhangInfo(req).then(res => {
  261. cacheManager.set('zhangInfo', res.data)
  262. let zhang = cacheManager.get('zhangInfo').zhangList.findIndex(zhang => zhang.zhangId == localAuth
  263. .value.zhangId);
  264. console.log('zhang', zhang);
  265. if (zhang != -1) {
  266. cacheManager.updateObject('auth', {
  267. currentZhang: zhang
  268. })
  269. } else {
  270. const zhangIndex = findZhangindex(cacheManager.get('zhangInfo'))
  271. console.log(zhangIndex);
  272. cacheManager.updateObject('auth', {
  273. currentZhang: zhangIndex
  274. })
  275. }
  276. nextTick(() => {
  277. translateData(res.data)
  278. zhangList.value = res.data.zhangList
  279. current.value = cacheManager.get('auth').currentZhang
  280. infoData.zhangId = res.data.zhangList[current.value].zhangId
  281. recordZhangJie()
  282. })
  283. }).catch((err) => {
  284. toast('数据异常,请重新登录!')
  285. // cacheManager.clearAll();
  286. // uni.reLaunch({
  287. // url: '/pages/login/index'
  288. // });
  289. })
  290. }
  291. function getCommonZhang(data) {
  292. let req = {
  293. levelId: data.levelId,
  294. }
  295. getCommonZhangInfo(req).then(res => {
  296. translateData(res.data)
  297. youkeImage.value = res.data.icon
  298. zhangList.value = res.data.zhangList
  299. current.value = 0
  300. }).catch((err) => {
  301. toast('数据异常,请重新登录!')
  302. cacheManager.clearAll();
  303. uni.reLaunch({
  304. url: '/pages/login/index'
  305. });
  306. })
  307. }
  308. function recordZhangJie() {
  309. let req = {
  310. levelId: localAuth.value.levelId,
  311. userId: localAuth.value.userId,
  312. zhangId: infoData.zhangId,
  313. subjectId: currentProduct.value
  314. }
  315. userLocate(req).then(res => {
  316. })
  317. }
  318. function goPayPage() {
  319. let zhangInfoLocal = cacheManager.get('zhangInfo')
  320. if (!zhangInfoLocal.cardId) {
  321. toast("cardId 丢失请重新选择学科LevelId");
  322. return false
  323. }
  324. uni.redirectTo({
  325. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  326. zhangInfoLocal.subjectId
  327. })
  328. }
  329. function handleChangeZhang(data) {
  330. console.log(data);
  331. const authCode = getUserIdentity();
  332. if (authCode !== 'Visitor') {
  333. cacheManager.updateObject('auth', {
  334. zhangId: data.zhangId,
  335. currentZhang: zhangList.value.findIndex(citem => citem.zhangId == data.zhangId),
  336. })
  337. }
  338. currentDuration.value = 0
  339. setTimeout(() => {
  340. current.value = data.number - 1
  341. nextTick(() => {
  342. currentDuration.value = 500
  343. })
  344. }, 100)
  345. // init()
  346. }
  347. function goKaoshi(data) {
  348. uni.redirectTo({
  349. // url: `/pages/unitTest/index?jieNumber=` + data.number
  350. url: `/pages/unitTest/index?jieId=` + data.jieId
  351. })
  352. }
  353. function goLookShipin(data, index) {
  354. if (!cacheManager.get('auth')) {
  355. console.log('zhangList.value[0].jieList', zhangList.value[0].jieList);
  356. console.log('zhangList.value[0].jieList.index', zhangList.value[0].jieList[index]);
  357. let youkeData = {
  358. levelId: levelId.value,
  359. typeId: typeId.value,
  360. subjectId: subjectId.value,
  361. tipFlag: tipFlag.value,
  362. jieList: zhangList.value[0].jieList[index],
  363. jieName: zhangList.value[0].jieList[index].jieName
  364. }
  365. if (youkeData.typeId == 1) {
  366. if (!data.videoId) {
  367. toast("videoId 丢失!");
  368. return false
  369. }
  370. uni.redirectTo({
  371. url: '/pages/study/lookShipinNew?youkePageData=' + JSON.stringify(youkeData)
  372. })
  373. } else {
  374. if (!data.videoId) {
  375. toast("videoId 丢失!");
  376. return false
  377. }
  378. uni.redirectTo({
  379. url: '/pages/study/lookShipin?youkePageData=' + JSON.stringify(youkeData)
  380. })
  381. }
  382. } else {
  383. if (typeId.value == 1) {
  384. // 1新 2旧
  385. if (!data.videoId) {
  386. toast("videoId 丢失!");
  387. return false
  388. }
  389. uni.redirectTo({
  390. url: '/pages/study/lookShipinNew?jieId=' + data.jieId
  391. })
  392. } else {
  393. if (!data.videoId) {
  394. toast("videoId 丢失!");
  395. return false
  396. }
  397. uni.redirectTo({
  398. url: '/pages/study/lookShipin?jieId=' + data.jieId
  399. })
  400. }
  401. }
  402. }
  403. function translateData(data) {
  404. // gradeTerm.value = termMapping[data.subjectId] +' · '+ data.levelName
  405. gradeTerm.value = data.levelName
  406. }
  407. function listClick(data, data2, index) {
  408. console.log('data', data); // 节内容
  409. console.log('data2', data2); //章内容
  410. if (!cacheManager.get('auth') && data.firstFlag != 1) {
  411. youkeDialogRef.value.handleShow();
  412. return;
  413. }
  414. const authCode = getUserIdentity();
  415. console.log('authCode', authCode);
  416. if (!(authCode == 'VIP' || data.firstFlag == 1)) {
  417. // debugger
  418. goPayDialogRef.value.handleShow();
  419. return false
  420. }
  421. if (data.type == 2) {
  422. // 最后一项
  423. goKaoshi(data, index)
  424. } else {
  425. goLookShipin(data, index)
  426. }
  427. }
  428. function handleCheckCatalogue(item) {
  429. catalogueRef.value.showPopup(item);
  430. }
  431. function clickGradeTerm() {
  432. // if(cacheManager.get('auth')){
  433. // cacheManager.updateObject('auth', {
  434. // currentZhang: 0
  435. // })
  436. // }
  437. uni.navigateTo({
  438. url: `/pages/selectGradesTerms/index?tipFlag=${tipFlag.value}&from=daoPage&productId=${levelId.value}&xuekeId=${subjectId.value}`
  439. })
  440. }
  441. // 游客弹窗---确定
  442. function ykConfirm() {
  443. uni.redirectTo({
  444. url: '/pages/login/index'
  445. });
  446. }
  447. function eggBtn() {
  448. console.log('点击:开启提分之旅');
  449. getProjectImg();
  450. cacheManager.updateObject('auth', {
  451. firstLogin: false
  452. })
  453. }
  454. </script>
  455. <style>
  456. </style>