index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view>
  3. <view class="logo_box">
  4. <image src="../../static/logo2.jpg" class="logo_image"></image>
  5. </view>
  6. <!-- #ifdef MP-WEIXIN -->
  7. <button open-type="getPhoneNumber" @getphonenumber="getPhonenumber" class="get_phone">授权登录</button>
  8. <!-- #endif -->
  9. <!-- #ifdef H5 -->
  10. <button @click="toPhoneLogin" class="get_phone">授权登录</button>
  11. <!-- #endif -->
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {};
  18. },
  19. methods: {
  20. getPhonenumber(re) {
  21. // // 如果授权失败的话
  22. if (re.detail.errMsg != "getPhoneNumber:ok") {
  23. uni.showToast({
  24. icon: "error",
  25. title: "授权失败",
  26. });
  27. return;
  28. }
  29. // 授权成功以后,调用登录
  30. this.$http.request("api/wechat/phone_number", { code: re.detail.code }, "post").then((re) => {
  31. // 成功的话
  32. if (re.code == "success") {
  33. // 存储登录标识
  34. uni.setStorageSync("userLogin", re.data);
  35. // 跳转到页面
  36. uni.switchTab({ url: "/pages/user/index" });
  37. } else {
  38. uni.showToast({
  39. title: re.msg,
  40. icon: "none",
  41. });
  42. }
  43. });
  44. },
  45. toPhoneLogin(re) {
  46. // 登录效果
  47. this.$http.request("api/wechat/phone_number", this.requestParam).then((re) => {
  48. // 成功的话
  49. if (re.code == "success") {
  50. // 存储登录标识
  51. uni.setStorageSync("userLogin", re.data);
  52. // 跳转到页面
  53. uni.switchTab({ url: "/pages/user/index" });
  54. } else {
  55. uni.showToast({
  56. title: re.msg,
  57. icon: "none",
  58. });
  59. }
  60. });
  61. },
  62. },
  63. };
  64. </script>
  65. <style lang="less">
  66. .logo_box {
  67. display: block;
  68. margin: 0rpx auto;
  69. margin-top: 80rpx;
  70. .logo_image {
  71. width: 320rpx;
  72. height: 320rpx;
  73. display: block;
  74. margin: 0rpx auto;
  75. }
  76. }
  77. .get_phone {
  78. display: block;
  79. width: 180rpx;
  80. height: 60rpx;
  81. color: #ffffff;
  82. font-size: 28rpx;
  83. background: green;
  84. margin: 0rpx auto;
  85. line-height: 60rpx;
  86. margin-top: 160rpx;
  87. border-radius: 30rpx;
  88. border: 0rpx solid #dddddd;
  89. }
  90. .get_phone::after {
  91. border: 0rpx solid #dddddd;
  92. }
  93. </style>