+
-
- 登录
-
-
-
+
+
+ 登录
+
+
+
+
+
+
+
+ 登录
+ 清空
+
-
-
-
-
- 登录
- 清空
-
-
-
+ 没有账号?
-
+ 去注册
-
-
+ >
+
+
+
+
三方登录
+
+
+
+
微软登录
+
+
+
+
QQ登录
+
+
+
+
+
+
+
@@ -84,6 +105,23 @@ export default {
}
},
methods: {
+ thirdLogin (type) {
+ if (type === 'azure') {
+ this.azureLogin()
+ } else {
+ this.qqLogin()
+ }
+ },
+ azureLogin () {
+ const url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=3a46d800-6bcc-47b5-9724-5a651b336bdb&scope=User.Read%20openid%20profile%20offline_access&redirect_uri=https%3A%2F%2Fyongma16.xyz%2Fazure_login_callback%2F&client-request-id=d4f3e873-d59f-417d-8101-ad19aac54168&response_mode=fragment&response_type=code&x-client-SKU=msal.js.browser&x-client-VER=2.26.0&client_info=1&code_challenge=pmwq-hZFKj0arSiO6WXFHngszqW0cH0fwMpd-a1Vuns&code_challenge_method=S256&nonce=e8d65872-8fe9-45b4-9b4d-b0c7db70a61f&state=eyJpZCI6IjVjNGUyZDQyLTI5Y2MtNDc5MS1iMmQ4LTBiZDAwZWM5Y2M2MyIsIm1ldGEiOnsiaW50ZXJhY3Rpb25UeXBlIjoicG9wdXAifX0%3D'
+ const openHandle = window.open(url, '_black')
+ console.log('openHandle', openHandle)
+ },
+ qqLogin () {
+ const url = 'https://graph.qq.com/oauth2.0/show?which=Login&display=pc&client_id=100330589&response_type=token&scope=all&redirect_uri=https%3A%2F%2Fconnect.qq.com%2Fsdk%2Fwebtools%2Findex2.html'
+ const openHandle = window.open(url, '_black')
+ console.log('openHandle', openHandle)
+ },
submitForm (formName) {
const that = this // this指向
this.$refs[formName].validate((valid) => {
@@ -160,6 +198,7 @@ export default {
}
.box-card {
+ position: relative;
align-self: center;
align-content: center;
display: flex;
@@ -169,5 +208,6 @@ export default {
opacity: 1;
margin-top: 80px;
background-color: #ffffff;
+ box-sizing: border-box;
}
diff --git a/src/importElement.js b/src/importElement.js
index e99554321ee1cfe68e3cc71115a86a8a1876e174..7bd062fa0238d3043e09d6cfc952688f44cc1e0b 100644
--- a/src/importElement.js
+++ b/src/importElement.js
@@ -23,11 +23,17 @@ import {
Pagination,
Alert,
Notification,
- Select
+ Select,
+ Divider,
+ Row,
+ Col
} from 'element-ui'
const importElementComponents = (Vue) => {
Vue.use(Container)
+ Vue.use(Divider)
+ Vue.use(Row)
+ Vue.use(Col)
Vue.use(Header)
Vue.use(Main)
Vue.use(Aside)
diff --git a/src/main.js b/src/main.js
index c21d697376666e4148c7c5c826da9b49b9b2631c..73ba28f6a175f53984f43cd4f52e1ff8e6e42718 100644
--- a/src/main.js
+++ b/src/main.js
@@ -2,7 +2,6 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// vue cdn
import Vue from 'vue'
-import VueRouter from 'vue-router'
import axios from 'axios'
import hljs from 'highlight.js'
import * as echarts from 'echarts'
@@ -13,6 +12,7 @@ import 'github-markdown-css/github-markdown.css'
import 'nprogress/nprogress.css'
// 无需cdn
import useRouter from './router'
+import VueRouter from 'vue-router'
import cookies from 'vue-cookies'
import App from './App'
import 'highlight.js/styles/github.css'
@@ -36,7 +36,7 @@ if (env === 'production') {
// cookie
Vue.prototype.$cookies = cookies
// axios
- Vue.use(axios)
+ // Vue.use(axios)
Vue.prototype.$axios = axios
window.$axios_w = axios
Vue.prototype.$echarts = echarts
diff --git a/src/router/index.js b/src/router/index.js
index db0edfea5e7f80a6031eb0dda36574a6624fd2a7..b24978ff56a18b0e5615598060c9e6b6b180dee8 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -20,13 +20,13 @@ const defaultRoutes = [
path: '/login',
name: 'Login',
component: Login,
- hidden: true
+ hidden: false
},
{
path: '/register',
name: 'Register',
component: Register,
- hidden: true
+ hidden: false
},
{
path: '/home',
@@ -82,32 +82,50 @@ const useRouter = (Vue, VueRouter) => {
// const whiteList = ['/login', '/register']
router.beforeEach(async (to, from, next) => {
- next()
let yma16siteUserInfo = localStorage.getItem('yma16siteUserInfo')
? JSON.parse(localStorage.getItem('yma16siteUserInfo'))
- : ''
+ : {}
let name = yma16siteUserInfo.username
let pwd = yma16siteUserInfo.password
+ console.log('to', to)
let hasToken = {
name: name,
password: pwd
}
console.log('localStorage', hasToken)
if (hasToken.name && hasToken.password) {
- if (isEmpty(store.state.user.userInfo)) {
- // 空的 modules下的user
- console.log('路由的登录认证')
- // 用户自主登录
- await store.dispatch('user/loginUserInfo', hasToken)
- next()
+ if (!isEmpty(store.state.user.userInfo)) {
+ try {
+ // 空的 modules下的user
+ console.log('路由的登录认证')
+ // 用户自主登录
+ await store.dispatch('user/loginUserInfo', hasToken)
+ next()
+ } catch (e) {
+ console.error(e, 'e')
+ if (to.name === 'Login' || to.path === '/login' || to.name === 'register' || to.path === '/Register') {
+ // 避免同名路由无限循环
+ console.log('next')
+ next()
+ } else {
+ console.log('login router')
+ return next({ name: 'Login' }) // 去登录
+ }
+ }
} else {
+ console.log('next')
next()
}
- } else {
- // next({ path: "/login" }); //去登录
+ } else if (to.name === 'Login' || to.path === '/login' || to.name === 'Register' || to.path === '/register') {
+ console.log('next login register')
+ // 避免同名路由无限循环
next()
+ } else {
+ console.log('login router')
+ return next({ name: 'Login' }) // 去登录
}
+ return false
})
Vue.use(VueRouter)
diff --git a/src/service/user.service.js b/src/service/user.service.js
index d755ae007625479a50fbfcfb76c2d47d4419b8ca..71f525ba5078981139a50faf06c6c43aa0f8ddb0 100644
--- a/src/service/user.service.js
+++ b/src/service/user.service.js
@@ -1,11 +1,10 @@
-export function loginUser (data) {
- console.log('用户登录service!', data)
- let baseUrl = '/api/user/login/'
- let res = null
- window.$axios_w && window.$axios_w
- .post(baseUrl, data)
- .then((o) => {
- res = o
+export async function loginUser (data) {
+ return new Promise(resolve => {
+ try {
+ console.log('用户登录service!', data)
+ let baseUrl = '/api/user/login/'
+ const res = window.$echarts_w
+ .post(baseUrl, data)
console.log('成功认证', res)
// 只返回username
localStorage.setItem(
@@ -15,9 +14,10 @@ export function loginUser (data) {
password: data.password
})
)
- })
- .catch((r) => {
+ resolve(true)
+ } catch (r) {
console.log('登录失败!', r)
- })
- return res
+ resolve(false)
+ }
+ })
}
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 3f79507166709ca2fc733b7621aff8143090b6c4..03c7d219204112e6a6b7fa3e7e7c09a9c5cae1fc 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,4 +1,4 @@
-import { loginUser } from '@/service/user.service'
+import { loginUser } from '../../service/user.service'
export default {
// 自带命名空间
namespaced: true,