5a67f0d6299f6e57b7969449d7a7ef5cd8f2c3e9.svn-base 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="login-container">
  3. <img src="@/assets/images/logo.png" alt class="logo">
  4. <!-- <img src="@/assets/images/login-bujian.png" alt="" class="bujian"> -->
  5. <div class="login">
  6. <div class="logo" />
  7. <div class="title-container">
  8. <img src="@/assets/images/login-top.png">
  9. <!-- <h3 class="title">设备管理系统</h3>
  10. <b>Equipment Management System</b> -->
  11. <!-- <hr> -->
  12. </div>
  13. <el-form
  14. ref="loginForm"
  15. :model="loginForm"
  16. :rules="loginRules"
  17. class="login-form"
  18. auto-complete="on"
  19. label-position="left"
  20. >
  21. <el-form-item prop="username">
  22. <span class="svg-container">
  23. <svg-icon icon-class="user" />
  24. </span>
  25. <el-input
  26. ref="username"
  27. v-model="loginForm.username"
  28. placeholder="Username"
  29. name="username"
  30. type="text"
  31. tabindex="1"
  32. auto-complete="on"
  33. />
  34. </el-form-item>
  35. <el-form-item prop="password">
  36. <span class="svg-container">
  37. <svg-icon icon-class="password" />
  38. </span>
  39. <el-input
  40. :key="passwordType"
  41. ref="password"
  42. v-model="loginForm.password"
  43. :type="passwordType"
  44. placeholder="Password"
  45. name="password"
  46. tabindex="2"
  47. auto-complete="on"
  48. @keyup.enter.native="handleLogin"
  49. />
  50. <span class="show-pwd" @click="showPwd">
  51. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  52. </span>
  53. </el-form-item>
  54. </el-form>
  55. <el-button type="text" :loading="loading" class="btn" @click.native.prevent="handleLogin">登录</el-button>
  56. <span class="kpt">Copyright上海科湃腾信息科技有限公司. <br>All Rights Reserved</span>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import { validUsername } from '@/utils/validate'
  62. export default {
  63. name: 'Login',
  64. data() {
  65. const validateUsername = (rule, value, callback) => {
  66. if (!validUsername(value)) {
  67. callback(new Error('请输入正确的用户名'))
  68. } else {
  69. callback()
  70. }
  71. }
  72. const validatePassword = (rule, value, callback) => {
  73. if (value.length < 6) {
  74. callback(new Error('密码不能少于6个字符'))
  75. } else {
  76. callback()
  77. }
  78. }
  79. return {
  80. loginForm: {
  81. username: '',
  82. password: ''
  83. },
  84. loginRules: {
  85. username: [
  86. { required: true, trigger: 'blur', validator: validateUsername }
  87. ],
  88. password: [
  89. { required: true, trigger: 'blur', validator: validatePassword }
  90. ]
  91. },
  92. loading: false,
  93. passwordType: 'password',
  94. redirect: undefined
  95. }
  96. },
  97. watch: {
  98. $route: {
  99. handler: function(route) {
  100. this.redirect = route.query && route.query.redirect
  101. },
  102. immediate: true
  103. }
  104. },
  105. created() {
  106. var that = this
  107. document.onkeydown = function(e) {
  108. e = window.event || e
  109. // eslint-disable-next-line eqeqeq
  110. if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
  111. that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
  112. }
  113. }
  114. },
  115. methods: {
  116. showPwd() {
  117. if (this.passwordType === 'password') {
  118. this.passwordType = ''
  119. } else {
  120. this.passwordType = 'password'
  121. }
  122. this.$nextTick(() => {
  123. this.$refs.password.focus()
  124. })
  125. },
  126. handleLogin() {
  127. console.log(12)
  128. this.$refs.loginForm.validate(valid => {
  129. if (valid) {
  130. this.loading = true
  131. this.$store
  132. .dispatch('user/login', this.loginForm)
  133. .then(() => {
  134. this.$router.push({ path: this.redirect || '/' })
  135. this.loading = false
  136. })
  137. .catch(() => {
  138. this.loading = false
  139. })
  140. } else {
  141. console.log('error submit!!')
  142. return false
  143. }
  144. })
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss">
  150. /* 修复input 背景不协调 和光标变色 */
  151. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  152. // $bg: #283443;
  153. // $light_gray: #fff;
  154. // $cursor: #fff;
  155. // 更改
  156. $bg: #ccc;
  157. $light_gray: #ccc;
  158. $cursor: #000;
  159. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  160. .login-container .el-input input {
  161. color: $cursor;
  162. }
  163. }
  164. /* reset element-ui css */
  165. .login-container {
  166. .el-input {
  167. display: inline-block;
  168. height: 38px;
  169. width: 80%;
  170. input {
  171. background: #fff;
  172. border: 0px;
  173. -webkit-appearance: none;
  174. border-radius: 0px;
  175. padding: 5px 5px 5px 15px;
  176. color: #000;
  177. height: 38px;
  178. caret-color: $cursor;
  179. &:-webkit-autofill {
  180. box-shadow: 0 0 0px 1000px $bg inset !important;
  181. -webkit-text-fill-color: $cursor !important;
  182. }
  183. }
  184. }
  185. .el-form-item {
  186. border: 1px solid rgba(255, 255, 255, 0.1);
  187. // background: rgba(0, 0, 0, 0.2);
  188. background: #fff;
  189. border-radius: 5px;
  190. color: #454545;
  191. width: 80%;
  192. margin: 15px auto;
  193. .el-form-item__content {
  194. line-height: 30px;
  195. }
  196. }
  197. // .el-form{background-color: red;}
  198. .btn{
  199. position: relative;
  200. width: 520px;
  201. max-width: 100%;
  202. overflow: hidden;
  203. }
  204. .btn span{width:80%;background:#1767a6;border: #1767a6;border-radius: 5px;line-height: 40px; text-align: center;color:#fff; margin: -10px auto 0;display: block;}
  205. }
  206. </style>
  207. <style>
  208. .login-container .el-input input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill {
  209. -webkit-box-shadow: 0 0 0px 1000px #fff inset !important;
  210. box-shadow: 0 0 0px 1000px #fff inset !important;
  211. -webkit-text-fill-color: #000 !important;
  212. }
  213. </style>
  214. <style lang="scss" scoped>
  215. $bg: #2d3a4b;
  216. $dark_gray: #889aa4;
  217. $light_gray: #000;
  218. .login-container {
  219. min-height: 100%;
  220. width: 100%;
  221. height: 100%;
  222. position: relative;
  223. background: url("../../assets/images/login-bg.png") no-repeat;
  224. background-size:100%;
  225. overflow: hidden;
  226. .logo{
  227. padding: 5px;
  228. }
  229. .bujian{
  230. position: absolute;
  231. top: 0;
  232. bottom: 0;
  233. left: 0;
  234. right: 200px;
  235. margin: auto;
  236. }
  237. .login {
  238. border-radius: 5%;
  239. padding: 30px;
  240. background: rgba(0,0,0,0.4);
  241. width: 380px;
  242. height: 340px;
  243. position: relative;
  244. top: 50%;
  245. left: 50%;
  246. margin-left: -190px;
  247. margin-top: -270px;
  248. box-shadow:0px 0px 10px #fff;
  249. .login-form {
  250. margin-top: 60px;
  251. position: relative;
  252. width: 520px;
  253. max-width: 100%;
  254. overflow: hidden;
  255. }
  256. .tips {
  257. font-size: 14px;
  258. color: #fff;
  259. margin-bottom: 10px;
  260. span {
  261. &:first-of-type {
  262. margin-right: 16px;
  263. }
  264. }
  265. }
  266. .svg-container {
  267. padding: 6px 5px 6px 15px;
  268. color: $dark_gray;
  269. vertical-align: middle;
  270. width: 30px;
  271. display: inline-block;
  272. }
  273. .title-container {
  274. position: absolute;
  275. background: #000;
  276. height: 80px;
  277. width: 100%;
  278. top: 0;
  279. left: 0;
  280. border-radius: 12px 12px 0 0;
  281. opacity: 0.7;
  282. // img{height: 20px;}
  283. .title {
  284. font-size: 26px;
  285. color: $light_gray;
  286. margin: 0px auto 0 auto;
  287. text-align: center;
  288. font-weight: bold;
  289. }
  290. b {
  291. text-align: center;
  292. font: 14px/2 "";
  293. }
  294. }
  295. .show-pwd {
  296. position: absolute;
  297. right: 10px;
  298. top: 7px;
  299. font-size: 16px;
  300. color: $dark_gray;
  301. cursor: pointer;
  302. user-select: none;
  303. }
  304. .kpt{text-align: center;color: #fff;display: inline-block;width: 100%;font:12px/18px '';}
  305. // p{text-align: center;color: #fff;display: inline-block;width: 100%;font-size:12px;margin-top: 30px;}
  306. }
  307. }
  308. </style>