Files
zhxg_pc/src/layout/index.vue

227 lines
5.3 KiB
Vue
Raw Normal View History

2025-08-14 15:43:24 +08:00
<!--E:\桌面\AI辅导员\学工系统\zhxg_pc\src\layout\index.vue-->
2025-07-28 15:52:07 +08:00
<template>
<div :class="classObj" class="app-wrapper" :style="{ '--current-color': theme }">
<el-scrollbar>
<div v-if="device === 'mobile' && sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
<sidebar v-if="!sidebar.hide" class="sidebar-container" />
<div :class="{ hasTagsView: needTagsView, sidebarHide: sidebar.hide }" class="main-container">
<div :class="{ 'fixed-header': fixedHeader }">
<navbar />
<tags-view v-if="needTagsView" />
</div>
<app-main />
<right-panel>
<settings />
</right-panel>
</div>
</el-scrollbar>
<!-- ai悬停 -->
2025-08-14 15:43:24 +08:00
<div>
<!-- 其他页面内容 -->
<!-- 触发按钮控制弹窗显示隐藏 -->
<div class="ai-hover" @click="showAI = !showAI">
<span v-if="!showAI" style="font-size: 14px; font-weight: bold;">AI</span>
<i v-else class="el-icon-close" style="font-size: 20px;"></i>
2025-07-28 15:52:07 +08:00
</div>
2025-08-14 15:43:24 +08:00
<!-- 聊天弹窗通过 v-if 控制显隐 -->
<ChatPopup v-if="showAI" @close="showAI = false" />
2025-07-28 15:52:07 +08:00
</div>
2025-08-14 15:43:24 +08:00
2025-07-28 15:52:07 +08:00
</div>
</template>
<script>
import RightPanel from '@/components/RightPanel'
import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex'
import variables from '@/assets/styles/variables.scss'
2025-08-14 15:43:24 +08:00
import ChatPopup from '../layout/components/Aichat/ChatPopup.vue'
2025-07-28 15:52:07 +08:00
import {
initCoze
2025-08-14 15:43:24 +08:00
} from '@/utils/ai.js'
2025-07-28 15:52:07 +08:00
import {
getAccessToken
2025-08-14 15:43:24 +08:00
} from '@/api/aiJWT/aiJWT.js'
2025-07-28 15:52:07 +08:00
export default {
name: 'Layout',
components: {
AppMain,
Navbar,
RightPanel,
Settings,
Sidebar,
2025-08-14 15:43:24 +08:00
TagsView,
ChatPopup // 注册ChatPopup组件
2025-07-28 15:52:07 +08:00
},
mixins: [ResizeMixin],
2025-08-14 15:43:24 +08:00
data() {
return {
showAI: false // 控制AI弹窗显示/隐藏的变量
}
},
2025-07-28 15:52:07 +08:00
computed: {
...mapState({
theme: state => state.settings.theme,
sideTheme: state => state.settings.sideTheme,
sidebar: state => state.app.sidebar,
device: state => state.app.device,
needTagsView: state => state.settings.tagsView,
fixedHeader: state => state.settings.fixedHeader,
avatar: state => state.user.avatar,
userInfo: state => state.user.userInfo,
token: state => state.user.token
}),
classObj() {
return {
hideSidebar: !this.sidebar.opened,
openSidebar: this.sidebar.opened,
withoutAnimation: this.sidebar.withoutAnimation,
mobile: this.device === 'mobile'
}
},
variables() {
2025-08-14 15:43:24 +08:00
return variables
2025-07-28 15:52:07 +08:00
}
},
methods: {
handleClickOutside() {
this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
},
2025-08-14 15:43:24 +08:00
// 切换AI弹窗显示状态
toggleAI() {
this.showAI = !this.showAI
// 如果需要在显示时执行原有逻辑,可以取消下面的注释
// if (this.showAI) {
// this.initializeAI()
// }
},
// 原有AI初始化逻辑保持注释状态
async initializeAI() {
// let userInfo = {
// roleGroup: this.userInfo.roles[0].roleName || "student",
// nickName: this.userInfo.nickName,
// username: this.userInfo.userName,
// avater: this.avatar,
// user_token: this.token
// }
// console.log("请求AI的信息", userInfo)
//
// //1.获取token
// userInfo.accessToken = (await this.getAccessToken()).access_token;
// userInfo.onRefreshToken = async () => (await this.getAccessToken()).accessToken;
// const sdk = await initCoze(userInfo);
// sdk.showChatBot();
2025-07-28 15:52:07 +08:00
},
async getAccessToken() {
2025-08-14 15:43:24 +08:00
const res = await getAccessToken() // 调用请求函数
const data = JSON.parse(res.data) // 解析数据
return data // ✅ 返回 data
2025-07-28 15:52:07 +08:00
}
}
}
</script>
2025-08-14 15:43:24 +08:00
2025-07-28 15:52:07 +08:00
<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";
2025-08-14 15:43:24 +08:00
//~@/assets/styles/variables.scss
2025-07-28 15:52:07 +08:00
.app-wrapper {
@include clearfix;
position: relative;
height: 100%;
width: 100%;
.el-scrollbar {
height: 100%;
}
::v-deep .el-scrollbar__bar.is-vertical {
z-index: 10;
}
::v-deep .el-scrollbar__wrap {
overflow-x: hidden;
}
&.mobile.openSidebar {
position: fixed;
top: 0;
}
}
.drawer-bg {
background: #000;
opacity: 0.3;
width: 100%;
top: 0;
height: 100%;
position: absolute;
z-index: 999;
}
.fixed-header {
position: fixed;
top: 0;
right: 0;
z-index: 9;
width: calc(100% - #{$base-sidebar-width});
transition: width 0.28s;
}
.hideSidebar .fixed-header {
width: calc(100% - 54px);
}
.sidebarHide .fixed-header {
width: 100%;
}
.mobile .fixed-header {
width: 100%;
}
// ai悬停
.ai-hover {
position: fixed;
bottom: 20px;
right: 20px;
z-index: 999;
width: 50px;
height: 50px;
border-radius: 50%;
background-color: #409eff;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
2025-08-14 15:43:24 +08:00
//AI
.ai-hover {
position: fixed;
right: 20px;
bottom: 20px;
/* 和弹窗拉开距离 */
width: 40px;
height: 40px;
background-color: #409eff;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
cursor: pointer;
z-index: 9999;
}
2025-07-28 15:52:07 +08:00
</style>