use-tabbar.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="use-tabbar">
  3. <!--<u-loading-page :loading="pageLoading"></u-loading-page>-->
  4. <u-navbar v-if="navbar && showNavbar" :title="title" :autoBack="false" :placeholder="true" :leftIcon="leftIcon"
  5. :rightIcon="rightIcon" bgColor="#f5f5f5" :fixed="true" @rightClick="show" @leftClick="back">
  6. </u-navbar>
  7. <u-tabbar height="55" v-if="tabbar && nav.length > 0" :value="value" @change="go" :fixed="true" :placeholder="false" activeColor="#d81e06"
  8. :safeAreaInsetBottom="true" :fit="true">
  9. <u-tabbar-item :text="v.name" v-for="(v, k) in nav" :key="k">
  10. <image class="u-page__item__slot-icon" slot="inactive-icon" :src="v.icon" v-if="v.icon"></image>
  11. <image class="u-page__item__slot-icon" slot="inactive-icon" src="@/static/images/tabbar/category.png"
  12. v-if="!v.icon && v.type == 11"></image>
  13. <image class="u-page__item__slot-icon" slot="inactive-icon" src="@/static/images/tabbar/home.png"
  14. v-if="!v.icon && v.type == 10"></image>
  15. <image class="u-page__item__slot-icon" slot="inactive-icon" src="@/static/images/tabbar/cart.png"
  16. v-if="!v.icon && v.type == 2"></image>
  17. <image class="u-page__item__slot-icon" slot="inactive-icon" src="@/static/images/tabbar/user.png"
  18. v-if="!v.icon && v.type == 1"></image>
  19. <image class="u-page__item__slot-icon" slot="active-icon" :src="v.icon_select" v-if="v.icon_select">
  20. </image>
  21. <image class="u-page__item__slot-icon" slot="active-icon" src="@/static/images/tabbar/category-active.png"
  22. v-if="!v.icon && v.type == 11"></image>
  23. <image class="u-page__item__slot-icon" slot="active-icon" src="@/static/images/tabbar/home-active.png"
  24. v-if="!v.icon && v.type == 10"></image>
  25. <image class="u-page__item__slot-icon" slot="active-icon"
  26. src="@/static/images/tabbar/cart-active.png" v-if="!v.icon && v.type == 2"></image>
  27. <image class="u-page__item__slot-icon" slot="active-icon" src="@/static/images/tabbar/user-active.png"
  28. v-if="!v.icon && v.type == 1"></image>
  29. </u-tabbar-item>
  30. </u-tabbar>
  31. <u-modal :show="content.show" confirmText="关闭" @close="confirm" @confirm="confirm" :title="title" :closeOnClickOverlay="true">
  32. <view class="slot-content">
  33. <u-parse :content="content.value"></u-parse>
  34. </view>
  35. </u-modal>
  36. </view>
  37. </template>
  38. <script>
  39. export default {
  40. props: {
  41. navbar: {
  42. type: Boolean,
  43. default: true
  44. },
  45. tabbar: {
  46. type: Boolean,
  47. default: true
  48. },
  49. },
  50. data() {
  51. return {
  52. showNavbar: true,
  53. value: 0,
  54. title: '',
  55. logo: '',
  56. nav: [],
  57. canBack: false,
  58. leftIcon: '',
  59. rightIcon: '',
  60. content: {
  61. show : false,
  62. value: '',
  63. }
  64. };
  65. },
  66. activated() {
  67. this.init();
  68. },
  69. mounted() {
  70. this.init();
  71. this.load();
  72. },
  73. methods: {
  74. init() {
  75. this.check()
  76. if (this.Dever.platform == 'weixin' && this.Dever.env == 3) {
  77. this.showNavbar = false;
  78. }
  79. if (this.Dever.env != 5) {
  80. this.rightIcon = 'calendar'
  81. }
  82. uni.getStorage({
  83. key: 'nav',
  84. success: (res) => {
  85. this.value = res.data
  86. }
  87. })
  88. },
  89. load() {
  90. this.Dever.config().then(config => {
  91. this.title = config.n;
  92. this.nav = config.m;
  93. if (this.leftIcon == '') {
  94. uni.setNavigationBarTitle({
  95. title: this.title,
  96. });
  97. }
  98. });
  99. },
  100. show() {
  101. this.content.show = false;
  102. this.DeverApi.get(this, 'main.getContent', {noloading:1}, res => {
  103. this.content.value = res.content;
  104. this.content.show = true;
  105. })
  106. },
  107. confirm() {
  108. this.content.show = false;
  109. },
  110. check() {
  111. const pages = getCurrentPages();
  112. if (pages.length > 0) {
  113. this.canBack = pages.length > 1;
  114. const page = pages[pages.length - 1].route;
  115. const array = ['pages/source/home', 'pages/source/channel', 'pages/user/index']
  116. if (array.includes(page)) {
  117. this.leftIcon = '';
  118. } else {
  119. this.leftIcon = 'arrow-left';
  120. }
  121. }
  122. },
  123. back() {
  124. if (!this.leftIcon) {
  125. return;
  126. }
  127. if (!this.canBack) {
  128. this.Dever.goTabbar(this.nav, 0)
  129. } else {
  130. uni.navigateBack();
  131. }
  132. },
  133. go(value) {
  134. this.value = value;
  135. uni.setStorage({
  136. key: 'nav',
  137. data: this.value,
  138. success: (res) => {
  139. this.Dever.goTabbar(this.nav, this.value)
  140. }
  141. });
  142. }
  143. }
  144. };
  145. </script>
  146. <style lang="scss">
  147. .use-tabbar image {
  148. width: 48rpx;
  149. height: 48rpx;
  150. }
  151. </style>