login.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class='page'>
  3. <view class='bottom'>
  4. <!-- #ifdef MP-WEIXIN -->
  5. <button class='wxlogin' open-type='getUserInfo' @getuserinfo = "modalcancel">微信登录</button>
  6. <!-- #endif -->
  7. <button class='zhlogin' >账号登录</button>
  8. </view>
  9. </view>
  10. </template>
  11. <script>import {
  12. mapMutations
  13. } from "vuex"
  14. export default {
  15. data () {
  16. return {
  17. }
  18. },
  19. methods:{
  20. ...mapMutations(["setUserinfo"]),
  21. // 账号登录 手机号授权
  22. modalconfirm: function (e) {
  23. console.log("111111111111", e)
  24. },
  25. // 微信登录
  26. modalcancel: function (e) {
  27. console.log(e)
  28. var that = this;
  29. if (e.detail.errMsg != 'getUserInfo:ok') {
  30. //用户拒绝
  31. console.log("拒绝授权", e);
  32. } else {
  33. console.log("用户允许微信授权", e);
  34. uni.showLoading({
  35. title:"加载中..."
  36. })
  37. // 这里可以发送code到后台换取秘钥
  38. this.setUserinfo(e.detail.userInfo)
  39. setTimeout(function() {
  40. uni.hideLoading()
  41. uni.reLaunch({
  42. url:"/pages/index/index"
  43. })
  44. }, 100);
  45. }
  46. },
  47. }
  48. }
  49. </script>
  50. <style scoped>
  51. .page{
  52. position: fixed;
  53. top: 0;
  54. left: 0;
  55. width: 100%;
  56. height: 100%;
  57. }
  58. .bottom{
  59. box-sizing: border-box;
  60. position: absolute;
  61. bottom: 100rpx;
  62. width: 100%;
  63. }
  64. .bottom .wxlogin,
  65. .bottom .zhlogin{
  66. background: #1296db;
  67. font-size: 32rpx;
  68. color: #fff;
  69. width: 80%;
  70. margin: 30rpx auto;
  71. }
  72. </style>