index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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" scoped>
  157. /deep/.el-input__inner{
  158. background-color:transparent!important;
  159. border:1px solid transparent!important
  160. }
  161. .login-container .el-input input:-webkit-autofill{
  162. background-color:transparent!important;
  163. }
  164. .login-input {
  165. background-color:transparent!important;
  166. }
  167. /* 修复input 背景不协调 和光标变色 */
  168. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  169. .loginBtn {
  170. background-color: rgb(19, 129, 122);
  171. text-align: center;
  172. width: 100%;
  173. height: 51px;
  174. line-height: 51px;
  175. color: #fff;
  176. border-radius: 25px;
  177. cursor: pointer;
  178. margin-bottom: 10px !important;
  179. }
  180. .loginBtn.disabled {
  181. background-color: #777;
  182. }
  183. ::-webkit-input-placeholder {
  184. /* WebKit browsers */
  185. color: #444;
  186. font-size: 14px;
  187. }
  188. ::-moz-placeholder {
  189. /* Mozilla Firefox 19+ */
  190. color: #444;
  191. font-size: 14px;
  192. }
  193. :-ms-input-placeholder {
  194. /* Internet Explorer 10+ */
  195. color: #444;
  196. font-size: 14px;
  197. }
  198. .logitem {
  199. border-radius: 25px !important;
  200. border: 1px solid #444 !important;
  201. background-color: transparent !important;
  202. }
  203. .login-container .el-input input {
  204. color: #444 !important;
  205. caret-color: #444 !important;
  206. }
  207. .remberBox {
  208. display: flex;
  209. flex-direction: row;
  210. justify-content: flex-end;
  211. margin-bottom: 50px;
  212. align-items: center;
  213. cursor: pointer;
  214. .dotWrap {
  215. width: 18px;
  216. height: 18px;
  217. border: 1px solid #444;
  218. border-radius: 50%;
  219. margin-right: 8px;
  220. position: relative;
  221. overflow: hidden;
  222. .active {
  223. width: 10px;
  224. height: 10px;
  225. background-color: #444;
  226. border-radius: 50%;
  227. overflow: hidden;
  228. position: absolute;
  229. top: 3px;
  230. left: 3px;
  231. }
  232. }
  233. }
  234. $bg: #fff;
  235. $light_gray: #000;
  236. $cursor: #000;
  237. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  238. .login-container .el-input input {
  239. color: $cursor;
  240. &::first-line {
  241. color: $light_gray;
  242. }
  243. }
  244. }
  245. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  246. .login-container .el-input input {
  247. color: $cursor;
  248. }
  249. }
  250. /* reset element-ui css */
  251. .login-container {
  252. .el-input {
  253. display: inline-block;
  254. height: 47px;
  255. width: 85%;
  256. input {
  257. background: transparent!important;
  258. border: 0px;
  259. -webkit-appearance: none;
  260. border-radius: 0px;
  261. padding: 12px 5px 12px 15px;
  262. color: $light_gray;
  263. height: 47px;
  264. caret-color: $cursor;
  265. &:-webkit-autofill {
  266. box-shadow: 0 0 0px 1000px $bg inset !important;
  267. -webkit-text-fill-color: $cursor !important;
  268. }
  269. }
  270. }
  271. .el-form-item {
  272. border: 1px solid rgba(255, 255, 255, 0.1);
  273. background: rgba(0, 0, 0, 0.1);
  274. border-radius: 5px;
  275. color: #454545;
  276. }
  277. }
  278. </style>
  279. <style lang="scss" scoped>
  280. $bg: #fff;
  281. $dark_gray: #000;
  282. $light_gray: #eee;
  283. .login-container {
  284. min-height: 100%;
  285. width: 100%;
  286. // background-color: $bg;
  287. background: url("../../assets/images/base/login-bg.png") no-repeat 100% 100%;
  288. background-size: cover;
  289. overflow: hidden;
  290. .login-form {
  291. position: relative;
  292. width: 500px;
  293. max-width: 90%;
  294. padding: 0px 35px;
  295. margin: 12% auto 0;
  296. overflow: hidden;
  297. background-color: rgba(255, 255, 255, 0.85);
  298. // opacity: 0.85;
  299. box-shadow: 0px 0px 12px 0px rgba(0, 0, 0, 0.66);
  300. border-radius: 20px;
  301. }
  302. .tips {
  303. font-size: 14px;
  304. color: #fff;
  305. margin-bottom: 10px;
  306. span {
  307. &:first-of-type {
  308. margin-right: 16px;
  309. }
  310. }
  311. }
  312. .svg-container {
  313. padding: 6px 5px 6px 15px;
  314. color: $dark_gray;
  315. vertical-align: middle;
  316. width: 30px;
  317. display: inline-block;
  318. }
  319. .title-container {
  320. position: relative;
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. padding: 20% 0;
  325. img {
  326. width: 48%;
  327. }
  328. .title {
  329. font-size: 26px;
  330. color: $light_gray;
  331. margin: 0px auto 40px auto;
  332. text-align: center;
  333. font-weight: bold;
  334. }
  335. }
  336. .show-pwd {
  337. position: absolute;
  338. right: 10px;
  339. top: 7px;
  340. font-size: 14px;
  341. color: $dark_gray;
  342. cursor: pointer;
  343. user-select: none;
  344. }
  345. }
  346. </style>