index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div class="home g-flex">
  3. <keep-alive>
  4. <component class="g-flex__body" :is="components[componentId]"></component>
  5. </keep-alive>
  6. <app-tabbar class="home-tabbar" :data-list="tabList" @change="onChange" fixed />
  7. </div>
  8. </template>
  9. <script lang="ts" setup>
  10. import { ref } from 'vue'
  11. import { dialog } from '@/utils/vant'
  12. import { Tabbar } from '@mobile/components/base/tabbar/interface'
  13. import { GetAppUpdateInfo } from '@/services/api/common'
  14. import plus from '@/utils/h5plus'
  15. import AppTabbar from '@mobile/components/base/tabbar/index.vue'
  16. import Home from './components/main/index.vue'
  17. import Purchase from './components/purchase/index.vue'
  18. import SupplyDemand from './components/supply-demand/index.vue'
  19. import Market from './components/market/index.vue'
  20. import Mine from './components/mine/index.vue'
  21. import axios from 'axios'
  22. const components = {
  23. home: Home,
  24. purchase: Purchase,
  25. supplyDemand: SupplyDemand,
  26. market: Market,
  27. mine: Mine
  28. }
  29. const componentId = ref('home')
  30. const tabList: Tabbar[] = [
  31. {
  32. name: 'home',
  33. label: '首页',
  34. icon: 'icon-shouye-1',
  35. activeIcon: 'icon-shouye'
  36. },
  37. {
  38. name: 'purchase',
  39. label: '采购',
  40. icon: 'icon-caigou-1',
  41. activeIcon: 'icon-caigou'
  42. },
  43. {
  44. name: 'supplyDemand',
  45. label: '供求',
  46. icon: 'icon-gongqiu-1',
  47. activeIcon: 'icon-gongqiu'
  48. },
  49. {
  50. name: 'mine',
  51. label: '我的',
  52. icon: 'icon-wode-1',
  53. activeIcon: 'icon-wode'
  54. }
  55. ]
  56. const onChange = (index: number) => {
  57. if (![2].includes(index)) {
  58. componentId.value = tabList[index].name
  59. }
  60. }
  61. plus.onPlusReady(() => {
  62. // 获取应用配置信息
  63. axios('./config/appconfig.json').then((res) => {
  64. const config = res.data
  65. // 获取应用更新信息
  66. GetAppUpdateInfo({
  67. success: (res) => {
  68. const data = JSON.parse(res)
  69. if (data) {
  70. const { LastVersionCode, ApkUrl } = data[0] as Model.AppUpdateInfo
  71. if (Number(LastVersionCode) > Number(config.versionCode)) {
  72. dialog('发现新版本,是否更新?', {
  73. showCancelButton: true,
  74. confirmButtonText: '更新'
  75. }).then(() => {
  76. plus.updateApp(ApkUrl)
  77. })
  78. }
  79. }
  80. }
  81. })
  82. })
  83. })
  84. </script>
  85. <style lang="less">
  86. @import './index.less';
  87. </style>