index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <!-- <div class="login-container">
  3. <div class="content">
  4. <div class="content-l"></div>
  5. <div class="login">
  6. <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left" >
  7. <div class="title-container">
  8. <h3 class="title">万象设备管理系统</h3>
  9. <b>WanXiang Equipment Management System</b>
  10. <hr>
  11. </div>
  12. <el-form-item prop="username">
  13. <span class="svg-container">
  14. <svg-icon icon-class="user" />
  15. </span>
  16. <el-input ref="username" v-model="loginForm.username" placeholder="Username" name="username" type="text" tabindex="1" auto-complete="on" />
  17. </el-form-item>
  18. <el-form-item prop="password">
  19. <span class="svg-container">
  20. <svg-icon icon-class="password" />
  21. </span>
  22. <el-input :key="passwordType" ref="password" v-model="loginForm.password" :type="passwordType" placeholder="Password" name="password" tabindex="2" auto-complete="on" @keyup.enter.native="handleLogin" />
  23. <span class="show-pwd" @click="showPwd">
  24. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  25. </span>
  26. </el-form-item>
  27. <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;background:#50b5ff;" @click.native.prevent="handleLogin" >登录</el-button>
  28. </el-form>
  29. </div>
  30. </div>
  31. </div> -->
  32. </template>
  33. <script>
  34. import { validUsername } from '@/utils/validate'
  35. import { getJson } from '@/api/common'
  36. import Cookies from 'js-cookie'
  37. import axios from 'axios';
  38. import { setToken } from '@/utils/auth' // get token from cookie
  39. export default {
  40. name: 'Login',
  41. data() {
  42. const validateUsername = (rule, value, callback) => {
  43. if (!validUsername(value)) {
  44. callback(new Error('请输入正确的用户名'))
  45. } else {
  46. callback()
  47. }
  48. }
  49. const validatePassword = (rule, value, callback) => {
  50. const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
  51. if (value === '') {
  52. callback(new Error('请输入密码'))
  53. } else if (!re.test(value)) {
  54. callback(new Error('密码由8位以上数字,大小写字母,特殊字符组成'))
  55. } else {
  56. callback()
  57. }
  58. }
  59. return {
  60. loginForm: {
  61. username: '',
  62. password: ''
  63. },
  64. loginRules: {
  65. username: [
  66. { required: true, trigger: 'blur', validator: validateUsername }
  67. ],
  68. password: [
  69. { required: true, trigger: 'blur', validator: validatePassword }
  70. ]
  71. },
  72. loading: false,
  73. passwordType: 'password',
  74. redirect: undefined
  75. }
  76. },
  77. watch: {
  78. $route: {
  79. handler: function(route) {
  80. this.redirect = route.query && route.query.redirect
  81. },
  82. immediate: true
  83. }
  84. },
  85. created() {
  86. // var that = this
  87. // document.onkeydown = function(e) {
  88. // e = window.event || e
  89. // // eslint-disable-next-line eqeqeq
  90. // if (that.$route.path == '/login' && (e.code == 'Enter' || e.code == 'Num Enter')) { // 验证在登录界面和按得键是回车键enter
  91. // that.handleLogin('ruleForm2') // 登录函数 (handleSubmit2('ruleForm2')-登录按钮的点击事件)
  92. // }
  93. // }
  94. this.getcodeList()
  95. },
  96. methods: {
  97. showPwd() {
  98. if (this.passwordType === 'password') {
  99. this.passwordType = ''
  100. } else {
  101. this.passwordType = 'password'
  102. }
  103. this.$nextTick(() => {
  104. this.$refs.password.focus()
  105. })
  106. },
  107. // handleLogin() {
  108. // this.$refs.loginForm.validate(valid => {
  109. // if (valid) {
  110. // this.$store.dispatch('user/login', this.loginForm) .then(() => {
  111. // // const re = new RegExp(`^(?=.*[a-z])(?=.*\\d)(?=.*\\W)[^]{8,32}$`)
  112. // // if (!re.test(this.loginForm.password)) {
  113. // // this.$router.push('/console/Changpwd')
  114. // // console.log('密码不符合要求')
  115. // // }
  116. // this.$router.push({ path: this.redirect || '/' })
  117. // this.loading = false
  118. // }).catch(() => {
  119. // this.loading = false
  120. // })
  121. // } else {
  122. // console.log('error submit!!')
  123. // return false
  124. // }
  125. // })
  126. // }
  127. getcodeList(){
  128. this.$store.dispatch('user/login', this.loginForm) .then(() => {
  129. }).catch(() => {
  130. this.loading = false
  131. })
  132. // // 获取完整的URL
  133. // const fullURL = window.location.href;
  134. // // 使用正则表达式提取code参数的值
  135. // const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
  136. // if (codeMatch) {
  137. // // 如果匹配成功,将code的值存储在组件的data中
  138. // this.code = codeMatch[1];
  139. // console.log(this.code)
  140. // //TODO 保存token
  141. // // 去除后面的#/login
  142. // if ( this.code && this.code.includes("#/login")) {
  143. // this.code = this.code.replace("#/login", "");
  144. // }
  145. // console.log(this.code)
  146. // //base64解密this.cose
  147. // // atob(this.code)
  148. // console.log( atob(this.code))
  149. // let token = atob(this.code)
  150. // setToken(token)
  151. // } else {
  152. // console.log('error submit!!')
  153. // return false
  154. // }
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss">
  160. /* 修复input 背景不协调 和光标变色 */
  161. /* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
  162. // $bg: #283443;
  163. // $light_gray: #fff;
  164. // $cursor: #fff;
  165. // 更改
  166. $bg: #ccc;
  167. $light_gray: #ccc;
  168. $cursor: #000;
  169. @supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  170. .login-container .el-input input {
  171. color: $cursor;
  172. }
  173. }
  174. /* reset element-ui css */
  175. .login-container {
  176. .el-input {
  177. display: inline-block;
  178. height: 38px;
  179. width: 85%;
  180. input {
  181. background: transparent;
  182. border: 0px;
  183. -webkit-appearance: none;
  184. border-radius: 0px;
  185. padding: 5px 5px 5px 15px;
  186. color: #000;
  187. height: 38px;
  188. caret-color: $cursor;
  189. &:-webkit-autofill {
  190. box-shadow: 0 0 0px 1000px $bg inset !important;
  191. -webkit-text-fill-color: $cursor !important;
  192. }
  193. }
  194. }
  195. .el-form-item {
  196. border: 1px solid rgba(255, 255, 255, 0.1);
  197. background: rgba(0, 0, 0, 0.2);
  198. border-radius: 5px;
  199. color: #454545;
  200. .el-form-item__content {
  201. line-height: 30px;
  202. }
  203. }
  204. }
  205. </style>
  206. <style lang="scss" scoped>
  207. $bg: #2d3a4b;
  208. $dark_gray: #889aa4;
  209. $light_gray: #000;
  210. .login-container {
  211. min-height: 100%;
  212. width: 100%;
  213. position: relative;
  214. background: url("../../assets/images/login.png") no-repeat;
  215. background-size:cover;
  216. overflow: hidden;
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. .logo{
  221. padding: 5px;
  222. }
  223. .bujian{
  224. position: absolute;
  225. top: 0;
  226. bottom: 0;
  227. left: 0;
  228. right: 200px;
  229. margin: auto;
  230. }
  231. .login {
  232. padding: 30px;
  233. display: flex;
  234. justify-content: center;
  235. align-items: center;
  236. margin: auto;
  237. bottom: 0;
  238. .tips {
  239. font-size: 14px; color: #fff; margin-bottom: 10px;
  240. span { &:first-of-type { margin-right: 16px; } }
  241. }
  242. .svg-container { padding: 6px 5px 6px 15px; color: $dark_gray; vertical-align: middle; width: 30px; display: inline-block; }
  243. .title-container {
  244. position: relative;
  245. .title { font-size: 28px; color: $light_gray; margin: 0px auto 0 auto; text-align: center; font-weight: bold; }
  246. b { text-align: center; font: 14px/2 ""; display: block; }
  247. }
  248. .show-pwd { position: absolute; right: 10px; top: 7px; font-size: 16px; color: $dark_gray; cursor: pointer; user-select: none; }
  249. hr { color: #ccc; margin: 20px 0; }
  250. }
  251. }
  252. .content{
  253. left: 0;
  254. right: 0;
  255. bottom: 0;
  256. top: 0;
  257. margin: 0 auto;
  258. }
  259. @media (min-width: 770px) {
  260. .content{
  261. width: 770px;
  262. height: 420px;
  263. }
  264. .content-l{
  265. float: left;
  266. width: 420px;
  267. height: 420px;
  268. background: url("../../assets/images/login-l.jpg") no-repeat;
  269. background-size:cover;
  270. }
  271. .login{
  272. float: left;
  273. width: 350px;
  274. height: 420px;
  275. background: url("../../assets/images/login-r.jpg") no-repeat;
  276. background-size:cover;
  277. }
  278. .login-form { position: relative; width: 224px; max-width: 100%; overflow: hidden; }
  279. }
  280. @media (min-width: 1100px) {
  281. .content{
  282. width: 1100px;
  283. height: 600px;
  284. }
  285. .content-l{
  286. float: left;
  287. width: 593px;
  288. height: 593px;
  289. background: url("../../assets/images/login-l.jpg") no-repeat;
  290. background-size:cover;
  291. }
  292. .login{
  293. float: left;
  294. width: 495px;
  295. height: 593px;
  296. background: url("../../assets/images/login-r.jpg") no-repeat;
  297. background-size:cover;
  298. }
  299. .login-form { position: relative; width: 330px; max-width: 100%; overflow: hidden; }
  300. }
  301. </style>