index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="authorizedLogin-container" v-if="show">
  3. <image src="/static/logo.png" class="logo"></image>
  4. <view class="statement">
  5. <label>
  6. <label class="radio" @click="changecheck">
  7. <radio class="check-bt" value="1" :checked="checked" style="transform:scale(0.6)" />
  8. <text>我已阅读并同意</text>
  9. <text class="link" @click="statement">《隐私政策》</text>
  10. <text>首次使用自动注册登录</text>
  11. </label>
  12. </label>
  13. </view>
  14. <button class="btn-submit" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" v-if="checked">
  15. <view >一键登录</view>
  16. </button>
  17. <button class="btn-submit" @click="onSubmit" v-else>
  18. <view >一键登录</view>
  19. </button>
  20. </view>
  21. </template>
  22. <script>
  23. import { wxLogin,wxDecryptUserInfo} from '@/api/openApi.js'
  24. export default {
  25. name:"AuthorizedLogin",
  26. data() {
  27. return {
  28. show:true,
  29. checked:false
  30. };
  31. },
  32. methods:{
  33. changecheck(){
  34. this.checked= !this.checked
  35. },
  36. statement(){
  37. uni.navigateTo({
  38. url:'/pages/service_agreement/service_agreement'
  39. })
  40. },
  41. onSubmit(){
  42. if(!this.checked){
  43. uni.showToast({
  44. icon:"none",
  45. title:"请先阅读隐私协议"
  46. })
  47. return
  48. }
  49. },
  50. getPhoneNumber(e){
  51. let qrcode=uni.getStorageSync('qrcode')
  52. uni.getProvider({
  53. service:"oauth",
  54. success(res){
  55. let provider=res.provider
  56. uni.login({
  57. provider,
  58. success: function (loginRes) {
  59. let code=loginRes.code;
  60. wxLogin({
  61. jsCode:code,
  62. ocId:qrcode.ocId
  63. }).then((resp)=>{
  64. const { code, data, msg } = resp
  65. if(data){
  66. if(data&&data.unionid){
  67. const sessionKey=data.sessionKey;
  68. const { encryptedData, iv, code} = e.detail;
  69. wxDecryptUserInfo({
  70. wxCode:data.unionid,
  71. ocId:qrcode.ocId,
  72. encryptedData,
  73. iv,
  74. sessionKey
  75. }).then((resp)=>{
  76. uni.setStorageSync('unionid',data.unionid)
  77. uni.setStorageSync('isLogin',true)
  78. uni.setStorageSync('phone-info',resp.data)
  79. uni.setStorageSync('isAccount',data.isAccount)
  80. uni.reLaunch({
  81. url: '/pages/index/index'
  82. })
  83. })
  84. }
  85. }
  86. })
  87. }
  88. })
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .authorizedLogin-container{
  97. position: fixed;
  98. left: 0;
  99. right: 0;
  100. top: 0;
  101. bottom: 0;
  102. background-color: rgba(255,255,255,1);
  103. z-index: 999;
  104. padding: 20rpx;
  105. box-sizing: border-box;
  106. .logo{
  107. display: block;
  108. width: 100rpx;
  109. height: 100rpx;
  110. margin: 100rpx auto;
  111. }
  112. .statement{
  113. font-size: 24rpx;
  114. color: #666;
  115. .check-bt{
  116. ::v-deep .uni-radio-input{
  117. margin-right: 0 !important;
  118. }
  119. }
  120. .link{
  121. color: #3D90F4;
  122. }
  123. }
  124. .btn-submit{
  125. width: 600rpx;
  126. height: 72rpx;
  127. line-height: 72rpx;
  128. text-align: center;
  129. background:#3D90F4;
  130. border-radius: 42rpx;
  131. font-size: 32rpx;
  132. font-family: PingFang SC;
  133. font-weight: 400;
  134. color: #FFFFFF;
  135. z-index: 999;
  136. margin: 50rpx auto;
  137. }
  138. }
  139. </style>