use-tabbar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="use-tabbar">
  3. <!--<u-loading-page :loading="pageLoading"></u-loading-page>-->
  4. <u-navbar v-if="navbar" :title="title" :autoBack="true" :placeholder="true" :leftIcon="leftIcon"
  5. rightIcon="calendar" bgColor="#f5f5f5" :fixed="true" @rightClick="show" @leftClick="back">
  6. </u-navbar>
  7. <u-tabbar 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. value: 0,
  53. title: '',
  54. logo: '',
  55. nav: [],
  56. canBack: false,
  57. leftIcon: '',
  58. content: {
  59. show : false,
  60. value: '',
  61. }
  62. };
  63. },
  64. activated() {
  65. this.init();
  66. },
  67. mounted() {
  68. this.init();
  69. const pages = getCurrentPages();
  70. if (pages.length > 0) {
  71. this.canBack = pages.length > 1;
  72. const page = pages[pages.length - 1].route;
  73. if (page == 'pages/source/home') {
  74. this.leftIcon = '';
  75. this.value = 0;
  76. uni.setStorage({
  77. key: 'nav',
  78. data: 0,
  79. });
  80. } else if (page == 'pages/source/cate') {
  81. this.leftIcon = '';
  82. this.value = 1;
  83. uni.setStorage({
  84. key: 'nav',
  85. data: 1,
  86. });
  87. } else {
  88. this.leftIcon = 'arrow-left';
  89. }
  90. }
  91. this.load();
  92. },
  93. methods: {
  94. init() {
  95. uni.getStorage({
  96. key: 'nav',
  97. success: (res) => {
  98. this.value = res.data
  99. }
  100. })
  101. },
  102. load() {
  103. this.Dever.config().then(config => {
  104. this.title = config.n;
  105. this.nav = config.m;
  106. if (this.leftIcon == '') {
  107. uni.setNavigationBarTitle({
  108. title: this.title,
  109. });
  110. }
  111. });
  112. },
  113. show() {
  114. this.content.show = false;
  115. this.DeverApi.get(this, 'main.getContent', {noloading:1}, res => {
  116. this.content.value = res.content;
  117. this.content.show = true;
  118. })
  119. },
  120. confirm() {
  121. this.content.show = false;
  122. },
  123. back() {
  124. if (!this.canBack) {
  125. var item = this.nav[0];
  126. this.Dever.goTabbar(item)
  127. }
  128. },
  129. go(value) {
  130. this.value = value;
  131. uni.setStorage({
  132. key: 'nav',
  133. data: this.value,
  134. success: (res) => {
  135. var item = this.nav[this.value];
  136. this.Dever.goTabbar(item)
  137. }
  138. });
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss">
  144. .use-tabbar image {
  145. width: 48rpx;
  146. height: 48rpx;
  147. }
  148. </style>