login.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="login">
  3. <StarBackground />
  4. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
  5. <h3 class="title"> 通榆县乡村振兴综合监管平台</h3>
  6. <h3 class="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 StarBackground from '@/components/star'
  47. import {
  48. getCodeImg
  49. } from '@/api/login'
  50. import Cookies from 'js-cookie'
  51. import {
  52. encrypt,
  53. decrypt
  54. } from '@/utils/jsencrypt'
  55. export default {
  56. beforeCreate: function() {
  57.     document.getElementsByTagName('body')[0].style.overflow = 'hidden'
  58.   },
  59. name: 'Login',
  60. components:{
  61. StarBackground
  62. },
  63. data() {
  64. return {
  65. codeUrl: '',
  66. loginForm: {
  67. username: 'admin',
  68. password: 'admin123',
  69. rememberMe: false,
  70. code: '',
  71. uuid: ''
  72. },
  73. loginRules: {
  74. username: [{
  75. required: true,
  76. trigger: 'blur',
  77. message: '请输入您的账号'
  78. }],
  79. password: [{
  80. required: true,
  81. trigger: 'blur',
  82. message: '请输入您的密码'
  83. }],
  84. code: [{
  85. required: true,
  86. trigger: 'change',
  87. message: '请输入验证码'
  88. }]
  89. },
  90. loading: false,
  91. // 验证码开关
  92. captchaOnOff: true,
  93. // 注册开关
  94. register: false,
  95. redirect: undefined
  96. }
  97. },
  98. watch: {
  99. $route: {
  100. handler: function(route) {
  101. this.redirect = route.query && route.query.redirect
  102. },
  103. immediate: true
  104. }
  105. },
  106. created() {
  107. this.getCode()
  108. this.getCookie()
  109. },
  110. methods: {
  111. getCode() {
  112. getCodeImg().then(res => {
  113. this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff
  114. if (this.captchaOnOff) {
  115. this.codeUrl = 'data:image/gif;base64,' + res.img
  116. this.loginForm.uuid = res.uuid
  117. }
  118. })
  119. },
  120. getCookie() {
  121. const username = Cookies.get('username')
  122. const password = Cookies.get('password')
  123. const rememberMe = Cookies.get('rememberMe')
  124. this.loginForm = {
  125. username: username === undefined ? this.loginForm.username : username,
  126. password: password === undefined ? this.loginForm.password : decrypt(password),
  127. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  128. }
  129. },
  130. handleLogin() {
  131. this.$refs.loginForm.validate(valid => {
  132. if (valid) {
  133. this.loading = true
  134. // if (this.loginForm.rememberMe) {
  135. //无论如何我都记-孙一石
  136. if (true) {
  137. Cookies.set('username', this.loginForm.username, {
  138. expires: 30
  139. })
  140. Cookies.set('password', encrypt(this.loginForm.password), {
  141. expires: 30
  142. })
  143. Cookies.set('rememberMe', this.loginForm.rememberMe, {
  144. expires: 30
  145. })
  146. } else {
  147. Cookies.remove('username')
  148. Cookies.remove('password')
  149. Cookies.remove('rememberMe')
  150. }
  151. this.$store.dispatch('Login', this.loginForm).then(() => {
  152. console.log('!@!@!@', this.redirect)
  153. this.$router.push({
  154. //path: this.redirect || '/'
  155. path: '/'
  156. }).catch(() => {})
  157. }).catch(() => {
  158. this.loading = false
  159. if (this.captchaOnOff) {
  160. this.getCode()
  161. }
  162. })
  163. }
  164. })
  165. }
  166. }
  167. }
  168. </script>
  169. <style rel="stylesheet/scss" lang="scss" scoped>
  170. @import '@/assets/styles/base.scss';
  171. .login {
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. height: 100%;
  176. background: url("../../assets/images/login/login-ty.jpg") center;
  177. background-size: cover;
  178. }
  179. .m-b-15 {
  180. margin-bottom: 15px;
  181. }
  182. .title {
  183. margin: 0px auto 30px auto;
  184. text-align: center;
  185. color: #fff;
  186. font-family: $fontFk;
  187. font-size: 38px;
  188. }
  189. .login-form {
  190. border-radius: 6px;
  191. display: flex;
  192. flex-direction: column;
  193. align-items: center;
  194. h3 {
  195. text-shadow: 0 0 15px rgba($color: #00f6ff, $alpha: .7);
  196. }
  197. .login-container {
  198. border-radius: 6px;
  199. background: rgba($color: #fff, $alpha: .7);
  200. width: 450px;
  201. padding: 30px;
  202. box-shadow: 0 0 20px rgba($color: #fff, $alpha: .5);
  203. h4 {
  204. border-bottom: #3e6bfb 1px solid;
  205. width: fit-content;
  206. display: inline-block;
  207. margin-top: 0;
  208. padding-bottom: 5px;
  209. margin-bottom: 20px;
  210. }
  211. }
  212. .el-input {
  213. height: 38px;
  214. input {
  215. height: 38px;
  216. }
  217. }
  218. .input-icon {
  219. height: 39px;
  220. width: 14px;
  221. margin-left: 2px;
  222. color: #3e69fb;
  223. }
  224. .el-button--primary {
  225. font-size: 20px;
  226. background: #3e69fb;
  227. padding: 15px
  228. }
  229. }
  230. .login-tip {
  231. font-size: 13px;
  232. text-align: center;
  233. color: #bfbfbf;
  234. }
  235. .login-code {
  236. width: 33%;
  237. height: 38px;
  238. float: right;
  239. img {
  240. cursor: pointer;
  241. vertical-align: middle;
  242. }
  243. }
  244. .el-login-footer {
  245. height: 40px;
  246. line-height: 40px;
  247. position: fixed;
  248. bottom: 0;
  249. width: 100%;
  250. text-align: center;
  251. color: #fff;
  252. font-family: Arial;
  253. font-size: 12px;
  254. letter-spacing: 1px;
  255. }
  256. .login-code-img {
  257. height: 38px;
  258. }
  259. </style>