login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  4. <h3 class="title">途宝智慧云仓平台</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. <!--青岛途宝软件开发有限公司-->
  54. <!-- <div class="el-login-footer">-->
  55. <!-- <img src="./icp.png" alt="" height="14px" style="margin-right:2px"> <span><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=37021302000853">鲁公网安备 37021302000853号</a> <a href="https://beian.miit.gov.cn/">鲁ICP备2021017300号-1</a> 青岛途宝软件开发有限公司</span>-->
  56. <!-- </div>-->
  57. <!--青岛靖润科技物流有限公司-->
  58. <!-- <div class="el-login-footer">-->
  59. <!-- <img src="./icp.png" alt="" height="14px" style="margin-right:2px"> <span><a href="https://beian.miit.gov.cn/">鲁ICP备2021033363号-1</a> 青岛靖润科技物流有限公司</span>-->
  60. <!-- </div>-->
  61. <!-- 凯和-->
  62. <div class="el-login-footer">
  63. <img src="./icp.png" alt="" height="14px" style="margin-right:2px"> <span><a href="https://beian.miit.gov.cn/">鲁ICP备2021017300号-1</a> 青岛凯和志诚物流有限公司</span>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import { getCodeImg } from "@/api/login";
  69. import Cookies from "js-cookie";
  70. import { encrypt, decrypt } from '@/utils/jsencrypt'
  71. export default {
  72. name: "Login",
  73. data() {
  74. return {
  75. codeUrl: "",
  76. company_name:'中电物流',
  77. cookiePassword: "",
  78. loginForm: {
  79. username: "",
  80. password: "",
  81. rememberMe: false,
  82. code: "",
  83. uuid: ""
  84. },
  85. loginRules: {
  86. username: [
  87. { required: true, trigger: "blur", message: "用户名不能为空" }
  88. ],
  89. password: [
  90. { required: true, trigger: "blur", message: "密码不能为空" }
  91. ],
  92. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  93. },
  94. loading: false,
  95. redirect: undefined
  96. };
  97. },
  98. watch: {
  99. $route: {
  100. handler: function(route) {
  101. this.redirect = route.query && route.query.redirect;
  102. },
  103. immediate: true
  104. }
  105. },
  106. created() {
  107. this.getCode();
  108. this.getCookie();
  109. },
  110. methods: {
  111. getCode() {
  112. getCodeImg().then(res => {
  113. this.codeUrl = "data:image/gif;base64," + res.img;
  114. this.loginForm.uuid = res.uuid;
  115. });
  116. },
  117. getCookie() {
  118. const username = Cookies.get("username");
  119. const password = Cookies.get("password");
  120. const rememberMe = Cookies.get('rememberMe')
  121. this.loginForm = {
  122. username: username === undefined ? this.loginForm.username : username,
  123. password: password === undefined ? this.loginForm.password : decrypt(password),
  124. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  125. };
  126. },
  127. handleLogin() {
  128. this.$refs.loginForm.validate(valid => {
  129. if (valid) {
  130. this.loading = true;
  131. if (this.loginForm.rememberMe) {
  132. Cookies.set("username", this.loginForm.username, { expires: 30 });
  133. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  134. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  135. } else {
  136. Cookies.remove("username");
  137. Cookies.remove("password");
  138. Cookies.remove('rememberMe');
  139. }
  140. this.$store
  141. .dispatch("Login", this.loginForm)
  142. .then(() => {
  143. //设置localStroage值
  144. // localStorage.setItem('companyName',this.company_name)
  145. this.$router.push({ path: this.redirect || "/" });
  146. })
  147. .catch(() => {
  148. this.loading = false;
  149. this.getCode();
  150. });
  151. }
  152. });
  153. }
  154. }
  155. };
  156. </script>
  157. <style rel="stylesheet/scss" lang="scss">
  158. .login {
  159. display: flex;
  160. justify-content: center;
  161. align-items: center;
  162. height: 100%;
  163. background-image: url("../assets/images/login-background.jpg");
  164. background-size: cover;
  165. }
  166. .title {
  167. margin: 0px auto 30px auto;
  168. text-align: center;
  169. font-size: 30px;
  170. color: #FFFFFF;
  171. }
  172. .login-form {
  173. border-radius: 6px;
  174. //background: none;
  175. background-color: rgba(0,0,0,0.05);
  176. width: 400px;
  177. padding: 25px 25px 5px 25px;
  178. .el-input {
  179. height: 38px;
  180. input {
  181. height: 40px;
  182. border-radius: 200px;
  183. color: #000000;
  184. background-color: rgba(245,248,250,0.8);
  185. border-color:rgba(0,0,0,0.1);
  186. }
  187. input::placeholder {
  188. color: #c1c1c1;
  189. }
  190. }
  191. .input-icon {
  192. height: 39px;
  193. width: 15px;
  194. margin-left: 2px;
  195. color: #565656;
  196. }
  197. }
  198. .login-tip {
  199. font-size: 13px;
  200. text-align: center;
  201. color: #bfbfbf;
  202. }
  203. .login-code {
  204. width: 33%;
  205. height: 38px;
  206. float: right;
  207. border-color: #fff;
  208. img {
  209. cursor: pointer;
  210. vertical-align: middle;
  211. }
  212. }
  213. .el-login-footer {
  214. height: 40px;
  215. position: fixed;
  216. bottom: 0;
  217. width: 100%;
  218. text-align: center;
  219. color: #fff;
  220. font-family: Arial;
  221. font-size: 12px;
  222. display: flex;
  223. justify-content: center;
  224. align-items: center;
  225. }
  226. .login-code-img {
  227. height: 38px;
  228. }
  229. </style>