index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. onShow() {
  33. let qrcode=uni.getStorageSync('qrcode')
  34. if(!qrcode){
  35. uni.showToast({
  36. icon:"none",
  37. title:"请重新扫码"
  38. })
  39. }
  40. },
  41. methods:{
  42. changecheck(){
  43. this.checked= !this.checked
  44. },
  45. statement(){
  46. uni.navigateTo({
  47. url:'/pages/service_agreement/service_agreement'
  48. })
  49. },
  50. onSubmit(){
  51. if(!this.checked){
  52. uni.showToast({
  53. icon:"none",
  54. title:"请先阅读隐私协议"
  55. })
  56. return
  57. }
  58. },
  59. getPhoneNumber(e){
  60. let qrcode=uni.getStorageSync('qrcode')
  61. if(!qrcode){
  62. uni.showToast({
  63. icon:"none",
  64. title:"请重新扫码"
  65. })
  66. return
  67. }
  68. uni.getProvider({
  69. service:"oauth",
  70. success(res){
  71. let provider=res.provider
  72. uni.login({
  73. provider,
  74. success: function (loginRes) {
  75. let code=loginRes.code;
  76. wxLogin({
  77. jsCode:code,
  78. ocId:qrcode.ocId
  79. }).then((resp)=>{
  80. const { code, data, msg } = resp
  81. if(data){
  82. if(data&&data.unionid){
  83. const sessionKey=data.sessionKey;
  84. const { encryptedData, iv, code} = e.detail;
  85. wxDecryptUserInfo({
  86. wxCode:data.unionid,
  87. ocId:qrcode.ocId,
  88. encryptedData,
  89. iv,
  90. sessionKey
  91. }).then((resp)=>{
  92. uni.setStorageSync('unionid',data.unionid)
  93. uni.setStorageSync('isLogin',true)
  94. uni.setStorageSync('phone-info',resp.data)
  95. uni.setStorageSync('isAccount',data.isAccount)
  96. uni.setStorageSync('wxId',data.wxId)
  97. uni.setStorageSync('wxName',data.wxName)
  98. uni.reLaunch({
  99. url: '/pages/index/index'
  100. })
  101. })
  102. }
  103. }
  104. })
  105. }
  106. })
  107. }
  108. })
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. .authorizedLogin-container{
  115. position: fixed;
  116. left: 0;
  117. right: 0;
  118. top: 0;
  119. bottom: 0;
  120. background-color: rgba(255,255,255,1);
  121. z-index: 999;
  122. padding: 20rpx;
  123. box-sizing: border-box;
  124. .logo{
  125. display: block;
  126. width: 100rpx;
  127. height: 100rpx;
  128. margin: 100rpx auto;
  129. }
  130. .statement{
  131. font-size: 24rpx;
  132. color: #666;
  133. .check-bt{
  134. ::v-deep .uni-radio-input{
  135. margin-right: 0 !important;
  136. }
  137. }
  138. .link{
  139. color: #3D90F4;
  140. }
  141. }
  142. .btn-submit{
  143. width: 600rpx;
  144. height: 72rpx;
  145. line-height: 72rpx;
  146. text-align: center;
  147. background:#3D90F4;
  148. border-radius: 42rpx;
  149. font-size: 32rpx;
  150. font-family: PingFang SC;
  151. font-weight: 400;
  152. color: #FFFFFF;
  153. z-index: 999;
  154. margin: 50rpx auto;
  155. }
  156. }
  157. </style>