tabbar_cjx.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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="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. text: '溯源信息',
  40. icon: 'traceability.png'
  41. },
  42. {
  43. text: '意见反馈',
  44. icon: 'opinion.png'
  45. },
  46. {
  47. text: '公司简介',
  48. icon: 'company.png'
  49. },
  50. {
  51. text: '个人中心',
  52. icon: 'scan.png'
  53. },
  54. ]
  55. };
  56. },
  57. created() {
  58. // // 监听事件
  59. // uni.$on('updateSelectedIndex', (index) => {
  60. // this.selectedIndex = index;
  61. // });
  62. },
  63. methods: {
  64. open() {
  65. // console.log('open');
  66. },
  67. close() {
  68. this.show = false
  69. // console.log('close');
  70. },
  71. onTabChange(index) {
  72. //判断是否已经授权
  73. if (uni.getStorageSync('Authorization-status')) {
  74. this.handleTabSwitch(index);
  75. return;
  76. }
  77. this.handleLogin();
  78. this.show = true;
  79. this.selectedIndex = index;
  80. return;
  81. },
  82. async handleLogin() {
  83. const [loginRes, profileRes] = await Promise.all([
  84. uni.login({
  85. provider: 'weixin'
  86. }),
  87. uni.getUserProfile({
  88. desc: '登录需要'
  89. })
  90. ])
  91. this.loginDate.iv = profileRes.iv;
  92. this.loginDate.encryptedData = profileRes.encryptedData;
  93. this.loginDate.jsCode = loginRes.code;
  94. },
  95. handlePhone(e) {
  96. if (e.detail.code) {
  97. this.loginDate.code = e.detail.code;
  98. // this.loginDate.iv = e.detail.iv;
  99. // this.loginDate.encryptedData = e.detail.encryptedData;
  100. getUserInfo(this.loginDate).then(res => {
  101. if (res.code === 0) {
  102. uni.setStorageSync('Authorization-status', true);
  103. this.show = false;
  104. this.handleTabSwitch(this.selectedIndex);
  105. } else {
  106. }
  107. })
  108. }
  109. },
  110. handleTabSwitch(index) {
  111. let url = '';
  112. switch (index) {
  113. case 0:
  114. url = '/pages/cjx/introduction/introduction';
  115. break;
  116. case 1:
  117. url = '/pages/cjx/traceability/traceability';
  118. break;
  119. case 2:
  120. url = '/pages/cjx/feedback/feedback';
  121. break;
  122. case 3:
  123. url = '/pages/cjx/my/my';
  124. break;
  125. default:
  126. break;
  127. }
  128. uni.navigateTo({
  129. url: url
  130. });
  131. }
  132. }
  133. };
  134. </script>
  135. <style scoped>
  136. /* 修复内容区域样式 */
  137. ::v-deep .u-tabbar__content {
  138. background-color: transparent !important;
  139. box-shadow: none !important;
  140. height: 140rpx;
  141. border: none;
  142. }
  143. /* 修复图标尺寸 - 精确选择器路径 */
  144. ::v-deep .custom-tabbar .u-tabbar-item .u-tabbar-item__icon .u-icon__img {
  145. width: 80rpx !important;
  146. height: 80rpx !important;
  147. }
  148. .login-text {
  149. text-align: center;
  150. font-size: 18px;
  151. font-weight: 800;
  152. margin-bottom: 10px;
  153. }
  154. .login-btn {
  155. border-radius: 22px;
  156. border: none !important;
  157. background-color: #5ac725;
  158. color: white;
  159. font-size: 15px;
  160. margin-bottom: 15px;
  161. }
  162. </style>