login.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="content">
  3. <u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</u-button>
  4. </view>
  5. </template>
  6. <script>
  7. import {
  8. login
  9. } from "@/api/login.js"
  10. export default {
  11. components: {},
  12. data() {
  13. return {
  14. path: '/pages/index/index',
  15. lanuch: true
  16. }
  17. },
  18. onShow() {
  19. },
  20. mounted() {},
  21. onLoad(option) {
  22. console.log(option)
  23. const {
  24. path,
  25. lanuch
  26. } = option;
  27. this.lanuch = (lanuch + '') === 'true';
  28. if (path) {
  29. this.path = decodeURIComponent(path);
  30. }
  31. },
  32. methods: {
  33. getPhoneNumber(e) {
  34. let _this = this
  35. uni.showLoading({
  36. mask: true,
  37. title: '加载中'
  38. });
  39. console.log(e.target.encryptedData,'eeeeeee')
  40. if (e.target.errMsg === 'getPhoneNumber:ok') {
  41. uni.login({
  42. success(res) {
  43. login({
  44. code: res.code,
  45. encryptedData: e.target.encryptedData,
  46. iv: e.target.iv
  47. }).then(res => {
  48. uni.hideLoading();
  49. console.log(res, 'login data')
  50. if (res.status == '200') {
  51. console.log(res.data, 'login data')
  52. getApp().globalData.token = res.data
  53. _this.$u.vuex('vuex_token',res.data)
  54. if (_this.path === '/pages/index/main' || _this.lanuch) {
  55. uni.reLaunch({
  56. url: _this.path
  57. });
  58. } else {
  59. uni.redirectTo({
  60. url: _this.path
  61. });
  62. }
  63. } else {
  64. uni.showToast({
  65. title: res.message,
  66. icon: 'none',
  67. duration: 2500
  68. });
  69. }
  70. });
  71. }
  72. })
  73. } else {
  74. uni.showToast({
  75. title: '授权失败',
  76. icon: 'none',
  77. duration: 2500
  78. });
  79. }
  80. }
  81. }
  82. }
  83. </script>
  84. <style>
  85. .content {
  86. padding: 0;
  87. display: flex;
  88. align-items: center;
  89. justify-content: center;
  90. }
  91. </style>