tabbar.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="">
  3. <u-tabbar :value="initIndex" @click="handleLogin" @change="onTabChange" :fixed="true" :placeholder="true"
  4. :safeAreaInsetBottom="true" class="custom-tabbar" activeColor="#d81e06" inactiveColor="#fff">
  5. <u-tabbar-item v-for="(item, index) in items" :key="index" :text="item.text"
  6. :icon="require(`@/static/images/tabbar/${item.icon}`)" />
  7. </u-tabbar>
  8. <u-popup :show="show" mode="bottom" class="popup-view" @close="close" @open="open">
  9. <view style="margin: 20px">
  10. <view class="login-text">
  11. 梅山古镇
  12. </view>
  13. <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="handlePhone">
  14. 授权登录
  15. </button>
  16. </view>
  17. </u-popup>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. getUserInfo
  23. } from '@/api/login'
  24. export default {
  25. data() {
  26. return {
  27. show: false,
  28. loginDate: {
  29. jsCode: '',
  30. encryptedData: '',
  31. code: '',
  32. iv: ''
  33. },
  34. // 选中的 tab 索引
  35. initIndex:4,
  36. selectedIndex: 4,
  37. // 自定义 tab 数据
  38. items: [
  39. {
  40. text: '溯源信息',
  41. icon: 'traceability.png'
  42. },
  43. {
  44. text: '意见反馈',
  45. icon: 'opinion.png'
  46. },
  47. {
  48. text: '公司简介',
  49. icon: 'company.png'
  50. },
  51. {
  52. text: '个人中心',
  53. icon: 'my.png'
  54. },
  55. ]
  56. };
  57. },
  58. created() {
  59. // // 监听事件
  60. // uni.$on('updateSelectedIndex', (index) => {
  61. // this.selectedIndex = index;
  62. // });
  63. },
  64. methods: {
  65. open() {
  66. // console.log('open');
  67. },
  68. close() {
  69. this.show = false
  70. // console.log('close');
  71. },
  72. onTabChange(index) {
  73. //判断是否已经授权
  74. if(uni.getStorageSync('Authorization-status')){
  75. this.handleTabSwitch(index);
  76. return;
  77. }
  78. this.handleLogin();
  79. this.show = true;
  80. this.selectedIndex = index;
  81. return;
  82. },
  83. async handleLogin() {
  84. const [loginRes,profileRes] = await Promise.all([
  85. uni.login({
  86. provider: 'weixin'
  87. }),
  88. uni.getUserProfile({
  89. desc: '登录需要'
  90. })
  91. ])
  92. this.loginDate.iv = profileRes.iv;
  93. this.loginDate.encryptedData = profileRes.encryptedData;
  94. this.loginDate.jsCode = loginRes.code;
  95. },
  96. handlePhone(e) {
  97. if (e.detail.code) {
  98. this.loginDate.code = e.detail.code;
  99. // this.loginDate.iv = e.detail.iv;
  100. // this.loginDate.encryptedData = e.detail.encryptedData;
  101. getUserInfo(this.loginDate).then(res => {
  102. if (res.code === 0) {
  103. uni.setStorageSync('Authorization-status',true);
  104. this.show = false;
  105. this.handleTabSwitch(this.selectedIndex);
  106. } else {
  107. }
  108. })
  109. }
  110. },
  111. handleTabSwitch(index) {
  112. let url = '';
  113. switch (index) {
  114. case 0:
  115. url = '/pages/lgz/traceability/traceability';
  116. break;
  117. case 1:
  118. url = '/pages/lgz/feedback/feedback';
  119. break;
  120. case 2:
  121. url = '/pages/lgz/introduction/introduction';
  122. break;
  123. case 3:
  124. url = '/pages/lgz/my/my';
  125. break;
  126. default:
  127. break;
  128. }
  129. uni.navigateTo({
  130. url: url
  131. });
  132. }
  133. }
  134. };
  135. </script>
  136. <style scoped>
  137. /* 修复内容区域样式 */
  138. ::v-deep .u-tabbar__content {
  139. background-color: transparent !important;
  140. box-shadow: none !important;
  141. height: 140rpx;
  142. border: none;
  143. }
  144. /* 修复图标尺寸 - 精确选择器路径 */
  145. ::v-deep .custom-tabbar .u-tabbar-item .u-tabbar-item__icon .u-icon__img {
  146. width: 80rpx !important;
  147. height: 80rpx !important;
  148. }
  149. .login-text {
  150. text-align: center;
  151. font-size: 18px;
  152. font-weight: 800;
  153. margin-bottom: 10px;
  154. }
  155. .login-btn {
  156. border-radius: 22px;
  157. border: none !important;
  158. background-color: #5ac725;
  159. color: white;
  160. font-size: 15px;
  161. margin-bottom: 15px;
  162. }
  163. </style>