login.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="login" id="loginBox">
  3. <div class="logopositon">
  4. <img src="../assets/images/yunlian_logo.png" alt="">
  5. </div>
  6. <div class="login-con">
  7. <div class="img-box">
  8. <div class="imgline1">
  9. 一站式私域平台
  10. </div>
  11. <div class="imgline2">
  12. 助力企业打造自主客户资产池!
  13. </div>
  14. </div>
  15. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  16. <div class="title">{{vueAppTitle}}</div>
  17. <div class="title-line"></div>
  18. <el-form-item prop="username">
  19. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" class="username" >
  20. <img slot="prefix" src="../assets/images/user.png" class="input-icon "/>
  21. </el-input>
  22. </el-form-item>
  23. <el-form-item prop="password">
  24. <el-input
  25. v-model="loginForm.password"
  26. :type="passwordtype"
  27. auto-complete="off"
  28. placeholder="密码"
  29. @keyup.enter.native="handleLogin"
  30. class="password"
  31. >
  32. <!-- <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> -->
  33. <img slot="prefix" src="../assets/images/pass.png" class="input-icon" />
  34. <img slot="suffix" src="../assets/images/eyeoff.png" class="input-icon2" v-if="ispassword" @click.stop="changetype()"/>
  35. <img slot="suffix" src="../assets/images/eyeopen.png" class="input-icon2" v-else @click.stop="changetype()"/>
  36. </el-input>
  37. </el-form-item>
  38. <el-form-item prop="code">
  39. <el-input
  40. v-model="loginForm.code"
  41. auto-complete="off"
  42. placeholder="验证码"
  43. style="width: 63%"
  44. @keyup.enter.native="handleLogin"
  45. >
  46. <!-- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/> -->
  47. <img slot="prefix" src="../assets/images/code.png" class="input-icon" />
  48. </el-input>
  49. <div class="login-code">
  50. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  51. </div>
  52. </el-form-item>
  53. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  54. <el-form-item style="width:100%;">
  55. <el-button
  56. :loading="loading"
  57. size="medium"
  58. type="primary"
  59. style="width:100%;"
  60. @click.native.prevent="handleLogin"
  61. >
  62. <span v-if="!loading">登 录</span>
  63. <span v-else>登 录 中...</span>
  64. </el-button>
  65. </el-form-item>
  66. </el-form>
  67. </div>
  68. <!-- 底部 -->
  69. <div class="el-login-footer">
  70. <span>{{companyName}}</span>
  71. <a :href="icpUrl" target="_bank">{{icpRecord}}</a>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import { getCodeImg } from "@/api/login";
  77. import Cookies from "js-cookie";
  78. import { encrypt, decrypt } from '@/utils/jsencrypt'
  79. export default {
  80. name: "Login",
  81. data() {
  82. return {
  83. codeUrl: "",
  84. vueAppTitle: process.env.VUE_APP_TITLE,
  85. companyName: process.env.VUE_APP_COMPANY_NAME,
  86. icpRecord: process.env.VUE_APP_ICP_RECORD,
  87. icpUrl: process.env.VUE_APP_ICP_URL,
  88. cookiePassword: "",
  89. loginForm: {
  90. username: "",
  91. password: "",
  92. rememberMe: false,
  93. code: "",
  94. uuid: ""
  95. },
  96. loginRules: {
  97. username: [
  98. { required: true, trigger: "blur", message: "用户名不能为空" }
  99. ],
  100. password: [
  101. { required: true, trigger: "blur", message: "密码不能为空" },
  102. {
  103. pattern: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[^A-Za-z0-9]).{8,20}$/,
  104. message: "密码长度为8-20 位,必须包含字母、数字和特殊字符",
  105. trigger: ["blur", "change"],
  106. }
  107. ],
  108. code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
  109. },
  110. loading: false,
  111. redirect: undefined,
  112. passwordtype:'password',
  113. ispassword:true
  114. };
  115. },
  116. watch: {
  117. $route: {
  118. handler: function(route) {
  119. this.redirect = route.query && route.query.redirect;
  120. },
  121. immediate: true
  122. }
  123. },
  124. mounted () {
  125. },
  126. created() {
  127. this.getCode();
  128. this.getCookie();
  129. },
  130. methods: {
  131. getCode() {
  132. getCodeImg().then(res => {
  133. this.codeUrl = "data:image/gif;base64," + res.img;
  134. this.loginForm.uuid = res.uuid;
  135. });
  136. },
  137. getCookie() {
  138. const username = Cookies.get("username");
  139. const password = Cookies.get("password");
  140. const rememberMe = Cookies.get('rememberMe')
  141. this.loginForm = {
  142. username: username === undefined ? this.loginForm.username : username,
  143. password: password === undefined ? this.loginForm.password : decrypt(password),
  144. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  145. };
  146. },
  147. handleLogin() {
  148. this.$refs.loginForm.validate(valid => {
  149. if (valid) {
  150. this.loading = true;
  151. if (this.loginForm.rememberMe) {
  152. Cookies.set("username", this.loginForm.username, { expires: 30 });
  153. Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
  154. Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
  155. } else {
  156. Cookies.remove("username");
  157. Cookies.remove("password");
  158. Cookies.remove('rememberMe');
  159. }
  160. this.$store
  161. .dispatch("Login", this.loginForm)
  162. .then(() => {
  163. this.$router.push({ path: this.redirect || "/" });
  164. })
  165. .catch(() => {
  166. this.loading = false;
  167. this.getCode();
  168. });
  169. }
  170. });
  171. },
  172. changetype(){
  173. this.ispassword=!this.ispassword
  174. if(this.ispassword){
  175. this.passwordtype="password"
  176. }else{
  177. this.passwordtype="text"
  178. }
  179. }
  180. }
  181. };
  182. </script>
  183. <style rel="stylesheet/scss" lang="scss">
  184. .login {
  185. .logopositon{
  186. position: fixed;
  187. left: 30px;
  188. top: 30px;
  189. }
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. height: 100%;
  194. width: 100%;
  195. background-image: (url(../assets/images/login_bg.png) );
  196. background-size: 100% 100%;
  197. background-size: cover;
  198. .login-con{
  199. width: 880px;
  200. display: flex;
  201. align-items: center;
  202. justify-content: space-between;
  203. border-radius: 10px;
  204. .img-box{
  205. width: 440px;
  206. height: 500px;
  207. background-image: url(../assets/images/login_left.png);
  208. background-size: 100% 100%;
  209. color: #FFFFFF;
  210. .imgline1{
  211. font-size: 34px;
  212. font-weight:400;
  213. margin-left: 38px;
  214. margin-top: 38px;
  215. letter-spacing: 2px;
  216. }
  217. .imgline2{
  218. margin-left: 38px;
  219. font-size: 16px;
  220. margin-top: 6px;
  221. letter-spacing: 1px;
  222. }
  223. }
  224. }
  225. }
  226. .title {
  227. margin: 0px auto 15px auto;
  228. text-align: center;
  229. color: #202124;
  230. font-weight: 500;
  231. font-size: 20px;
  232. }
  233. .title-line{
  234. width: 40px;
  235. border-bottom: 2px solid #006CFF;
  236. margin: 0px auto 30px auto;
  237. }
  238. .login-form {
  239. box-sizing: border-box;
  240. background: #ffffff;
  241. width: 440px;
  242. height: 500px;
  243. padding: 40px 25px 5px 25px;
  244. box-shadow:4px -4px 10px rgba(0, 108, 255, 0.15);
  245. .el-input {
  246. height: 38px;
  247. input {
  248. height: 38px;
  249. }
  250. }
  251. .input-icon {
  252. height: 20px;
  253. width: 20px;
  254. margin-left: 2px;
  255. margin-top: 10px;
  256. }
  257. .input-icon2{
  258. height: 20px;
  259. width: 20px;
  260. margin-right: 4px;
  261. margin-top: 10px;
  262. }
  263. }
  264. .login-tip {
  265. font-size: 13px;
  266. text-align: center;
  267. color: #bfbfbf;
  268. }
  269. .login-code {
  270. width: 33%;
  271. height: 38px;
  272. float: right;
  273. img {
  274. cursor: pointer;
  275. vertical-align: middle;
  276. }
  277. }
  278. .el-login-footer {
  279. height: 40px;
  280. line-height: 40px;
  281. position: fixed;
  282. bottom: 0;
  283. width: 100%;
  284. text-align: center;
  285. color: #fff;
  286. font-family: Arial;
  287. font-size: 12px;
  288. letter-spacing: 1px;
  289. }
  290. .login-code-img {
  291. height: 38px;
  292. }
  293. </style>