login.vue 7.1 KB

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