index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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);float: left">记住密码</el-checkbox>
  39. <el-form-item style="width:100%;">
  40. <el-button
  41. :loading="loading"
  42. size="medium"
  43. style="width:100%;border-radius: 200px"
  44. @click.native.prevent="handleLogin"
  45. >
  46. <span v-if="!loading">登 录</span>
  47. <span v-else>登 录 中...</span>
  48. </el-button>
  49. </el-form-item>
  50. </el-form>
  51. <!-- 底部 -->
  52. <!-- <div class="el-login-footer">-->
  53. <!-- <span><a href="https://beian.miit.gov.cn/">鲁ICP备2021000559号-1</a> 青岛途宝软件开发有限公司</span>-->
  54. <!-- </div>-->
  55. </div>
  56. </template>
  57. <script>
  58. import {request} from '../../request/request'
  59. import Cookies from "js-cookie";
  60. export default {
  61. name: "Login",
  62. data() {
  63. return {
  64. codeUrl: "",
  65. company_name:'凯和船运',
  66. cookiePassword: "",
  67. loginForm: {
  68. username: "admin",
  69. password: "admin123",
  70. rememberMe: false,
  71. code: "",
  72. uuid: ""
  73. },
  74. loginRules: {
  75. username: [
  76. { required: true, trigger: "blur", message: "用户名不能为空" }
  77. ],
  78. password: [
  79. { required: true, trigger: "blur", message: "密码不能为空" }
  80. ],
  81. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  82. },
  83. loading: false,
  84. redirect: undefined
  85. };
  86. },
  87. watch: {
  88. $route: {
  89. handler: function(route) {
  90. this.redirect = route.query && route.query.redirect;
  91. },
  92. immediate: true
  93. }
  94. },
  95. created() {
  96. this.getCode();
  97. this.getCookie();
  98. },
  99. methods: {
  100. getCode() {
  101. request({
  102. url: '/captchaImage',
  103. method: 'get'
  104. }).then(res => {
  105. console.log(res)
  106. this.codeUrl = "data:image/gif;base64," + res.data.img;
  107. this.loginForm.uuid = res.uuid;
  108. }).catch(err => {
  109. console.log(err);
  110. })
  111. },
  112. getCookie() {
  113. const username = Cookies.get("username");
  114. const password = Cookies.get("password");
  115. const rememberMe = Cookies.get('rememberMe')
  116. this.loginForm = {
  117. username: username === undefined ? this.loginForm.username : username,
  118. password: password === undefined ? this.loginForm.password : decrypt(password),
  119. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  120. };
  121. },
  122. handleLogin() {
  123. this.$refs.loginForm.validate(valid => {
  124. if (valid) {
  125. this.loading = true;
  126. if (this.loginForm.rememberMe) {
  127. Cookies.set("username", this.loginForm.username, { expires: 30 });
  128. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  129. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  130. } else {
  131. Cookies.remove("username");
  132. Cookies.remove("password");
  133. Cookies.remove('rememberMe');
  134. }
  135. request({
  136. url: '/login',
  137. method: 'post',
  138. data: this.loginForm
  139. }).then(res => {
  140. // console.log(res.data.token);
  141. // localStorage.setItem('companyName', this.company_name);
  142. if (res.data.code === 500){
  143. this.$message.error(res.data.msg);
  144. this.loading = false;
  145. }else {
  146. Cookies.set("username",this.loginForm.username);
  147. Cookies.set('TokenKey', res.data.token)
  148. console.log(Cookies.get());
  149. this.$router.push({ path: this.redirect || '/' });
  150. this.loading = false;
  151. }
  152. }).catch(err => {
  153. console.log(err);
  154. this.loading = false;
  155. this.getCode();
  156. })
  157. }
  158. });
  159. }
  160. }
  161. };
  162. </script>
  163. <style rel="stylesheet/scss" lang="scss">
  164. .login {
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. width: 100%;
  169. height: 100%;
  170. background-color: #2c3e50;
  171. position: absolute;
  172. background-image: url("../../assets/login-background.jpg");
  173. background-size: cover;
  174. }
  175. .title {
  176. margin: 0px auto 30px auto;
  177. text-align: center;
  178. font-size: 30px;
  179. color: #FFFFFF;
  180. }
  181. .login-form {
  182. border-radius: 6px;
  183. //background: none;
  184. background-color: rgba(0,0,0,0.1);
  185. width: 400px;
  186. padding: 25px 25px 5px 25px;
  187. .el-input {
  188. height: 38px;
  189. input {
  190. height: 40px;
  191. border-radius: 200px;
  192. color: #000000;
  193. background-color: rgba(245,248,250,0.8);
  194. border-color:rgba(0,0,0,0.1);
  195. }
  196. input::placeholder {
  197. color: #c1c1c1;
  198. }
  199. }
  200. .input-icon {
  201. height: 39px;
  202. width: 15px;
  203. margin-left: 2px;
  204. color: #565656;
  205. }
  206. }
  207. .login-tip {
  208. font-size: 13px;
  209. text-align: center;
  210. color: #bfbfbf;
  211. }
  212. .login-code {
  213. width: 33%;
  214. height: 38px;
  215. float: right;
  216. border-color: #fff;
  217. img {
  218. cursor: pointer;
  219. vertical-align: middle;
  220. }
  221. }
  222. .el-login-footer {
  223. height: 40px;
  224. line-height: 40px;
  225. position: fixed;
  226. bottom: 0;
  227. width: 100%;
  228. text-align: center;
  229. color: #fff;
  230. font-family: Arial;
  231. font-size: 12px;
  232. letter-spacing: 1px;
  233. }
  234. .login-code-img {
  235. height: 38px;
  236. }
  237. </style>