login.vue 8.0 KB

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