index.vue 14 KB

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