login.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <template>
  2. <div class="login" :style="{ backgroundImage: 'url(' + backgroudImg + ')' }">
  3. <!-- 二维码开始 -->
  4. <!-- <el-popover placement="top-start" trigger="hover" :show="bindQRCode">-->
  5. <!-- <img :src="QRCode" width="120px" height="120px" alt="" />-->
  6. <!-- <el-tag slot="reference" class="el-icon-mobile-phone" style="-->
  7. <!-- position: absolute;-->
  8. <!-- top: 1rem;-->
  9. <!-- right: 1rem;-->
  10. <!-- padding: 0 1rem;-->
  11. <!-- cursor: pointer;-->
  12. <!-- " effect="dark">-->
  13. <!-- 下载APP</el-tag>-->
  14. <!-- </el-popover>-->
  15. <!-- 二维码结束 -->
  16. <!-- 二维码开始 -->
  17. <el-popover
  18. placement="top-start"
  19. trigger="click"
  20. :show="bindQRCode"
  21. popper-class="sj-pop"
  22. >
  23. <div class="img-container">
  24. <a class="img-list" onclick="window.open('https://pan.baidu.com/s/1MlWyhFw6pEYiaLvzsje-BA?pwd=3jps')">
  25. <img src="../../assets/images/login-b-1.png" alt="" />
  26. <span>视频插件</span>
  27. </a>
  28. <a class="img-list" onclick="window.open('https://pan.baidu.com/s/1MlWyhFw6pEYiaLvzsje-BA?pwd=3jps')">
  29. <img src="../../assets/images/login-b-2.png" alt="" />
  30. <span>会议插件</span>
  31. </a>
  32. <el-popover placement="left" trigger="hover">
  33. <img :src="QRCode" width="120px" height="120px" alt="" />
  34. <div class="img-list" slot="reference">
  35. <img src="../../assets/images/login-b-3.png" alt="" />
  36. <span>手机APP</span>
  37. </div>
  38. </el-popover>
  39. <a class="img-list" onclick="window.open('https://pan.baidu.com/s/1MlWyhFw6pEYiaLvzsje-BA?pwd=3jps')">
  40. <img src="../../assets/images/login-b-4.png" alt="" />
  41. <span>使用帮助</span>
  42. </a>
  43. </div>
  44. <el-tag slot="reference" class="el-icon-info sj-tag" effect="dark">
  45. 用户引导</el-tag
  46. >
  47. </el-popover>
  48. <!-- 二维码结束 -->
  49. <StarBackground />
  50. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form to-right">
  51. <h3 class="title">{{ systemTitle.title }}</h3>
  52. <h3 class="sub-title" v-if="systemTitle.subTitle">
  53. {{ systemTitle.subTitle }}
  54. </h3>
  55. <div class="login-container">
  56. <h4>请登录</h4>
  57. <el-form-item prop="username">
  58. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" class="m-b-15">
  59. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  60. </el-input>
  61. </el-form-item>
  62. <el-form-item prop="password">
  63. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
  64. @keyup.enter.native="handleLogin" class="m-b-15">
  65. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  66. </el-input>
  67. </el-form-item>
  68. <el-form-item prop="code" v-if="captchaOnOff">
  69. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"
  70. >
  71. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  72. </el-input>
  73. <div class="login-code">
  74. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  75. </div>
  76. </el-form-item>
  77. <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>-->
  78. <el-form-item style="width: 100%">
  79. <el-popover placement="top" trigger="click" @hide="onhide" v-model="popoverVisible">
  80. <!-- 滑动拼图验证区 -->
  81. <el-form-item v-if="sliderOnOff">
  82. <SliderVerify
  83. ref="sliderVerify"
  84. :l="42"
  85. :r="10"
  86. :w="390"
  87. :h="155"
  88. slider-text="向右拖动滑块完成验证"
  89. @success="onSuccess"
  90. @fail="onFail"
  91. />
  92. </el-form-item>
  93. <!-- 滑动拼图验证区 -->
  94. <el-button
  95. slot="reference"
  96. :loading="loading"
  97. :disabled="!verified"
  98. size="medium"
  99. type="primary"
  100. style="width: 100%"
  101. @click.native.prevent="handleLogin"
  102. >
  103. <span v-if="!loading">登 录</span>
  104. <span v-else>登 录 中...</span>
  105. </el-button>
  106. <div style="float: right" v-if="register">
  107. <router-link class="link-type" :to="'/register'"
  108. >立即注册</router-link
  109. >
  110. </div>
  111. </el-popover>
  112. </el-form-item>
  113. </div>
  114. </el-form>
  115. </div>
  116. </template>
  117. <script>
  118. import StarBackground from "@/components/star";
  119. import {
  120. getCodeImg,
  121. fontConfig,
  122. getSecretKey
  123. } from "@/api/login";
  124. import {
  125. encryptedData
  126. } from "@/api/encrypt";
  127. import Cookies from "js-cookie";
  128. import {
  129. encrypt,
  130. decrypt
  131. } from "@/utils/jsencrypt";
  132. import {
  133. getVersionInfo
  134. } from "@/api/system/version"
  135. import axios from 'axios'
  136. import SliderVerify from "@/components/SliderVerify/slider-verify";
  137. export default {
  138. beforeCreate: function() {
  139. document.getElementsByTagName("body")[0].style.overflow = "hidden";
  140. },
  141. beforeDestroy: function() {
  142. document.getElementsByTagName("body")[0].style="";
  143. },
  144. name: "Login",
  145. components: {
  146. StarBackground,
  147. SliderVerify
  148. },
  149. data() {
  150. return {
  151. sliderOnOff: false,
  152. verified: true,
  153. popoverVisible:false,
  154. QRCode: "",
  155. backgroudImg: "", //背景图片
  156. systemTitle: {
  157. title: "", //标题
  158. subTitle: "", //副标题 数字林业
  159. },
  160. codeUrl: "",
  161. loginForm: {
  162. username: "",
  163. password: "",
  164. rememberMe: false,
  165. code: "",
  166. uuid: "",
  167. },
  168. loginRules: {
  169. username: [{
  170. required: true,
  171. trigger: "blur",
  172. message: "请输入您的账号",
  173. }, ],
  174. password: [{
  175. required: true,
  176. trigger: "blur",
  177. message: "请输入您的密码",
  178. }, ],
  179. code: [{
  180. required: true,
  181. trigger: "change",
  182. message: "请输入验证码",
  183. }, ],
  184. },
  185. loading: false,
  186. // 验证码开关
  187. captchaOnOff: true,
  188. // 注册开关
  189. register: false,
  190. redirect: undefined,
  191. appDowPath: ''
  192. };
  193. },
  194. watch: {
  195. $route: {
  196. handler: function(route) {
  197. this.redirect = route.query && route.query.redirect;
  198. },
  199. immediate: true,
  200. },
  201. },
  202. created() {
  203. this.getCode();
  204. this.getCookie();
  205. this.fontConfig();
  206. },
  207. mounted(){
  208. this.getVersionInfo();
  209. },
  210. methods: {
  211. getVersionInfo(){
  212. getVersionInfo().then(res => {
  213. this.QRCode = res.data.picUrl
  214. })
  215. },
  216. fontConfig() {
  217. fontConfig().then((res) => {
  218. this.systemTitle.title = res.data.fontTitle;
  219. this.systemTitle.subTitle = res.data.subTitle;
  220. this.backgroudImg = res.data.picUrl;
  221. });
  222. },
  223. getCode() {
  224. getCodeImg().then((res) => {
  225. this.captchaOnOff =
  226. res.captchaOnOff === undefined ? true : res.captchaOnOff;
  227. if (this.captchaOnOff) {
  228. this.codeUrl = "data:image/gif;base64," + res.img;
  229. this.loginForm.uuid = res.uuid;
  230. }
  231. });
  232. },
  233. getCookie() {
  234. const username = Cookies.get("username");
  235. const password = Cookies.get("password");
  236. const rememberMe = Cookies.get("rememberMe");
  237. this.loginForm = {
  238. username: username === undefined ? this.loginForm.username : username,
  239. password: password === undefined ? this.loginForm.password : decrypt(password),
  240. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  241. };
  242. },
  243. handleLogin() {
  244. this.verified = false;
  245. this.sliderOnOff = true;
  246. },
  247. onSuccess() {
  248. this.$refs.loginForm.validate((valid) => {
  249. if (valid) {
  250. this.verified = true;
  251. this.loading = true;
  252. // if (this.loginForm.rememberMe) {
  253. //无论如何我都记
  254. if (true) {
  255. Cookies.set("username", this.loginForm.username, {
  256. expires: 30,
  257. });
  258. Cookies.set("password", encrypt(this.loginForm.password), {
  259. expires: 30,
  260. });
  261. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  262. expires: 30,
  263. });
  264. } else {
  265. Cookies.remove("username");
  266. Cookies.remove("password");
  267. Cookies.remove("rememberMe");
  268. }
  269. //登录前先获取密码加密传输的公钥,对密码进行加密
  270. getSecretKey().then((res) => {
  271. const encryptedPassword = encryptedData(
  272. res.data,
  273. this.loginForm.password
  274. );
  275. this.loginForm.password = encryptedPassword;
  276. this.$store
  277. .dispatch("Login", this.loginForm)
  278. .then(() => {
  279. this.$router.push({
  280. //path: this.redirect || '/'
  281. path: "/",
  282. });
  283. })
  284. .catch(() => {
  285. this.loginForm.password = null;
  286. this.loading = false;
  287. this.popoverVisible = false;
  288. this.$refs.sliderVerify.refresh();
  289. if (this.captchaOnOff) {
  290. this.getCode();
  291. }
  292. });
  293. });
  294. }
  295. });
  296. },
  297. onFail() {},
  298. onhide() {
  299. this.verified = true;
  300. },
  301. },
  302. };
  303. </script>
  304. <style lang="scss">
  305. .sj-pop {
  306. background: #369cfc !important;
  307. border: 1px solid #369cfc;
  308. border-radius: 10px;
  309. }
  310. </style>
  311. <style rel="stylesheet/scss" lang="scss" scoped>
  312. @import "@/assets/styles/base.scss";
  313. .login {
  314. display: flex;
  315. justify-content: center;
  316. align-items: center;
  317. height: 100%;
  318. background: url("../../assets/images/login/login-ty.jpg") center;
  319. background-size: cover;
  320. }
  321. .m-b-15 {
  322. margin-bottom: 15px;
  323. }
  324. .sub-title {
  325. margin: 0px auto 10px auto;
  326. text-align: center;
  327. color: #fff;
  328. font-family: $fontFk;
  329. font-size: 55px;
  330. }
  331. .title {
  332. margin: 0px auto 10px auto;
  333. text-align: center;
  334. color: #fff;
  335. font-family: $fontFk;
  336. font-size: 38px;
  337. }
  338. .sub-title {
  339. text-align: center;
  340. color: #fff;
  341. font-family: $fontFk;
  342. font-size: 38px;
  343. }
  344. .to-right {
  345. margin-left: 30%;
  346. }
  347. .login-form {
  348. border-radius: 6px;
  349. display: flex;
  350. flex-direction: column;
  351. align-items: center;
  352. h3 {
  353. text-shadow: 0 0 15px rgba($color: #00f6ff, $alpha: 0.7);
  354. }
  355. .login-container {
  356. border-radius: 6px;
  357. background: rgba($color: #fff, $alpha: 0.7);
  358. width: 450px;
  359. padding: 30px;
  360. box-shadow: 0 0 20px rgba($color: #fff, $alpha: 0.5);
  361. h4 {
  362. border-bottom: #3e6bfb 1px solid;
  363. width: fit-content;
  364. display: inline-block;
  365. margin-top: 0;
  366. padding-bottom: 5px;
  367. margin-bottom: 20px;
  368. }
  369. }
  370. .el-input {
  371. height: 38px;
  372. input {
  373. height: 38px;
  374. }
  375. }
  376. .input-icon {
  377. height: 39px;
  378. width: 14px;
  379. margin-left: 2px;
  380. color: #3e69fb;
  381. }
  382. .el-button--primary {
  383. font-size: 20px;
  384. background: #3e69fb;
  385. padding: 15px;
  386. }
  387. }
  388. .login-tip {
  389. font-size: 13px;
  390. text-align: center;
  391. color: #bfbfbf;
  392. }
  393. .login-code {
  394. width: 33%;
  395. height: 38px;
  396. float: right;
  397. img {
  398. cursor: pointer;
  399. vertical-align: middle;
  400. }
  401. }
  402. .el-login-footer {
  403. height: 40px;
  404. line-height: 40px;
  405. position: fixed;
  406. bottom: 0;
  407. width: 100%;
  408. text-align: center;
  409. color: #fff;
  410. font-family: Arial;
  411. font-size: 12px;
  412. letter-spacing: 1px;
  413. }
  414. .login-code-img {
  415. height: 38px;
  416. }
  417. .img-container {
  418. width: 380px;
  419. display: flex;
  420. flex-wrap: wrap;
  421. align-items: center;
  422. justify-content: center;
  423. .img-list {
  424. display: flex;
  425. flex-direction: column;
  426. justify-content: center;
  427. align-items: center;
  428. padding: 15px 10px;
  429. border-radius: 10px;
  430. color: white;
  431. img {
  432. width: 160px;
  433. height: 106px;
  434. border-radius: 10px;
  435. margin-bottom: 8px;
  436. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  437. }
  438. }
  439. .img-list:hover {
  440. background: #dbf1ff;
  441. color: #3e69fb;
  442. font-weight: bolder;
  443. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  444. }
  445. }
  446. .sj-tag {
  447. position: absolute;
  448. top: 1rem;
  449. right: 1rem;
  450. padding: 0 1rem;
  451. cursor: pointer;
  452. }
  453. </style>