login.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="regbox" v-if="loginflag">
  3. <image :src="lbg" class="navbg"></image>
  4. <image :src="fbg" class="fbg"></image>
  5. <view class="wymain">
  6. <image :src="headimg" class="headimg"></image>
  7. <!-- 微信登录 -->
  8. <button type="primary" class="rbtn" open-type="getUserInfo" @getuserinfo="getuserinfo">
  9. <image :src="vxtab" class="vxtab"></image>
  10. <text class="btn-txt">微信一键登录</text>
  11. </button>
  12. <button type="primary" class=" rbtn" @click="getlogin">
  13. <image :src="zhtab" class="zhtab"></image>
  14. <text class="btn-txt">账号密码登录</text>
  15. </button>
  16. <view class="line"></view>
  17. <view class="rbtn btna" @click="getregister">还没账号?去注册</view>
  18. </view>
  19. <phone-btn :type="typeflag" @getPhoneNumber='getPhoneNumber' @getClose="getClose"></phone-btn>
  20. </view>
  21. </template>
  22. <script>
  23. import * as base64 from "base-64"
  24. // import {getUserProfile} from "@/api/system/user.js"
  25. import {
  26. getToken
  27. } from '@/utils/auth'
  28. import phoneBtn from "@/components/toptab/phonebtn.vue"
  29. export default {
  30. components: {
  31. phoneBtn
  32. },
  33. data() {
  34. return {
  35. lbg: require('@/static/images/mine/lbg.png'),
  36. fbg: require('@/static/images/mine/fbg.png'),
  37. vxtab: require('@/static/images/mine/vxtab.png'),
  38. zhtab: require('@/static/images/mine/zhtab.png'),
  39. fbg: require('@/static/images/mine/fbg.png'),
  40. headimg: require('@/static/logo.png'),
  41. typeflag: false,
  42. loginflag: false,
  43. loginForm: {
  44. username: "",
  45. code: "",
  46. password: '',
  47. },
  48. }
  49. },
  50. methods: {
  51. handlePrivacy() {
  52. this.$tab.navigateTo(`/pages/agreement`)
  53. },
  54. getlogin(){
  55. this.$tab.navigateTo(`/pages/tlogin`)
  56. },
  57. getregister(){
  58. this.$tab.navigateTo(`/pages/register`)
  59. },
  60. async getuserinfo(e) {
  61. // if(!this.checkflag){
  62. // this.$toast("请同意用户协议")
  63. // return
  64. // }
  65. // 判断是不是有学校
  66. const {
  67. iv,
  68. encryptedData
  69. } = e.detail
  70. const {
  71. nickName,
  72. avatarUrl,
  73. ...userInfo
  74. } = e.detail.userInfo
  75. // console.log(e.detail)
  76. try {
  77. uni.login({
  78. provider: 'weixin',
  79. success: (res) => {
  80. // 获取用户信息
  81. if (res.code) {
  82. this.avatarUrl = avatarUrl
  83. this.nickName = nickName
  84. this.code = res.code
  85. this.userInfo = e.detail.userInfo
  86. uni.setStorageSync('userInfo', e.detail.userInfo)
  87. uni.setStorageSync('lcheckflag', true)
  88. this.typeflag = true;
  89. }
  90. }
  91. })
  92. } catch (e) {
  93. //TODO handle the exception
  94. }
  95. },
  96. getClose() {
  97. this.typeflag = false
  98. },
  99. getPhoneNumber(data) {
  100. var that = this;
  101. var params = data
  102. that.$store.dispatch('Login', params).then(() => {
  103. that.$modal.closeLoading()
  104. that.$toast('登录成功')
  105. that.typeflag = false;
  106. that.loginSuccess(data)
  107. }).catch(() => {
  108. // if (this.captchaEnabled) {
  109. // this.getCode()
  110. // }
  111. })
  112. },
  113. // 登录成功后,处理函数
  114. loginSuccess(result) {
  115. // 设置用户信息
  116. var that = this;
  117. this.$store.dispatch('GetInfo').then(res => {
  118. this.$tab.reLaunch('/pages/index')
  119. })
  120. },
  121. },
  122. onLoad: function() {
  123. if (getToken()) {
  124. this.$tab.reLaunch('/pages/index')
  125. // 判断有什么角色
  126. } else {
  127. this.loginflag = true;
  128. }
  129. },
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .navbg{width: 100%;height: 100vh;}
  134. .fbg{width: 100%;height: 750rpx;position: absolute;bottom: 0;left: 0;}
  135. .wymain{z-index: 2;position: relative;padding: 320rpx 60rpx;}
  136. .headimg{width: 110rpx;height: 110rpx;margin:0 auto 128rpx;display: block;}
  137. .rbtn {height: 84rpx;margin-bottom:60rpx;font-weight: bold;font-size: 28rpx;color: #FFFFFF;display: flex;align-items: center;justify-content: center;background: #0156FE;
  138. border-radius: 10rpx;
  139. .vxtab{width: 38rpx;height: 32rpx;margin-right: 18rpx;}
  140. .zhtab{width: 30rpx;height: 34rpx;margin-right: 22rpx;}
  141. &.btna{background: #D9E6FF;color: #0156FE;}
  142. }
  143. .line{width: 60rpx;height: 6rpx;background: #CDCDCD;margin: 0 auto 60rpx;}
  144. </style>