index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <div class="login-container">
  3. <el-form
  4. ref="loginForm"
  5. :model="loginForm"
  6. class="login-form"
  7. auto-complete="on"
  8. label-position="left"
  9. >
  10. <div class="title-container">
  11. <h3 class="title">湖南智企云开放平台</h3>
  12. </div>
  13. <el-form-item prop="username">
  14. <span class="svg-container el-icon-user-solid" />
  15. <el-input
  16. ref="username"
  17. v-model="loginForm.username"
  18. placeholder="请输入手机号/邮箱"
  19. name="username"
  20. type="text"
  21. auto-complete="on"
  22. />
  23. </el-form-item>
  24. <el-form-item prop="password">
  25. <span class="svg-container el-icon-lock" />
  26. <el-input
  27. :key="passwordType"
  28. ref="password"
  29. v-model="loginForm.password"
  30. :type="passwordType"
  31. placeholder="请输入登录密码"
  32. name="password"
  33. auto-complete="on"
  34. @keyup.enter.native="handleLogin"
  35. />
  36. <span class="show-pwd" @click="showPwd">
  37. <svg-icon
  38. :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
  39. />
  40. </span>
  41. </el-form-item>
  42. <el-form-item prop="password">
  43. <span class="svg-container el-icon-warning" />
  44. <el-input
  45. ref="captcha"
  46. v-model="loginForm.captcha"
  47. placeholder="请输入验证码"
  48. name="captcha"
  49. type="text"
  50. />
  51. <img
  52. :src="captcha"
  53. class="show-pwd"
  54. style="height: 38px"
  55. @click="refreshCaptcha"
  56. >
  57. </el-form-item>
  58. <el-button
  59. :loading="loading"
  60. type="primary"
  61. style="width: 100%; margin-bottom: 30px"
  62. @click.native.prevent="handleLogin"
  63. >立即登录
  64. </el-button>
  65. </el-form>
  66. </div>
  67. </template>
  68. <script>
  69. import { getCaptcha } from '@/api/oauth'
  70. export default {
  71. name: 'Login',
  72. data() {
  73. return {
  74. loginForm: {
  75. username: '18888888888',
  76. password: 'a111111',
  77. captcha: ''
  78. },
  79. loading: false,
  80. passwordType: 'password',
  81. redirect: undefined,
  82. token: '',
  83. captcha: ''
  84. }
  85. },
  86. watch: {
  87. $route: {
  88. handler: function(route) {
  89. this.redirect = route.query && route.query.redirect
  90. },
  91. immediate: true
  92. }
  93. },
  94. created() {
  95. this.refreshCaptcha()
  96. },
  97. methods: {
  98. refreshCaptcha() {
  99. getCaptcha().then((v) => {
  100. console.log(v)
  101. this.token = v.token
  102. this.captcha = v.captcha
  103. })
  104. },
  105. showPwd() {
  106. if (this.passwordType === 'password') {
  107. this.passwordType = ''
  108. } else {
  109. this.passwordType = 'password'
  110. }
  111. this.$nextTick(() => {
  112. this.$refs.password.focus()
  113. })
  114. },
  115. handleLogin() {
  116. this.$refs.loginForm.validate((valid) => {
  117. if (valid) {
  118. this.loading = true
  119. this.$store
  120. .dispatch('user/login', { ...this.loginForm, token: this.token })
  121. .then(() => {
  122. this.$router.push({ path: this.redirect || '/' })
  123. this.loading = false
  124. })
  125. .catch(() => {
  126. this.loading = false
  127. })
  128. } else {
  129. console.log('error submit!!')
  130. return false
  131. }
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. $bg: #283443;
  139. $light_gray: #fff;
  140. $cursor: #fff;
  141. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  142. .login-container .el-input input {
  143. color: $cursor;
  144. }
  145. }
  146. /* reset element-ui css */
  147. .login-container {
  148. .el-input {
  149. display: inline-block;
  150. height: 47px;
  151. width: 85%;
  152. input {
  153. background: transparent;
  154. border: 0px;
  155. -webkit-appearance: none;
  156. border-radius: 0px;
  157. padding: 12px 5px 12px 15px;
  158. color: $light_gray;
  159. height: 47px;
  160. caret-color: $cursor;
  161. &:-webkit-autofill {
  162. box-shadow: 0 0 0px 1000px $bg inset !important;
  163. -webkit-text-fill-color: $cursor !important;
  164. }
  165. }
  166. }
  167. .el-form-item {
  168. border: 1px solid rgba(255, 255, 255, 0.1);
  169. background: rgba(0, 0, 0, 0.1);
  170. border-radius: 5px;
  171. color: #454545;
  172. }
  173. }
  174. </style>
  175. <style lang="scss" scoped>
  176. $bg: #2d3a4b;
  177. $dark_gray: #889aa4;
  178. $light_gray: #eee;
  179. .login-container {
  180. min-height: 100%;
  181. width: 100%;
  182. background-color: $bg;
  183. overflow: hidden;
  184. .login-form {
  185. position: relative;
  186. width: 520px;
  187. max-width: 100%;
  188. padding: 160px 35px 0;
  189. margin: 0 auto;
  190. overflow: hidden;
  191. }
  192. .svg-container {
  193. padding: 6px 5px 6px 15px;
  194. color: $dark_gray;
  195. vertical-align: middle;
  196. width: 30px;
  197. display: inline-block;
  198. }
  199. .title-container {
  200. position: relative;
  201. .title {
  202. font-size: 26px;
  203. color: $light_gray;
  204. margin: 0px auto 40px auto;
  205. text-align: center;
  206. font-weight: bold;
  207. }
  208. }
  209. .show-pwd {
  210. position: absolute;
  211. right: 10px;
  212. top: 7px;
  213. font-size: 16px;
  214. color: $dark_gray;
  215. cursor: pointer;
  216. user-select: none;
  217. }
  218. }
  219. </style>