index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div class="login-container">
  3. <div id="particles-js">
  4. <vue-particles
  5. color="#dedede"
  6. :particle-opacity="0.7"
  7. :particles-number="80"
  8. shape-type="circle"
  9. :particle-size="4"
  10. lines-color="#dedede"
  11. :lines-width="1"
  12. :line-linked="true"
  13. :line-opacity="0.4"
  14. :lines-distance="150"
  15. :move-speed="3"
  16. :hover-effect="true"
  17. hover-mode="grab"
  18. :click-effect="true"
  19. click-mode="push"
  20. />
  21. </div>
  22. <div class="login-weaper animated bounceInDown">
  23. <div class="login-left">
  24. <div class="login-time" v-text="currentTime" />
  25. <img :src="logo" alt="" class="img" />
  26. <p class="title" v-text="title" />
  27. </div>
  28. <div class="login-border">
  29. <div class="login-main">
  30. <div class="login-title">用户登录</div>
  31. <el-form
  32. ref="loginForm"
  33. :model="loginForm"
  34. :rules="loginRules"
  35. class="login-form"
  36. autocomplete="on"
  37. label-position="left"
  38. >
  39. <el-form-item prop="username">
  40. <span class="svg-container">
  41. <i class="el-icon-user" />
  42. </span>
  43. <el-input
  44. ref="username"
  45. v-model="loginForm.username"
  46. placeholder="用户名"
  47. name="username"
  48. type="text"
  49. tabindex="1"
  50. autocomplete="on"
  51. />
  52. </el-form-item>
  53. <el-tooltip
  54. v-model="capsTooltip"
  55. content="Caps lock is On"
  56. placement="right"
  57. manual
  58. >
  59. <el-form-item prop="password">
  60. <span class="svg-container">
  61. <svg-icon icon-class="password" />
  62. </span>
  63. <el-input
  64. :key="passwordType"
  65. ref="password"
  66. v-model="loginForm.password"
  67. :type="passwordType"
  68. placeholder="密码"
  69. name="password"
  70. tabindex="2"
  71. autocomplete="on"
  72. @keyup.native="checkCapslock"
  73. @blur="capsTooltip = false"
  74. @keyup.enter.native="handleLogin"
  75. />
  76. <span class="show-pwd" @click="showPwd">
  77. <svg-icon
  78. :icon-class="
  79. passwordType === 'password' ? 'eye' : 'eye-open'
  80. "
  81. />
  82. </span>
  83. </el-form-item>
  84. </el-tooltip>
  85. <!-- <el-form-item prop="code" style="width: 66%;float: left;">
  86. <span class="svg-container">
  87. <svg-icon icon-class="validCode" />
  88. </span>
  89. <el-input
  90. ref="username"
  91. v-model="loginForm.code"
  92. placeholder="验证码"
  93. name="username"
  94. type="text"
  95. tabindex="3"
  96. maxlength="5"
  97. autocomplete="off"
  98. style=" width: 75%;"
  99. @keyup.enter.native="handleLogin"
  100. />
  101. </el-form-item> -->
  102. <!-- <div class="login-code" style="cursor:pointer; width: 30%;height: 48px;float: right;background-color: #f0f1f5;">
  103. <img style="height: 48px;width: 100%;border: 1px solid rgba(0,0,0, 0.1);border-radius:5px;" :src="codeUrl" @click="getCode">
  104. </div> -->
  105. <!-- <div prop="code" style="width: 100%;float: left;margin-bottom: 13px">
  106. <el-checkbox v-model="isLdap">LDAP登陆</el-checkbox>
  107. </div> -->
  108. <el-button
  109. :loading="loading"
  110. type="primary"
  111. style="width: 100%; padding: 12px 20px; margin-bottom: 30px"
  112. @click.native.prevent="handleLogin"
  113. >
  114. <span v-if="!loading">登 录</span>
  115. <span v-else>登 录 中...</span>
  116. </el-button>
  117. </el-form>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </template>
  123. <script>
  124. import { getCodeImg } from "@/api/login";
  125. import moment from "moment";
  126. import { mapGetters } from "vuex";
  127. export default {
  128. name: "Login",
  129. data() {
  130. const validateUsername = (rule, value, callback) => {
  131. // validUsername
  132. if (!value) {
  133. callback(new Error("请输入用户名"));
  134. } else {
  135. callback();
  136. }
  137. };
  138. const validatePassword = (rule, value, callback) => {
  139. if (value.length < 6) {
  140. callback(new Error("密码必须大于六位"));
  141. } else {
  142. callback();
  143. }
  144. };
  145. return {
  146. codeUrl: "",
  147. cookiePassword: "",
  148. loginForm: {
  149. username: "",
  150. password: "",
  151. rememberMe: false,
  152. code: "",
  153. uuid: "",
  154. loginType: 1,
  155. },
  156. loginRules: {
  157. username: [
  158. { required: true, trigger: "blur", validator: validateUsername },
  159. ],
  160. password: [
  161. { required: true, trigger: "blur", validator: validatePassword },
  162. ],
  163. },
  164. passwordType: "password",
  165. capsTooltip: false,
  166. loading: false,
  167. redirect: undefined,
  168. otherQuery: {},
  169. currentTime: null,
  170. };
  171. },
  172. computed: {
  173. ...mapGetters(["title", "logo", "isLdap"]),
  174. },
  175. watch: {
  176. $route: {
  177. handler: function (route) {
  178. const query = route.query;
  179. if (query) {
  180. this.redirect = query.redirect;
  181. this.otherQuery = this.getOtherQuery(query);
  182. }
  183. },
  184. immediate: true,
  185. },
  186. },
  187. created() {
  188. // this.getCode()
  189. // window.addEventListener('storage', this.afterQRScan)
  190. this.getCurrentTime();
  191. },
  192. mounted() {
  193. if (this.loginForm.username === "") {
  194. this.$refs.username.focus();
  195. } else if (this.loginForm.password === "") {
  196. this.$refs.password.focus();
  197. }
  198. },
  199. destroyed() {
  200. clearInterval(this.timer);
  201. // window.removeEventListener('storage', this.afterQRScan)
  202. },
  203. methods: {
  204. getCurrentTime() {
  205. this.timer = setInterval((_) => {
  206. this.currentTime = moment().format("YYYY-MM-DD HH时mm分ss秒");
  207. }, 1000);
  208. },
  209. getCode() {
  210. getCodeImg().then((res) => {
  211. if (res !== undefined) {
  212. this.codeUrl = res.data;
  213. this.loginForm.uuid = res.id;
  214. }
  215. });
  216. },
  217. checkCapslock({ shiftKey, key } = {}) {
  218. if (key && key.length === 1) {
  219. if (
  220. (shiftKey && key >= "a" && key <= "z") ||
  221. (!shiftKey && key >= "A" && key <= "Z")
  222. ) {
  223. this.capsTooltip = true;
  224. } else {
  225. this.capsTooltip = false;
  226. }
  227. }
  228. if (key === "CapsLock" && this.capsTooltip === true) {
  229. this.capsTooltip = false;
  230. }
  231. },
  232. showPwd() {
  233. if (this.passwordType === "password") {
  234. this.passwordType = "";
  235. } else {
  236. this.passwordType = "password";
  237. }
  238. this.$nextTick(() => {
  239. this.$refs.password.focus();
  240. });
  241. },
  242. handleLogin() {
  243. this.$refs.loginForm.validate((valid) => {
  244. if (valid) {
  245. if (this.isLdap) {
  246. this.loginForm.loginType = 1;
  247. } else {
  248. this.loginForm.loginType = 0;
  249. }
  250. localStorage.removeItem("searchs");
  251. this.loading = true;
  252. this.$store
  253. .dispatch("user/login", this.loginForm)
  254. .then(() => {
  255. // this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
  256. this.$router.push({ path: "/" });
  257. this.loading = false;
  258. })
  259. .catch(() => {
  260. this.loading = false;
  261. // this.getCode()
  262. });
  263. } else {
  264. return false;
  265. }
  266. });
  267. },
  268. getOtherQuery(query) {
  269. return Object.keys(query).reduce((acc, cur) => {
  270. if (cur !== "redirect") {
  271. acc[cur] = query[cur];
  272. }
  273. return acc;
  274. }, {});
  275. },
  276. },
  277. };
  278. </script>
  279. <style lang="scss" scoped>
  280. /* 修复input 背景不协调 和光标变色 */
  281. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  282. $bg: #283443;
  283. $light_gray: #fff;
  284. $cursor: #fff;
  285. .login-container {
  286. display: -webkit-box;
  287. display: -ms-flexbox;
  288. display: flex;
  289. -webkit-box-align: center;
  290. -ms-flex-align: center;
  291. align-items: center;
  292. width: 100%;
  293. height: 100%;
  294. margin: 0 auto;
  295. background: url("../../assets/login.png") no-repeat;
  296. background-color: #304175;
  297. position: relative;
  298. background-size: cover;
  299. height: 100vh;
  300. background-position: 50%;
  301. }
  302. #particles-js {
  303. z-index: 1;
  304. width: 100%;
  305. height: 100%;
  306. position: absolute;
  307. }
  308. .login-weaper {
  309. margin: 0 auto;
  310. width: 1000px;
  311. -webkit-box-shadow: -4px 5px 10px rgba(0, 0, 0, 0.4);
  312. box-shadow: -4px 5px 10px rgba(0, 0, 0, 0.4);
  313. z-index: 1000;
  314. }
  315. .login-left {
  316. border-top-left-radius: 5px;
  317. border-bottom-left-radius: 5px;
  318. -webkit-box-pack: center;
  319. -ms-flex-pack: center;
  320. justify-content: center;
  321. -webkit-box-orient: vertical;
  322. -webkit-box-direction: normal;
  323. -ms-flex-direction: column;
  324. flex-direction: column;
  325. background-color: rgba(64, 158, 255, 0);
  326. color: #fff;
  327. float: left;
  328. width: 50%;
  329. position: relative;
  330. min-height: 500px;
  331. -webkit-box-align: center;
  332. -ms-flex-align: center;
  333. align-items: center;
  334. display: -webkit-box;
  335. display: -ms-flexbox;
  336. display: flex;
  337. .login-time {
  338. position: absolute;
  339. left: 25px;
  340. top: 25px;
  341. width: 100%;
  342. color: #fff;
  343. opacity: 0.9;
  344. font-size: 18px;
  345. overflow: hidden;
  346. font-weight: 500;
  347. }
  348. }
  349. .login-left .img {
  350. width: 120px;
  351. height: 120px;
  352. border-radius: 3px;
  353. }
  354. .login-left .title {
  355. text-align: center;
  356. color: #fff;
  357. letter-spacing: 2px;
  358. font-size: 30px;
  359. font-weight: 600;
  360. }
  361. .login-border {
  362. position: relative;
  363. min-height: 500px;
  364. -webkit-box-align: center;
  365. -ms-flex-align: center;
  366. align-items: center;
  367. display: -webkit-box;
  368. display: -ms-flexbox;
  369. display: flex;
  370. border-left: none;
  371. border-top-right-radius: 5px;
  372. border-bottom-right-radius: 5px;
  373. color: #fff;
  374. background-color: hsla(0, 0%, 100%, 0.9);
  375. width: 50%;
  376. float: left;
  377. }
  378. .login-main {
  379. margin: 0 auto;
  380. width: 65%;
  381. }
  382. .login-title {
  383. color: #333;
  384. margin-bottom: 40px;
  385. font-weight: 500;
  386. font-size: 22px;
  387. text-align: center;
  388. letter-spacing: 4px;
  389. }
  390. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  391. .login-container .el-input input {
  392. color: $cursor;
  393. }
  394. }
  395. /* reset element-ui css */
  396. .login-container {
  397. :deep(.el-input) {
  398. display: inline-block;
  399. height: 47px;
  400. width: 85%;
  401. input {
  402. background: transparent;
  403. border: 0px;
  404. -webkit-appearance: none;
  405. border-radius: 0px;
  406. padding: 12px 5px 12px 15px;
  407. color: #333;
  408. height: 47px;
  409. caret-color: #333;
  410. &:-webkit-autofill {
  411. box-shadow: 0 0 0px 1000px $bg inset !important;
  412. -webkit-text-fill-color: $cursor !important;
  413. }
  414. }
  415. }
  416. .el-form-item {
  417. border: 1px solid rgba(0, 0, 0, 0.1);
  418. background: rgba(255, 255, 255, 0.8);
  419. border-radius: 5px;
  420. color: #454545;
  421. }
  422. }
  423. $bg: #2d3a4b;
  424. $dark_gray: #889aa4;
  425. $light_gray: #eee;
  426. .login-container {
  427. .tips {
  428. font-size: 14px;
  429. color: #fff;
  430. margin-bottom: 10px;
  431. span {
  432. &:first-of-type {
  433. margin-right: 16px;
  434. }
  435. }
  436. }
  437. .svg-container {
  438. padding: 6px 5px 6px 15px;
  439. color: $dark_gray;
  440. vertical-align: middle;
  441. width: 30px;
  442. display: inline-block;
  443. }
  444. .title-container {
  445. position: relative;
  446. .title {
  447. font-size: 26px;
  448. color: $light_gray;
  449. margin: 0px auto 40px auto;
  450. text-align: center;
  451. font-weight: bold;
  452. }
  453. }
  454. .show-pwd {
  455. position: absolute;
  456. right: 10px;
  457. top: 7px;
  458. font-size: 16px;
  459. color: $dark_gray;
  460. cursor: pointer;
  461. user-select: none;
  462. }
  463. .thirdparty-button {
  464. position: absolute;
  465. right: 0;
  466. bottom: 6px;
  467. }
  468. @media only screen and (max-width: 470px) {
  469. .thirdparty-button {
  470. display: none;
  471. }
  472. }
  473. }
  474. </style>