index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <route lang="yaml">
  2. style:
  3. navigationBarTitleText: 登录
  4. </route>
  5. <script lang="ts" setup>
  6. import { weixinMiniAppLogin } from '../../core/libs/requests'
  7. import { logo } from '../../core/libs/svgs'
  8. import { useUserStore } from '../../store'
  9. const userStore = useUserStore()
  10. const { setUserInfo } = userStore
  11. const loginCode = ref('')
  12. const phoneCode = ref('')
  13. const getPhoneNumber = async ({ detail: { code: phoneCode } }) => {
  14. const { code } = await uni.login()
  15. console.log(code, phoneCode)
  16. const { data } = await weixinMiniAppLogin(phoneCode, code, '9b2ffbc1-7425-4155-9894-9d5c08541d62')
  17. setUserInfo({
  18. token: data.accessToken,
  19. userId: data.userId,
  20. accessToken: data.accessToken,
  21. refreshToken: data.refreshToken,
  22. expiresTime: data.expiresTime,
  23. openid: data.openid,
  24. })
  25. uni.switchTab({
  26. url: '/pages/mine/index',
  27. })
  28. }
  29. const getTestCode = async ({ detail }) => {
  30. phoneCode.value = detail.code
  31. const { code } = await uni.login()
  32. loginCode.value = code
  33. }
  34. </script>
  35. <template>
  36. <div class="flex-grow flex flex-col items-center justify-around px-3.5">
  37. <div>
  38. <wd-img :src="logo" width="78" height="78"></wd-img>
  39. <div class="text-black text-2xl font-normal font-['PingFang SC'] leading-[10.18px]">
  40. 筑巢荟
  41. </div>
  42. </div>
  43. <div class="w-full">
  44. <button
  45. type="primary"
  46. size="large"
  47. :style="{
  48. backgroundColor: 'black',
  49. }"
  50. open-type="getPhoneNumber"
  51. @getphonenumber="getPhoneNumber"
  52. >
  53. 手机号一键登录
  54. </button>
  55. <div class="w-[318px] mt-8">
  56. <span class="text-black/40 text-xs font-normal font-['PingFang SC'] leading-tight">
  57. 如您点击授权,您将同意并授权
  58. </span>
  59. <span class="text-[#0cbe7c] text-xs font-normal font-['PingFang SC'] leading-tight">
  60. 《筑巢荟用户服务协议》、《隐私政策》、《注册协议》
  61. </span>
  62. </div>
  63. </div>
  64. </div>
  65. <!-- <view class="content">
  66. <textarea v-model="loginCode" placeholder="" placeholder-class="textarea-placeholder" />
  67. <textarea v-model="phoneCode" placeholder="" placeholder-class="textarea-placeholder" />
  68. <button style="margin: 20px 0 20px 0" @click="toUserInfoPage">个人资料</button>
  69. <uni-forms-item label="切换登录方式" labelWidth="70">
  70. <uni-data-checkbox
  71. :multiple="false"
  72. v-model="loginType"
  73. :localdata="loginTypeOption"
  74. mode="button"
  75. ></uni-data-checkbox>
  76. </uni-forms-item>
  77. <button @click="weixinLogin">前往登录</button> -->
  78. <!-- #ifdef MP-WEIXIN -->
  79. <!-- <button type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"> -->
  80. <!-- 手机号一键登录
  81. </button> -->
  82. <!-- #endif -->
  83. <!-- #ifdef MP-WEIXIN -->
  84. <!-- <button type="primary" open-type="getPhoneNumber" @getphonenumber="getTestCode">
  85. 获取测试码
  86. </button> -->
  87. <!-- #endif -->
  88. <!-- </view> -->
  89. </template>
  90. <style lang="scss">
  91. .content {
  92. display: flex;
  93. flex-direction: column;
  94. align-items: center;
  95. justify-content: center;
  96. padding: 6rpx;
  97. }
  98. .logo {
  99. width: 200rpx;
  100. height: 200rpx;
  101. margin-top: 200rpx;
  102. margin-right: auto;
  103. margin-bottom: 50rpx;
  104. margin-left: auto;
  105. }
  106. .text-area {
  107. display: flex;
  108. justify-content: center;
  109. }
  110. .title {
  111. font-size: 18px;
  112. color: #8f8f94;
  113. }
  114. </style>