login.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <section id="login">
  3. <div class="login-wrap">
  4. <div class="login-inner login-form">
  5. <div class="login-title">
  6. <span>管理员登录</span>
  7. </div>
  8. <div class="username-input">
  9. <input type="text" placeholder="请输入用户名" class="sign-input" v-model="adminTb.name">
  10. </div>
  11. <div class="password-input">
  12. <i class="eye" @click="changeShow"></i>
  13. <input :type="pwdtype" placeholder="请输入密码" class="sign-input" v-model="adminTb.password">
  14. </div>
  15. <div class="sign-btn">
  16. <button class="button-sign" @click="Signin">后台登录</button>
  17. </div>
  18. </div>
  19. </div>
  20. </section>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. adminTb: {
  27. name: '',
  28. password: ''
  29. },
  30. // 密码的type类型
  31. pwdtype: 'password',
  32. // 密码显示隐藏状态
  33. changepwd: true,
  34. }
  35. },
  36. methods: {
  37. // 切换输入密码框密码显示隐藏
  38. changeShow() {
  39. this.changepwd = !this.changepwd
  40. this.pwdtype = this.changepwd == true?'password':'text'
  41. },
  42. // 输入错误延迟显示,并在初期隐藏错误提示
  43. showError(str) {
  44. setTimeout(()=>{
  45. this[str] = true
  46. },1000)
  47. },
  48. // 登录操作
  49. Signin() {
  50. this.$axios({
  51. url: '/login',
  52. method: 'post',
  53. params: {
  54. name : this.adminTb.name,
  55. password: this.adminTb.password
  56. }
  57. }).then(res=> {
  58. if(res.data.code === 200){
  59. setTimeout(()=>{
  60. localStorage.setItem('adminInfo', JSON.stringify(res.data.data), 60); // 设置半天的过期时间
  61. this.$Notice.success({
  62. title: '登录成功'
  63. });
  64. this.$router.push("/")
  65. },1000)
  66. }else {
  67. this.$Message.warning('请确认登录权限');
  68. }
  69. })
  70. .catch(err=> {
  71. console.log(err)
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="less">
  78. #login {
  79. top: 0;
  80. left: 0;
  81. position: fixed;
  82. z-index: 1000;
  83. width: 100%;
  84. height: 100vh;
  85. font-size: 16px;
  86. background-color: #fff;
  87. }
  88. .login-wrap {
  89. width: 100%;
  90. height: 100%;
  91. background-image: url("../../static/background.png");
  92. background-size: cover;
  93. position: relative;
  94. display: flex;
  95. }
  96. .login-inner {
  97. width: 400px;
  98. height: 400px;
  99. padding: 40px 20px;
  100. position: absolute;
  101. top: 0;
  102. left: 0;
  103. bottom: 0;
  104. right: 0;
  105. margin: auto;
  106. background-color: rgba(255, 255, 255, .8);
  107. }
  108. .login-title {
  109. color: #000;
  110. font-size: 24px;
  111. font-weight: bolder;
  112. margin-bottom: 20px;
  113. }
  114. .username-input {
  115. width: 100%;
  116. margin-bottom: 30px;
  117. }
  118. .password-input {
  119. width: 100%;
  120. margin-bottom: 30px;
  121. position: relative;
  122. }
  123. .eye {
  124. top: 18px;
  125. bottom: 18px;
  126. right: 10px;
  127. position: absolute;
  128. width: 25px;
  129. height: 15px;
  130. background-image: url("../../static/eye.png");
  131. background-size: cover;
  132. }
  133. .sign-input {
  134. cursor: pointer;
  135. -webkit-appearance: none;
  136. background-color: #fff;
  137. background-image: none;
  138. border-radius: 4px;
  139. border: 1px solid #d0d0d0;
  140. -webkit-box-sizing: border-box;
  141. box-sizing: border-box;
  142. color: #606266;
  143. display: inline-block;
  144. font-size: inherit;
  145. height: 51px;
  146. line-height: 1;
  147. outline: 0;
  148. padding: 0 15px;
  149. -webkit-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  150. -o-transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  151. transition: border-color .2s cubic-bezier(.645, .045, .355, 1);
  152. width: 100%;
  153. }
  154. .sign-input:focus, .sign-input:hover {
  155. border-color: #0c328a;
  156. }
  157. .sign-input:active {
  158. border-color: #0c328a;
  159. }
  160. .sign-input:active {
  161. outline: 0
  162. }
  163. input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
  164. font-weight: 500;
  165. color: #999999;
  166. font-size: 14px;
  167. vertical-align: middle;
  168. }
  169. input:-moz-placeholder, textarea:-moz-placeholder {
  170. font-weight: 500;
  171. color: #999999;
  172. font-size: 14px;
  173. vertical-align: middle;
  174. }
  175. input::-moz-placeholder, textarea::-moz-placeholder {
  176. font-weight: 500;
  177. color: #999999;
  178. font-size: 14px;
  179. vertical-align: middle;
  180. }
  181. input:-ms-input-placeholder, textarea:-ms-input-placeholder {
  182. font-weight: 500;
  183. color: #999999;
  184. font-size: 14px;
  185. vertical-align: middle;
  186. }
  187. .button-sign {
  188. width: 100%;
  189. height: 51px;
  190. display: inline-block;
  191. border-radius: 4px;
  192. border: 1px solid #35495e;
  193. color: #fff;
  194. font-size: 18px;
  195. background-color: #0c328a;
  196. text-decoration: none;
  197. padding: 10px 30px;
  198. }
  199. .button-sign:hover {
  200. color: #fff;
  201. background-color: #35495e;
  202. }
  203. .button-sign:focus, .button-sign:hover {
  204. background: rgba(12, 50, 138, .8);
  205. border-color: rgba(12, 50, 138, .8);
  206. color: #fff
  207. }
  208. .button-sign:active {
  209. background: rgba(12, 50, 138, .8);
  210. border-color: rgba(12, 50, 138, .8);
  211. color: #fff
  212. }
  213. </style>