home.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="container">
  3. <view class="pages">
  4. <Home ref="homeRef" v-if="current==0" />
  5. <Equipment ref="equipmentRef" v-if="current==1" />
  6. <Commodity ref="commodityRef" v-if="current==2" />
  7. <Account ref="accountRef" v-if="current==3" />
  8. </view>
  9. <u-tabbar v-if="menu&&menu.length>0" v-model="current" :list="list" :mid-button="false"></u-tabbar>
  10. </view>
  11. </template>
  12. <script setup>
  13. import Home from './components/home.vue'
  14. import Equipment from './components/equipment.vue'
  15. import Commodity from './components/commodity.vue'
  16. import Account from './components/account.vue'
  17. import {
  18. watch,
  19. computed,
  20. onBeforeMount,
  21. onMounted,
  22. reactive,
  23. toRefs,
  24. ref
  25. } from "vue";
  26. import {
  27. onShow,
  28. onLoad
  29. } from '@dcloudio/uni-app'
  30. import usePermissionStore from '@/stores/permission.js'
  31. const current = ref(0)
  32. const client = ref(null)
  33. const tabName = ref(null)
  34. const list = ref([{
  35. iconPath: "home",
  36. selectedIconPath: "home-fill",
  37. text: '平台运维',
  38. },
  39. {
  40. iconPath: "photo",
  41. selectedIconPath: "photo-fill",
  42. text: '质检出场',
  43. },
  44. {
  45. iconPath: "play-right",
  46. selectedIconPath: "play-right-fill",
  47. text: '数据中心',
  48. },
  49. {
  50. iconPath: "account",
  51. selectedIconPath: "account-fill",
  52. text: '商户运营',
  53. },
  54. ])
  55. onShow(() => {
  56. console.log('onShow')
  57. // 版本自动更新代码
  58. const updateManager = wx.getUpdateManager()
  59. updateManager.onUpdateReady(function() {
  60. wx.showModal({
  61. title: '更新检测',
  62. content: '检测到新版本,是否重启小程序?',
  63. success: function(res) {
  64. if (res.confirm) {
  65. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  66. updateManager.applyUpdate()
  67. }
  68. }
  69. })
  70. })
  71. updateManager.onUpdateFailed(function() {
  72. // 新的版本下载失败
  73. wx.showModal({
  74. title: '已有新版本咯',
  75. content: '请您删除当前小程序,重新打开呦~',
  76. showCancel: false
  77. })
  78. })
  79. })
  80. onLoad((o) => {
  81. console.log('onLoad', o)
  82. if (o.tabName) { //公库添加商品到私库完毕,显示商品界面
  83. tabName.value = o.tabName;
  84. if (menu.value && menu.value.length > 0) {
  85. menu.value.forEach((item, index) => {
  86. if (item.name == o.tabName) {
  87. tcurrent.value = index
  88. }
  89. })
  90. }
  91. }
  92. })
  93. const menu = computed(() => JSON.parse(usePermissionStore().permissions_menu))
  94. watch(
  95. () => menu,
  96. (menu, prevMenu) => {
  97. if (menu.length > 0) {
  98. tabName.value = menu[0].name
  99. } else {
  100. tabName.value = null
  101. }
  102. }
  103. )
  104. function tabChange(e) {
  105. current.value = e
  106. }
  107. function tabClick(e) {
  108. tabName.value = e.name
  109. }
  110. </script>
  111. <style lang="scss">
  112. .container {
  113. .pages {
  114. height: 100%;
  115. }
  116. .u-page__item__slot-icon {
  117. width: 44rpx;
  118. height: 44rpx;
  119. }
  120. }
  121. </style>