login.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="bg">
  3. <view class="p">
  4. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717472782145.jpg" class="pic" mode="widthFix"></image>
  5. </view>
  6. <view class="xy">
  7. <u-checkbox-group class="checkbox" v-model="item.checked">
  8. <u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="14" name="true"></u-checkbox>
  9. </u-checkbox-group>
  10. <text class="a" @click="go('/pages/other/agreement?title=用户协议')">《用户协议》</text>
  11. <text>和</text>
  12. <text class="a" @click="go('/pages/other/agreement?title=隐私政策')">《隐私政策》</text>
  13. </view>
  14. <button class="btn" @click="getUserProfile()" :disabled="disabled">微信一键登录</button>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. item: {},
  22. disabled: false //防止重复点击
  23. };
  24. },
  25. methods: {
  26. getUserProfile() {
  27. let rule = [{ name: 'checked', checkType: 'notnull', errorMsg: '请同意并勾选协议' }];
  28. if (!this.verify.check(this.item, rule)) {
  29. uni.showModal({ content: this.verify.error, showCancel: false });
  30. return false;
  31. }
  32. this.disabled = true;
  33. let code = '';
  34. uni.login({
  35. provider: 'weixin',
  36. success: (res) => {
  37. code = res.code;
  38. }
  39. });
  40. //获取用户信息
  41. uni.getUserProfile({
  42. desc: '用于完善会员资料',
  43. lang: 'zh_CN',
  44. provider: 'weixin',
  45. success: (info) => {
  46. let item = info.userInfo;
  47. item.code = code;
  48. this.http.request({
  49. url: '/app/user/login',
  50. data: item,
  51. method: 'POST',
  52. success: (res) => {
  53. this.disabled = false;
  54. uni.setStorageSync('user', res.data.data);
  55. uni.navigateBack();
  56. },
  57. fail: (res) => {
  58. this.disabled = false;
  59. }
  60. });
  61. },
  62. fail: (res) => {
  63. this.disabled = false;
  64. }
  65. });
  66. },
  67. go(url) {
  68. uni.navigateTo({ url: url });
  69. }
  70. }
  71. };
  72. </script>
  73. <style lang="scss">
  74. .bg {
  75. padding: 30px;
  76. .p {
  77. text-align: center;
  78. padding: 45px 15px 15px 15px;
  79. .pic {
  80. width: 150px;
  81. height: 150px;
  82. border-radius: 50%;
  83. }
  84. }
  85. }
  86. </style>