|
@@ -41,6 +41,9 @@
|
|
|
<script>
|
|
|
import { validUsername } from '@/utils/validate'
|
|
|
import { getJson } from '@/api/common'
|
|
|
+import Cookies from 'js-cookie'
|
|
|
+import axios from 'axios';
|
|
|
+import { setToken } from '@/utils/auth' // get token from cookie
|
|
|
export default {
|
|
|
name: 'Login',
|
|
|
data() {
|
|
@@ -130,24 +133,35 @@ export default {
|
|
|
// })
|
|
|
// }
|
|
|
getcodeList(){
|
|
|
- // 获取完整的URL
|
|
|
- const fullURL = window.location.href;
|
|
|
- // 使用正则表达式提取code参数的值
|
|
|
- const codeMatch = fullURL.match(/[\?&]code=([^&]+)/);
|
|
|
- if (codeMatch) {
|
|
|
- // 如果匹配成功,将code的值存储在组件的data中
|
|
|
- this.code = codeMatch[1];
|
|
|
- let url = 'http://tmrwatch.cn:8082/api/v1/oauth2/token'
|
|
|
- let data = '?code='+this.code
|
|
|
- console.log('logincode====>',this.code)
|
|
|
- getJson(url,data).then(response => {
|
|
|
- console.log(response)
|
|
|
- //TODO 保存token
|
|
|
- })
|
|
|
- } else {
|
|
|
- console.log('error submit!!')
|
|
|
- return false
|
|
|
- }
|
|
|
+ this.$store.dispatch('user/login', this.loginForm) .then(() => {
|
|
|
+
|
|
|
+ }).catch(() => {
|
|
|
+ this.loading = false
|
|
|
+ })
|
|
|
+ // // 获取完整的URL
|
|
|
+ // const fullURL = window.location.href;
|
|
|
+ // // 使用正则表达式提取code参数的值
|
|
|
+ // const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
|
|
|
+ // if (codeMatch) {
|
|
|
+ // // 如果匹配成功,将code的值存储在组件的data中
|
|
|
+ // this.code = codeMatch[1];
|
|
|
+ // console.log(this.code)
|
|
|
+ // //TODO 保存token
|
|
|
+ // // 去除后面的#/login
|
|
|
+ // if ( this.code && this.code.includes("#/login")) {
|
|
|
+ // this.code = this.code.replace("#/login", "");
|
|
|
+ // }
|
|
|
+ // console.log(this.code)
|
|
|
+ // //base64解密this.cose
|
|
|
+ // // atob(this.code)
|
|
|
+ // console.log( atob(this.code))
|
|
|
+ // let token = atob(this.code)
|
|
|
+ // setToken(token)
|
|
|
+
|
|
|
+ // } else {
|
|
|
+ // console.log('error submit!!')
|
|
|
+ // return false
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
}
|