Login.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="container">
  3. <el-row>
  4. <el-col :span="24">
  5. <div id="login_form">
  6. <div id="logo"></div>
  7. <div id="title">南昌交通学院热水端管理后台</div>
  8. <el-form label-width="0px" :model="ruleForm" status-icon :rules="rules" ref="ruleForm"
  9. class="demo-ruleForm">
  10. <el-form-item prop="uname">
  11. <el-input ref="zhanghao" placeholder="请输入账号" maxlength="16" v-model="ruleForm.uname"
  12. prefix-icon="el-icon-login-user"></el-input>
  13. </el-form-item>
  14. <el-form-item prop="upass">
  15. <el-input ref="mima" placeholder="请输入密码" maxlength="16" type="password"
  16. v-model="ruleForm.upass" prefix-icon="el-icon-login-pass"
  17. @keyup.enter.native="submitForm('ruleForm')">
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" @click="submitForm('ruleForm')">登 陆</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. }
  50. setTimeout(() => {
  51. if (value.length < 5) {
  52. callback(new Error('密码长度不小于5位'));
  53. } else {
  54. callback();
  55. }
  56. }, 30);
  57. };
  58. return {
  59. ruleForm: {
  60. uname: '',
  61. upass: ''
  62. },
  63. rules: {
  64. uname: [{
  65. validator: checkName,
  66. trigger: 'blur'
  67. }],
  68. upass: [{
  69. validator: validatePass,
  70. trigger: 'blur'
  71. }]
  72. }
  73. };
  74. },
  75. methods: {
  76. submitForm(formName) {
  77. let _this = this;
  78. let params = {
  79. number: '',
  80. password: ''
  81. }
  82. var username = String(_this.ruleForm.uname).trim()
  83. var userpass = String(_this.ruleForm.upass).trim()
  84. if (username && userpass) {
  85. params.number = username
  86. params.password = userpass
  87. } else {
  88. _this.$message.warning('请输入账号和密码!')
  89. if (!username)
  90. _this.$refs['zhanghao'].focus()
  91. else
  92. _this.$refs['mima'].focus()
  93. return
  94. }
  95. _this.$refs[formName].validate((valid) => {
  96. _this.$axios.get('/jxch-smartmp-api/HotWaters/waterlogin.action', {
  97. params: params
  98. })
  99. .then(res => {
  100. // console.log(res.data);
  101. if (typeof(res.data.msg) != 'undefined' && res.data.msg != '' && JSON.stringify(res
  102. .data) !=
  103. '{}') {
  104. _this.$message.success(res.data.msg);
  105. sessionStorage.setItem('uname', username)
  106. if (typeof(res.data.name) == 'undefined') {
  107. sessionStorage.setItem('unic', '未设置昵称')
  108. } else {
  109. sessionStorage.setItem('unic', res.data.name)
  110. }
  111. _this.$router.replace('/index'); //跳转到首页
  112. } else {
  113. _this.$message({
  114. showClose: true,
  115. message: "登陆异常:" + res.data.msg,
  116. type: 'error'
  117. });
  118. }
  119. })
  120. .catch(err => {
  121. // console.log(err);
  122. _this.$message.error('捕捉异常:' + err)
  123. })
  124. });
  125. }
  126. }
  127. }
  128. </script>
  129. <style scoped>
  130. @import url("./login.css");
  131. </style>