index.vue 8.6 KB

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