login.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <h3 class="title">{{company_name}}仓储管理系统</h3>
  5. <el-form-item prop="username">
  6. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  7. <!-- <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />-->
  8. <i slot="prefix" class="el-icon-user" style="font-size: 20px;padding-top: 11px;padding-left: 2px;color: #565656;"></i>
  9. </el-input>
  10. </el-form-item>
  11. <el-form-item prop="password">
  12. <el-input
  13. v-model="loginForm.password"
  14. type="password"
  15. auto-complete="off"
  16. placeholder="密码"
  17. @keyup.enter.native="handleLogin"
  18. >
  19. <!-- <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />-->
  20. <i slot="prefix" class="el-icon-lock" style="font-size: 20px;padding-top: 11px;padding-left: 2px;color: #565656;"></i>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="code">
  24. <el-input
  25. v-model="loginForm.code"
  26. auto-complete="off"
  27. placeholder="验证码"
  28. style="width: 63%"
  29. @keyup.enter.native="handleLogin"
  30. >
  31. <!-- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />-->
  32. <i slot="prefix" class="el-icon-connection" style="font-size: 20px;padding-top: 11px;padding-left: 2px;color: #565656;"></i>
  33. </el-input>
  34. <div class="login-code">
  35. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  36. </div>
  37. </el-form-item>
  38. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;color: rgba(245, 248, 250, 0.8)">记住密码</el-checkbox>
  39. <el-form-item style="width:100%;">
  40. <el-button
  41. :loading="loading"
  42. size="medium"
  43. type="primary"
  44. style="width:100%;border-radius: 200px"
  45. @click.native.prevent="handleLogin"
  46. >
  47. <span v-if="!loading">登 录</span>
  48. <span v-else>登 录 中...</span>
  49. </el-button>
  50. </el-form-item>
  51. </el-form>
  52. <!-- 底部 -->
  53. <div class="el-login-footer">
  54. <span>Copyright © 2020-2022 {{company_name}}仓储管理系统</span>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import { getCodeImg } from "@/api/login";
  60. import Cookies from "js-cookie";
  61. import { encrypt, decrypt } from '@/utils/jsencrypt'
  62. export default {
  63. name: "Login",
  64. data() {
  65. return {
  66. codeUrl: "",
  67. company_name:'途宝',
  68. cookiePassword: "",
  69. loginForm: {
  70. username: "admin",
  71. password: "admin123",
  72. rememberMe: false,
  73. code: "",
  74. uuid: ""
  75. },
  76. loginRules: {
  77. username: [
  78. { required: true, trigger: "blur", message: "用户名不能为空" }
  79. ],
  80. password: [
  81. { required: true, trigger: "blur", message: "密码不能为空" }
  82. ],
  83. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  84. },
  85. loading: false,
  86. redirect: undefined
  87. };
  88. },
  89. watch: {
  90. $route: {
  91. handler: function(route) {
  92. this.redirect = route.query && route.query.redirect;
  93. },
  94. immediate: true
  95. }
  96. },
  97. created() {
  98. this.getCode();
  99. this.getCookie();
  100. },
  101. methods: {
  102. getCode() {
  103. getCodeImg().then(res => {
  104. this.codeUrl = "data:image/gif;base64," + res.img;
  105. this.loginForm.uuid = res.uuid;
  106. });
  107. },
  108. getCookie() {
  109. const username = Cookies.get("username");
  110. const password = Cookies.get("password");
  111. const rememberMe = Cookies.get('rememberMe')
  112. this.loginForm = {
  113. username: username === undefined ? this.loginForm.username : username,
  114. password: password === undefined ? this.loginForm.password : decrypt(password),
  115. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  116. };
  117. },
  118. handleLogin() {
  119. this.$refs.loginForm.validate(valid => {
  120. if (valid) {
  121. this.loading = true;
  122. if (this.loginForm.rememberMe) {
  123. console.log("username")
  124. console.log(this.loginForm.username)
  125. Cookies.set("username", this.loginForm.username, { expires: 30 });
  126. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  127. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  128. } else {
  129. Cookies.remove("username");
  130. Cookies.remove("password");
  131. Cookies.remove('rememberMe');
  132. }
  133. this.$store
  134. .dispatch("Login", this.loginForm)
  135. .then(() => {
  136. //设置localStroage值
  137. console.log(this.company_name)
  138. localStorage.setItem('companyName',this.company_name)
  139. this.$router.push({ path: this.redirect || "/" });
  140. })
  141. .catch(() => {
  142. this.loading = false;
  143. this.getCode();
  144. });
  145. }
  146. });
  147. }
  148. }
  149. };
  150. </script>
  151. <style rel="stylesheet/scss" lang="scss">
  152. .login {
  153. display: flex;
  154. justify-content: center;
  155. align-items: center;
  156. height: 100%;
  157. background-image: url("../assets/images/login-background.jpg");
  158. background-size: cover;
  159. }
  160. .title {
  161. margin: 0px auto 30px auto;
  162. text-align: center;
  163. font-size: 30px;
  164. color: #FFFFFF;
  165. }
  166. .login-form {
  167. border-radius: 6px;
  168. //background: none;
  169. background-color: rgba(0,0,0,0.05);
  170. width: 400px;
  171. padding: 25px 25px 5px 25px;
  172. .el-input {
  173. height: 38px;
  174. input {
  175. height: 40px;
  176. border-radius: 200px;
  177. color: #000000;
  178. background-color: rgba(245,248,250,0.8);
  179. border-color:rgba(0,0,0,0.1);
  180. }
  181. input::placeholder {
  182. color: #c1c1c1;
  183. }
  184. }
  185. .input-icon {
  186. height: 39px;
  187. width: 15px;
  188. margin-left: 2px;
  189. color: #565656;
  190. }
  191. }
  192. .login-tip {
  193. font-size: 13px;
  194. text-align: center;
  195. color: #bfbfbf;
  196. }
  197. .login-code {
  198. width: 33%;
  199. height: 38px;
  200. float: right;
  201. border-color: #fff;
  202. img {
  203. cursor: pointer;
  204. vertical-align: middle;
  205. }
  206. }
  207. .el-login-footer {
  208. height: 40px;
  209. line-height: 40px;
  210. position: fixed;
  211. bottom: 0;
  212. width: 100%;
  213. text-align: center;
  214. color: #fff;
  215. font-family: Arial;
  216. font-size: 12px;
  217. letter-spacing: 1px;
  218. }
  219. .login-code-img {
  220. height: 38px;
  221. }
  222. </style>