login.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. @click="handleLogin"
  31. />
  32. <view
  33. class="forget"
  34. @click="$u.route({url: '/pages/forget'})"
  35. >忘记密码?</view>
  36. </view>
  37. <view class="wechat-login">
  38. <div class="static-text">其他登陆方式</div>
  39. <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"><view class="icon" /></button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import Cache from '../utils/cache'
  45. export default {
  46. name: 'Login',
  47. data() {
  48. return {
  49. passwordShow: true,
  50. model: {
  51. account: '',
  52. password: ''
  53. },
  54. path: '/pages/index',
  55. inputStyle: {
  56. borderRadius: 0,
  57. borderColor: '#000 !important',
  58. marginTop: '30rpx',
  59. padding: '20rpx 30rpx',
  60. fontSize: '38rpx'
  61. },
  62. btnStyle: {
  63. marginTop: '30rpx',
  64. width: '100%',
  65. borderRadius: 0,
  66. height: '92rpx',
  67. letterSpacing: '0.1rem',
  68. fontSize: '38rpx'
  69. }
  70. }
  71. },
  72. computed: {},
  73. methods: {
  74. handleLogin() {
  75. if (!this.model.account || this.model.account.length < 11) {
  76. this.$u.toast('请输入正确的手机号')
  77. return
  78. }
  79. if (!this.model.password) {
  80. this.$u.toast('请输入密码')
  81. return
  82. }
  83. this.$loading('登陆中...')
  84. uni.login({
  85. provider: uni.$u.platform,
  86. success: loginRes => {
  87. uni.hideLoading()
  88. this.$api.user.login(this.model.account, this.model.password, loginRes.code).then(async res => {
  89. this.$hideLoading()
  90. await this.$store.dispatch('user/token', res.data.token)
  91. await this.$store.dispatch('user/info', res.data.user_info)
  92. uni.reLaunch({
  93. url: this.path.replace('//', '/')
  94. })
  95. }).catch(() => {
  96. this.$hideLoading()
  97. })
  98. }
  99. })
  100. },
  101. getPhoneNumber({ detail }) {
  102. this.$loading('登陆中...')
  103. uni.login({
  104. provider: uni.$u.platform,
  105. success: loginRes => {
  106. const data = {
  107. iv: detail.iv,
  108. encryptedData: detail.encryptedData,
  109. code: loginRes.code
  110. }
  111. this.$api.user.phoneQuickLogin(data).then(async res => {
  112. await this.$store.dispatch('user/token', res.data.token)
  113. await this.$store.dispatch('user/info', res.data.user_info)
  114. uni.reLaunch({
  115. url: this.path.replace('//', '/')
  116. })
  117. }).catch(() => {
  118. this.$hideLoading()
  119. })
  120. }
  121. })
  122. }
  123. },
  124. onLoad() {
  125. if (Cache.get('path')) {
  126. this.path = Cache.get('path')
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. .login-page {
  133. padding: 0 80rpx;
  134. .logo{
  135. margin: 100rpx auto 50rpx;
  136. }
  137. .forget{
  138. color: #999999;
  139. margin-top: 20rpx;
  140. font-size: 26rpx;
  141. }
  142. .wechat-login{
  143. margin-top: 80rpx;
  144. .static-text{
  145. color: #333333;
  146. }
  147. button{
  148. width: 80rpx;
  149. height: 80rpx;
  150. background: transparent;
  151. margin-top: 30rpx;
  152. .icon{
  153. width: 80rpx;
  154. height: 80rpx;
  155. background: url("/static/image/login/wechat.png") no-repeat center;
  156. }
  157. }
  158. }
  159. }
  160. </style>