index.vue 4.0 KB

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