Login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="container">
  3. <el-row>
  4. <el-col :span="24">
  5. <div id="login_form">
  6. <div class="title-item">
  7. <div id="logo"></div>
  8. <div id="title">学费缴纳对账管理平台</div>
  9. </div>
  10. <el-form label-width="0px" :model="ruleForm" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm">
  11. <el-form-item prop="uname">
  12. <el-input placeholder="请输入账号" maxlength="16" v-model="ruleForm.uname" prefix-icon="el-icon-login-user">
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item prop="upass">
  16. <el-input placeholder="请输入密码" maxlength="16" type="password" v-model="ruleForm.upass"
  17. prefix-icon="el-icon-login-pass"></el-input>
  18. </el-form-item>
  19. <el-form-item>
  20. <!-- <el-button type="primary" @click="submitForm('ruleForm')">登 陆</el-button> -->
  21. <el-button type="primary" @click="onSubmit()">登 陆</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. </el-col>
  26. </el-row>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. var checkName = (rule, value, callback) => {
  33. console.log(rule, value, callback);
  34. if (!value) {
  35. return callback(new Error('请输入账号'));
  36. }
  37. setTimeout(() => {
  38. if (value.length < 5) {
  39. callback(new Error('账号长度不小于5位'));
  40. } else {
  41. callback();
  42. }
  43. }, 30);
  44. };
  45. var validatePass = (rule, value, callback) => {
  46. console.log(rule, value, callback);
  47. if (value === '') {
  48. callback(new Error('请输入密码'));
  49. } else {
  50. callback();
  51. }
  52. };
  53. return {
  54. ruleForm: {
  55. uname: '',
  56. upass: ''
  57. },
  58. rules: {
  59. uname: [{
  60. validator: checkName,
  61. trigger: 'blur'
  62. }],
  63. upass: [{
  64. validator: validatePass,
  65. trigger: 'blur'
  66. }]
  67. },
  68. user_info: {}
  69. };
  70. },
  71. methods: {
  72. onSubmit() {
  73. this.getLogin(this.$Api.login)
  74. },
  75. //登录
  76. getLogin(url) {
  77. this.$axios.post(url + '?' + this.$qs.stringify({
  78. userName: this.ruleForm.uname,
  79. password: this.ruleForm.upass
  80. }), {
  81. headers: {
  82. 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  83. 'Author': 'codingliang'
  84. }
  85. })
  86. .then(res => {
  87. if (res.data.code == 1) {
  88. this.user_info.userName = this.ruleForm.uname
  89. this.user_info.password = this.ruleForm.upass
  90. this.user_info.token = res.data.data.token
  91. let user_info_Str = JSON.stringify(this.user_info)
  92. sessionStorage.setItem('usr_info', user_info_Str)
  93. this.$message.success('用户登录成功')
  94. this.$router.push({
  95. path: '/index'
  96. })
  97. } else {
  98. this.$message.error('用户名或密码错误');
  99. }
  100. })
  101. .catch(err => {
  102. console.log(err)
  103. })
  104. },
  105. }
  106. }
  107. </script>
  108. <style scoped>
  109. @import url("./login.css");
  110. </style>