index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="login-container">
  3. <div style="width: 100%;text-align: center">
  4. <img style="margin: 0 auto;margin-top: 8%" :src="title" alt="">
  5. </div>
  6. <el-row class="window-login">
  7. <el-col :span="15" class="picColor">
  8. <img style="width: 100%;height: 100%" :src="pic" alt="">
  9. </el-col>
  10. <el-col :span="9" style="background-color: #fff">
  11. <el-form
  12. ref="loginForm"
  13. :model="loginForm"
  14. :rules="loginRules"
  15. auto-complete="on"
  16. label-position="top"
  17. >
  18. <div class="title-container" style="margin-top:45px;margin-bottom: 20px;">
  19. 系统账户登录
  20. </div>
  21. <el-form-item label="账号名称" prop="username">
  22. <el-input
  23. ref="username"
  24. v-model="loginForm.username"
  25. placeholder="请输入用户名"
  26. name="username"
  27. type="text"
  28. tabindex="1"
  29. auto-complete="on"
  30. size="small"
  31. @keyup.enter.native="handleLogin"
  32. />
  33. </el-form-item>
  34. <el-form-item label="账号密码" prop="password" style="position: relative">
  35. <el-input
  36. :key="passwordType"
  37. ref="password"
  38. v-model="loginForm.password"
  39. :type="passwordType"
  40. placeholder="请输入密码"
  41. name="password"
  42. tabindex="2"
  43. auto-complete="on"
  44. size="small"
  45. @keyup.enter.native="handleLogin"
  46. />
  47. <span class="show-pwd" style="position: absolute;right: 12px;" @click="showPwd">
  48. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  49. </span>
  50. </el-form-item>
  51. <el-form-item label="验证码">
  52. <el-input
  53. ref="code"
  54. v-model="loginForm.code"
  55. style="width: 60%;vertical-align:middle"
  56. placeholder="请输入验证码"
  57. tabindex="2"
  58. auto-complete="on"
  59. size="mini"
  60. @keyup.enter.native="handleLogin"
  61. />
  62. <img :src="imgSrc" alt="" style="margin-left:5%;width: 35%;height: 40px;vertical-align:middle;" @click="captchaImage">
  63. </el-form-item>
  64. <el-form-item>
  65. <el-tooltip class="item" effect="dark" content="请联系管理员重置密码" placement="top">
  66. <el-button
  67. type="text"
  68. style="float: right;padding:0;
  69. color: #406AE1;
  70. font-family: Source Han Sans CN;
  71. font-weight: regular;
  72. font-size: 12px;
  73. line-height: 22px;
  74. letter-spacing: 0px;"
  75. >忘记密码?</el-button>
  76. </el-tooltip>
  77. </el-form-item>
  78. <el-button
  79. type="primary"
  80. style="width:100%;
  81. margin:10px 0 35px;
  82. border-radius: 40px;
  83. background: #406AE1;
  84. box-shadow: 0px 6px 4px 0px #547BD53F;"
  85. @keyup.enter.native="handleLogin"
  86. @click.native.prevent="handleLogin"
  87. >
  88. <h3 style="margin: 0;color: white">登 录</h3>
  89. </el-button>
  90. </el-form>
  91. </el-col>
  92. </el-row>
  93. </div>
  94. </template>
  95. <script>
  96. import { captchaImage } from '@/api/user'
  97. import pic from '@/assets/login/pic.png'
  98. import title from '@/assets/login/title@1.png'
  99. export default {
  100. name: 'Login',
  101. data() {
  102. return {
  103. pic: pic,
  104. title: title,
  105. loginForm: {
  106. username: '',
  107. password: '',
  108. code: '',
  109. uuid: ''
  110. },
  111. loginRules: {
  112. username: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
  113. password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
  114. code: [{ required: true, trigger: 'blur', message: '请输入验证码' }]
  115. },
  116. loading: false,
  117. passwordType: 'password',
  118. redirect: undefined,
  119. imgSrc: ''
  120. }
  121. },
  122. watch: {
  123. $route: {
  124. handler: function(route) {
  125. this.redirect = route.query && route.query.redirect
  126. },
  127. immediate: true
  128. }
  129. },
  130. created() {
  131. this.captchaImage()
  132. },
  133. methods: {
  134. captchaImage() {
  135. captchaImage({ type: 'math' }).then(res => {
  136. const url = 'data:image/jpg;base64,' + res.img
  137. this.imgSrc = url
  138. this.loginForm.uuid = res.uuid
  139. })
  140. },
  141. showPwd() {
  142. if (this.passwordType === 'password') {
  143. this.passwordType = ''
  144. } else {
  145. this.passwordType = 'password'
  146. }
  147. this.$nextTick(() => {
  148. this.$refs.password.focus()
  149. })
  150. },
  151. handleLogin() {
  152. this.$refs.loginForm.validate(valid => {
  153. if (valid) {
  154. this.loading = true
  155. this.$store.dispatch('user/login', this.loginForm).then(() => {
  156. this.$router.push({ path: this.redirect || '/' })
  157. this.loading = false
  158. }).catch(() => {
  159. this.loading = false
  160. })
  161. } else {
  162. console.log('error submit!!')
  163. return false
  164. }
  165. })
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. .login-container {
  172. background-image: url('../../assets/login/bg.png');
  173. .el-form {
  174. width: 70%;
  175. margin: 0 auto;
  176. .el-input__inner{
  177. height: 40px;
  178. }
  179. }
  180. }
  181. </style>
  182. <style lang="css" scoped>
  183. .title-container{
  184. color: #547BD4;
  185. font-family: Noto Sans Malayalam UI;
  186. font-size: 28px;
  187. line-height: 26px;
  188. letter-spacing: 0px;
  189. }
  190. /deep/ .el-input__inner {
  191. border: 0;
  192. border-bottom: 1px solid #DCDFE6;
  193. border-radius: 0;
  194. padding: 0;
  195. }
  196. /deep/ .el-form-item__label{
  197. padding:0;
  198. }
  199. .login-container {
  200. min-height: 100%;
  201. width: 100%;
  202. overflow: hidden;
  203. }
  204. /deep/ .el-form-item{
  205. margin-bottom: 15px;
  206. }
  207. .window-login {
  208. overflow: hidden;
  209. border-radius: 15px;
  210. margin: 0 auto;
  211. margin-top: 50px;
  212. width: 900px;
  213. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
  214. }
  215. .picColor{
  216. background: linear-gradient(166.06deg, #2782DF 0%, #003DAE 100%);
  217. box-shadow: 0px 4px 8px 0px #46BBFD5B;
  218. }
  219. </style>