login-sp.vue 7.1 KB

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