index.vue 5.1 KB

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