添加项目之间跳转,无需重复登录
This commit is contained in:
parent
6a81db1133
commit
d04c7c8399
|
|
@ -251,6 +251,23 @@ export const updateUserUIconfigInfoService = (Data: UserUISettings, token:string
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getUserTokenCode = (Data) => {
|
||||||
|
return request.get('/user/get_token_code', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${Data.token}`, // 使用 Bearer 认证方式
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getTokenByCode = (Data) => {
|
||||||
|
let url = '/user/get_token_by_code' + "?code=" + Data.code
|
||||||
|
return request.get(url, {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${Data.token}`, // 使用 Bearer 认证方式
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const fetchUserData = () => {
|
export const fetchUserData = () => {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -232,6 +232,12 @@ export const menuData: Menus[] = [
|
||||||
index: '/ai-ppt',
|
index: '/ai-ppt',
|
||||||
title: '智能PPT生成',
|
title: '智能PPT生成',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: '59',
|
||||||
|
icon: 'ChatDotSquare',
|
||||||
|
index: '/project-select',
|
||||||
|
title: '项目选择',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: '6',
|
id: '6',
|
||||||
icon: 'DocumentAdd',
|
icon: 'DocumentAdd',
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,25 @@ const routes: RouteRecordRaw[] = [
|
||||||
component: () => import(/* webpackChunkName: "ai-ppt" */ '../views/system/ai-ppt.vue'),
|
component: () => import(/* webpackChunkName: "ai-ppt" */ '../views/system/ai-ppt.vue'),
|
||||||
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/project-select',
|
||||||
|
name: 'project-select',
|
||||||
|
meta: {
|
||||||
|
title: '项目选择',
|
||||||
|
permiss: '59',
|
||||||
|
},
|
||||||
|
component: () => import(/* webpackChunkName: "project-select" */ '../views/system/project-select.vue'),
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/callback',
|
||||||
|
name: 'callback',
|
||||||
|
meta: {
|
||||||
|
title: '回调地址',
|
||||||
|
noAuth: true,
|
||||||
|
},
|
||||||
|
component: () => import(/* webpackChunkName: "callback" */ '../views/system/callback.vue'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/gen-prompt',
|
path: '/gen-prompt',
|
||||||
name: 'gen-prompt',
|
name: 'gen-prompt',
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,10 @@ export const usePermissStore = defineStore("permiss", {
|
||||||
"56", //文件管理
|
"56", //文件管理
|
||||||
"57", //智能ppt生成
|
"57", //智能ppt生成
|
||||||
"58", //知识库管理
|
"58", //知识库管理
|
||||||
|
"59", //项目选择
|
||||||
"71", //用户功能管理
|
"71", //用户功能管理
|
||||||
],
|
],
|
||||||
user: ["0", "8", "7", "9", "51" ,"53","55" ,"56", "57", "58", "61", "71"],
|
user: ["0", "8", "7", "9", "51" ,"53","55" ,"56", "57", "58", "59", "61", "71"],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ import { GetUserInfoService } from "@/api/user";
|
||||||
import { UserToken } from "@/types/user";
|
import { UserToken } from "@/types/user";
|
||||||
import { usePermissStore } from "@/store/permiss";
|
import { usePermissStore } from "@/store/permiss";
|
||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import {getThirdPartyUUID,getThirdPartyLoginStatus,getGithubLoginUrl,getQQLoginUrl,getThirdPartyLoginUrl} from "@/api/user";
|
import {getThirdPartyUUID,getThirdPartyLoginStatus,getThirdPartyLoginUrl} from "@/api/user";
|
||||||
// 从本地存储获取登录参数
|
// 从本地存储获取登录参数
|
||||||
const lgStr = localStorage.getItem("login-param");
|
const lgStr = localStorage.getItem("login-param");
|
||||||
const defParam = lgStr ? JSON.parse(lgStr) : null;
|
const defParam = lgStr ? JSON.parse(lgStr) : null;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<p>回调页面,加载授权信息中...</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
//获取query参数
|
||||||
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
import { usePermissStore } from "@/store/permiss";
|
||||||
|
import { getTokenByCode } from '@/api/user';
|
||||||
|
import { GetUserInfoService } from "@/api/user";
|
||||||
|
import { UserToken } from "@/types/user";
|
||||||
|
const route = useRoute();
|
||||||
|
const permiss = usePermissStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// 获取query参数
|
||||||
|
const queryParams = route.query;
|
||||||
|
console.log('Received query parameters:', queryParams);
|
||||||
|
let code = queryParams.code;
|
||||||
|
if (code) {
|
||||||
|
let req = {
|
||||||
|
code: code,
|
||||||
|
};
|
||||||
|
await getTokenByCode(req).then((res: any) => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
console.log('获取Token成功:', res);
|
||||||
|
let userTokenInfo: UserToken = res.data;
|
||||||
|
localStorage.setItem("token", userTokenInfo.access_token);
|
||||||
|
localStorage.setItem("refresh_token", userTokenInfo.refresh_token);
|
||||||
|
localStorage.setItem("userId", userTokenInfo.user_id.toString());
|
||||||
|
localStorage.setItem("username", userTokenInfo.username);
|
||||||
|
getMyUserInfo(userTokenInfo.user_id);
|
||||||
|
} else {
|
||||||
|
console.error('获取Token失败:', res.message);
|
||||||
|
}
|
||||||
|
}).catch((error: any) => {
|
||||||
|
console.error('请求错误:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
const getMyUserInfo = async (id) => {
|
||||||
|
let result = {};
|
||||||
|
try {
|
||||||
|
let tokenData = {
|
||||||
|
token: localStorage.getItem("token"),
|
||||||
|
id: id,
|
||||||
|
};
|
||||||
|
result = await GetUserInfoService(tokenData);
|
||||||
|
if (result["code"] === 0) {
|
||||||
|
localStorage.setItem("ms_username", result["data"]["Name"]);
|
||||||
|
const keys =
|
||||||
|
permiss.defaultList[result["data"]["Role"] == "admin" ? "admin" : "user"];
|
||||||
|
localStorage.setItem("ms_imgurl", result["data"]["Avatar"]);
|
||||||
|
permiss.handleSet(keys);
|
||||||
|
localStorage.setItem("ms_keys", JSON.stringify(keys));
|
||||||
|
localStorage.setItem("ms_role", result["data"]["Role"]);
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1,126 @@
|
||||||
|
<template>
|
||||||
|
<div class="project-container">
|
||||||
|
<h1 class="title">选择要跳转项目</h1>
|
||||||
|
<div class="project-list">
|
||||||
|
<el-card
|
||||||
|
v-for="project in projects"
|
||||||
|
:key="project.id"
|
||||||
|
class="project-card"
|
||||||
|
@click="handleSelect(project)"
|
||||||
|
>
|
||||||
|
<div class="card-content">
|
||||||
|
<el-avatar :size="60" :src="project.avatar" />
|
||||||
|
<div class="project-info">
|
||||||
|
<h3>{{ project.name }}</h3>
|
||||||
|
<p class="description">{{ project.description }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</el-card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
import {getUserTokenCode} from '@/api/user'
|
||||||
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
|
interface Project {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
avatar: string
|
||||||
|
path: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
// 模拟项目数据
|
||||||
|
const projects = ref<Project[]>([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: 'vp系统',
|
||||||
|
description: '视频及系统管理工具',
|
||||||
|
avatar: 'https://www.ljsea.top/wp-content/uploads/2025/06/ljsea.jpg',
|
||||||
|
path: 'https://gs.ljsea.top/callback' //path: 'https://gs.ljsea.top/callback' 'http://localhost:5173/#/callback'
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const GetTokenCode =async () => {
|
||||||
|
let req ={
|
||||||
|
token: localStorage.getItem('token') || ''
|
||||||
|
}
|
||||||
|
await getUserTokenCode(req).then((res: any) => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
if (res.data.code === '') {
|
||||||
|
ElMessage.error('获取失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
alert('获取成功:'+res.data.code);
|
||||||
|
localStorage.setItem('tokenCode', res.data.code);
|
||||||
|
} else {
|
||||||
|
console.error('获取Token失败:', res.message);
|
||||||
|
}
|
||||||
|
}).catch((error: any) => {
|
||||||
|
console.error('请求错误:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSelect = async (project: Project) => {
|
||||||
|
await GetTokenCode();
|
||||||
|
let url = project.path + '?code=' + localStorage.getItem('tokenCode');
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.project-container {
|
||||||
|
padding: 20px;
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-card {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.3s, box-shadow 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-card:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-info {
|
||||||
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.project-info h3 {
|
||||||
|
margin: 0 0 8px 0;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
margin: 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
Reference in New Issue