wx-login.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <fs-modal v-model="modelValue" :showTitle="false" :showCancel="false" :showConfirm="false" :maskClickable="maskClickable">
  3. <view style="padding: 20rpx;">
  4. <view class="title bold" style="font-size: 18px;margin-bottom: 30rpx;">授权微信访问</view>
  5. <view class="content" style="font-size: 15px;">
  6. 为了保护他人的隐私,授权后可查看对方的名片
  7. </view>
  8. <view class="wxlogin-btn">
  9. <fs-button full round type="success" @click="getUserProfile" v-if="canIUseGetUserProfile">授权微信</fs-button>
  10. <fs-button full round type="success" open-type="getUserInfo" @getuserinfo="getUserInfo" v-else>授权微信</fs-button>
  11. </view>
  12. <view class="footer">
  13. <fs-checkbox-group v-model="checkboxArray" checkedColorType="primary">
  14. <fs-checkbox value="1">
  15. <view class="sub">
  16. 同意<text @click="read('/modules/common/about/agreement')">《用户服务协议》</text>和<text @click="read('/modules/common/about/policy')">《隐私政策》</text>
  17. </view>
  18. </fs-checkbox>
  19. </fs-checkbox-group>
  20. </view>
  21. </view>
  22. </fs-modal>
  23. </template>
  24. <script setup>
  25. import { ref } from 'vue'
  26. import { wxLogin } from '@/services/common'
  27. const props = defineProps({
  28. modelValue: Boolean,
  29. maskClickable: {
  30. type: Boolean,
  31. default: true
  32. }
  33. })
  34. const emits = defineEmits(['update:modelValue', 'success'])
  35. const checkboxArray = ref(['1'])
  36. const canIUseGetUserProfile = ref(wx.getUserProfile ? true : false)
  37. const getUserProfile = () => {
  38. if (!checkboxArray.value.length) {
  39. return uni.showToast({
  40. title: '请勾选用户协议和隐私政策',
  41. icon: 'none'
  42. })
  43. }
  44. wx.getUserProfile({
  45. desc: '用于完善会员资料',
  46. }).then(res => {
  47. login(res)
  48. })
  49. }
  50. const getUserInfo = e => {
  51. if (!checkboxArray.value.length) {
  52. return uni.showToast({
  53. title: '请先勾选用户协议和隐私政策',
  54. icon: 'none'
  55. })
  56. }
  57. login(e)
  58. }
  59. const closeModal = () => {
  60. emits('update:modelValue', false)
  61. }
  62. const login = data => {
  63. wxLogin(data).then(() => {
  64. closeModal()
  65. emits('success')
  66. }).catch(() => {
  67. closeModal()
  68. })
  69. }
  70. const read = url => {
  71. uni.navigateTo({
  72. url
  73. })
  74. }
  75. </script>
  76. <style scoped>
  77. .wxlogin-btn{
  78. margin: 30rpx 0;
  79. }
  80. </style>