index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="content">
  3. <view class="wx">
  4. <view class="wx_1">
  5. <text class="iconfont icon-weixin"></text>
  6. </view>
  7. <view class="wx_2">
  8. <button size="mini" @tap="otherLogin('wx')">微信信任登录</button>
  9. </view>
  10. <view class="wx_3">
  11. <checkbox-group @change="changeAgree">
  12. <label>
  13. <checkbox :checked="agree" />
  14. <text @tap.stop="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
  15. </label>
  16. </checkbox-group>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script setup lang="ts">
  22. import moment from 'moment';
  23. import { getCurrentInstance, computed, ref } from 'vue';
  24. // 请求接口
  25. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  26. // openid
  27. const openid = computed(() => {
  28. return uni.getStorageSync('openid');
  29. })
  30. // 用户协议
  31. const agree = ref(false);
  32. // 其他登录方式
  33. const otherLogin = () => {
  34. if (agree.value) {
  35. if (openid.value) {
  36. uni.getUserProfile({
  37. desc: '用于展示',
  38. success: async function (res) {
  39. let parmas = {
  40. openid: openid.value,
  41. icon: res.userInfo.avatarUrl,
  42. nickname: res.userInfo.nickName + moment().valueOf()
  43. }
  44. const arr = await that.$api(`matchUser`, 'POST', parmas);
  45. if (arr.code === 200) {
  46. uni.setStorage({
  47. key: 'user',
  48. data: arr.data,
  49. success: function () {
  50. uni.navigateBack({
  51. delta: 1
  52. })
  53. }
  54. });
  55. } else {
  56. uni.showToast({
  57. title: arr.msg,
  58. icon: 'error'
  59. });
  60. }
  61. },
  62. fail: function (err) {
  63. console.log(err);
  64. }
  65. })
  66. } else {
  67. uni.showToast({
  68. title: '系统更新中,请稍后再试!',
  69. icon: 'none'
  70. })
  71. }
  72. } else {
  73. uni.showToast({
  74. title: '请阅读并同意用户协议和隐私政策',
  75. icon: 'none'
  76. })
  77. }
  78. };
  79. // 查看隐私协议
  80. const toAgree = () => {
  81. uni.navigateTo({
  82. url: `/pagesHome/agree/index`
  83. })
  84. };
  85. </script>
  86. <style lang="scss" scoped>
  87. .content {
  88. display: flex;
  89. flex-direction: column;
  90. .wx {
  91. text-align: center;
  92. margin: 25vw 0 0 0;
  93. .wx_1 {
  94. margin: 0 0 5vw 0;
  95. text {
  96. font-size: 50px;
  97. color: var(--f35BColor);
  98. }
  99. }
  100. .wx_2 {
  101. button {
  102. background: var(--f35BColor);
  103. color: var(--fffColor);
  104. font-size: var(--font16Size);
  105. }
  106. }
  107. .wx_3 {
  108. position: absolute;
  109. bottom: 10vw;
  110. width: 100vw;
  111. text-align: center;
  112. font-size: 12px;
  113. }
  114. }
  115. }
  116. </style>