logion.vue 3.6 KB

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