initial.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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="`${FILE_URL}/login-icon.png`"
  6. mode="aspectFit" style="height: 80rpx;"></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 { onLoad } from '@dcloudio/uni-app'
  43. import { wxLoginOpenid, wxloginPhone } from '@/api/login.js'
  44. import {
  45. msg,
  46. msgSuccess,
  47. alert
  48. } from "@/utils/common.js"
  49. import { ref } from 'vue'
  50. import {
  51. useAuthStore
  52. } from '@/store/authStore'
  53. import {
  54. me
  55. } from '@/api/user.js'
  56. import configService from '@/utils/baseurl.js'
  57. const FILE_URL = configService.FILE_URL;
  58. const authStore = useAuthStore()
  59. const userBook = ref(true)
  60. const userBookModal = ref(false)
  61. function toLogin() {
  62. uni.navigateTo({
  63. url: "/pages/login/login"
  64. })
  65. }
  66. async function wxlogin(){
  67. const loginRes = await wx.login();
  68. const code = loginRes.code;
  69. wxLoginOpenid({code}).then(res=>{
  70. if(res?.data){
  71. const { openid, sessionKey } = res.data
  72. }
  73. })
  74. }
  75. function confirmModal() {
  76. userBook.value = true
  77. // this.wxlogin()
  78. }
  79. function checkUserBook() {
  80. if (!userBook.value) {
  81. userBookModal.value = true
  82. return false;
  83. }
  84. return true
  85. }
  86. function check(){
  87. if (!checkUserBook()) return;
  88. }
  89. async function decryptPhoneNumber(e){
  90. if (e.detail.encryptedData) {
  91. const {
  92. encryptedData,
  93. iv,
  94. code
  95. } = e.detail;
  96. const loginRes = await wx.login();
  97. const wxcode = loginRes.code;
  98. try{
  99. const openidRes = await wxLoginOpenid({code : wxcode})
  100. if(openidRes?.data){
  101. const { openid, sessionKey } = openidRes.data
  102. authStore.setOpenid(openid);
  103. const phoneRes = await wxloginPhone({ openid, phoneCode: code})
  104. const { phone, isNewUser } = phoneRes.data;
  105. authStore.setPhone(phone);
  106. // uni.reLaunch({
  107. // url: "/pages/register/register?mode=refine"
  108. // })
  109. if(isNewUser){
  110. //新用户,跳转:完善用户信息
  111. // console.log("完善用户信息")
  112. uni.reLaunch({
  113. url: "/pages/register/register?mode=refine"
  114. })
  115. }else{
  116. const { token } = phoneRes.data;
  117. authStore.setAuthToken(token);
  118. // 老用户,跳转至:首页
  119. msgSuccess("授权成功!")
  120. let userRes = await me();
  121. if(userRes && userRes?.code===0){
  122. authStore.setUserInfo(userRes.data)
  123. setTimeout(()=>{
  124. uni.switchTab({
  125. url: "/pages/index/index"
  126. })
  127. }, 1000)
  128. }
  129. }
  130. }
  131. }catch(err){
  132. console.log("ee", err)
  133. }
  134. // 将 encryptedData 和 iv 发送到后端进行解密
  135. } else {
  136. msg('取消授权手机号');
  137. }
  138. }
  139. onLoad((load) => {
  140. if (load.isCancelAccount) {
  141. alert('账号注销7个工作日内,您无法通过相同手机号或身份证重新注册/登录广州市房地产中介协会会员中心小程序账号。', '提示')
  142. }
  143. })
  144. </script>
  145. <style lang="scss">
  146. .form-item .u-input--border {
  147. border-radius: 16rpx !important;
  148. }
  149. .custom-button {
  150. .u-btn {
  151. display: block !important;
  152. width: fit-content;
  153. padding: 0 !important;
  154. border-radius: 50rpx;
  155. }
  156. .u-btn--default {
  157. border: none !important;
  158. background-color: transparent !important;
  159. }
  160. }
  161. </style>
  162. <style lang="scss" scoped>
  163. .app-login-page {
  164. background-color: #ffffff;
  165. width: 100vw;
  166. height: 100vh;
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. }
  171. .app-login {
  172. width: 90%;
  173. }
  174. .app-icon {
  175. display: flex;
  176. justify-content: center;
  177. align-items: center;
  178. height: 90rpx;
  179. text-align: center;
  180. }
  181. .app-title {
  182. text-align: center;
  183. font-size: 44rpx;
  184. letter-spacing: 2px;
  185. font-weight: 700;
  186. }
  187. .mb-30 {
  188. margin-bottom: 30rpx;
  189. }
  190. .login-button {
  191. background: linear-gradient(90deg, #006af5, #21b0fc);
  192. border-radius: 20rpx;
  193. line-height: 80rpx;
  194. text-align: center;
  195. color: #fff;
  196. margin-bottom: 50rpx;
  197. width: 550rpx;
  198. margin: 0 auto;
  199. font-size: 32rpx;
  200. letter-spacing: 4rpx;
  201. }
  202. .other-button{
  203. color: #006af5;
  204. background: #e5e5e5;
  205. }
  206. // 用户手册模拟态
  207. .modal {
  208. .modal-content {
  209. padding: 50rpx;
  210. .content-a {
  211. color: #2979ff;
  212. }
  213. }
  214. }
  215. </style>