index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. login
  42. } from '@/api/user'
  43. export default {
  44. name: 'Login',
  45. data() {
  46. const validateUsername = (rule, value, callback) => {
  47. if (!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('请输入密码,不小于6位'))
  56. } else {
  57. callback()
  58. }
  59. }
  60. return {
  61. loginForm: {
  62. username: '',
  63. password: ''
  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. /**
  102. * 登录
  103. */
  104. handleLogin() {
  105. this.$refs.loginForm.validate(valid => {
  106. if (valid) {
  107. this.loading = true
  108. this.$store.dispatch('user/login', this.loginForm)
  109. .then((res) => {
  110. if (res.code == 200) {
  111. this.$router.push({
  112. path: this.redirect || '/'
  113. });
  114. this.$message.success(res.message);
  115. } else {
  116. this.$message.error(res.message);
  117. }
  118. this.loading = false;
  119. }).catch((err) => {
  120. // console.log(err);
  121. this.$message.error(err.message);
  122. this.loading = false;
  123. });
  124. } else {
  125. // this.$message.error('请输入账号或密码!');
  126. return false;
  127. }
  128. })
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. /* 修复input 背景不协调 和光标变色 */
  135. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  136. $bg:#283443;
  137. $cursor: #fff;
  138. /* reset element-ui css */
  139. .login-container {
  140. .el-input {
  141. display: inline-block;
  142. height: 74px;
  143. width: 85%;
  144. input {
  145. background: transparent;
  146. border: 0px;
  147. -webkit-appearance: none;
  148. border-radius: 0px;
  149. padding: 12px 5px 12px 15px;
  150. height: 74px;
  151. font-size: 28px;
  152. &:-webkit-autofill {
  153. box-shadow: 0 0 0px 1000px $bg inset !important;
  154. -webkit-text-fill-color: $cursor !important;
  155. }
  156. }
  157. }
  158. .el-form-item {
  159. border: 2px solid rgba(238, 238, 238, 1);
  160. padding: 0 0 0 30px;
  161. border-radius: 37px;
  162. }
  163. }
  164. </style>
  165. <style lang="scss" scoped>
  166. $bg:#2d3a4b;
  167. $dark_gray:#889aa4;
  168. $light_gray:#eee;
  169. html,
  170. body,
  171. .login-container {
  172. display: flex;
  173. flex-direction: column;
  174. justify-content: center;
  175. background: url(../../icons/images/login/login_bg.png) no-repeat;
  176. background-size: 100% 100%;
  177. width: 100vw;
  178. height: 100vh;
  179. margin-bottom: 0;
  180. .form-container {
  181. display: flex;
  182. justify-content: flex-end;
  183. align-items: center;
  184. margin: 0 auto;
  185. width: 1220px;
  186. height: 650px;
  187. background: url(../../icons/images/login/login_form_bg.png) no-repeat;
  188. background-size: 100% 100%;
  189. #login_form {
  190. display: flex;
  191. flex-direction: column;
  192. justify-content: space-around;
  193. align-items: center;
  194. width: 640px;
  195. height: 500px;
  196. .title-container {
  197. display: flex;
  198. justify-content: space-between;
  199. align-items: center;
  200. width: 500px;
  201. #logo {
  202. width: 63px;
  203. height: 63px;
  204. background: url('../../icons/images/login/logo_login.png') 0 0 no-repeat;
  205. background-size: 63px 63px;
  206. }
  207. #title {
  208. font-size: 42px;
  209. font-family: Microsoft YaHei-3970(82674968);
  210. font-weight: bold;
  211. color: #2B4CFE;
  212. }
  213. }
  214. #caption {
  215. display: flex;
  216. justify-content: center;
  217. font-size: 30px;
  218. font-family: Adobe Heiti Std;
  219. font-weight: bold;
  220. color: #2B4CFE;
  221. margin-top: 60px;
  222. }
  223. .login-form {
  224. width: 500px;
  225. max-width: 100%;
  226. padding: 0 35px;
  227. margin: 0 auto;
  228. overflow: hidden;
  229. .svg-container {
  230. margin-top: -100px;
  231. font-size: 22px;
  232. color: $dark_gray;
  233. display: inline-block;
  234. }
  235. .btn_submit {
  236. width: 100%;
  237. height: 74px;
  238. background: #2B4CFE;
  239. border-radius: 37px;
  240. font-size: 22px;
  241. margin-top: 10px;
  242. }
  243. .btn_link {
  244. width: 100%;
  245. margin-top: 10px;
  246. font-size: 20px;
  247. font-family: Microsoft YaHei-3970(82674968);
  248. font-weight: 400;
  249. color: #2B4CFE;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. // .login-container {
  256. // min-height: 100%;
  257. // width: 100%;
  258. // background-color: $bg;
  259. // overflow: hidden;
  260. // .tips {
  261. // font-size: 14px;
  262. // color: #fff;
  263. // margin-bottom: 10px;
  264. // span {
  265. // &:first-of-type {
  266. // margin-right: 16px;
  267. // }
  268. // }
  269. // }
  270. // .title-container {
  271. // display: flex;
  272. // justify-content: space-between;
  273. // align-items: center;
  274. // position: relative;
  275. // .title {
  276. // font-size: 42px;
  277. // font-family: Microsoft YaHei-3970(82674968);
  278. // font-weight: bold;
  279. // color: #2B4CFE;
  280. // }
  281. // }
  282. // .caption {
  283. // display: flex;
  284. // justify-content: center;
  285. // font-size: 30px;
  286. // font-family: Adobe Heiti Std;
  287. // font-weight: bold;
  288. // color: #2B4CFE;
  289. // }
  290. // .show-pwd {
  291. // position: absolute;
  292. // right: 10px;
  293. // top: 7px;
  294. // font-size: 16px;
  295. // color: $dark_gray;
  296. // cursor: pointer;
  297. // user-select: none;
  298. // }
  299. // }
  300. </style>