login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. <StarBackground />
  17. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form to-right">
  18. <h3 class="title">{{ systemTitle.title }}</h3>
  19. <h3 class="sub-title" v-if="systemTitle.subTitle">
  20. {{ systemTitle.subTitle }}
  21. </h3>
  22. <div class="login-container">
  23. <h4>请登录</h4>
  24. <el-form-item prop="username">
  25. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" class="m-b-15">
  26. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
  27. </el-input>
  28. </el-form-item>
  29. <el-form-item prop="password">
  30. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
  31. @keyup.enter.native="handleLogin" class="m-b-15">
  32. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
  33. </el-input>
  34. </el-form-item>
  35. <el-form-item prop="code" v-if="captchaOnOff">
  36. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"
  37. @keyup.enter.native="handleLogin">
  38. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
  39. </el-input>
  40. <div class="login-code">
  41. <img :src="codeUrl" @click="getCode" class="login-code-img" />
  42. </div>
  43. </el-form-item>
  44. <!-- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>-->
  45. <el-form-item style="width: 100%">
  46. <el-button :loading="loading" size="medium" type="primary" style="width: 100%"
  47. @click.native.prevent="handleLogin">
  48. <span v-if="!loading">登 录</span>
  49. <span v-else>登 录 中...</span>
  50. </el-button>
  51. <div style="float: right" v-if="register">
  52. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  53. </div>
  54. </el-form-item>
  55. </div>
  56. </el-form>
  57. </div>
  58. </template>
  59. <script>
  60. import StarBackground from "@/components/star";
  61. import {
  62. getCodeImg,
  63. fontConfig,
  64. getSecretKey
  65. } from "@/api/login";
  66. import {
  67. encryptedData
  68. } from "@/api/encrypt";
  69. import Cookies from "js-cookie";
  70. import {
  71. encrypt,
  72. decrypt
  73. } from "@/utils/jsencrypt";
  74. import {
  75. getVersionInfo
  76. } from "@/api/system/version"
  77. import axios from 'axios'
  78. export default {
  79. beforeCreate: function() {
  80. document.getElementsByTagName("body")[0].style.overflow = "hidden";
  81. },
  82. name: "Login",
  83. components: {
  84. StarBackground,
  85. },
  86. data() {
  87. return {
  88. QRCode: "",
  89. backgroudImg: "", //背景图片
  90. systemTitle: {
  91. title: "", //标题
  92. subTitle: "", //副标题 数字林业
  93. },
  94. codeUrl: "",
  95. loginForm: {
  96. username: "",
  97. password: "",
  98. rememberMe: false,
  99. code: "",
  100. uuid: "",
  101. },
  102. loginRules: {
  103. username: [{
  104. required: true,
  105. trigger: "blur",
  106. message: "请输入您的账号",
  107. }, ],
  108. password: [{
  109. required: true,
  110. trigger: "blur",
  111. message: "请输入您的密码",
  112. }, ],
  113. code: [{
  114. required: true,
  115. trigger: "change",
  116. message: "请输入验证码",
  117. }, ],
  118. },
  119. loading: false,
  120. // 验证码开关
  121. captchaOnOff: true,
  122. // 注册开关
  123. register: false,
  124. redirect: undefined,
  125. appDowPath: ''
  126. };
  127. },
  128. watch: {
  129. $route: {
  130. handler: function(route) {
  131. this.redirect = route.query && route.query.redirect;
  132. },
  133. immediate: true,
  134. },
  135. },
  136. created() {
  137. this.getCode();
  138. this.getCookie();
  139. this.fontConfig();
  140. },
  141. methods: {
  142. getVersionInfo(){
  143. getVersionInfo().then(res => {
  144. this.QRCode = res.data.QRCode
  145. })
  146. },
  147. fontConfig() {
  148. fontConfig().then((res) => {
  149. this.systemTitle.title = res.data.fontTitle;
  150. this.systemTitle.subTitle = res.data.subTitle;
  151. this.backgroudImg = res.data.picUrl;
  152. });
  153. },
  154. getCode() {
  155. getCodeImg().then((res) => {
  156. this.captchaOnOff =
  157. res.captchaOnOff === undefined ? true : res.captchaOnOff;
  158. if (this.captchaOnOff) {
  159. this.codeUrl = "data:image/gif;base64," + res.img;
  160. this.loginForm.uuid = res.uuid;
  161. }
  162. });
  163. },
  164. getCookie() {
  165. const username = Cookies.get("username");
  166. const password = Cookies.get("password");
  167. const rememberMe = Cookies.get("rememberMe");
  168. this.loginForm = {
  169. username: username === undefined ? this.loginForm.username : username,
  170. password: password === undefined ? this.loginForm.password : decrypt(password),
  171. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  172. };
  173. },
  174. handleLogin() {
  175. this.$refs.loginForm.validate((valid) => {
  176. if (valid) {
  177. this.loading = true;
  178. // if (this.loginForm.rememberMe) {
  179. //无论如何我都记-孙一石
  180. if (true) {
  181. Cookies.set("username", this.loginForm.username, {
  182. expires: 30,
  183. });
  184. Cookies.set("password", encrypt(this.loginForm.password), {
  185. expires: 30,
  186. });
  187. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  188. expires: 30,
  189. });
  190. } else {
  191. Cookies.remove("username");
  192. Cookies.remove("password");
  193. Cookies.remove("rememberMe");
  194. }
  195. //登录前先获取密码加密传输的公钥,对密码进行加密
  196. getSecretKey().then((res) => {
  197. const encryptedPassword = encryptedData(
  198. res.data,
  199. this.loginForm.password
  200. );
  201. this.loginForm.password = encryptedPassword;
  202. this.$store
  203. .dispatch("Login", this.loginForm)
  204. .then(() => {
  205. this.$router.push({
  206. //path: this.redirect || '/'
  207. path: "/",
  208. });
  209. })
  210. .catch(() => {
  211. this.loading = false;
  212. if (this.captchaOnOff) {
  213. this.getCode();
  214. }
  215. });
  216. });
  217. }
  218. });
  219. },
  220. },
  221. };
  222. </script>
  223. <style rel="stylesheet/scss" lang="scss" scoped>
  224. @import "@/assets/styles/base.scss";
  225. .login {
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. height: 100%;
  230. background: url("../../assets/images/login/login-ty.jpg") center;
  231. background-size: cover;
  232. }
  233. .m-b-15 {
  234. margin-bottom: 15px;
  235. }
  236. .sub-title {
  237. margin: 0px auto 10px auto;
  238. text-align: center;
  239. color: #fff;
  240. font-family: $fontFk;
  241. font-size: 55px;
  242. }
  243. .title {
  244. margin: 0px auto 10px auto;
  245. text-align: center;
  246. color: #fff;
  247. font-family: $fontFk;
  248. font-size: 38px;
  249. }
  250. .sub-title {
  251. text-align: center;
  252. color: #fff;
  253. font-family: $fontFk;
  254. font-size: 38px;
  255. }
  256. .to-right {
  257. margin-left: 30%;
  258. }
  259. .login-form {
  260. border-radius: 6px;
  261. display: flex;
  262. flex-direction: column;
  263. align-items: center;
  264. h3 {
  265. text-shadow: 0 0 15px rgba($color: #00f6ff, $alpha: 0.7);
  266. }
  267. .login-container {
  268. border-radius: 6px;
  269. background: rgba($color: #fff, $alpha: 0.7);
  270. width: 450px;
  271. padding: 30px;
  272. box-shadow: 0 0 20px rgba($color: #fff, $alpha: 0.5);
  273. h4 {
  274. border-bottom: #3e6bfb 1px solid;
  275. width: fit-content;
  276. display: inline-block;
  277. margin-top: 0;
  278. padding-bottom: 5px;
  279. margin-bottom: 20px;
  280. }
  281. }
  282. .el-input {
  283. height: 38px;
  284. input {
  285. height: 38px;
  286. }
  287. }
  288. .input-icon {
  289. height: 39px;
  290. width: 14px;
  291. margin-left: 2px;
  292. color: #3e69fb;
  293. }
  294. .el-button--primary {
  295. font-size: 20px;
  296. background: #3e69fb;
  297. padding: 15px;
  298. }
  299. }
  300. .login-tip {
  301. font-size: 13px;
  302. text-align: center;
  303. color: #bfbfbf;
  304. }
  305. .login-code {
  306. width: 33%;
  307. height: 38px;
  308. float: right;
  309. img {
  310. cursor: pointer;
  311. vertical-align: middle;
  312. }
  313. }
  314. .el-login-footer {
  315. height: 40px;
  316. line-height: 40px;
  317. position: fixed;
  318. bottom: 0;
  319. width: 100%;
  320. text-align: center;
  321. color: #fff;
  322. font-family: Arial;
  323. font-size: 12px;
  324. letter-spacing: 1px;
  325. }
  326. .login-code-img {
  327. height: 38px;
  328. }
  329. </style>