initial.vue 5.4 KB

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