tabbar_cjx.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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/cjx/${item.icon}`)" />
  7. </u-tabbar>
  8. <u-popup :show="showTabbar" 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. showTabbar: 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.showTabbar = 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.showTabbar = 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. uni.setStorageSync('userPhone', res.data.mobile);
  105. this.showTabbar = false;
  106. this.handleTabSwitch(this.selectedIndex);
  107. } else {
  108. }
  109. })
  110. }
  111. },
  112. handleTabSwitch(index) {
  113. let url = '';
  114. switch (index) {
  115. case 0:
  116. url = '/pages/cjx/traceability/traceability';
  117. break;
  118. case 1:
  119. url = '/pages/cjx/feedback/feedback';
  120. break;
  121. case 2:
  122. url = '/pages/cjx/introduction/introduction';
  123. break;
  124. case 3:
  125. url = '/pages/cjx/my/my';
  126. break;
  127. default:
  128. break;
  129. }
  130. uni.navigateTo({
  131. url: url
  132. });
  133. }
  134. }
  135. };
  136. </script>
  137. <style scoped>
  138. /* 修复内容区域样式 */
  139. ::v-deep .u-tabbar__content {
  140. background-color: transparent !important;
  141. box-shadow: none !important;
  142. height: 140rpx;
  143. border: none;
  144. }
  145. /* 修复图标尺寸 - 精确选择器路径 */
  146. ::v-deep .custom-tabbar .u-tabbar-item .u-tabbar-item__icon .u-icon__img {
  147. width: 80rpx !important;
  148. height: 80rpx !important;
  149. }
  150. .login-text {
  151. text-align: center;
  152. font-size: 18px;
  153. font-weight: 800;
  154. margin-bottom: 10px;
  155. }
  156. .login-btn {
  157. border-radius: 22px;
  158. border: none !important;
  159. background-color: #5ac725;
  160. color: white;
  161. font-size: 15px;
  162. margin-bottom: 15px;
  163. }
  164. </style>