index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <!-- index.wxml -->
  3. <view class="wrap">
  4. <view class="wrap_nr">
  5. <image class="user_thumb" :src="userInfo.thumb"></image>
  6. <view class="user_name">您好,{{ userInfo.nickname }}</view>
  7. <view class="tips">为了您的账户安全,请绑定手机号</view>
  8. <button class="custom_btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  9. <van-icon name="wechat" size="24" color="#ffffff" />
  10. 微信手机号一键绑定
  11. </button>
  12. <view class="single" @tap="toPhoneLogin">使用其他手机号</view>
  13. </view>
  14. </view>
  15. <!-- loading -->
  16. <!-- <van-overlay show="{{ loading }}" z-index="100">
  17. <van-loading custom-class="custom_loading" />
  18. </van-overlay> -->
  19. </template>
  20. <script>
  21. // index.js
  22. let myPro = require('../../../utils/wxRequest.js');
  23. let util = require('../../../utils/util.js');
  24. export default {
  25. data() {
  26. return {
  27. // 全局loading
  28. loading: false,
  29. userInfo: {
  30. thumb: '',
  31. nickname: ''
  32. },
  33. store: ''
  34. };
  35. },
  36. onLoad: function (options) {
  37. // Do some initialize when page load.
  38. },
  39. onShow: function () {
  40. // Do something when page show.
  41. let that = this;
  42. that.setData({
  43. userInfo: getApp().globalData.userInfo
  44. }); // console.log('用户信息',that.data.userInfo)
  45. // 店铺
  46. uni.getStorage({
  47. key: 'store',
  48. success: function (res) {
  49. that.setData({
  50. store: JSON.parse(res.data)
  51. });
  52. }
  53. });
  54. },
  55. onReady: function () {
  56. // Do something when page ready.
  57. },
  58. onHide: function () {
  59. // Do something when page hide.
  60. },
  61. onUnload: function () {
  62. // Do something when page close.
  63. },
  64. onPullDownRefresh: function () {
  65. // Do something when pull down.
  66. },
  67. onReachBottom: function () {
  68. // Do something when page reach bottom.
  69. },
  70. onPageScroll: function () {
  71. // Do something when page scroll
  72. },
  73. onResize: function () {
  74. // Do something when page resize
  75. },
  76. methods: {
  77. // 手机号授权
  78. getPhoneNumber(event) {
  79. let that = this;
  80. if (event.detail.errMsg == 'getPhoneNumber:ok') {
  81. console.log('手机号授权', event); // return;
  82. let params = {
  83. openid: getApp().globalData.openid,
  84. session_key: getApp().globalData.session_key,
  85. encryptedData: event.detail.encryptedData,
  86. iv: event.detail.iv,
  87. nickname: getApp().globalData.userInfo.nickname,
  88. sex: getApp().globalData.userInfo.sex,
  89. thumb: getApp().globalData.userInfo.thumb,
  90. store_id: that.store ? that.store.id : 1 // 门店id
  91. };
  92. myPro
  93. .wxRequest('user/v2/wxlogin', 'POST', params)
  94. .then((res) => {
  95. // 存下token
  96. getApp().globalData.token = res.result.token;
  97. uni.setStorage({
  98. key: 'token',
  99. data: res.result.token
  100. }); // 存在会员
  101. getApp().globalData.is_member = res.result.user.is_member; // 会员 0否 1是
  102. // 存下角色
  103. if (res.result.user.store) {
  104. getApp().globalData.role = 1; // 有店铺,即为门店
  105. }
  106. uni.reLaunch({
  107. url: '/pages/index/index'
  108. });
  109. })
  110. .catch((err) => {
  111. console.log('报错信息', err);
  112. uni.showToast({
  113. title: err,
  114. icon: 'none'
  115. });
  116. });
  117. }
  118. },
  119. // 去手机号登录
  120. toPhoneLogin() {
  121. let that = this;
  122. uni.navigateTo({
  123. url: '/pages/login/phone/index'
  124. });
  125. }
  126. }
  127. };
  128. </script>
  129. <style>
  130. /**index.wxss**/
  131. .wrap_nr {
  132. padding-top: 200rpx;
  133. text-align: center;
  134. }
  135. .user_thumb {
  136. width: 148rpx;
  137. height: 148rpx;
  138. border-radius: 50%;
  139. }
  140. .user_name {
  141. padding-top: 50rpx;
  142. font-size: 40rpx;
  143. color: #333333;
  144. }
  145. .tips {
  146. padding-top: 20rpx;
  147. font-size: 28rpx;
  148. color: rgba(51, 51, 51, 0.54);
  149. }
  150. .custom_btn {
  151. width: 604rpx !important;
  152. height: 90rpx;
  153. padding: 0;
  154. margin: 300rpx auto 0 auto;
  155. line-height: unset;
  156. font-weight: normal;
  157. background: #295c56;
  158. border-radius: 45rpx;
  159. font-size: 34rpx;
  160. color: #ffffff;
  161. display: flex;
  162. align-items: center;
  163. justify-content: center;
  164. }
  165. .custom_btn .van-icon {
  166. /* width: 37rpx;
  167. height: 30rpx;
  168. background: #FFFFFF; */
  169. margin-right: 10rpx;
  170. }
  171. .single {
  172. margin-top: 50rpx;
  173. font-size: 26rpx;
  174. color: rgba(0, 0, 0, 0.54);
  175. }
  176. </style>