fix: 修复iot账号无法登录可视化

This commit is contained in:
xieyonghong 2023-04-27 17:51:44 +08:00
parent ce4d63be55
commit b59ad04c37
3 changed files with 46 additions and 25 deletions

View File

@ -6,7 +6,7 @@ export default {
title: 'Jetlinks', // 浏览器标签页title title: 'Jetlinks', // 浏览器标签页title
layout: { layout: {
title: '物联网平台', // 平台title title: '物联网平台', // 平台title
logo: '/icons/icon-192x192.png', // 平台logo logo: '/logo.png', // 平台logo
siderWidth: 208, // 左侧菜单栏宽度 siderWidth: 208, // 左侧菜单栏宽度
headerHeight: 48, // 头部高度 headerHeight: 48, // 头部高度
collapsedWidth: 48, collapsedWidth: 48,

View File

@ -20,7 +20,6 @@ const noTokenPath = [ AccountCenterBindPath, OauthPath ]
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
// TODO 切换路由取消请求 // TODO 切换路由取消请求
const token = getToken() const token = getToken()
console.log(to.path, noTokenPath.includes(to.path))
if (noTokenPath.includes(to.path)) { if (noTokenPath.includes(to.path)) {
next() next()
} else if (token) { } else if (token) {

View File

@ -14,6 +14,7 @@
<div class='oauth-content-header'> <div class='oauth-content-header'>
<img :src='headerImg' /> <img :src='headerImg' />
</div> </div>
<h2>授权登录</h2>
<div class='oauth-content-content'> <div class='oauth-content-content'>
<div class='oauth-content-content-text'> <div class='oauth-content-content-text'>
您正在授权登录, {{ appName }} 将获得以下权限: 您正在授权登录, {{ appName }} 将获得以下权限:
@ -32,15 +33,16 @@
<div class='oauth-content-header'> <div class='oauth-content-header'>
<img :src='headerImg' /> <img :src='headerImg' />
</div> </div>
<h2>授权登录</h2>
<div class='oauth-content-login'> <div class='oauth-content-login'>
<j-form layout='horizontal' size='large' :model='formModel' > <j-form layout='vertical' :model='formModel' ref='formRef' >
<j-form-item name='username'> <j-form-item label='用户名' name='username' required :rules='[{ required: true, message: "请输入用户名"}]'>
<j-input placeholder='用户名' v-model:value='formModel.username' /> <j-input placeholder='用户名' v-model:value='formModel.username' />
</j-form-item> </j-form-item>
<j-form-item name='password'> <j-form-item label='密码' name='password' required :rules='[{ required: true, message: "请输入密码"}]'>
<j-input-password placeholder='密码' v-model:value='formModel.password' /> <j-input-password placeholder='密码' v-model:value='formModel.password' />
</j-form-item> </j-form-item>
<j-form-item name='verifyCode' v-if='captcha.base64'> <j-form-item name='verifyCode' v-if='captcha.base64' required :rules='[{ required: true, message: "请输入验证码"}]'>
<j-input placeholder='请输入验证码' v-model:value='formModel.verifyCode' > <j-input placeholder='请输入验证码' v-model:value='formModel.verifyCode' >
<template #addonAfter> <template #addonAfter>
<img <img
@ -72,9 +74,10 @@
<script setup lang='ts' name='Oauth'> <script setup lang='ts' name='Oauth'>
import { TOKEN_KEY } from '@/utils/variable' import { TOKEN_KEY } from '@/utils/variable'
import { config, code, getOAuth2, initApplication, authLogin } from '@/api/login' import { config, code, getOAuth2, initApplication, authLogin, settingDetail } from '@/api/login'
import { getMe_api } from '@/api/home' import { getMe_api } from '@/api/home'
import { getImage, getToken } from '@/utils/comm' import { getImage, getToken } from '@/utils/comm'
import Config from '../../../config/config'
const spinning = ref(true) const spinning = ref(true)
const isLogin = ref(false) const isLogin = ref(false)
@ -85,6 +88,9 @@ const userName = ref('-')
const internal = ref('false') const internal = ref('false')
const params = ref() const params = ref()
document.title = `OAuth授权-${Config.title}`;
headerImg.value = getImage(Config.layout.logo)
type LoginParam = { type LoginParam = {
username: string; username: string;
password: string; password: string;
@ -104,6 +110,8 @@ const captcha = reactive<{base64?: string, key?: string }>({
key: undefined key: undefined
}) })
const formRef = ref()
const getApplication = async (clientId: string) => { const getApplication = async (clientId: string) => {
const res = await initApplication(clientId) const res = await initApplication(clientId)
if (res.success && res.result) { if (res.success && res.result) {
@ -141,7 +149,6 @@ const changeAccount = () => {
} }
const getLoginUser = async (data?: any) => { const getLoginUser = async (data?: any) => {
console.log(getToken())
if (getToken()) { // if (getToken()) { //
const res = await getMe_api() const res = await getMe_api()
if (res.success) { if (res.success) {
@ -182,7 +189,8 @@ const getQueryVariable = (variable: any) => {
return ''; return '';
} }
const doLogin = async () => { const doLogin = () => {
formRef.value.validate().then( async data => {
const res = await authLogin({ const res = await authLogin({
verifyKey: captcha.key, verifyKey: captcha.key,
...formModel ...formModel
@ -191,10 +199,11 @@ const doLogin = async () => {
const token = res.result.token const token = res.result.token
localStorage.setItem(TOKEN_KEY, token) localStorage.setItem(TOKEN_KEY, token)
getLoginUser() getLoginUser()
goOAuth2Fn() // goOAuth2Fn()
} else { } else {
getCode() getCode()
} }
})
} }
const initPage = async () => { const initPage = async () => {
@ -213,7 +222,6 @@ const initPage = async () => {
const url = `${origin.join('/')}${items.redirect_uri?.split('redirect=')[1]}` const url = `${origin.join('/')}${items.redirect_uri?.split('redirect=')[1]}`
// redirectUrl = `${items.redirect_uri?.split('redirect_uri=')[0]}?redirect=${url}` // redirectUrl = `${items.redirect_uri?.split('redirect_uri=')[0]}?redirect=${url}`
redirectUrl = items.redirect_uri redirectUrl = items.redirect_uri
console.log(origin, items.redirect_uri)
} }
// //
getLoginUser({ getLoginUser({
@ -229,9 +237,22 @@ const initPage = async () => {
} }
} }
document.title = 'OAuth授权-jetlinks'; const getSettingDetail = () => {
headerImg.value = getImage('/logo.png') settingDetail('front').then((res: any) => {
if (res.status === 200) {
const ico: any = document.querySelector('link[rel="icon"]');
ico.href = res.result.ico;
headerImg.value = res.result.logo
if (res.result.title) {
document.title = `OAuth授权-${res.result.title}`;
} else {
document.title = 'OAuth授权';
}
}
});
}
getSettingDetail()
getCode() getCode()
initPage() initPage()
@ -320,7 +341,8 @@ initPage()
gap: 24px; gap: 24px;
} }
.oauth-content-login { .oauth-content-login {
max-width: 300px; width: 100%;
padding: 0 24px;
} }
} }
} }