login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <template>
  2. <view class="container login">
  3. <!-- logo区域 -->
  4. <view class="login-main">
  5. <image class="logo" :src="StaticUrl + 'icon-logo@2x.png'" mode="widthFix"></image>
  6. </view>
  7. <!-- 邀请码 -->
  8. <view class="login-input">
  9. <input
  10. class="input"
  11. type="number"
  12. v-model="params.mobile"
  13. @blur="handBlurInput"
  14. placeholder="请输入手机号"
  15. maxlength="11"
  16. />
  17. </view>
  18. <view class="login-input">
  19. <input
  20. class="input_code"
  21. type="number"
  22. v-model="params.verificationCode"
  23. placeholder="请输入短信验证码"
  24. maxlength="6"
  25. />
  26. <view class="code-btn" :class="[isMobileDisabled ? 'disabled' : '']">
  27. <button type="button" @click.stop="GetMobileCodeFn" :disabled="isMobileDisabled" class="button">
  28. {{ mobileCodeText }}
  29. </button>
  30. </view>
  31. </view>
  32. <!-- 提示信息 -->
  33. <view class="logo-message"
  34. ><text>{{ loginMessage }}</text></view
  35. >
  36. <button
  37. class="login-btn"
  38. :class="[isLoginStatus ? 'disabled' : '']"
  39. type="primary"
  40. open-type="getUserInfo"
  41. size="small"
  42. @click="SubMitLogins"
  43. lang="zh_CN"
  44. >
  45. 登录
  46. </button>
  47. </view>
  48. </template>
  49. <script>
  50. import authorize from '@/common/authorize.js'
  51. import wxLogin from '@/services/wxLogin.js'
  52. import { mapGetters, mapActions } from 'vuex'
  53. export default {
  54. data() {
  55. return {
  56. invitationCode: '', //获取用户登录的邀请码
  57. loginMessage: '未注册的手机号验证后自动创建呵呵商城账户', //登录信息反馈
  58. StaticUrl: this.$Static,
  59. disabled: false,
  60. params: {
  61. mobile: '',
  62. headImgUrl: '', //微信头像
  63. nickName: '', //微信昵称
  64. openId: '', //微信openId
  65. verificationCode: '' //短信验证码
  66. },
  67. count: '', //倒计时
  68. isMobileDisabled: true, //获取手机短信按钮
  69. mobileCodeText: '获取验证码',
  70. codeTime: null,
  71. isLoginStatus: false
  72. }
  73. },
  74. onLoad() {
  75. if(this.hasLogin) return this.$api.switchTabTo('/pages/tabBar/index/index')
  76. },
  77. computed:{
  78. ...mapGetters(['hasLogin'])
  79. },
  80. methods: {
  81. ...mapActions('user', ['customLogin']),
  82. // 登录
  83. SubMitLogins() {
  84. if (this.isLoginStatus) {
  85. return
  86. }
  87. if (!this.params.mobile) {
  88. this.$util.msg('请输入手机号', 2000)
  89. return
  90. }
  91. if (!this.$reg.isMobile(this.params.mobile)) {
  92. this.$util.msg('请输入正确的手机号', 2000)
  93. return
  94. }
  95. if (this.params.verificationCode == '') {
  96. this.$util.msg('请输入短信验证码', 2000)
  97. return
  98. }
  99. this.params.openId = uni.getStorageSync('openId')
  100. this.GetUserProfile()
  101. },
  102. GetUserProfile() {
  103. const self = this
  104. wx.getUserProfile({
  105. desc: '呵呵商城小程序获取您的信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  106. success(res) {
  107. self.params.nickName = res.userInfo.nickName
  108. self.params.headImgUrl = res.userInfo.avatarUrl
  109. self.isLoginStatus = true
  110. self.LoginGetUser()
  111. },
  112. fail() {
  113. self.$util.msg('授权失败', 2000)
  114. }
  115. })
  116. },
  117. LoginGetUser() {
  118. this.customLogin(this.params)
  119. this.isLoginStatus = false
  120. },
  121. GetMobileCodeFn() {
  122. //获取手机验证码
  123. if (this.params.mobile == '') {
  124. this.$util.msg('请输入手机号', 2000)
  125. return
  126. }
  127. if (!this.$reg.isMobile(this.params.mobile)) {
  128. this.$util.msg('请输入正确的手机号', 2000)
  129. return
  130. }
  131. this.isMobileDisabled = true
  132. this.PublicService.GetheHeSend({
  133. mobile: this.params.mobile
  134. })
  135. .then(res => {
  136. const TIME_COUNT = 60
  137. this.$util.msg('验证短信已发送', 2000)
  138. if (!this.codeTime) {
  139. this.count = TIME_COUNT
  140. this.isMobileDisabled = true
  141. this.codeTime = setInterval(() => {
  142. if (this.count > 1 && this.count <= TIME_COUNT) {
  143. this.count--
  144. this.mobileCodeText = this.count + 's重新发送'
  145. } else {
  146. this.isMobileDisabled = false
  147. clearInterval(this.codeTime)
  148. this.codeTime = null
  149. this.mobileCodeText = '获取验证码'
  150. }
  151. }, 1000)
  152. }
  153. })
  154. .catch(error => {
  155. this.$util.msg(error.msg, 2000)
  156. this.isMobileDisabled = false
  157. })
  158. },
  159. handBlurInput(e) {
  160. console.log(e)
  161. if (e.detail.value) {
  162. this.isMobileDisabled = false
  163. } else {
  164. this.isMobileDisabled = true
  165. }
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. .login {
  172. display: flex;
  173. align-items: center;
  174. flex-direction: column;
  175. .login-main,
  176. .login-title,
  177. .logo-message {
  178. width: 590rpx;
  179. }
  180. .login-main {
  181. display: flex;
  182. justify-content: center;
  183. margin: 180rpx 0 60rpx;
  184. .logo {
  185. width: 200rpx;
  186. height: 200rpx;
  187. display: block;
  188. }
  189. }
  190. .login-title {
  191. display: flex;
  192. justify-content: flex-start;
  193. image {
  194. width: 40rpx;
  195. height: 40rpx;
  196. margin-right: 6rpx;
  197. }
  198. }
  199. .login-btn {
  200. width: 600rpx;
  201. height: 90rpx;
  202. text-align: center;
  203. line-height: 90rpx;
  204. background: $btn-confirm;
  205. border-radius: 45rpx;
  206. color: #fff !important;
  207. margin-top: 40rpx;
  208. &.disabled {
  209. background: #e1e1e1;
  210. color: #999999;
  211. }
  212. }
  213. .login-input {
  214. margin: 10rpx 0;
  215. width: 600rpx;
  216. height: 90rpx;
  217. box-sizing: border-box;
  218. padding: 25rpx 0;
  219. border-bottom: 1px solid #e1e1e1;
  220. .input {
  221. width: 100%;
  222. height: 40rpx;
  223. left: 40rpx;
  224. font-size: $font-size-28;
  225. color: #333333;
  226. }
  227. .input_code {
  228. width: 420rpx;
  229. height: 40rpx;
  230. left: 40rpx;
  231. font-size: $font-size-28;
  232. color: #333333;
  233. float: left;
  234. }
  235. .code-btn {
  236. width: 180rpx;
  237. height: 40rpx;
  238. line-height: 40rpx;
  239. font-size: $font-size-28;
  240. color: #333333;
  241. float: right;
  242. text-align: center;
  243. .button {
  244. width: 180rpx;
  245. height: 40rpx;
  246. line-height: 40rpx;
  247. padding: 0;
  248. color: $color-system;
  249. }
  250. &.disabled {
  251. .button {
  252. color: #b2b2b2;
  253. }
  254. }
  255. }
  256. }
  257. .logo-message {
  258. font-size: 24rpx;
  259. line-height: 44rpx;
  260. color: #fc464c;
  261. text-align: left;
  262. }
  263. }
  264. </style>