login.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="bg">
  3. <view class="p">
  4. <image src="../../static/favicon.png" class="pic" mode="widthFix"></image>
  5. </view>
  6. <view class="title">承揽时代:</view>
  7. <view class="info">您的公开信息(昵称,头像等)</view>
  8. <button class="btn" @click="getUserProfile()" :disabled="disabled">微信一键登录</button>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. disabled: false //防止重复点击
  16. };
  17. },
  18. methods: {
  19. getUserProfile() {
  20. this.disabled = true;
  21. let code = '';
  22. uni.login({
  23. provider: 'weixin',
  24. success: (res) => {
  25. code = res.code;
  26. }
  27. });
  28. //获取用户信息
  29. uni.getUserProfile({
  30. desc: '用于完善会员资料',
  31. lang: 'zh_CN',
  32. provider: 'weixin',
  33. success: (info) => {
  34. let item = info.userInfo;
  35. item.code = code;
  36. this.http.request({
  37. url: '/app/user/login',
  38. data: item,
  39. method: 'POST',
  40. success: (res) => {
  41. this.disabled = false;
  42. uni.setStorageSync('user', res.data.data);
  43. uni.navigateBack();
  44. },
  45. fail: (res) => {
  46. this.disabled = false;
  47. }
  48. });
  49. },
  50. fail: (res) => {
  51. this.disabled = false;
  52. }
  53. });
  54. },
  55. cancel() {
  56. uni.navigateBack();
  57. }
  58. }
  59. };
  60. </script>
  61. <style lang="scss">
  62. .bg {
  63. padding: 30px;
  64. .p {
  65. text-align: center;
  66. padding: 15px;
  67. .pic {
  68. width: 90px;
  69. height: 90px;
  70. border-radius: 50%;
  71. }
  72. }
  73. .title {
  74. font-weight: bold;
  75. font-size: 16px;
  76. color: $font-c;
  77. }
  78. .info {
  79. color: #8b918d;
  80. margin-top: 10px;
  81. font-size: 13px;
  82. .icon {
  83. padding-right: 3px;
  84. }
  85. }
  86. .btn {
  87. margin-top: 20px;
  88. border-radius: 30px;
  89. }
  90. }
  91. </style>