login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div class="login view-box">
  3. <div class="login-header">
  4. <img class="login-header-img" src="../assets/images/logo-sj.png">
  5. <span class="login-h-text">首佳科技SSO平台</span>
  6. </div>
  7. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-box">
  8. <div class="from-box">
  9. <div class="login-tit">请登录</div>
  10. <el-form-item prop="username">
  11. <el-input
  12. v-model="loginForm.username"
  13. auto-complete="off"
  14. placeholder="账号"
  15. type="text"
  16. class="sj-input-style"
  17. >
  18. </el-input>
  19. </el-form-item>
  20. <el-form-item prop="password">
  21. <el-input
  22. v-model="loginForm.password"
  23. auto-complete="off"
  24. placeholder="密码"
  25. type="password"
  26. @keyup.enter.native="handleLogin"
  27. class="sj-input-style"
  28. >
  29. </el-input>
  30. </el-form-item>
  31. <el-form-item v-if="captchaEnabled" prop="code" class="flex-r">
  32. <el-input
  33. v-model="loginForm.code"
  34. auto-complete="off"
  35. placeholder="验证码"
  36. style="width: 63%"
  37. @keyup.enter.native="handleLogin"
  38. class="sj-input-style"
  39. >
  40. </el-input>
  41. <div class="login-code">
  42. <img :src="codeUrl" class="login-code-img" @click="getCode"/>
  43. </div>
  44. </el-form-item>
  45. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;text-decoration: none;
  46. color: #50aeff; float: left;" >记住密码</el-checkbox>
  47. <el-form-item style="width:100%;">
  48. <el-button
  49. :loading="loading"
  50. size="medium"
  51. style="width:100%;"
  52. type="primary"
  53. @click.native.prevent="handleLogin"
  54. class="s-input s-btn login-btn"
  55. >
  56. <span v-if="!loading">登 录</span>
  57. <span v-else>登 录 中...</span>
  58. </el-button>
  59. <div v-if="register" style="float: right;">
  60. <router-link :to="'/register'" class="link-type">立即注册</router-link>
  61. </div>
  62. </el-form-item>
  63. </div>
  64. </el-form>
  65. </div>
  66. </template>
  67. <script>
  68. import {getCodeImg, getSecretKey} from "@/api/login";
  69. import Cookies from "js-cookie";
  70. import {decrypt, encrypt} from '@/utils/jsencrypt'
  71. import {encryptedData} from "@/api/tool/encrypt";
  72. export default {
  73. name: "Login",
  74. data() {
  75. return {
  76. codeUrl: "",
  77. loginForm: {
  78. username: "admin",
  79. password: "admin123",
  80. rememberMe: false,
  81. code: "",
  82. uuid: ""
  83. },
  84. loginRules: {
  85. username: [
  86. {required: true, trigger: "blur", message: "请输入您的账号"}
  87. ],
  88. password: [
  89. {required: true, trigger: "blur", message: "请输入您的密码"}
  90. ],
  91. code: [{required: true, trigger: "change", message: "请输入验证码"}]
  92. },
  93. loading: false,
  94. // 验证码开关
  95. captchaEnabled: true,
  96. // 注册开关
  97. register: false,
  98. redirect: undefined
  99. };
  100. },
  101. watch: {
  102. $route: {
  103. handler: function (route) {
  104. this.redirect = route.query && route.query.redirect;
  105. },
  106. immediate: true
  107. }
  108. },
  109. created() {
  110. this.getCode();
  111. this.getCookie();
  112. },
  113. methods: {
  114. getCode() {
  115. getCodeImg().then(res => {
  116. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
  117. if (this.captchaEnabled) {
  118. this.codeUrl = "data:image/gif;base64," + res.img;
  119. this.loginForm.uuid = res.uuid;
  120. }
  121. });
  122. },
  123. getCookie() {
  124. const username = Cookies.get("username");
  125. const password = Cookies.get("password");
  126. const rememberMe = Cookies.get('rememberMe')
  127. this.loginForm = {
  128. username: username === undefined ? this.loginForm.username : username,
  129. password: password === undefined ? this.loginForm.password : decrypt(password),
  130. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  131. };
  132. },
  133. handleLogin() {
  134. this.$refs.loginForm.validate(valid => {
  135. if (valid) {
  136. this.loading = true;
  137. if (this.loginForm.rememberMe) {
  138. Cookies.set("username", this.loginForm.username, {expires: 30});
  139. Cookies.set("password", encrypt(this.loginForm.password), {expires: 30});
  140. Cookies.set('rememberMe', this.loginForm.rememberMe, {expires: 30});
  141. } else {
  142. Cookies.remove("username");
  143. Cookies.remove("password");
  144. Cookies.remove('rememberMe');
  145. }
  146. //登录前先获取密码加密传输的公钥,对密码进行加密
  147. getSecretKey().then((res) => {
  148. const encryptedPassword = encryptedData(
  149. res.data,
  150. this.loginForm.password
  151. );
  152. this.loginForm.password = encryptedPassword;
  153. this.$store.dispatch("Login", this.loginForm).then(() => {
  154. this.$router.push({path: "/"}).catch(() => {
  155. });
  156. }).catch(() => {
  157. this.loading = false;
  158. if (this.captchaEnabled) {
  159. this.getCode();
  160. }
  161. });
  162. });
  163. }
  164. });
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="scss" rel="stylesheet/scss">
  170. .login {
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. height: 100%;
  175. background-image: url("../assets/images/login-background.jpg");
  176. background-size: cover;
  177. }
  178. .title {
  179. margin: 0px auto 30px auto;
  180. text-align: center;
  181. color: #707070;
  182. }
  183. .login-form {
  184. border-radius: 6px;
  185. background: #ffffff;
  186. width: 400px;
  187. padding: 25px 25px 5px 25px;
  188. .el-input {
  189. height: 38px;
  190. input {
  191. height: 38px;
  192. }
  193. }
  194. .input-icon {
  195. height: 39px;
  196. width: 14px;
  197. margin-left: 2px;
  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. img {
  210. cursor: pointer;
  211. vertical-align: middle;
  212. }
  213. }
  214. .el-login-footer {
  215. height: 40px;
  216. line-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. letter-spacing: 1px;
  225. }
  226. .login-code-img {
  227. height: 38px;
  228. }
  229. ::-webkit-input-placeholder {
  230. color: #ccc;
  231. }
  232. /* 视图盒子 */
  233. .view-box {
  234. position: relative;
  235. width: 100vw;
  236. height: 100vh;
  237. overflow: hidden;
  238. background: url("../assets/images/login-bg.jpg") no-repeat;
  239. background-size: 100% 100%;
  240. }
  241. /* 头部 */
  242. .login-header {
  243. position: absolute;
  244. top: 0;
  245. width: 100%;
  246. height: 84px;
  247. background: url("../assets/images/login-header.png") no-repeat;
  248. background-size: 100% 100%;
  249. text-align: center;
  250. font-size: 34px;
  251. color: #fff;
  252. font-weight: bolder;
  253. display: flex;
  254. padding-top: 10px;
  255. justify-content: center;
  256. z-index: 1000;
  257. }
  258. .login-h-text {
  259. background-image: linear-gradient(180deg, #ffffff, #0c8eff);
  260. background-clip:text;
  261. color: transparent;
  262. }
  263. .login-header-img {
  264. margin-top: 6px;
  265. margin-right: 10px;
  266. width: 40px;
  267. height: 40px;
  268. }
  269. /* 登录盒子 */
  270. /* .login-box{width: 400px; height: 400px; position: absolute; left: calc(50% - 200px); top: calc(50% - 200px); max-width: 90%; } */
  271. .login-box {
  272. width: 663px;
  273. margin: auto;
  274. max-width: 90%;
  275. height: 100%;
  276. text-align: center;
  277. }
  278. /* logo */
  279. .logo-box {
  280. height: 150px;
  281. line-height: 150px;
  282. }
  283. .logo-box img {
  284. height: 100px;
  285. margin-right: 20px;
  286. }
  287. .login-tit {
  288. width: 50%;
  289. height: 64px;
  290. line-height: 64px;
  291. text-align: left;
  292. margin-top: 26px;
  293. margin-left: 20px;
  294. font-size: 24px;
  295. font-weight: bolder;
  296. color: #90c8ff;
  297. float: left;
  298. margin-bottom: 50px;
  299. }
  300. /* 表单 */
  301. .from-box {
  302. /* width: 100%; */
  303. height: 597px;
  304. background: url("../assets/images/login-box-bg.png") no-repeat;
  305. border-radius: 0px;
  306. transition: all 0.2s;
  307. background-size: cover;
  308. position: relative;
  309. top: 50%;
  310. transform: translateY(-50%);
  311. }
  312. .from-box > * {
  313. padding: 0px 80px;
  314. }
  315. .from-title {
  316. margin-top: 40px;
  317. margin-bottom: 40px;
  318. text-align: left;
  319. float: left;
  320. }
  321. .tab-box {
  322. }
  323. .tab-box > span {
  324. cursor: pointer;
  325. display: inline-block;
  326. margin-right: 10px;
  327. font-size: 17px; /* letter-spacing: 1px; */
  328. color: #90c8ff;
  329. }
  330. .tab-box > span.nat-tab {
  331. font-weight: bold;
  332. }
  333. .title-border {
  334. width: 68px;
  335. height: 3px;
  336. margin-top: 5px;
  337. background-color: #0084ff;
  338. border-radius: 5px;
  339. transform: translate3d(0px, 0px, 0px);
  340. transition: all 0.2s;
  341. }
  342. .title-border-2 {
  343. transform: translate3d(83px, 0px, 0px);
  344. }
  345. .login-dev,
  346. .reg-dev {
  347. display: none;
  348. }
  349. .native {
  350. display: block;
  351. }
  352. /* 输入框 */
  353. .from-item {
  354. border: 0px #000 solid;
  355. margin-bottom: 40px;
  356. }
  357. .s-input {
  358. width: 100%;
  359. line-height: 50px;
  360. color: #90c8ff;
  361. height: 50px;
  362. text-indent: 1em;
  363. outline: 0;
  364. border: 1px #4982c8 solid;
  365. border-radius: 0px;
  366. transition: all 0.2s;
  367. background: rgba(26, 61, 102, 0.8);
  368. }
  369. .s-input {
  370. font-size: 18px;
  371. }
  372. .s-input:focus {
  373. border-color: #409eff;
  374. }
  375. [name="vc"] {
  376. width: 200px;
  377. }
  378. .send-vc {
  379. font-size: 14px;
  380. color: #666;
  381. float: right;
  382. line-height: 40px;
  383. }
  384. .send-vc a {
  385. cursor: pointer;
  386. color: #409eff;
  387. }
  388. .send-vc a:hover {
  389. text-decoration: underline;
  390. }
  391. /* 登录按钮 */
  392. .s-btn {
  393. text-indent: 0;
  394. font-size: 14px;
  395. cursor: pointer;
  396. background-color: #409eff;
  397. border-color: #409eff;
  398. color: #fff;
  399. }
  400. .s-btn:hover {
  401. background-color: #50aeff;
  402. }
  403. .reg-tips {
  404. text-align: left;
  405. color: #50aeff;
  406. font-size: 14px;
  407. }
  408. .login-btn{
  409. background:linear-gradient(0deg,#23d6ee,#52a9ff );
  410. font-size: 23px;
  411. font-weight: bolder;
  412. display: flex;
  413. justify-content: center;
  414. align-items: center;
  415. }
  416. .login-btn:hover{
  417. background: linear-gradient(0deg,#63e7f8,#6fb6fd );
  418. }
  419. .reg-btn:hover{
  420. background: linear-gradient(0deg,#63e7f8,#3179df );
  421. }
  422. .reg-btn{
  423. background: linear-gradient(0deg,#63e7f8,#17478b );
  424. font-size: 23px;
  425. font-weight: bolder;
  426. }
  427. /* 重置按钮 */
  428. .reset-box {
  429. text-align: left;
  430. font-size: 14px;
  431. }
  432. .reset-box a {
  433. text-decoration: none;
  434. color: #50aeff;
  435. }
  436. .reset-box a:hover {
  437. text-decoration: underline;
  438. }
  439. /* loading框样式 */
  440. .ajax-layer-load.layui-layer-dialog {
  441. min-width: 0px !important;
  442. background-color: rgba(0, 0, 0, 0.85);
  443. }
  444. .ajax-layer-load.layui-layer-dialog .layui-layer-content {
  445. padding: 10px 20px 10px 40px;
  446. color: #fff;
  447. }
  448. .ajax-layer-load.layui-layer-dialog .layui-layer-content .layui-layer-ico {
  449. width: 20px;
  450. height: 20px;
  451. background-size: 20px 20px;
  452. top: 12px;
  453. }
  454. .sj-input-style{
  455. .el-input__inner{
  456. width: 100%;
  457. line-height: 50px;
  458. color: #90c8ff;
  459. height: 50px;
  460. text-indent: 1em;
  461. outline: 0;
  462. border: 1px #4982c8 solid;
  463. border-radius: 0px;
  464. transition: all 0.2s;
  465. background: rgba(26, 61, 102, 0.8);
  466. font-size: 18px;
  467. padding-left: 0;
  468. }
  469. }
  470. .flex-r{
  471. .el-form-item__content{
  472. display: flex;
  473. }
  474. }
  475. </style>