update
parent
14657a074b
commit
4f011e0831
|
|
@ -1,3 +1,14 @@
|
|||
# 开发环境配置
|
||||
# 留空则通过 vite proxy 代理到 http://101.133.172.2:8082
|
||||
VITE_API_BASE_URL=
|
||||
|
||||
# ===== mineru_ai_chat 智能问答(iframe 免登集成) =====
|
||||
# 问答服务地址(本地调试指向本机后端;上线改为 http://192.168.16.49:8081)
|
||||
VITE_AI_CHAT_BASE=http://localhost:8081
|
||||
# 问答页面前端地址(iframe 加载用;本地开发是 Vite 5173,生产留空即与 BASE 同源)
|
||||
VITE_AI_CHAT_WEB=http://localhost:5173
|
||||
# 免登密钥,须与 mineru 后端 SSO_SECRET 一致。
|
||||
# 注意:本密钥会随前端打包暴露,后端已做安全边界——该通道仅能开通 viewer
|
||||
# (普通问答访客)账号,无法冒充 editor/admin 等特权账号。
|
||||
VITE_AI_CHAT_SECRET=yunsan-sso-dev-secret
|
||||
VITE_AI_CHAT_TITLE=AI问答(快速查询应急方案)
|
||||
|
|
|
|||
|
|
@ -1,2 +1,10 @@
|
|||
# 生产环境配置(直连实际地址,需包含应用 context path)
|
||||
VITE_API_BASE_URL=http://10.104.10.151:8888/juntech-ysdp
|
||||
|
||||
# ===== mineru_ai_chat 智能问答(iframe 免登集成) =====
|
||||
VITE_AI_CHAT_BASE=http://192.168.16.49:8081
|
||||
# 生产问答页面与后端同源(8081 托管构建产物),留空即可
|
||||
VITE_AI_CHAT_WEB=
|
||||
# 上线前改为正式密钥(与 mineru 容器 SSO_SECRET 一致);通道仅能开通 viewer 账号
|
||||
VITE_AI_CHAT_SECRET=
|
||||
VITE_AI_CHAT_TITLE=AI问答(快速查询应急方案)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,258 @@
|
|||
<template>
|
||||
<!-- 大屏整页被 #app 的 transform:scale 缩放,fixed 元素必须 Teleport 到 body 才按视口定位、拖动不偏移 -->
|
||||
<Teleport to="body">
|
||||
<!-- 可拖动悬浮按钮:点击弹出智能问答 iframe -->
|
||||
<div
|
||||
ref="btnRef"
|
||||
class="ai-float-btn"
|
||||
:style="{ left: pos.x + 'px', top: pos.y + 'px' }"
|
||||
@pointerdown="onDown"
|
||||
@pointermove="onMove"
|
||||
@pointerup="onUp"
|
||||
>
|
||||
<svg viewBox="0 0 24 24" width="30" height="30">
|
||||
<path fill="currentColor" d="M12 2a1.5 1.5 0 0 1 1.5 1.5V5h3A2.5 2.5 0 0 1 19 7.5v8A2.5 2.5 0 0 1 16.5 18h-9A2.5 2.5 0 0 1 5 15.5v-8A2.5 2.5 0 0 1 7.5 5h3V3.5A1.5 1.5 0 0 1 12 2Zm-2.5 8a1.25 1.25 0 1 0 0 2.5 1.25 1.25 0 0 0 0-2.5Zm5 0a1.25 1.25 0 1 0 0 2.5 1.25 1.25 0 0 0 0-2.5ZM9 20h6v2H9v-2Z"/>
|
||||
</svg>
|
||||
<span class="ai-float-label">AI问答</span>
|
||||
</div>
|
||||
|
||||
<!-- 问答弹窗(v-show 保留 iframe 会话,关闭不销毁) -->
|
||||
<div v-show="panelOpen" class="ai-chat-mask" @click.self="panelOpen = false">
|
||||
<div class="ai-chat-dialog">
|
||||
<div class="ai-chat-header">
|
||||
<span class="ai-chat-title"></span>
|
||||
<button class="ai-chat-close" title="关闭" @click="panelOpen = false">✕</button>
|
||||
</div>
|
||||
|
||||
<div v-if="state === 'loading'" class="ai-chat-center">
|
||||
<div class="ai-spinner"></div>
|
||||
<p>正在连接智能问答服务…</p>
|
||||
</div>
|
||||
<div v-else-if="state === 'error'" class="ai-chat-center">
|
||||
<p class="ai-err">{{ errorMsg }}</p>
|
||||
<button class="ai-retry" @click="applyTicket">重试</button>
|
||||
</div>
|
||||
<iframe
|
||||
v-show="state === 'ready'"
|
||||
:src="embedUrl"
|
||||
class="ai-chat-frame"
|
||||
frameborder="0"
|
||||
allow="fullscreen"
|
||||
></iframe>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, watch, onUnmounted } from 'vue'
|
||||
// 与 aichat 页面一致:localhost 会在运行时自动替换为当前访问 host(见 utils/aiChat.js)
|
||||
import { AI_BASE, AI_WEB, AI_SECRET, AI_TITLE } from '@/utils/aiChat'
|
||||
|
||||
// ==================== 悬浮按钮:拖动 + 点击 ====================
|
||||
const btnRef = ref(null)
|
||||
const POS_KEY = 'ai_float_btn_pos'
|
||||
// 位置按视口比例记录:大屏/窗口尺寸变化后自动跟随自适应,不会停留在屏幕外
|
||||
const ratio = loadRatio()
|
||||
const pos = reactive({ x: 0, y: 0 })
|
||||
|
||||
function loadRatio() {
|
||||
try {
|
||||
const p = JSON.parse(localStorage.getItem(POS_KEY) || 'null')
|
||||
if (p && typeof p.x === 'number' && typeof p.y === 'number') {
|
||||
// 兼容旧版存的绝对像素坐标,换算成当前视口比例
|
||||
if (p.x > 1 || p.y > 1) return { rx: p.x / window.innerWidth, ry: p.y / window.innerHeight }
|
||||
return { rx: p.x, ry: p.y }
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
return { rx: (window.innerWidth - 90) / window.innerWidth, ry: 0.45 }
|
||||
}
|
||||
|
||||
// 比例 -> 视口像素并钳制,保证按钮始终完整可见
|
||||
function applyViewport() {
|
||||
pos.x = Math.min(Math.max(ratio.rx * window.innerWidth, 4), window.innerWidth - 84)
|
||||
pos.y = Math.min(Math.max(ratio.ry * window.innerHeight, 4), window.innerHeight - 84)
|
||||
}
|
||||
|
||||
applyViewport()
|
||||
window.addEventListener('resize', applyViewport)
|
||||
onUnmounted(() => window.removeEventListener('resize', applyViewport))
|
||||
|
||||
let dragging = false
|
||||
let moved = false
|
||||
let start = { x: 0, y: 0, bx: 0, by: 0 }
|
||||
|
||||
const onDown = (e) => {
|
||||
dragging = true
|
||||
moved = false
|
||||
start = { x: e.clientX, y: e.clientY, bx: pos.x, by: pos.y }
|
||||
btnRef.value?.setPointerCapture(e.pointerId)
|
||||
}
|
||||
const onMove = (e) => {
|
||||
if (!dragging) return
|
||||
const dx = e.clientX - start.x
|
||||
const dy = e.clientY - start.y
|
||||
if (Math.abs(dx) > 5 || Math.abs(dy) > 5) moved = true
|
||||
if (!moved) return
|
||||
pos.x = Math.min(Math.max(start.bx + dx, 4), window.innerWidth - 84)
|
||||
pos.y = Math.min(Math.max(start.by + dy, 4), window.innerHeight - 84)
|
||||
}
|
||||
const onUp = (e) => {
|
||||
if (!dragging) return
|
||||
dragging = false
|
||||
btnRef.value?.releasePointerCapture(e.pointerId)
|
||||
if (moved) {
|
||||
// 存比例而非像素,换屏幕/缩放后仍落在相同相对位置
|
||||
localStorage.setItem(POS_KEY, JSON.stringify({ x: pos.x / window.innerWidth, y: pos.y / window.innerHeight }))
|
||||
} else {
|
||||
// 未移动 = 点击:打开弹窗,首次打开才申请 ticket
|
||||
panelOpen.value = true
|
||||
if (!embedUrl.value && state.value !== 'loading') applyTicket()
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 弹窗问答:ticket 免登 + 自动续期 ====================
|
||||
const panelOpen = ref(false)
|
||||
const state = ref('idle') // idle | loading | ready | error
|
||||
const errorMsg = ref('')
|
||||
const embedUrl = ref('')
|
||||
|
||||
const currentUsername = () => {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem('userInfo') || '{}').username || 'yunsan_guest'
|
||||
} catch (e) {
|
||||
return 'yunsan_guest'
|
||||
}
|
||||
}
|
||||
|
||||
const applyTicket = async () => {
|
||||
state.value = 'loading'
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
// 原生 fetch,绕开 request.js 的 SM4 加密拦截器
|
||||
const resp = await fetch(`${AI_BASE}/api/auth/sso/ticket`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ secret: AI_SECRET, username: currentUsername(), display_name: currentUsername() })
|
||||
})
|
||||
const data = await resp.json().catch(() => ({}))
|
||||
if (!resp.ok || !data.ticket) throw new Error(data.detail || `HTTP ${resp.status}`)
|
||||
embedUrl.value = `${AI_WEB}/embed?ticket=${encodeURIComponent(data.ticket)}&title=${encodeURIComponent(AI_TITLE)}`
|
||||
state.value = 'ready'
|
||||
} catch (e) {
|
||||
state.value = 'error'
|
||||
errorMsg.value = `无法连接智能问答服务:${e.message}`
|
||||
}
|
||||
}
|
||||
|
||||
// iframe 内 JWT 过期 → 重新签 ticket 刷新(防抖避免循环)
|
||||
let lastRenew = 0
|
||||
const onEmbedExpired = async (e) => {
|
||||
if (e.data?.type !== 'mineru-embed-auth-expired') return
|
||||
if (Date.now() - lastRenew < 3000) return
|
||||
lastRenew = Date.now()
|
||||
await applyTicket()
|
||||
}
|
||||
window.addEventListener('message', onEmbedExpired)
|
||||
onUnmounted(() => window.removeEventListener('message', onEmbedExpired))
|
||||
|
||||
// 弹窗打开但上次是失败态时自动重试
|
||||
watch(panelOpen, (open) => {
|
||||
if (open && state.value === 'error') applyTicket()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.ai-float-btn {
|
||||
position: fixed;
|
||||
z-index: 3000;
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border-radius: 50%;
|
||||
background: linear-gradient(135deg, #3f7dff, #6aa5ff);
|
||||
color: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
cursor: grab;
|
||||
user-select: none;
|
||||
touch-action: none;
|
||||
box-shadow: 0 6px 20px rgba(20, 60, 160, 0.45);
|
||||
border: 2px solid rgba(255, 255, 255, 0.35);
|
||||
|
||||
&:active { cursor: grabbing; }
|
||||
.ai-float-label { font-size: 11px; line-height: 1; }
|
||||
}
|
||||
|
||||
.ai-chat-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 3001;
|
||||
background: rgba(5, 12, 30, 0.55);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.ai-chat-dialog {
|
||||
width: min(1100px, 92vw);
|
||||
height: min(780px, 90vh);
|
||||
background: #0b1a3e;
|
||||
border: 1px solid rgba(120, 160, 255, 0.35);
|
||||
border-radius: 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 16px 60px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
.ai-chat-header {
|
||||
flex-shrink: 0;
|
||||
height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0 16px;
|
||||
background: rgba(30, 58, 138, 0.6);
|
||||
border-bottom: 1px solid rgba(120, 160, 255, 0.25);
|
||||
.ai-chat-title { color: #fff; font-size: 15px; font-weight: 600; }
|
||||
.ai-chat-close {
|
||||
width: 28px; height: 28px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #dbe6ff;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
&:hover { background: rgba(255, 90, 90, 0.65); color: #fff; }
|
||||
}
|
||||
}
|
||||
.ai-chat-center {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 14px;
|
||||
color: #c9d8ff;
|
||||
.ai-err { font-size: 14px; max-width: 480px; text-align: center; }
|
||||
.ai-retry {
|
||||
padding: 6px 22px;
|
||||
border: 1px solid rgba(160, 195, 255, 0.5);
|
||||
border-radius: 16px;
|
||||
background: transparent;
|
||||
color: #cfe0ff;
|
||||
cursor: pointer;
|
||||
&:hover { background: rgba(79, 140, 255, 0.2); }
|
||||
}
|
||||
}
|
||||
.ai-spinner {
|
||||
width: 34px; height: 34px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.2);
|
||||
border-top-color: #4f8cff;
|
||||
border-radius: 50%;
|
||||
animation: ai-spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes ai-spin { to { transform: rotate(360deg); } }
|
||||
.ai-chat-frame { flex: 1; width: 100%; border: none; }
|
||||
</style>
|
||||
|
|
@ -49,6 +49,12 @@ const routes = [
|
|||
],
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/aichat',
|
||||
name: 'AiChat',
|
||||
component: () => import('@/views/aichat/index.vue'),
|
||||
meta: { title: '智能问答', requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/404',
|
||||
name: '404',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// AI 问答服务地址解析(aichat 整页与悬浮窗组件共用)
|
||||
// env 里可能配成 localhost/127.0.0.1:局域网其他机器访问时,localhost 指向的是
|
||||
// 访问者自己的电脑,必然连不上。这里在运行时把 localhost 替换为当前页面的
|
||||
// host(IP 或域名),端口保持不变;配置的本来就是 IP/域名则原样使用。
|
||||
function resolveAiUrl(raw) {
|
||||
if (!raw) return ''
|
||||
try {
|
||||
const u = new URL(raw, window.location.href)
|
||||
if (u.hostname === 'localhost' || u.hostname === '127.0.0.1') {
|
||||
u.hostname = window.location.hostname
|
||||
}
|
||||
return u.origin + u.pathname.replace(/\/$/, '')
|
||||
} catch (e) {
|
||||
return raw
|
||||
}
|
||||
}
|
||||
|
||||
// mineru_ai_chat 服务地址与免登密钥(.env 配置,勿走 request.js —— 避开 SM4 加密拦截器)
|
||||
// AI_BASE:后端 API 地址;AI_WEB:问答页面前端地址(iframe 用,留空即与 BASE 同源)
|
||||
export const AI_BASE = resolveAiUrl(import.meta.env.VITE_AI_CHAT_BASE || 'http://localhost:8081')
|
||||
export const AI_WEB = resolveAiUrl(import.meta.env.VITE_AI_CHAT_WEB || AI_BASE)
|
||||
export const AI_SECRET = import.meta.env.VITE_AI_CHAT_SECRET || ''
|
||||
export const AI_TITLE = import.meta.env.VITE_AI_CHAT_TITLE || 'AI问答(快速查询应急方案)'
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
<template>
|
||||
<div class="aichat-page">
|
||||
<div class="aichat-topbar">
|
||||
<el-button size="small" @click="goBack">← 返回首页</el-button>
|
||||
<span class="aichat-title">智能问答</span>
|
||||
</div>
|
||||
|
||||
<!-- 申请 ticket 中 -->
|
||||
<div v-if="state === 'loading'" class="aichat-center">
|
||||
<div class="spinner"></div>
|
||||
<p>正在连接智能问答服务…</p>
|
||||
</div>
|
||||
|
||||
<!-- 失败:可重试 -->
|
||||
<div v-else-if="state === 'error'" class="aichat-center">
|
||||
<p class="err-text">{{ errorMsg }}</p>
|
||||
<el-button type="primary" @click="applyTicket">重试</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 成功:iframe 嵌入 mineru 免登问答页 -->
|
||||
<iframe
|
||||
v-else
|
||||
:src="embedUrl"
|
||||
class="aichat-frame"
|
||||
frameborder="0"
|
||||
allow="fullscreen"
|
||||
></iframe>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
// mineru_ai_chat 服务地址与免登密钥;localhost 会在运行时自动替换为当前访问 host(见 utils/aiChat.js)
|
||||
import { AI_BASE, AI_WEB, AI_SECRET, AI_TITLE } from '@/utils/aiChat'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const state = ref('loading') // loading | ready | error
|
||||
const errorMsg = ref('')
|
||||
const embedUrl = ref('')
|
||||
|
||||
const currentUsername = () => {
|
||||
try {
|
||||
return JSON.parse(localStorage.getItem('userInfo') || '{}').username || 'yunsan_guest'
|
||||
} catch (e) {
|
||||
return 'yunsan_guest'
|
||||
}
|
||||
}
|
||||
|
||||
const applyTicket = async () => {
|
||||
state.value = 'loading'
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
const resp = await fetch(`${AI_BASE}/api/auth/sso/ticket`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
secret: AI_SECRET,
|
||||
username: currentUsername(),
|
||||
display_name: currentUsername()
|
||||
})
|
||||
})
|
||||
const data = await resp.json().catch(() => ({}))
|
||||
if (!resp.ok || !data.ticket) {
|
||||
throw new Error(data.detail || `HTTP ${resp.status}`)
|
||||
}
|
||||
// ticket 为一次性凭证(60 秒有效),拿到后立即渲染 iframe
|
||||
embedUrl.value = `${AI_WEB}/embed?ticket=${encodeURIComponent(data.ticket)}&title=${encodeURIComponent(AI_TITLE)}`
|
||||
state.value = 'ready'
|
||||
} catch (e) {
|
||||
state.value = 'error'
|
||||
errorMsg.value = `无法连接智能问答服务:${e.message}`
|
||||
ElMessage.error(errorMsg.value)
|
||||
}
|
||||
}
|
||||
|
||||
const goBack = () => router.push('/home')
|
||||
|
||||
onMounted(applyTicket)
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.aichat-page {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: #0b1a3e;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
z-index: 2000;
|
||||
}
|
||||
.aichat-topbar {
|
||||
flex-shrink: 0;
|
||||
height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 0 16px;
|
||||
background: rgba(30, 58, 138, 0.55);
|
||||
border-bottom: 1px solid rgba(120, 160, 255, 0.25);
|
||||
.aichat-title {
|
||||
color: #fff;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
.aichat-center {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
color: #c9d8ff;
|
||||
.err-text {
|
||||
font-size: 14px;
|
||||
max-width: 480px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
.spinner {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.2);
|
||||
border-top-color: #4f8cff;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
.aichat-frame {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -25,10 +25,14 @@
|
|||
<!-- 模块10 -->
|
||||
<ModuleTen />
|
||||
</div>
|
||||
|
||||
<!-- 可拖动悬浮按钮:点击弹出智能问答(iframe 免登) -->
|
||||
<AiChatFloat />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted } from 'vue'
|
||||
import AiChatFloat from '@/components/AiChatFloat.vue'
|
||||
import ModuleOne from './components/ModuleOne.vue'
|
||||
import ModuleTwo from './components/ModuleTwo.vue'
|
||||
import ModuleThree from './components/ModuleThree.vue'
|
||||
|
|
|
|||
Loading…
Reference in New Issue