logion.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view>
  3. <view style="text-align: center;margin-top: 60upx;">
  4. <image src="../../static/logo.png" style="width: 150upx;height: 150upx;" />
  5. </view>
  6. <view v-if='!hasLogin'>
  7. <view style="text-align: center;margin: 50upx 0 10upx 0;font-size: 36upx;">圈在网申请获取您的以下权限</view>
  8. <view style="text-align: center;margin: 0 0 50upx 0;font-size: 24upx;color: #666666;">获取您的公开信息(昵称,头像等)</view>
  9. <view style="width: 50%;margin: 0 auto;">
  10. <button @click="wxlogion" type="warn" open-type='getUserInfo'>
  11. 授权登录
  12. </button>
  13. </view>
  14. </view>
  15. <view v-if='hasLogin&& !successlogion'>
  16. <view style="text-align: center;margin: 100upx;font-size: 36upx;">登录即注册立即成为圈在网会员</view>
  17. <view style="width: 50%;margin: 0 auto;">
  18. <button type="warn" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">使用微信手机号登录</button>
  19. </view>
  20. </view>
  21. <view @click="closesure" style="width: 50%;margin: 30upx auto;text-align:center;font-szie: 30upx;">
  22. 暂不授权
  23. </view>
  24. <view style="position: fixed; bottom: 30upx;width: 100%;">
  25. <view style="text-align: center;padding-bottom: 20upx;">
  26. 请仔细阅读以下协议,若不同意相关内容,您应停止授权
  27. </view>
  28. <view style="text-align: center;">
  29. <span style="color: #D9332E;padding-right: 20upx;" @click="gouser"> 《用户协议》 </span>
  30. <span style="color: #D9332E;" @click="goforate"> 《隐私政策》 </span>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. mapMutations,mapState
  38. } from 'vuex'
  39. export default {
  40. props:{
  41. showdialog:{
  42. default: false,
  43. type: Boolean
  44. },
  45. ishow:{
  46. default: true,
  47. type: Boolean
  48. },
  49. },
  50. data() {
  51. return{
  52. show: false
  53. }
  54. },
  55. computed:{
  56. ...mapState([
  57. 'hasLogin', // 用户是否同意授权
  58. 'userInfo', // 同意授权用户头像
  59. 'successlogion', // 同意手机号授权 登录成功
  60. 'sessionId', // 登录成功的token
  61. 'getcode', // logion时候获取的code session_key oppen_id
  62. ]),
  63. },
  64. onLoad(){
  65. console.log(this.successlogion);
  66. },
  67. methods:{
  68. ...mapMutations(['login','showDialog', 'setOpenid', 'setcode','islogionsuccess']),
  69. closesure() {
  70. uni.navigateBack();
  71. },
  72. // 隐私政策
  73. goforate() {
  74. uni.navigateTo({
  75. url: './goforate'
  76. })
  77. },
  78. // 用户协议
  79. gouser() {
  80. uni.navigateTo({
  81. url: './gouser'
  82. })
  83. },
  84. // 授权用户信息头像
  85. wxlogion() {
  86. let that = this;
  87.     uni.getUserInfo({
  88.      success: (res) => {
  89. that.login(res.userInfo);
  90. that.showDialog(true); // 改变haslogion的值
  91. that.$msg("授权成功");
  92. if(this.successlogion) {
  93. uni.navigateBack();
  94. }
  95.      },
  96.      fail(res) {
  97. that.showDialog(false);
  98. that.$msg("授权失败")
  99.      }
  100.     })
  101. },
  102. // 获取手机号码
  103. decryptPhoneNumber(e) {
  104. console.log(e);
  105. if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
  106. console.log(e);
  107. } else {
  108. console.log('用户同意提供手机号');
  109. console.log(this.getcode);
  110. let encryptedData = e.detail.encryptedData;
  111. let iv = e.detail.iv;
  112. console.log(this.userInfo);
  113. // 调取注册账号
  114. this.request({
  115. url: '/v1/entry/mp_account',
  116. method:'POST',
  117. data: {
  118. code: this.getcode.code,
  119. encryptedData: encryptedData,
  120. iv: iv,
  121. name: this.userInfo.nickName,
  122. avatar: this.userInfo.avatarUrl
  123. },
  124. success: (res) => {
  125. let token = res.data.data.token;
  126. this.setOpenid(token);
  127. this.islogionsuccess(true);
  128. uni.navigateBack();
  129. },
  130. fail: (res) => {
  131. this.islogionsuccess(false);
  132. this.setOpenid('');
  133. this.$msg("获取失败")
  134.      }
  135. })
  136. }
  137. },
  138. }
  139. }
  140. </script>
  141. <style>
  142. </style>