login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="login-page">
  3. <view class="logo logo-white" />
  4. <view class="form-box">
  5. <u-input
  6. v-model="model.account"
  7. placeholder="手机号码"
  8. :custom-style="inputStyle"
  9. :max-length="11"
  10. />
  11. <u-input
  12. v-model="model.password"
  13. :password="passwordShow"
  14. placeholder="密码"
  15. :custom-style="inputStyle"
  16. >
  17. <template slot="suffix">
  18. <u-icon
  19. size="42rpx"
  20. :name="passwordShow?'eye-fill':'eye-off'"
  21. @click="passwordShow=!passwordShow"
  22. />
  23. </template>
  24. </u-input>
  25. <u-button
  26. text="登陆"
  27. color="#000"
  28. shape="square"
  29. :custom-style="btnStyle"
  30. :loading="loading"
  31. @click="handleLogin"
  32. />
  33. <view
  34. class="forget"
  35. @click="$u.route({url: '/pages/forget'})"
  36. >忘记密码?</view>
  37. </view>
  38. <view class="wechat-login">
  39. <div class="static-text">其他登陆方式</div>
  40. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"><view class="icon" /></button>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import Cache from '../utils/cache'
  46. export default {
  47. name: 'Login',
  48. data() {
  49. return {
  50. passwordShow: true,
  51. model: {
  52. account: '',
  53. password: ''
  54. },
  55. path: '/pages/index',
  56. loading: false,
  57. inputStyle: {
  58. borderRadius: 0,
  59. borderColor: '#000 !important',
  60. marginTop: '30rpx',
  61. padding: '20rpx 30rpx',
  62. fontSize: '38rpx'
  63. },
  64. btnStyle: {
  65. marginTop: '30rpx',
  66. width: '100%',
  67. borderRadius: 0,
  68. height: '92rpx',
  69. letterSpacing: '0.1rem',
  70. fontSize: '38rpx'
  71. }
  72. }
  73. },
  74. computed: {},
  75. methods: {
  76. handleLogin() {
  77. if (!this.model.account || this.model.account.length < 11) {
  78. this.$u.toast('请输入正确的手机号')
  79. return
  80. }
  81. if (!this.model.password) {
  82. this.$u.toast('请输入密码')
  83. return
  84. }
  85. this.loading = true
  86. uni.login({
  87. provider: uni.$u.platform,
  88. success: loginRes => {
  89. uni.hideLoading()
  90. this.$api.user.login(this.model.account, this.model.password, loginRes.code).then(async res => {
  91. this.loading = false
  92. await this.$store.dispatch('user/token', res.data.token)
  93. await this.$store.dispatch('user/info', res.data.user_info)
  94. uni.reLaunch({
  95. url: this.path.replace('//', '/')
  96. })
  97. }).catch(() => {
  98. this.loading = false
  99. })
  100. }
  101. })
  102. },
  103. getPhoneNumber(res) {
  104. console.log('-->data', res)
  105. }
  106. },
  107. onLoad() {
  108. if (Cache.get('path')) {
  109. this.path = Cache.get('path')
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .login-page {
  116. padding: 0 80rpx;
  117. .logo{
  118. margin: 100rpx auto 50rpx;
  119. }
  120. .forget{
  121. color: #999999;
  122. margin-top: 20rpx;
  123. font-size: 26rpx;
  124. }
  125. .wechat-login{
  126. margin-top: 80rpx;
  127. .static-text{
  128. color: #333333;
  129. }
  130. button{
  131. width: 80rpx;
  132. height: 80rpx;
  133. background: transparent;
  134. margin-top: 30rpx;
  135. .icon{
  136. width: 80rpx;
  137. height: 80rpx;
  138. background: url("/static/image/login/wechat.png") no-repeat center;
  139. }
  140. }
  141. }
  142. }
  143. </style>