index.vue 8.7 KB

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