bindPhone.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view>
  3. <u-notify ref="uNotify"></u-notify>
  4. <view class="logoBox text-center">
  5. <view class="logo">
  6. <!-- <u--image :showLoading="true" shape="circle" :src="getFilePath(logo)" width="100px" height="100px"></u--image> -->
  7. </view>
  8. <view class="">欢迎加入{{appName}}</view>
  9. </view>
  10. <view class="invalidColor fz14px text-center mb20px">申请获取您的微信绑定手机号</view>
  11. <view class="contain">
  12. <u-button text="一键注册" type="success" openType="getPhoneNumber" @getphonenumber="decryptPhoneNumber"></u-button>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. // import {
  18. // logo
  19. // } from '../../env/dev';
  20. export default {
  21. data() {
  22. return {
  23. // logo: this.logo,
  24. // appName: this.appName
  25. appName: '餐车活动'
  26. };
  27. },
  28. onLoad(options) { // 监听页面加载
  29. },
  30. onUnload() { // 监听页面卸载
  31. },
  32. onShow() { // 监听页面显示
  33. },
  34. onHide() { // 监听页面隐藏
  35. },
  36. onReachBottom() { // 上拉触底
  37. },
  38. methods: {
  39. async decryptPhoneNumber(e) {
  40. // 获取手机号
  41. let result = await this.$request('post', '/userinfo/auth/getWxPhone', {
  42. code: e.detail.code,
  43. appid: this.appId
  44. })
  45. if (!result) {
  46. uni.showToast({
  47. title: '授权失败',
  48. icon: 'success'
  49. })
  50. return
  51. }
  52. const code = await new Promise((resolve) => {
  53. uni.login({
  54. success: (res) => {
  55. resolve(res.code)
  56. },
  57. fail: () => {
  58. resolve(false)
  59. }
  60. })
  61. })
  62. // 注册
  63. const res = await this.$request('post', '/userinfo/auth/bindPhone', {
  64. code,
  65. appid: this.appId,
  66. phone: result.msg
  67. })
  68. if (res) {
  69. uni.showToast({
  70. title: '注册成功',
  71. icon: 'success'
  72. })
  73. uni.setStorageSync("token", res.data.token);
  74. await this.getUser()
  75. uni.navigateBack(-1)
  76. }
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .logoBox {
  83. margin: 200rpx 0 300rpx;
  84. .logo {
  85. display: inline-block;
  86. }
  87. }
  88. </style>