西藏巴青项目

index.vue 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <view class="tab-page">
  3. <SupplierHomePanel
  4. v-if="isSupplier && isLoggedIn"
  5. ref="homePanel"
  6. />
  7. <DistributorHomePanel
  8. v-else-if="isDistributor && isLoggedIn"
  9. ref="homePanel"
  10. />
  11. <GuestView
  12. v-else-if="!isLoggedIn"
  13. hint="登录后查看交易数据"
  14. @login="goLogin"
  15. />
  16. </view>
  17. </template>
  18. <script>
  19. import SupplierHomePanel from '@/components/supplier/home-panel.vue'
  20. import DistributorHomePanel from '@/components/distributor/home-panel.vue'
  21. import GuestView from '@/components/partner/guest-view.vue'
  22. import { useUserStore } from '@/store/user'
  23. import { isEffectiveDistributorRole, isEffectiveSupplierRole } from '@/utils/partnerRole'
  24. import { refreshTabPanelOnShow } from '@/utils/tabPanel'
  25. export default {
  26. components: {
  27. SupplierHomePanel,
  28. DistributorHomePanel,
  29. GuestView
  30. },
  31. data() {
  32. return {
  33. isLoggedIn: false,
  34. isSupplier: false,
  35. isDistributor: false
  36. }
  37. },
  38. onShow() {
  39. refreshTabPanelOnShow(this, {
  40. refreshRole: this.refreshRole,
  41. refName: 'homePanel',
  42. shouldReload: () => this.isLoggedIn && (this.isSupplier || this.isDistributor)
  43. })
  44. },
  45. onHide() {
  46. const panel = this.$refs.homePanel
  47. if (panel && typeof panel.stopRealtimePoll === 'function') {
  48. panel.stopRealtimePoll()
  49. }
  50. },
  51. methods: {
  52. refreshRole() {
  53. const userStore = useUserStore()
  54. const roles = userStore.state.roles
  55. this.isLoggedIn = userStore.isLoggedIn()
  56. this.isSupplier = isEffectiveSupplierRole(roles)
  57. this.isDistributor = isEffectiveDistributorRole(roles)
  58. },
  59. goLogin() {
  60. uni.navigateTo({ url: '/pages/login/index' })
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. @import '@/styles/tab-page.scss';
  67. </style>