index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="ss-p-30 head-box">
  3. <template v-if="changeType === 'login'">
  4. <view class="head-title ss-m-b-30 MiSans-Semibold">欢迎来到辞图科技,请先登录</view>
  5. <view class="ss-m-t-100">
  6. <view>
  7. <button
  8. v-if="!protocol"
  9. class="send-button MiSans-Medium"
  10. @click="showProtocolToast"
  11. >
  12. 手机号快捷登录
  13. </button>
  14. <button
  15. v-else
  16. class="send-button MiSans-Medium"
  17. :loading="phoneNumberLoading"
  18. :disabled="phoneNumberLoading"
  19. open-type="getPhoneNumber"
  20. @getphonenumber="getPhoneNumber"
  21. >
  22. 手机号快捷登录
  23. </button>
  24. </view>
  25. <view class="ss-flex ss-row-center ss-m-y-50">
  26. <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00B760' : '#ccc'" @tap="protocol = !protocol"></uni-icons>
  27. <view class="color-999 ss-flex ss-col-center ss-m-l-8 font-size-13">
  28. <span class="MiSans-Normal">我已阅读并遵守</span>
  29. <view class="color-primary MiSans-Medium" @tap.stop="handleToDetail('user')">
  30. 《用户协议》
  31. </view>
  32. <view class="agreement-text MiSans-Normal">和</view>
  33. <view class="color-primary MiSans-Medium" @tap.stop="handleToDetail('privacy')">
  34. 《隐私协议》
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. </view>
  41. </template>
  42. <script setup>
  43. import { ref } from 'vue'
  44. import { userStore } from '@/store/user'
  45. const useUserStore = userStore()
  46. const phoneNumberLoading = ref(false)
  47. const protocol = ref(false)
  48. const changeType = ref('login')
  49. // 查看协议详情
  50. const handleToDetail = (type) => {
  51. const url = type === 'user' ? '/pagesA/agreement/user' : '/pagesA/agreement/privacy'
  52. uni.navigateTo({
  53. url
  54. })
  55. }
  56. const showProtocolToast = () => {
  57. uni.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
  58. }
  59. // 微信登录
  60. const getPhoneNumber = async (e) => {
  61. if (e?.detail?.errMsg !== 'getPhoneNumber:ok') {
  62. uni.showToast({ title: '微信登录失败', icon: 'none' })
  63. return
  64. }
  65. changeType.value = 'login'
  66. phoneNumberLoading.value = true
  67. wx.login({
  68. success: async (result) => {
  69. console.log(result, '微信登录返回res', e)
  70. const wxLoginCode = result?.code || ''
  71. const query = {
  72. loginCode: wxLoginCode,
  73. phoneCode: e.detail.code,
  74. state: e.detail.encryptedData,
  75. }
  76. // await useUserStore.handleSmsLogin(query, current.value)
  77. phoneNumberLoading.value = false
  78. },
  79. fail:(res)=> {
  80. phoneNumberLoading.value = false
  81. console.log("获取登录凭证code失败!", res)
  82. }
  83. })
  84. }
  85. </script>
  86. <style scoped lang="scss">
  87. .head-title {
  88. font-size: 40rpx;
  89. text-align: center;
  90. color: #00B760;
  91. margin-top: 30rpx;
  92. }
  93. </style>