login.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="login">
  3. <view class="login-box">
  4. <view class="login-box-title">
  5. <view>智慧停车</view>
  6. <view>运营数据系统</view>
  7. </view>
  8. <view class="login-box-form">
  9. <view class="login-box-form-box">
  10. <u--form :model="form" :rules="rules" ref="uForm">
  11. <u-form-item label="" prop="phoneNumber">
  12. <u--input v-model="form.phoneNumber"
  13. :prefixIcon="require('@/static/icons/job-number-icon.svg')" placeholder="请输入手机号"
  14. :maxlength="11" type="number" border="none" class="custom-input"
  15. :prefixIconStyle="{ marginRight: '10px' }" fontSize="14px" color="#ffffff" placeholderStyle="color: #fff"/>
  16. </u-form-item>
  17. <u-form-item label="" prop="password">
  18. <u--input v-model="form.password" :prefixIcon="require('@/static/icons/password-icon.svg')"
  19. placeholder="请输入密码" :password="true" border="none" class="custom-input"
  20. :prefixIconStyle="{ marginRight: '10px' }" fontSize="14px" color="#ffffff" placeholderStyle="color: #fff"/>
  21. </u-form-item>
  22. </u--form>
  23. </view>
  24. <view class="login-box-form-btn">
  25. <u-button class="login-btn" type="primary" text="登录" :loading="loading" @click="submitLogin">
  26. </u-button>
  27. </view>
  28. </view>
  29. </view>
  30. <u-toast ref="uToast"></u-toast>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. form: {
  38. phoneNumber: '',
  39. password: ''
  40. },
  41. loading: false,
  42. rules: {
  43. phoneNumber: {
  44. required: true,
  45. message: '请输入手机号',
  46. trigger: ['change', 'blur']
  47. },
  48. password: {
  49. required: true,
  50. message: '请输入密码',
  51. trigger: ['change', 'blur']
  52. }
  53. }
  54. }
  55. },
  56. methods: {
  57. /**
  58. * 登录提交
  59. */
  60. submitLogin() {
  61. this.$refs.uForm.validate().then(res => {
  62. this.loading = true
  63. const form = {
  64. ...this.form
  65. }
  66. uni.$u.api.loginApi({
  67. telephone: form.phoneNumber,
  68. loginPwd: form.password
  69. }).then(res => {
  70. if (res.code === 200) {
  71. uni.$u.vuex('vuex_token', res.data.token);
  72. this.$u.vuex('vuex_user', res.data);
  73. this.$u.vuex('vuex_isLogin', true);
  74. this.$refs.uToast.show({
  75. loading: true,
  76. message: '登录成功!',
  77. type: 'success',
  78. complete() {
  79. uni.$u.route({
  80. url: 'pages/index/index',
  81. type: 'redirect'
  82. })
  83. }
  84. })
  85. } else {
  86. this.$refs.uToast.show({
  87. loading: true,
  88. message: res.msg || '登录失败',
  89. type: 'error'
  90. })
  91. }
  92. }).catch(err => {
  93. this.loading = false
  94. })
  95. }).catch(errors => {
  96. uni.$u.toast(errors[0].message || '必填项不能为空!')
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. page {
  104. height: 100vh;
  105. background: linear-gradient(183deg, #2D82FB 0%, #1558F8 100%);
  106. }
  107. </style>
  108. <style lang="scss" scoped>
  109. @import './login.scss';
  110. </style>