index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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"></span>
  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"></span>
  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"></span>
  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. >
  66. </el-form>
  67. </div>
  68. </template>
  69. <script>
  70. import { getCaptcha } from '@/api/oauth'
  71. export default {
  72. name: 'Login',
  73. data() {
  74. return {
  75. loginForm: {
  76. username: '18888888888',
  77. password: 'a111111',
  78. captcha: ''
  79. },
  80. loading: false,
  81. passwordType: 'password',
  82. redirect: undefined,
  83. token: '',
  84. captcha: ''
  85. }
  86. },
  87. created() {
  88. this.refreshCaptcha()
  89. },
  90. watch: {
  91. $route: {
  92. handler: function(route) {
  93. this.redirect = route.query && route.query.redirect
  94. },
  95. immediate: true
  96. }
  97. },
  98. methods: {
  99. refreshCaptcha() {
  100. getCaptcha().then((v) => {
  101. console.log(v)
  102. this.token = v.token
  103. this.captcha = v.captcha
  104. })
  105. },
  106. showPwd() {
  107. if (this.passwordType === 'password') {
  108. this.passwordType = ''
  109. } else {
  110. this.passwordType = 'password'
  111. }
  112. this.$nextTick(() => {
  113. this.$refs.password.focus()
  114. })
  115. },
  116. handleLogin() {
  117. this.$refs.loginForm.validate((valid) => {
  118. if (valid) {
  119. this.loading = true
  120. this.$store
  121. .dispatch('user/login', { ...this.loginForm, token: this.token })
  122. .then(() => {
  123. this.$router.push({ path: this.redirect || '/' })
  124. this.loading = false
  125. })
  126. .catch(() => {
  127. this.loading = false
  128. })
  129. } else {
  130. console.log('error submit!!')
  131. return false
  132. }
  133. })
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss">
  139. $bg: #283443;
  140. $light_gray: #fff;
  141. $cursor: #fff;
  142. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  143. .login-container .el-input input {
  144. color: $cursor;
  145. }
  146. }
  147. /* reset element-ui css */
  148. .login-container {
  149. .el-input {
  150. display: inline-block;
  151. height: 47px;
  152. width: 85%;
  153. input {
  154. background: transparent;
  155. border: 0px;
  156. -webkit-appearance: none;
  157. border-radius: 0px;
  158. padding: 12px 5px 12px 15px;
  159. color: $light_gray;
  160. height: 47px;
  161. caret-color: $cursor;
  162. &:-webkit-autofill {
  163. box-shadow: 0 0 0px 1000px $bg inset !important;
  164. -webkit-text-fill-color: $cursor !important;
  165. }
  166. }
  167. }
  168. .el-form-item {
  169. border: 1px solid rgba(255, 255, 255, 0.1);
  170. background: rgba(0, 0, 0, 0.1);
  171. border-radius: 5px;
  172. color: #454545;
  173. }
  174. }
  175. </style>
  176. <style lang="scss" scoped>
  177. $bg: #2d3a4b;
  178. $dark_gray: #889aa4;
  179. $light_gray: #eee;
  180. .login-container {
  181. min-height: 100%;
  182. width: 100%;
  183. background-color: $bg;
  184. overflow: hidden;
  185. .login-form {
  186. position: relative;
  187. width: 520px;
  188. max-width: 100%;
  189. padding: 160px 35px 0;
  190. margin: 0 auto;
  191. overflow: hidden;
  192. }
  193. .svg-container {
  194. padding: 6px 5px 6px 15px;
  195. color: $dark_gray;
  196. vertical-align: middle;
  197. width: 30px;
  198. display: inline-block;
  199. }
  200. .title-container {
  201. position: relative;
  202. .title {
  203. font-size: 26px;
  204. color: $light_gray;
  205. margin: 0px auto 40px auto;
  206. text-align: center;
  207. font-weight: bold;
  208. }
  209. }
  210. .show-pwd {
  211. position: absolute;
  212. right: 10px;
  213. top: 7px;
  214. font-size: 16px;
  215. color: $dark_gray;
  216. cursor: pointer;
  217. user-select: none;
  218. }
  219. }
  220. </style>