index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <view class="container">
  3. <u-navbar :placeholder="true" bgColor="#fff" :autoBack="true" title="微信授权"></u-navbar>
  4. <view class="flex login">
  5. <view class="flex login-image">
  6. <image src="../../static/logo.png" mode=""></image>
  7. <view class="login-image-txt">盲票</view>
  8. </view>
  9. <view class="login-txt">盲票将为您提供</view>
  10. <view class="login-title">商品兑换、盲票购买等服务 请先完成授权登录</view>
  11. <view class="login-btn">
  12. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信授权登录</button>
  13. </view>
  14. </view>
  15. <auth :auth-show="authShow" :auth-token="token" @close="authClose" />
  16. </view>
  17. </template>
  18. <script>
  19. import $http from '@/utils/request.js'
  20. import log from '@/common/log.js'
  21. import Auth from '../../components/auth/auth.vue'
  22. export default {
  23. components: {
  24. Auth
  25. },
  26. data() {
  27. return {
  28. authShow: false,
  29. token: '',
  30. };
  31. },
  32. methods: {
  33. getPhoneNumber(e) {
  34. let _this = this
  35. if(e.detail.errMsg == 'getPhoneNumber:ok'){
  36. uni.showLoading({
  37. title: '登录中'
  38. });
  39. if (e.detail & e.detail.code) {
  40. $http.post('/api/v1/mp/user/wxauth/mobile', {
  41. ...e.detail,
  42. identity: 1,
  43. noToken: true
  44. }).then(res => {
  45. uni.hideLoading();
  46. if (res.code == 0) {
  47. uni.setStorageSync('token', res.token)
  48. _this.getBaseInfo()
  49. }else{
  50. uni.getSystemInfo({
  51. success (res) {
  52. log.info(`错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`)
  53. }
  54. })
  55. }
  56. }).catch(() => {
  57. uni.hideLoading();
  58. uni.getSystemInfo({
  59. success (res) {
  60. log.info(`错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`)
  61. }
  62. })
  63. })
  64. }else{
  65. uni.login({
  66. success(res) {
  67. $http.post('/api/v1/mp/user/wxauth/mobile', {
  68. ...e.detail,
  69. loginCode: res.code,
  70. identity: 1,
  71. noToken: true
  72. }).then(res => {
  73. uni.hideLoading();
  74. if (res.code == 0) {
  75. uni.setStorageSync('token', res.token)
  76. _this.getBaseInfo()
  77. }else{
  78. uni.getSystemInfo({
  79. success (res) {
  80. log.info(`错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`)
  81. }
  82. })
  83. }
  84. }).catch(() => {
  85. uni.hideLoading();
  86. uni.getSystemInfo({
  87. success (res) {
  88. log.info(`错误信息:===基础库:${ res.SDKVersion },设备:${ res.model }-${ res.system }.===`)
  89. }
  90. })
  91. })
  92. }
  93. })
  94. }
  95. }
  96. },
  97. // 关闭授权
  98. authClose() {
  99. this.authShow = false
  100. setTimeout(() => {
  101. uni.navigateBack({
  102. delta: 1
  103. })
  104. }, 500)
  105. },
  106. getBaseInfo() {
  107. $http.post('/api/v1/mp/user/getLoginUserinfo', {}).then(res => {
  108. uni.hideLoading();
  109. if (res.code == 0) {
  110. uni.setStorageSync('userInfo', res.data)
  111. if (res.data.openId) {
  112. uni.$u.toast('登录成功');
  113. setTimeout(() => {
  114. uni.navigateBack({
  115. delta: 1
  116. })
  117. }, 500)
  118. } else {
  119. this.authShow = true
  120. }
  121. }
  122. }).catch(() => {
  123. uni.hideLoading();
  124. })
  125. },
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .container {
  131. height: 100vh;
  132. width: 100%;
  133. }
  134. .login {
  135. flex-direction: column;
  136. &-image {
  137. flex-direction: column;
  138. padding: 100rpx 0 200rpx;
  139. image {
  140. width: 164rpx;
  141. height: 164rpx;
  142. border-radius: 10rpx;
  143. margin-bottom: 14rpx;
  144. }
  145. &-txt {
  146. text-align: center;
  147. line-height: 40rpx;
  148. font-weight: bold;
  149. margin-bottom: 20rpx;
  150. font-size: 36rpx;
  151. }
  152. }
  153. &-txt {
  154. text-align: center;
  155. line-height: 40rpx;
  156. font-weight: bold;
  157. margin-bottom: 20rpx;
  158. }
  159. &-title {
  160. text-align: center;
  161. font-size: 24rpx;
  162. font-weight: normal;
  163. margin-bottom: 50rpx;
  164. }
  165. &-btn {
  166. button {
  167. width: 600rpx;
  168. height: 80rpx;
  169. line-height: 80rpx;
  170. border-radius: 40rpx;
  171. background-color: rgba(235, 112, 9, 100);
  172. color: rgba(255, 255, 255, 100);
  173. text-align: center;
  174. font-size: 28rpx;
  175. }
  176. }
  177. }
  178. </style>