login.vue 8.0 KB

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