index-copy.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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">
  6. {{ $t('login.title') }}
  7. </h3>
  8. <lang-select class="set-language" />
  9. </div> -->
  10. <el-form-item prop="username">
  11. <span class="svg-container">
  12. <svg-icon icon-class="user" />
  13. </span>
  14. <el-input
  15. ref="username"
  16. v-model="loginForm.username"
  17. :placeholder="$t('login.username')"
  18. name="username"
  19. type="text"
  20. tabindex="1"
  21. autocomplete="on"
  22. />
  23. </el-form-item>
  24. <el-tooltip v-model="capsTooltip" content="Caps lock is On" placement="right" manual>
  25. <el-form-item prop="password">
  26. <span class="svg-container">
  27. <svg-icon icon-class="password" />
  28. </span>
  29. <el-input
  30. :key="passwordType"
  31. ref="password"
  32. v-model="loginForm.password"
  33. :type="passwordType"
  34. :placeholder="$t('login.password')"
  35. name="password"
  36. tabindex="2"
  37. autocomplete="on"
  38. @keyup.native="checkCapslock"
  39. @blur="capsTooltip = false"
  40. @keyup.enter.native="handleLogin"
  41. />
  42. <span class="show-pwd" @click="showPwd">
  43. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  44. </span>
  45. </el-form-item>
  46. </el-tooltip>
  47. <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">
  48. {{ $t('login.logIn') }}
  49. </el-button>
  50. <!-- <div style="position:relative">
  51. <div class="tips">
  52. <span>{{ $t('login.username') }} : admin</span>
  53. <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
  54. </div>
  55. <div class="tips">
  56. <span style="margin-right:18px;">
  57. {{ $t('login.username') }} : editor
  58. </span>
  59. <span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
  60. </div>
  61. <el-button class="thirdparty-button" type="primary" @click="showDialog=true">
  62. {{ $t('login.thirdparty') }}
  63. </el-button>
  64. </div> -->
  65. </el-form>
  66. <el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog">
  67. {{ $t('login.thirdpartyTips') }}
  68. <br>
  69. <br>
  70. <br>
  71. <social-sign />
  72. </el-dialog>
  73. </div>
  74. </template>
  75. <script>
  76. import { validUsername } from '@/utils/validate'
  77. // import LangSelect from '@/components/LangSelect'
  78. // import SocialSign from './components/SocialSignin'
  79. export default {
  80. name: 'Login',
  81. // components: { LangSelect, SocialSign },
  82. data() {
  83. // 配置验证规则:用于表单验证
  84. const validateUsername = (rule, value, callback) => {
  85. if (!validUsername(value)) {
  86. callback(new Error('Please enter the correct user name'))
  87. } else {
  88. callback()
  89. }
  90. }
  91. const validatePassword = (rule, value, callback) => {
  92. if (value.length < 6) {
  93. callback(new Error('The password can not be less than 6 digits'))
  94. } else {
  95. callback()
  96. }
  97. }
  98. // 本页基础数据
  99. return {
  100. loginForm: { // 1.用户登录
  101. username: 'admin',
  102. password: '111111'
  103. },
  104. loginRules: { // 2.配置验证规则
  105. username: [{ required: true, trigger: 'blur', validator: validateUsername }],
  106. password: [{ required: true, trigger: 'blur', validator: validatePassword }]
  107. },
  108. passwordType: 'password',
  109. capsTooltip: false,
  110. loading: false,
  111. showDialog: false,
  112. redirect: undefined,
  113. otherQuery: {}
  114. }
  115. },
  116. watch: {
  117. $route: {
  118. handler: function(route) {
  119. const query = route.query
  120. if (query) {
  121. this.redirect = query.redirect
  122. this.otherQuery = this.getOtherQuery(query)
  123. }
  124. },
  125. immediate: true
  126. }
  127. },
  128. created() {
  129. // window.addEventListener('storage', this.afterQRScan)
  130. },
  131. mounted() {
  132. if (this.loginForm.username === '') {
  133. this.$refs.username.focus()
  134. } else if (this.loginForm.password === '') {
  135. this.$refs.password.focus()
  136. }
  137. },
  138. destroyed() {
  139. // window.removeEventListener('storage', this.afterQRScan)
  140. },
  141. methods: {
  142. checkCapslock(e) {
  143. const { key } = e
  144. this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z')
  145. },
  146. showPwd() {
  147. if (this.passwordType === 'password') {
  148. this.passwordType = ''
  149. } else {
  150. this.passwordType = 'password'
  151. }
  152. this.$nextTick(() => {
  153. this.$refs.password.focus()
  154. })
  155. },
  156. handleLogin() {
  157. this.$refs.loginForm.validate(valid => {
  158. if (valid) {
  159. this.loading = true
  160. this.$store.dispatch('user/login', this.loginForm)
  161. .then(() => {
  162. this.$router.push({ path: this.redirect || '/', query: this.otherQuery })
  163. this.loading = false
  164. })
  165. .catch(() => {
  166. this.loading = false
  167. })
  168. } else {
  169. console.log('error submit!!')
  170. return false
  171. }
  172. })
  173. },
  174. getOtherQuery(query) {
  175. return Object.keys(query).reduce((acc, cur) => {
  176. if (cur !== 'redirect') {
  177. acc[cur] = query[cur]
  178. }
  179. return acc
  180. }, {})
  181. }
  182. // afterQRScan() {
  183. // if (e.key === 'x-admin-oauth-code') {
  184. // const code = getQueryObject(e.newValue)
  185. // const codeMap = {
  186. // wechat: 'code',
  187. // tencent: 'code'
  188. // }
  189. // const type = codeMap[this.auth_type]
  190. // const codeName = code[type]
  191. // if (codeName) {
  192. // this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
  193. // this.$router.push({ path: this.redirect || '/' })
  194. // })
  195. // } else {
  196. // alert('第三方登录失败')
  197. // }
  198. // }
  199. // }
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. /* 修复input 背景不协调 和光标变色 */
  205. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  206. $bg:#283443;
  207. $light_gray:#fff;
  208. $cursor: #fff;
  209. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  210. .login-container .el-input input {
  211. color: $cursor;
  212. }
  213. }
  214. /* reset element-ui css */
  215. .login-container {
  216. .el-input {
  217. display: inline-block;
  218. height: 47px;
  219. width: 85%;
  220. input {
  221. background: transparent;
  222. border: 0px;
  223. -webkit-appearance: none;
  224. border-radius: 0px;
  225. padding: 12px 5px 12px 15px;
  226. color: $light_gray;
  227. height: 47px;
  228. caret-color: $cursor;
  229. &:-webkit-autofill {
  230. box-shadow: 0 0 0px 1000px $bg inset !important;
  231. -webkit-text-fill-color: $cursor !important;
  232. }
  233. }
  234. }
  235. .el-form-item {
  236. border: 1px solid rgba(255, 255, 255, 0.1);
  237. background: rgba(0, 0, 0, 0.1);
  238. border-radius: 5px;
  239. color: #454545;
  240. }
  241. }
  242. </style>
  243. <style lang="scss" scoped>
  244. $bg:#2d3a4b;
  245. $dark_gray:#889aa4;
  246. $light_gray:#eee;
  247. .login-container {
  248. min-height: 100%;
  249. width: 100%;
  250. background-color: $bg;
  251. overflow: hidden;
  252. .login-form {
  253. position: relative;
  254. width: 520px;
  255. max-width: 100%;
  256. padding: 160px 35px 0;
  257. margin: 0 auto;
  258. overflow: hidden;
  259. }
  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. .svg-container {
  271. padding: 6px 5px 6px 15px;
  272. color: $dark_gray;
  273. vertical-align: middle;
  274. width: 30px;
  275. display: inline-block;
  276. }
  277. .title-container {
  278. position: relative;
  279. .title {
  280. font-size: 26px;
  281. color: $light_gray;
  282. margin: 0px auto 40px auto;
  283. text-align: center;
  284. font-weight: bold;
  285. }
  286. .set-language {
  287. color: #fff;
  288. position: absolute;
  289. top: 3px;
  290. font-size: 18px;
  291. right: 0px;
  292. cursor: pointer;
  293. }
  294. }
  295. .show-pwd {
  296. position: absolute;
  297. right: 10px;
  298. top: 7px;
  299. font-size: 16px;
  300. color: $dark_gray;
  301. cursor: pointer;
  302. user-select: none;
  303. }
  304. .thirdparty-button {
  305. position: absolute;
  306. right: 0;
  307. bottom: 6px;
  308. }
  309. @media only screen and (max-width: 470px) {
  310. .thirdparty-button {
  311. display: none;
  312. }
  313. }
  314. }
  315. </style>