index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="login-container">
  3. <el-form ref="loginForm"
  4. :model="loginForm"
  5. :rules="loginRules"
  6. class="login-form"
  7. auto-complete="on"
  8. label-position="left">
  9. <div class="title-container">
  10. <img src="@/assets/images/base/login-logo.png"
  11. alt="">
  12. </div>
  13. <el-form-item prop="username"
  14. class='logitem'>
  15. <span class="svg-container">
  16. <svg-icon icon-class="user" />
  17. </span>
  18. <el-input ref="username"
  19. @keyup.enter.native="handleLogin"
  20. v-model.trim="loginForm.username"
  21. placeholder="请输入用户名"
  22. class='login-input'
  23. name="username"
  24. type="text"
  25. tabindex="1"
  26. auto-complete="off" />
  27. </el-form-item>
  28. <el-form-item prop="password"
  29. class='logitem'>
  30. <span class="svg-container">
  31. <svg-icon icon-class="password" />
  32. </span>
  33. <el-input :key="passwordType"
  34. ref="password"
  35. class='login-input'
  36. v-model.trim="loginForm.password"
  37. :type="passwordType"
  38. placeholder="请输入密码"
  39. name="password"
  40. tabindex="2"
  41. auto-complete="off"
  42. @keyup.enter.native="handleLogin" />
  43. <span class="show-pwd"
  44. @click="showPwd">
  45. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  46. </span>
  47. </el-form-item>
  48. <div class="loginBtn"
  49. :class="!loginForm.username || !loginForm.password?'disabled':''"
  50. style="width:100%;margin-bottom:30px;"
  51. @click="handleLogin">登录</div>
  52. <div class='remberBox'
  53. @click='saveUserInfo'>
  54. <div class="dotWrap">
  55. <div :class="isSaveUserInfo?'active':''"></div>
  56. </div>记住密码
  57. </div>
  58. </el-form>
  59. </div>
  60. </template>
  61. <script>
  62. import { validUsername } from "@/utils/validate";
  63. export default {
  64. name: "Login",
  65. data () {
  66. const validateUsername = (rule, value, callback) => {
  67. // validUsername
  68. if (!value) {
  69. callback(new Error("请输入用户名"));
  70. } else {
  71. callback();
  72. }
  73. }
  74. const validatePassword = (rule, value, callback) => {
  75. if (value.length < 6) {
  76. callback(new Error("密码必须大于六位"));
  77. } else {
  78. callback();
  79. }
  80. }
  81. return {
  82. loginForm: {
  83. username: "",
  84. password: ""
  85. },
  86. loginRules: {
  87. username: [
  88. { required: true, trigger: "blur", validator: validateUsername }
  89. ],
  90. password: [
  91. { required: true, trigger: "blur", validator: validatePassword }
  92. ]
  93. },
  94. passwordType: "password",
  95. redirect: undefined,
  96. isSaveUserInfo: true
  97. }
  98. },
  99. mounted () {
  100. this.loginForm.username = localStorage.getItem('username');
  101. this.loginForm.password = localStorage.getItem('password');
  102. },
  103. watch: {
  104. $route: {
  105. handler: function (route) {
  106. this.redirect = route.query && route.query.redirect;
  107. },
  108. immediate: true
  109. }
  110. },
  111. methods: {
  112. showPwd () {
  113. if (this.passwordType === "password") {
  114. this.passwordType = "";
  115. } else {
  116. this.passwordType = "password";
  117. }
  118. this.$nextTick(() => {
  119. this.$refs.password.focus();
  120. });
  121. },
  122. handleLogin () {
  123. // 判断是否点击了记住密码 => 存储密码
  124. if (this.isSaveUserInfo) {
  125. localStorage.setItem('username', this.loginForm.username);
  126. localStorage.setItem('password', this.loginForm.password);
  127. } else {
  128. localStorage.setItem('username', '');
  129. localStorage.setItem('password', '');
  130. }
  131. this.$refs.loginForm.validate(valid => {
  132. if (valid) {
  133. this.$store
  134. .dispatch("user/login", this.loginForm)
  135. .then(() => {
  136. this.$nextTick(res => {
  137. // 这里清空 tab
  138. this.$store
  139. .dispatch("delAllViews")
  140. this.$router.push({ path: "/main/main" });
  141. })
  142. })
  143. .catch(() => {
  144. });
  145. } else {
  146. return false;
  147. }
  148. });
  149. },
  150. saveUserInfo () {
  151. this.isSaveUserInfo = !this.isSaveUserInfo;
  152. }
  153. }
  154. };
  155. </script>
  156. <style lang="scss" rel="stylesheet/scss">
  157. .login-input {
  158. background-color: #fff;
  159. }
  160. /* 修复input 背景不协调 和光标变色 */
  161. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  162. .loginBtn {
  163. background-color: rgb(19, 129, 122);
  164. text-align: center;
  165. width: 100%;
  166. height: 51px;
  167. line-height: 51px;
  168. color: #fff;
  169. border-radius: 25px;
  170. cursor: pointer;
  171. margin-bottom: 10px !important;
  172. }
  173. .loginBtn.disabled {
  174. background-color: #777;
  175. }
  176. ::-webkit-input-placeholder {
  177. /* WebKit browsers */
  178. color: #444;
  179. font-size: 14px;
  180. }
  181. ::-moz-placeholder {
  182. /* Mozilla Firefox 19+ */
  183. color: #444;
  184. font-size: 14px;
  185. }
  186. :-ms-input-placeholder {
  187. /* Internet Explorer 10+ */
  188. color: #444;
  189. font-size: 14px;
  190. }
  191. .logitem {
  192. border-radius: 25px !important;
  193. border: 1px solid #444 !important;
  194. background-color: transparent !important;
  195. }
  196. .login-container .el-input input {
  197. color: #444 !important;
  198. caret-color: #444 !important;
  199. }
  200. .remberBox {
  201. display: flex;
  202. flex-direction: row;
  203. justify-content: flex-end;
  204. margin-bottom: 50px;
  205. align-items: center;
  206. cursor: pointer;
  207. .dotWrap {
  208. width: 18px;
  209. height: 18px;
  210. border: 1px solid #444;
  211. border-radius: 50%;
  212. margin-right: 8px;
  213. position: relative;
  214. overflow: hidden;
  215. .active {
  216. width: 10px;
  217. height: 10px;
  218. background-color: #444;
  219. border-radius: 50%;
  220. overflow: hidden;
  221. position: absolute;
  222. top: 3px;
  223. left: 3px;
  224. }
  225. }
  226. }
  227. $bg: #fff;
  228. $light_gray: #000;
  229. $cursor: #000;
  230. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  231. .login-container .el-input input {
  232. color: $cursor;
  233. &::first-line {
  234. color: $light_gray;
  235. }
  236. }
  237. }
  238. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  239. .login-container .el-input input {
  240. color: $cursor;
  241. }
  242. }
  243. /* reset element-ui css */
  244. .login-container {
  245. .el-input {
  246. display: inline-block;
  247. height: 47px;
  248. width: 85%;
  249. input {
  250. background: transparent;
  251. border: 0px;
  252. -webkit-appearance: none;
  253. border-radius: 0px;
  254. padding: 12px 5px 12px 15px;
  255. color: $light_gray;
  256. height: 47px;
  257. caret-color: $cursor;
  258. &:-webkit-autofill {
  259. box-shadow: 0 0 0px 1000px $bg inset !important;
  260. -webkit-text-fill-color: $cursor !important;
  261. }
  262. }
  263. }
  264. .el-form-item {
  265. border: 1px solid rgba(255, 255, 255, 0.1);
  266. background: rgba(0, 0, 0, 0.1);
  267. border-radius: 5px;
  268. color: #454545;
  269. }
  270. }
  271. </style>
  272. <style lang="scss" scoped>
  273. $bg: #fff;
  274. $dark_gray: #000;
  275. $light_gray: #eee;
  276. .login-container {
  277. min-height: 100%;
  278. width: 100%;
  279. // background-color: $bg;
  280. background: url("../../assets/images/base/login-bg.png") no-repeat 100% 100%;
  281. background-size: cover;
  282. overflow: hidden;
  283. .login-form {
  284. position: relative;
  285. width: 500px;
  286. max-width: 90%;
  287. padding: 0px 35px;
  288. margin: 12% auto 0;
  289. overflow: hidden;
  290. background-color: #fff;
  291. opacity: 0.85;
  292. box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.66);
  293. border-radius: 20px;
  294. }
  295. .tips {
  296. font-size: 14px;
  297. color: #fff;
  298. margin-bottom: 10px;
  299. span {
  300. &:first-of-type {
  301. margin-right: 16px;
  302. }
  303. }
  304. }
  305. .svg-container {
  306. padding: 6px 5px 6px 15px;
  307. color: $dark_gray;
  308. vertical-align: middle;
  309. width: 30px;
  310. display: inline-block;
  311. }
  312. .title-container {
  313. position: relative;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. padding: 20% 0;
  318. img {
  319. width: 48%;
  320. }
  321. .title {
  322. font-size: 26px;
  323. color: $light_gray;
  324. margin: 0px auto 40px auto;
  325. text-align: center;
  326. font-weight: bold;
  327. }
  328. }
  329. .show-pwd {
  330. position: absolute;
  331. right: 10px;
  332. top: 7px;
  333. font-size: 14px;
  334. color: $dark_gray;
  335. cursor: pointer;
  336. user-select: none;
  337. }
  338. }
  339. </style>