login.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. mounted(){
  142. this.getVersionInfo();
  143. },
  144. methods: {
  145. getVersionInfo(){
  146. getVersionInfo().then(res => {
  147. this.QRCode = res.data.picUrl
  148. })
  149. },
  150. fontConfig() {
  151. fontConfig().then((res) => {
  152. this.systemTitle.title = res.data.fontTitle;
  153. this.systemTitle.subTitle = res.data.subTitle;
  154. this.backgroudImg = res.data.picUrl;
  155. });
  156. },
  157. getCode() {
  158. getCodeImg().then((res) => {
  159. this.captchaOnOff =
  160. res.captchaOnOff === undefined ? true : res.captchaOnOff;
  161. if (this.captchaOnOff) {
  162. this.codeUrl = "data:image/gif;base64," + res.img;
  163. this.loginForm.uuid = res.uuid;
  164. }
  165. });
  166. },
  167. getCookie() {
  168. const username = Cookies.get("username");
  169. const password = Cookies.get("password");
  170. const rememberMe = Cookies.get("rememberMe");
  171. this.loginForm = {
  172. username: username === undefined ? this.loginForm.username : username,
  173. password: password === undefined ? this.loginForm.password : decrypt(password),
  174. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
  175. };
  176. },
  177. handleLogin() {
  178. this.$refs.loginForm.validate((valid) => {
  179. if (valid) {
  180. this.loading = true;
  181. // if (this.loginForm.rememberMe) {
  182. //无论如何我都记-孙一石
  183. if (true) {
  184. Cookies.set("username", this.loginForm.username, {
  185. expires: 30,
  186. });
  187. Cookies.set("password", encrypt(this.loginForm.password), {
  188. expires: 30,
  189. });
  190. Cookies.set("rememberMe", this.loginForm.rememberMe, {
  191. expires: 30,
  192. });
  193. } else {
  194. Cookies.remove("username");
  195. Cookies.remove("password");
  196. Cookies.remove("rememberMe");
  197. }
  198. //登录前先获取密码加密传输的公钥,对密码进行加密
  199. getSecretKey().then((res) => {
  200. const encryptedPassword = encryptedData(
  201. res.data,
  202. this.loginForm.password
  203. );
  204. this.loginForm.password = encryptedPassword;
  205. this.$store
  206. .dispatch("Login", this.loginForm)
  207. .then(() => {
  208. this.$router.push({
  209. //path: this.redirect || '/'
  210. path: "/",
  211. });
  212. })
  213. .catch(() => {
  214. this.loading = false;
  215. if (this.captchaOnOff) {
  216. this.getCode();
  217. }
  218. });
  219. });
  220. }
  221. });
  222. },
  223. },
  224. };
  225. </script>
  226. <style rel="stylesheet/scss" lang="scss" scoped>
  227. @import "@/assets/styles/base.scss";
  228. .login {
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. height: 100%;
  233. background: url("../../assets/images/login/login-ty.jpg") center;
  234. background-size: cover;
  235. }
  236. .m-b-15 {
  237. margin-bottom: 15px;
  238. }
  239. .sub-title {
  240. margin: 0px auto 10px auto;
  241. text-align: center;
  242. color: #fff;
  243. font-family: $fontFk;
  244. font-size: 55px;
  245. }
  246. .title {
  247. margin: 0px auto 10px auto;
  248. text-align: center;
  249. color: #fff;
  250. font-family: $fontFk;
  251. font-size: 38px;
  252. }
  253. .sub-title {
  254. text-align: center;
  255. color: #fff;
  256. font-family: $fontFk;
  257. font-size: 38px;
  258. }
  259. .to-right {
  260. margin-left: 30%;
  261. }
  262. .login-form {
  263. border-radius: 6px;
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. h3 {
  268. text-shadow: 0 0 15px rgba($color: #00f6ff, $alpha: 0.7);
  269. }
  270. .login-container {
  271. border-radius: 6px;
  272. background: rgba($color: #fff, $alpha: 0.7);
  273. width: 450px;
  274. padding: 30px;
  275. box-shadow: 0 0 20px rgba($color: #fff, $alpha: 0.5);
  276. h4 {
  277. border-bottom: #3e6bfb 1px solid;
  278. width: fit-content;
  279. display: inline-block;
  280. margin-top: 0;
  281. padding-bottom: 5px;
  282. margin-bottom: 20px;
  283. }
  284. }
  285. .el-input {
  286. height: 38px;
  287. input {
  288. height: 38px;
  289. }
  290. }
  291. .input-icon {
  292. height: 39px;
  293. width: 14px;
  294. margin-left: 2px;
  295. color: #3e69fb;
  296. }
  297. .el-button--primary {
  298. font-size: 20px;
  299. background: #3e69fb;
  300. padding: 15px;
  301. }
  302. }
  303. .login-tip {
  304. font-size: 13px;
  305. text-align: center;
  306. color: #bfbfbf;
  307. }
  308. .login-code {
  309. width: 33%;
  310. height: 38px;
  311. float: right;
  312. img {
  313. cursor: pointer;
  314. vertical-align: middle;
  315. }
  316. }
  317. .el-login-footer {
  318. height: 40px;
  319. line-height: 40px;
  320. position: fixed;
  321. bottom: 0;
  322. width: 100%;
  323. text-align: center;
  324. color: #fff;
  325. font-family: Arial;
  326. font-size: 12px;
  327. letter-spacing: 1px;
  328. }
  329. .login-code-img {
  330. height: 38px;
  331. }
  332. </style>