index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. uni.getProvider({
  52. service:"oauth",
  53. success(res){
  54. let provider=res.provider
  55. uni.login({
  56. provider,
  57. success: function (loginRes) {
  58. let code=loginRes.code;
  59. wxLogin(code).then((resp)=>{
  60. const { code, data, msg } = resp
  61. if(data){
  62. if(data&&data.unionid){
  63. const sessionKey=data.session_key;
  64. const { encryptedData, iv, code} = e.detail;
  65. wxDecryptUserInfo({
  66. encryptedData, iv,sessionKey
  67. }).then((resp)=>{
  68. uni.setStorageSync('unionid',data.unionid)
  69. uni.setStorageSync('isLogin',true)
  70. uni.setStorageSync('phone-info',resp.data)
  71. uni.reLaunch({
  72. url:'/pages/index/index'
  73. })
  74. })
  75. }
  76. }
  77. })
  78. }
  79. })
  80. }
  81. })
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .authorizedLogin-container{
  88. position: fixed;
  89. left: 0;
  90. right: 0;
  91. top: 0;
  92. bottom: 0;
  93. background-color: rgba(255,255,255,1);
  94. z-index: 999;
  95. padding: 20rpx;
  96. box-sizing: border-box;
  97. .logo{
  98. display: block;
  99. width: 100rpx;
  100. height: 100rpx;
  101. margin: 100rpx auto;
  102. }
  103. .statement{
  104. font-size: 24rpx;
  105. color: #666;
  106. .check-bt{
  107. ::v-deep .uni-radio-input{
  108. margin-right: 0 !important;
  109. }
  110. }
  111. .link{
  112. color: #3D90F4;
  113. }
  114. }
  115. .btn-submit{
  116. width: 600rpx;
  117. height: 72rpx;
  118. line-height: 72rpx;
  119. text-align: center;
  120. background:#3D90F4;
  121. border-radius: 42rpx;
  122. font-size: 32rpx;
  123. font-family: PingFang SC;
  124. font-weight: 400;
  125. color: #FFFFFF;
  126. z-index: 999;
  127. margin: 50rpx auto;
  128. }
  129. }
  130. </style>