index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="login-container">
  3. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on" label-position="left">
  4. <div class="title-container">
  5. <h3 class="title">正品联盟管理系统</h3>
  6. </div>
  7. <el-form-item prop="username">
  8. <span class="svg-container">
  9. <svg-icon icon-class="user" />
  10. </span>
  11. <el-input
  12. ref="username"
  13. v-model="loginForm.username"
  14. placeholder="请输入用户名"
  15. name="username"
  16. type="text"
  17. tabindex="1"
  18. autocomplete="on"
  19. @input="handleInput"
  20. />
  21. </el-form-item>
  22. <el-tooltip v-model="capsTooltip" content="大写已开启" placement="right" manual>
  23. <el-form-item prop="password">
  24. <span class="svg-container">
  25. <svg-icon icon-class="password" />
  26. </span>
  27. <el-input
  28. :key="passwordType"
  29. ref="password"
  30. v-model="loginForm.password"
  31. :type="passwordType"
  32. placeholder="请输入密码"
  33. name="password"
  34. tabindex="2"
  35. autocomplete="on"
  36. @keyup.native="checkCapslock"
  37. @blur="capsTooltip = false"
  38. @keyup.enter.native="handleLogin"
  39. />
  40. <span class="show-pwd" @click="showPwd">
  41. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  42. </span>
  43. </el-form-item>
  44. </el-tooltip>
  45. <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:44px;" @click.native.prevent="handleLogin">登录</el-button>
  46. </el-form>
  47. </div>
  48. </template>
  49. <script>
  50. export default {
  51. name: 'Login',
  52. data() {
  53. return {
  54. loginForm: {
  55. username: '',
  56. password: ''
  57. },
  58. loginRules: {
  59. username: [{ required: true, trigger: 'blur', message: '请输入登录账号' }],
  60. password: [{ required: true, trigger: 'blur', message: '请输入登录密码' }]
  61. },
  62. passwordType: 'password',
  63. capsTooltip: false,
  64. loading: false,
  65. redirect: undefined,
  66. otherQuery: {}
  67. }
  68. },
  69. watch: {
  70. $route: {
  71. handler: function(route) {
  72. const query = route.query
  73. if (query) {
  74. this.redirect = query.redirect
  75. this.otherQuery = this.getOtherQuery(query)
  76. }
  77. },
  78. immediate: true
  79. }
  80. },
  81. created() {
  82. // window.addEventListener('storage', this.afterQRScan)
  83. const isRefresh = this.$store.getters.isRefresh
  84. console.log(isRefresh)
  85. if (!isRefresh) {
  86. window.location.reload()
  87. }
  88. },
  89. mounted() {
  90. if (this.loginForm.username === '') {
  91. this.$refs.username.focus()
  92. } else if (this.loginForm.password === '') {
  93. this.$refs.password.focus()
  94. }
  95. },
  96. destroyed() {
  97. // window.removeEventListener('storage', this.afterQRScan)
  98. },
  99. methods: {
  100. checkCapslock(e) {
  101. const { key } = e
  102. this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
  103. },
  104. showPwd() {
  105. if (this.passwordType === 'password') {
  106. this.passwordType = ''
  107. } else {
  108. this.passwordType = 'password'
  109. }
  110. this.$nextTick(() => {
  111. this.$refs.password.focus()
  112. })
  113. },
  114. handleLogin() {
  115. this.$refs.loginForm.validate(valid => {
  116. if (valid) {
  117. this.loading = true
  118. this.$store.dispatch('user/login', this.loginForm)
  119. .then(() => {
  120. const isAdmin = this.$store.getters.userIdentity === 1
  121. isAdmin ? this.$router.push('/supplier/list') : this.$router.push('/auth/list')
  122. this.loading = false
  123. this.$message.success('登录成功')
  124. this.$store.commit('app/SET_IS_REFRESH', false)
  125. })
  126. .catch(() => {
  127. this.loading = false
  128. })
  129. } else {
  130. return false
  131. }
  132. })
  133. },
  134. getOtherQuery(query) {
  135. return Object.keys(query).reduce((acc, cur) => {
  136. if (cur !== 'redirect') {
  137. acc[cur] = query[cur]
  138. }
  139. return acc
  140. }, {})
  141. },
  142. handleInput() {
  143. this.loginForm.username = this.loginForm.username.replace(/[^\w\.\/]/ig, '')
  144. }
  145. // afterQRScan() {
  146. // if (e.key === 'x-admin-oauth-code') {
  147. // const code = getQueryObject(e.newValue)
  148. // const codeMap = {
  149. // wechat: 'code',
  150. // tencent: 'code'
  151. // }
  152. // const type = codeMap[this.auth_type]
  153. // const codeName = code[type]
  154. // if (codeName) {
  155. // this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
  156. // this.$router.push({ path: this.redirect || '/' })
  157. // })
  158. // } else {
  159. // alert('第三方登录失败')
  160. // }
  161. // }
  162. // }
  163. }
  164. }
  165. </script>
  166. <style lang="scss">
  167. /* 修复input 背景不协调 和光标变色 */
  168. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  169. $bg:#283443;
  170. $light_gray:#fff;
  171. $cursor: #fff;
  172. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  173. .login-container .el-input input {
  174. color: $cursor;
  175. }
  176. }
  177. /* reset element-ui css */
  178. .login-container {
  179. .el-input {
  180. display: inline-block;
  181. height: 47px;
  182. width: 85%;
  183. input {
  184. background: transparent;
  185. border: 0px;
  186. -webkit-appearance: none;
  187. border-radius: 0px;
  188. padding: 12px 5px 12px 15px;
  189. color: $light_gray;
  190. height: 47px;
  191. caret-color: $cursor;
  192. &:-webkit-autofill {
  193. box-shadow: 0 0 0px 1000px $bg inset !important;
  194. -webkit-text-fill-color: $cursor !important;
  195. }
  196. }
  197. }
  198. .el-form-item {
  199. border: 1px solid rgba(255, 255, 255, 0.1);
  200. background: rgba(0, 0, 0, 0.1);
  201. border-radius: 5px;
  202. color: #454545;
  203. }
  204. }
  205. </style>
  206. <style lang="scss" scoped>
  207. $bg:#2d3a4b;
  208. $dark_gray:#889aa4;
  209. $light_gray:#eee;
  210. .login-container {
  211. min-height: 100%;
  212. width: 100%;
  213. background-color: $bg;
  214. overflow: hidden;
  215. .login-form {
  216. position: relative;
  217. width: 520px;
  218. max-width: 100%;
  219. padding: 160px 35px 0;
  220. margin: 0 auto;
  221. overflow: hidden;
  222. }
  223. .tips {
  224. font-size: 14px;
  225. color: #fff;
  226. margin-bottom: 10px;
  227. span {
  228. &:first-of-type {
  229. margin-right: 16px;
  230. }
  231. }
  232. }
  233. .svg-container {
  234. padding: 6px 5px 6px 15px;
  235. color: $dark_gray;
  236. vertical-align: middle;
  237. width: 30px;
  238. display: inline-block;
  239. }
  240. .title-container {
  241. position: relative;
  242. .title {
  243. font-size:36px;
  244. color: $light_gray;
  245. margin: 0px auto 40px auto;
  246. text-align: center;
  247. font-weight: bold;
  248. }
  249. }
  250. .show-pwd {
  251. position: absolute;
  252. right: 10px;
  253. top: 7px;
  254. font-size: 16px;
  255. color: $dark_gray;
  256. cursor: pointer;
  257. user-select: none;
  258. }
  259. .thirdparty-button {
  260. position: absolute;
  261. right: 0;
  262. bottom: 6px;
  263. }
  264. @media only screen and (max-width: 470px) {
  265. .thirdparty-button {
  266. display: none;
  267. }
  268. }
  269. }
  270. </style>