login.vue 4.4 KB

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