index.vue 4.7 KB

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