index.vue 6.8 KB

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