index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="login">
  3. <div class="aside">
  4. <div class="aside-h">
  5. <h1>灵 巧 敏 捷 保 障 软 件 系 统</h1>
  6. </div>
  7. <el-form label-position="right" label-width="60px" ref="ruleForm" :model="ruleForm" :rules="rules" :hide-required-asterisk="true" class="login-form">
  8. <el-form-item prop="username" label="用户名">
  9. <el-input v-model="ruleForm.username" type="text" auto-complete="off" placeholder="账号" @keyup.enter.native="submitForm('ruleForm')" />
  10. </el-form-item>
  11. <el-form-item prop="password" label="密码">
  12. <el-input v-model="ruleForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="submitForm('ruleForm')" />
  13. </el-form-item>
  14. <el-form-item style="width: 100%">
  15. <el-button size="medium" type="primary" style="width: 70%; height: 40px; background: rgb(11, 143, 218); margin-left: 20px; border-radius: 15px" @click.native.prevent="submitForm('ruleForm')">
  16. <span style="font-size: 20px; font-weight: bold">登 录</span>
  17. </el-button>
  18. </el-form-item>
  19. </el-form>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import { getTile } from '@/utils/tags'
  25. import { useMessage } from '@/utils/element-ui'
  26. export default {
  27. name: 'Login',
  28. data() {
  29. // 这里存放数据
  30. var validateAccount = (rule, value, callback) => {
  31. if (value === '') {
  32. callback(new Error('请输入账号'))
  33. } else {
  34. callback()
  35. }
  36. }
  37. var validatePassword = (rule, value, callback) => {
  38. if (value === '') {
  39. callback(new Error('请输入密码'))
  40. } else {
  41. callback()
  42. }
  43. }
  44. return {
  45. passwordType: 'password',
  46. loading: false,
  47. ruleForm: {
  48. username: 'admin',
  49. password: 'admin123'
  50. },
  51. rules: {
  52. username: [{ validator: validateAccount, trigger: 'blur' }],
  53. password: [{ validator: validatePassword, trigger: 'blur' }]
  54. }
  55. }
  56. },
  57. methods: {
  58. onChangePsdType() {
  59. this.passwordType === 'password' ? (this.passwordType = 'text') : (this.passwordType = 'password')
  60. },
  61. submitForm(formName) {
  62. this.$refs[formName].validate((valid) => {
  63. if (valid) {
  64. this.loading = true
  65. this.$store.dispatch('user/login', this.ruleForm).then((res) => {
  66. if (res.code == 200) {
  67. this.loading = false
  68. } else {
  69. useMessage('error', res.msg)
  70. }
  71. })
  72. } else {
  73. return false
  74. }
  75. })
  76. },
  77. resetForm(formName) {
  78. this.$refs[formName].resetFields()
  79. }
  80. },
  81. beforeDestroy() {
  82. //登录成功去综合看板 设置tags
  83. const { fullPath, meta, name, params, path, query } = this.$route
  84. this.$store.commit('app/addTagsViewList', {
  85. fullPath,
  86. meta,
  87. name,
  88. params,
  89. path,
  90. query,
  91. title: getTile(this.$route)
  92. })
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. @import './index.scss';
  98. </style>