index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="login-container" @wheel.prevent="handleScroll">
  3. <div class="login-left">
  4. <div class="login-left-tbig">欢迎登陆</div>
  5. <div class="login-left-tlittle">靖安乡村民宿管理端</div>
  6. </div>
  7. <div class="login-right">
  8. <div class="login-right-ttop">靖安乡村民宿</div>
  9. <div class="login-right-tbottom">管理端</div>
  10. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
  11. <el-form-item prop="username">
  12. <span class="svg-container">
  13. <svg-icon icon-class="login_home" />
  14. </span>
  15. <el-input ref="username" v-model="loginForm.username" placeholder="请输入账号" name="username" type="text" tabindex="1" auto-complete="off" />
  16. </el-form-item>
  17. <el-form-item prop="password">
  18. <span class="svg-container">
  19. <svg-icon icon-class="password" />
  20. </span>
  21. <el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType" placeholder="请输入密码" name="password"
  22. tabindex="2" auto-complete="off" @keyup.enter.native="handleLogin" />
  23. <span class="show-pwd" @click="showPwd">
  24. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  25. </span>
  26. </el-form-item>
  27. <el-button :loading="loading" type="primary" class="btn_submit" @click.native.prevent="handleLogin">登 录</el-button>
  28. </el-form>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import {
  34. login
  35. } from '@/api/user'
  36. export default {
  37. name: 'Login',
  38. data() {
  39. const validateUsername = (rule, value, callback) => {
  40. if (!value) {
  41. this.$message.error('请输入账号')
  42. callback(new Error('请输入账号'))
  43. } else {
  44. callback()
  45. }
  46. }
  47. const validatePassword = (rule, value, callback) => {
  48. if (value.length < 6) {
  49. this.$message.error('请输入密码,不小于6位')
  50. callback(new Error('请输入密码,不小于6位'))
  51. } else {
  52. callback()
  53. }
  54. }
  55. return {
  56. loginForm: {
  57. username: '',
  58. password: ''
  59. },
  60. loginRules: {
  61. username: [{
  62. required: true,
  63. trigger: 'blur',
  64. validator: validateUsername
  65. }],
  66. password: [{
  67. required: true,
  68. trigger: 'blur',
  69. validator: validatePassword
  70. }]
  71. },
  72. loading: false,
  73. passwordType: 'password',
  74. redirect: undefined
  75. }
  76. },
  77. watch: {
  78. $route: {
  79. handler: function(route) {
  80. this.redirect = route.query && route.query.redirect
  81. },
  82. immediate: true
  83. }
  84. },
  85. methods: {
  86. handleScroll(event) {
  87. // 在这里可以添加其他逻辑,比如判断是否按下了Ctrl键
  88. if (event.ctrlKey) {
  89. event.preventDefault();
  90. }
  91. },
  92. showPwd() {
  93. if (this.passwordType === 'password') {
  94. this.passwordType = ''
  95. } else {
  96. this.passwordType = 'password'
  97. }
  98. this.$nextTick(() => {
  99. this.$refs.password.focus()
  100. })
  101. },
  102. /**
  103. * 登录
  104. */
  105. handleLogin() {
  106. this.$refs.loginForm.validate(valid => {
  107. if (valid) {
  108. this.loading = true
  109. this.$store.dispatch('user/login', this.loginForm)
  110. .then((res) => {
  111. // console.log(res);
  112. if (res.code == 200) {
  113. if (res.data.level == 2) {
  114. this.$router.push({
  115. path: this.redirect || '/'
  116. });
  117. } else {
  118. this.$router.replace({
  119. path: '/'
  120. });
  121. }
  122. this.$message.success(res.message);
  123. } else {
  124. this.$message.error(res.message);
  125. }
  126. this.loading = false;
  127. }).catch((err) => {
  128. // console.log(err);
  129. this.$message.error(err.message);
  130. this.loading = false;
  131. });
  132. } else {
  133. // this.$message.error('请输入账号或密码!');
  134. return false;
  135. }
  136. })
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss">
  142. .login-container {
  143. display: flex;
  144. .login-left {
  145. width: 40%;
  146. height: 100vh;
  147. display: flex;
  148. flex-direction: column;
  149. justify-content: center;
  150. align-items: center;
  151. background: url('../../icons/images/login/login_bg.png') no-repeat;
  152. background-size: cover;
  153. box-sizing: border-box;
  154. .login-left-tbig {
  155. left: 231px;
  156. top: 445px;
  157. width: 320px;
  158. height: 116px;
  159. opacity: 1;
  160. /** 文本1 */
  161. font-size: 80px;
  162. font-weight: 500;
  163. letter-spacing: 0px;
  164. line-height: 115.84px;
  165. color: rgba(255, 255, 255, 1);
  166. text-align: left;
  167. vertical-align: top;
  168. }
  169. .login-left-tlittle {
  170. left: 218px;
  171. top: 563px;
  172. width: 360px;
  173. height: 58px;
  174. opacity: 1;
  175. /** 文本1 */
  176. font-size: 40px;
  177. font-weight: 500;
  178. letter-spacing: 0px;
  179. line-height: 57.92px;
  180. color: rgba(255, 255, 255, 1);
  181. text-align: left;
  182. vertical-align: top;
  183. }
  184. }
  185. .login-right {
  186. width: 60%;
  187. height: 100vh;
  188. display: flex;
  189. flex-direction: column;
  190. justify-content: center;
  191. align-items: center;
  192. box-sizing: border-box;
  193. .login-right-ttop {
  194. width: 300px;
  195. height: 73px;
  196. opacity: 1;
  197. font-size: 50px;
  198. font-weight: 700;
  199. letter-spacing: 0px;
  200. line-height: 72.4px;
  201. color: rgba(0, 0, 0, 1);
  202. margin-bottom: 20px;
  203. }
  204. .login-right-tbottom {
  205. width: 240px;
  206. height: 116px;
  207. opacity: 1;
  208. font-size: 80px;
  209. font-weight: 700;
  210. letter-spacing: 0px;
  211. line-height: 115.84px;
  212. color: rgba(9, 101, 98, 1);
  213. margin-bottom: 60px;
  214. }
  215. .login-form {
  216. width: 500px;
  217. max-width: 100%;
  218. padding: 0 5px;
  219. overflow: hidden;
  220. display: flex;
  221. flex-direction: column;
  222. align-items: center;
  223. .svg-container {
  224. margin-top: -100px;
  225. font-size: 22px;
  226. display: inline-block;
  227. }
  228. .show-pwd {
  229. font-size: 20px;
  230. }
  231. .btn_submit {
  232. width: 408px;
  233. height: 56px;
  234. opacity: 1;
  235. border-radius: 56px;
  236. background: rgba(9, 101, 98, 1);
  237. font-size: 24px;
  238. font-weight: 400;
  239. letter-spacing: 0px;
  240. line-height: 33.6px;
  241. color: rgba(255, 255, 255, 1);
  242. vertical-align: top;
  243. margin: 30px 0;
  244. }
  245. }
  246. }
  247. .el-input {
  248. display: inline-block;
  249. width: 85%;
  250. input {
  251. background: transparent;
  252. border: 0;
  253. -webkit-appearance: none;
  254. border-radius: 0px;
  255. padding: 12px 5px 12px 15px;
  256. font-size: 20px;
  257. &:-webkit-autofill {
  258. box-shadow: 0 0 0px 1000px #283443 inset !important;
  259. -webkit-text-fill-color: #fff !important;
  260. }
  261. }
  262. }
  263. .el-form-item {
  264. width: 400px;
  265. border: 2px solid rgba(238, 238, 238, 1);
  266. padding: 0 0 0 20px;
  267. }
  268. }
  269. </style>