login.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view class="bg">
  3. <view class="title">智慧旅游小程序正在使用智慧旅游平台登陆提供的服务,平台登陆将使用:</view>
  4. <view class="info">
  5. <text class="icon"></text>
  6. <text v-if="first">您的公开信息(昵称,头像,性别等)</text>
  7. <text v-else>您的手机号</text>
  8. </view>
  9. <button class="btn" @click="getUserProfile()" v-if="first">允许使用</button>
  10. <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" style="background-color: #2196F3" v-else>允许使用</button>
  11. <button class="btn" style="background-color: #9E9E9E;" @click="cancel()">取消</button>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. item: {},
  19. first: true
  20. };
  21. },
  22. onLoad() {},
  23. methods: {
  24. getUserProfile() {
  25. //获取用户信息
  26. uni.getUserProfile({
  27. desc: '用于完善会员资料',
  28. lang: 'zh_CN',
  29. provider: 'weixin',
  30. success: info => {
  31. console.log('登陆:' + JSON.stringify(info));
  32. uni.login({
  33. provider: 'weixin',
  34. success: res => {
  35. console.log("res:"+JSON.stringify(res));
  36. this.$http.request({
  37. url: this.$http.urls.wxLogin+res.code,
  38. data:info,
  39. method:'POST',
  40. success: res => {
  41. res.data.data.memberInfo.apiToken=res.data.data.apiToken;
  42. uni.setStorageSync('user', res.data.data.memberInfo);
  43. uni.navigateBack({ delta: 1 });
  44. }
  45. });
  46. }
  47. });
  48. }
  49. });
  50. },
  51. // 绑定用户手机号
  52. getPhoneNumber(e) {
  53. uni.login({
  54. provider: 'weixin',
  55. success: res => {
  56. this.item.code = res.code;
  57. this.item.encryptedData = e.target.encryptedData;
  58. this.item.iv = e.target.iv;
  59. this.$http.request({
  60. url: this.$http.urls.bindPhone,
  61. data: this.item,
  62. success: res => {
  63. uni.setStorageSync('user', res.data.data);
  64. uni.$emit('update');
  65. uni.navigateBack({ delta: 1 });
  66. }
  67. });
  68. }
  69. });
  70. },
  71. cancel() {
  72. uni.navigateBack();
  73. }
  74. }
  75. };
  76. </script>
  77. <style lang="less">
  78. page {
  79. background-color: white;
  80. }
  81. .bg {
  82. padding: 30px;
  83. .title {
  84. font-weight: bold;
  85. }
  86. .info {
  87. color: #8b918d;
  88. margin-top: 10px;
  89. }
  90. .btn {
  91. margin-top: 20px;
  92. }
  93. }
  94. </style>