initial.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="app-login-page">
  3. <view class="app-login">
  4. <view class="app-icon u-m-b-30 ">
  5. <image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/login-icon.png"
  6. mode="aspectFit" style="height: 40px;"></image>
  7. </view>
  8. <view class="app-title u-m-b-60">
  9. 欢迎使用会员中心系统小程序
  10. </view>
  11. <view style="height: 25vh;">
  12. <u-button v-if="userBook" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber" class="custom-button" style="width: 40px;" plain :hair-line="false">
  13. <view class="login-button">
  14. 本机号码一键登录
  15. </view>
  16. </u-button>
  17. <u-button v-else class="custom-button" style="width: 40px;" plain :hair-line="false" @click="check">
  18. <view class="login-button">
  19. 本机号码一键登录
  20. </view>
  21. </u-button>
  22. <view class="login-button other-button u-m-b-50 u-m-t-50" @click="toLogin">
  23. 其他手机号/账号登录
  24. </view>
  25. </view>
  26. <view class="app-user-book mb-30">
  27. <u-checkbox-group style="display: flex;justify-content: center;">
  28. <u-checkbox v-model="userBook" name="yes" shape="circle">我已阅读&#x300A;运营商一键登录服务协议&#x300B;</u-checkbox>
  29. </u-checkbox-group>
  30. </view>
  31. </view>
  32. <u-modal v-model="userBookModal" mask-close-able class="modal" show-cancel-button
  33. :title-style="{fontWeight: 'bold'}" @confirm="confirmModal">
  34. <view class="modal-content">
  35. 为了更好地保障你的合法权益,进行下一步前,请阅读并同意
  36. <text class="content-a">&#x300A;运营商一键登录服务协议&#x300B;</text>
  37. </view>
  38. </u-modal>
  39. </view>
  40. </template>
  41. <script setup>
  42. import { wxLoginOpenid, wxloginPhone } from '@/api/login.js'
  43. import {
  44. msg,
  45. msgSuccess
  46. } from "@/utils/common.js"
  47. import { ref } from 'vue'
  48. import {
  49. useAuthStore
  50. } from '@/store/authStore'
  51. const authStore = useAuthStore()
  52. const userBook = ref(false)
  53. const userBookModal = ref(false)
  54. function toLogin() {
  55. uni.navigateTo({
  56. url: "/pages/login/login"
  57. })
  58. }
  59. async function wxlogin(){
  60. const loginRes = await wx.login();
  61. const code = loginRes.code;
  62. wxLoginOpenid({code}).then(res=>{
  63. if(res?.data){
  64. const { openid, sessionKey } = res.data
  65. }
  66. })
  67. }
  68. function confirmModal() {
  69. userBook.value = true
  70. // this.wxlogin()
  71. }
  72. function checkUserBook() {
  73. if (!userBook.value) {
  74. userBookModal.value = true
  75. return false;
  76. }
  77. return true
  78. }
  79. function check(){
  80. if (!checkUserBook()) return;
  81. }
  82. async function decryptPhoneNumber(e){
  83. if (e.detail.encryptedData) {
  84. const {
  85. encryptedData,
  86. iv,
  87. code
  88. } = e.detail;
  89. const loginRes = await wx.login();
  90. const wxcode = loginRes.code;
  91. try{
  92. const openidRes = await wxLoginOpenid({code : wxcode})
  93. if(openidRes?.data){
  94. const { openid, sessionKey } = openidRes.data
  95. const phoneRes = await wxloginPhone({ openid, phoneCode: code})
  96. const { phone, token, isNewUser } = phoneRes.data;
  97. authStore.setPhone(phone);
  98. authStore.setAuthToken(token);
  99. uni.reLaunch({
  100. url: "/pages/register/register?mode=refine"
  101. })
  102. // if(isNewUser){
  103. // //新用户,跳转:完善用户信息
  104. // // console.log("完善用户信息")
  105. // uni.reLaunch({
  106. // url: "/pages/register/register?mode=refine"
  107. // })
  108. // }else{
  109. // // 老用户,跳转至:首页
  110. // msgSuccess("授权成功!")
  111. // setTimeout(()=>{
  112. // uni.switchTab({
  113. // url: "/pages/index/index"
  114. // })
  115. // }, 1000)
  116. // }
  117. }
  118. }catch(err){
  119. console.log("ee", err)
  120. }
  121. // 将 encryptedData 和 iv 发送到后端进行解密
  122. } else {
  123. msg('取消授权手机号');
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .form-item .u-input--border {
  129. border-radius: 16rpx !important;
  130. }
  131. .custom-button {
  132. .u-btn {
  133. display: block !important;
  134. width: fit-content;
  135. padding: 0 !important;
  136. border-radius: 50rpx;
  137. }
  138. .u-btn--default {
  139. border: none !important;
  140. background-color: transparent !important;
  141. }
  142. }
  143. </style>
  144. <style lang="scss" scoped>
  145. .app-login-page {
  146. background-color: #ffffff;
  147. width: 100vw;
  148. height: 100vh;
  149. display: flex;
  150. justify-content: center;
  151. align-items: center;
  152. }
  153. .app-login {
  154. width: 90%;
  155. }
  156. .app-icon {
  157. text-align: center;
  158. }
  159. .app-title {
  160. text-align: center;
  161. font-size: 44rpx;
  162. letter-spacing: 2px;
  163. font-weight: 700;
  164. }
  165. .mb-30 {
  166. margin-bottom: 30rpx;
  167. }
  168. .login-button {
  169. background: linear-gradient(90deg, #006af5, #21b0fc);
  170. border-radius: 20rpx;
  171. line-height: 80rpx;
  172. text-align: center;
  173. color: #fff;
  174. margin-bottom: 50rpx;
  175. width: 550rpx;
  176. margin: 0 auto;
  177. font-size: 32rpx;
  178. letter-spacing: 4rpx;
  179. }
  180. .other-button{
  181. color: #006af5;
  182. background: #e5e5e5;
  183. }
  184. // 用户手册模拟态
  185. .modal {
  186. .modal-content {
  187. padding: 50rpx;
  188. .content-a {
  189. color: #2979ff;
  190. }
  191. }
  192. }
  193. </style>