index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="ezy-xuexi-page">
  3. <view class="icon-title-navBar-box">
  4. <text class="nav-bar-title">学习</text>
  5. </view>
  6. <chanpin1 v-if="chanpinId==1" ref="chanpin1Ref"></chanpin1>
  7. <chanpin2 v-if="chanpinId==2" ref="chanpin2Ref"></chanpin2>
  8. <tipMiddleDialog ref="tipDialogRef" :closeFlag='false' :title="tipTitle" @confirm-btn="BanbenConfirmBtn"
  9. :notClose="true" :content="tipContent"></tipMiddleDialog>
  10. <tipMiddleDialog ref="tipDialogRef2" :closeFlag='false' :title="tipTitle" @confirm-btn="BanbenConfirmBtn"
  11. :showTip="true" :notClose="true" :content="tipContentAndroid">
  12. </tipMiddleDialog>
  13. <!-- 底部 tabBar -->
  14. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  15. </view>
  16. </template>
  17. <script>
  18. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  19. import cacheManager from "@/utils/cacheManager.js";
  20. import {
  21. onLoad,
  22. onShow,
  23. onHide,
  24. onUnload
  25. } from "@dcloudio/uni-app"
  26. import {
  27. toast
  28. } from '../../utils/common';
  29. import chanpin1 from './chanpin1'
  30. import chanpin2 from './chanpin2'
  31. import {
  32. banbenImpinfo
  33. } from "@/api/login.js"
  34. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  35. import {
  36. useVersionUpdate
  37. } from "@/utils/versionUpdate.js";
  38. import {
  39. getVersion
  40. } from "../../api/login";
  41. import config from '../../config.js'
  42. export default {
  43. setup() {
  44. const {
  45. initDownload
  46. } = useVersionUpdate()
  47. return {
  48. initDownload
  49. }
  50. },
  51. data() {
  52. return {
  53. currentTabIndex: 1,
  54. banbenId: '',
  55. chanpinId: '',
  56. tipTitle: '升级提醒',
  57. tipContentAndroid: '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!',
  58. tipContent: '您的APP不是最新版本,部分功能不能使用,请升级至最新版本!',
  59. updateUrl: '',
  60. version: config.appInfo.version
  61. }
  62. },
  63. components: {
  64. CustomTabBar,
  65. chanpin1,
  66. chanpin2,
  67. tipMiddleDialog
  68. },
  69. onLoad(options) {
  70. this.getLoginInit()
  71. uni.hideTabBar()
  72. },
  73. onShow() {
  74. this.currentTabIndex = 1
  75. const cacheData = cacheManager.get('contentInfo');
  76. if (cacheData) {
  77. console.log('使用缓存数据');
  78. this.chanpinId = cacheData.chanpinId
  79. this.switchUseCache(cacheData)
  80. } else {
  81. console.log('重新请求数据,请求版本内容详情接口');
  82. this.getBanbenInfo();
  83. }
  84. },
  85. onHide() {
  86. console.log('学习页面隐藏')
  87. },
  88. onUnload() {
  89. // 页面卸载无需特殊处理
  90. },
  91. methods: {
  92. getLoginInit() {
  93. const systemInfo = uni.getSystemInfoSync();
  94. getVersion({}).then(res => {
  95. if (this.version != res.data.version) {
  96. this.updateUrl = res.data.updateUrl
  97. if (systemInfo.platform == 'ios') {
  98. this.$refs.tipDialogRef.handleShow();
  99. } else {
  100. this.$refs.tipDialogRef2.handleShow();
  101. }
  102. }
  103. })
  104. },
  105. BanbenConfirmBtn() {
  106. const systemInfo = uni.getSystemInfoSync();
  107. if (systemInfo.platform == 'ios') {
  108. const appStoreUrl = 'itms-apps://itunes.apple.com/app/6741551741'
  109. plus.runtime.openURL(appStoreUrl)
  110. } else {
  111. this.initDownload(this.updateUrl)
  112. }
  113. },
  114. switchUseCache(data) {
  115. switch (Number(data.chanpinId)) {
  116. case 1:
  117. this.$nextTick(() => {
  118. this.$refs.chanpin1Ref.initData()
  119. })
  120. break;
  121. case 2:
  122. this.$nextTick(() => {
  123. this.$refs.chanpin2Ref.initData()
  124. })
  125. break;
  126. default:
  127. }
  128. },
  129. switchGetNeiRongInfo(data) {
  130. switch (Number(data.chanpinId)) {
  131. case 1:
  132. const banbenId = data.banbenId
  133. this.$nextTick(() => {
  134. this.$refs.chanpin1Ref.initData(banbenId)
  135. })
  136. break;
  137. case 2:
  138. const dengjiId = data.dengjiId
  139. this.$nextTick(() => {
  140. this.$refs.chanpin2Ref.initData(dengjiId)
  141. })
  142. break;
  143. default:
  144. }
  145. },
  146. getBanbenInfo() {
  147. banbenImpinfo({}).then(res => {
  148. if (res.code == 0) {
  149. console.log('res', res)
  150. if (res.data.chanpinId == 0) {
  151. toast('请先进行选课!')
  152. uni.switchTab({
  153. url: '/pages/chanpinXuanze/index'
  154. })
  155. return;
  156. }
  157. this.chanpinId = res.data.chanpinId
  158. this.switchGetNeiRongInfo(res.data)
  159. } else {
  160. toast('请求版本内容详情接口数据异常')
  161. return
  162. }
  163. }).catch(() => {
  164. return false
  165. })
  166. },
  167. },
  168. computed: {}
  169. }
  170. </script>