index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div class="login-container">
  3. <div id="login_form">
  4. <div class="title-container">
  5. <div id="logo"></div>
  6. <div id="title">共享空调运营管理平台</div>
  7. </div>
  8. <div id="caption">登录</div>
  9. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on"
  10. 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"
  16. type="text" tabindex="1" auto-complete="off" />
  17. </el-form-item>
  18. <el-form-item prop="password">
  19. <span class="svg-container">
  20. <svg-icon icon-class="password" />
  21. </span>
  22. <el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType"
  23. placeholder="请输入密码" name="password" tabindex="2" auto-complete="off"
  24. @keyup.enter.native="handleLogin" />
  25. <span class="show-pwd" @click="showPwd">
  26. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  27. </span>
  28. </el-form-item>
  29. <el-button :loading="loading" type="primary" class="btn_submit" @click.native.prevent="handleLogin">登录
  30. </el-button>
  31. <el-link type="primary" class="btn_link" :underline="false" href="#">修改密码</el-link>
  32. </el-form>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import {
  38. validUsername
  39. } from '@/utils/validate'
  40. export default {
  41. name: 'Login',
  42. data() {
  43. const validateUsername = (rule, value, callback) => {
  44. if (!validUsername(value)) {
  45. callback(new Error('请输入密码'))
  46. } else {
  47. callback()
  48. }
  49. }
  50. const validatePassword = (rule, value, callback) => {
  51. if (value.length < 6) {
  52. callback(new Error('请输入密码'))
  53. } else {
  54. callback()
  55. }
  56. }
  57. return {
  58. loginForm: {
  59. username: 'admin',
  60. password: '111111'
  61. },
  62. loginRules: {
  63. username: [{
  64. required: true,
  65. trigger: 'blur',
  66. validator: validateUsername
  67. }],
  68. password: [{
  69. required: true,
  70. trigger: 'blur',
  71. validator: validatePassword
  72. }]
  73. },
  74. loading: false,
  75. passwordType: 'password',
  76. redirect: undefined
  77. }
  78. },
  79. watch: {
  80. $route: {
  81. handler: function(route) {
  82. this.redirect = route.query && route.query.redirect
  83. },
  84. immediate: true
  85. }
  86. },
  87. methods: {
  88. showPwd() {
  89. if (this.passwordType === 'password') {
  90. this.passwordType = ''
  91. } else {
  92. this.passwordType = 'password'
  93. }
  94. this.$nextTick(() => {
  95. this.$refs.password.focus()
  96. })
  97. },
  98. handleLogin() {
  99. this.$refs.loginForm.validate(valid => {
  100. if (valid) {
  101. this.loading = true
  102. this.$store.dispatch('user/login', this.loginForm).then(() => {
  103. this.$router.push({
  104. path: this.redirect || '/'
  105. })
  106. this.loading = false
  107. }).catch(() => {
  108. this.loading = false
  109. })
  110. } else {
  111. console.log('error submit!!')
  112. return false
  113. }
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. /* 修复input 背景不协调 和光标变色 */
  121. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  122. $bg:#283443;
  123. $cursor: #fff;
  124. /* reset element-ui css */
  125. .login-container {
  126. .el-input {
  127. display: inline-block;
  128. height: 74px;
  129. width: 85%;
  130. input {
  131. background: transparent;
  132. border: 0px;
  133. -webkit-appearance: none;
  134. border-radius: 0px;
  135. padding: 12px 5px 12px 15px;
  136. height: 74px;
  137. font-size: 28px;
  138. &:-webkit-autofill {
  139. box-shadow: 0 0 0px 1000px $bg inset !important;
  140. -webkit-text-fill-color: $cursor !important;
  141. }
  142. }
  143. }
  144. .el-form-item {
  145. border: 2px solid rgba(238, 238, 238, 1);
  146. padding: 0 0 0 30px;
  147. border-radius: 37px;
  148. }
  149. }
  150. </style>
  151. <style lang="scss" scoped>
  152. $bg:#2d3a4b;
  153. $dark_gray:#889aa4;
  154. $light_gray:#eee;
  155. html,
  156. body,
  157. .login-container {
  158. width: 100vw;
  159. height: 100vh;
  160. min-width: 1780px;
  161. min-height: 900px;
  162. background: url('../../icons/images/login/login_bg.png') no-repeat;
  163. background-size: 100% 100%;
  164. margin-bottom: 0;
  165. display: flex;
  166. flex-direction: column;
  167. justify-content: center;
  168. #login_form {
  169. display: flex;
  170. flex-direction: column;
  171. justify-content: space-around;
  172. align-items: center;
  173. width: 600px;
  174. height: 500px;
  175. position: absolute;
  176. left: 980px;
  177. top: 160px;
  178. .title-container {
  179. display: flex;
  180. justify-content: space-between;
  181. align-items: center;
  182. width: 500px;
  183. #logo {
  184. width: 63px;
  185. height: 63px;
  186. background: url('../../icons/images/login/logo_login.png') 0 0 no-repeat;
  187. background-size: 63px 63px;
  188. }
  189. #title {
  190. font-size: 42px;
  191. font-family: Microsoft YaHei-3970(82674968);
  192. font-weight: bold;
  193. color: #2B4CFE;
  194. }
  195. }
  196. #caption {
  197. display: flex;
  198. justify-content: center;
  199. font-size: 30px;
  200. font-family: Adobe Heiti Std;
  201. font-weight: bold;
  202. color: #2B4CFE;
  203. margin-top: 60px;
  204. }
  205. .login-form {
  206. width: 500px;
  207. max-width: 100%;
  208. padding: 0 35px;
  209. margin: 0 auto;
  210. overflow: hidden;
  211. .svg-container {
  212. margin-top: -100px;
  213. font-size: 22px;
  214. color: $dark_gray;
  215. display: inline-block;
  216. }
  217. .btn_submit {
  218. width: 100%;
  219. height: 74px;
  220. background: #2B4CFE;
  221. border-radius: 37px;
  222. font-size: 22px;
  223. margin-top: 10px;
  224. }
  225. .btn_link {
  226. width: 100%;
  227. margin-top: 10px;
  228. font-size: 20px;
  229. font-family: Microsoft YaHei-3970(82674968);
  230. font-weight: 400;
  231. color: #2B4CFE;
  232. }
  233. }
  234. }
  235. }
  236. // .login-container {
  237. // min-height: 100%;
  238. // width: 100%;
  239. // background-color: $bg;
  240. // overflow: hidden;
  241. // .tips {
  242. // font-size: 14px;
  243. // color: #fff;
  244. // margin-bottom: 10px;
  245. // span {
  246. // &:first-of-type {
  247. // margin-right: 16px;
  248. // }
  249. // }
  250. // }
  251. // .title-container {
  252. // display: flex;
  253. // justify-content: space-between;
  254. // align-items: center;
  255. // position: relative;
  256. // .title {
  257. // font-size: 42px;
  258. // font-family: Microsoft YaHei-3970(82674968);
  259. // font-weight: bold;
  260. // color: #2B4CFE;
  261. // }
  262. // }
  263. // .caption {
  264. // display: flex;
  265. // justify-content: center;
  266. // font-size: 30px;
  267. // font-family: Adobe Heiti Std;
  268. // font-weight: bold;
  269. // color: #2B4CFE;
  270. // }
  271. // .show-pwd {
  272. // position: absolute;
  273. // right: 10px;
  274. // top: 7px;
  275. // font-size: 16px;
  276. // color: $dark_gray;
  277. // cursor: pointer;
  278. // user-select: none;
  279. // }
  280. // }
  281. </style>