- 扩展 ToolConfig 配置类型,新增 external_api 类型
- 实现接口注册表,包含 90+ 睿美云开放接口定义
- 实现 TPOS SHA256WithRSA 签名鉴权
- 实现睿美云 API 客户端,支持多租户配置
- 新增代理路由 /api/ruimeiyun/call/{api_name}
- 支持接口权限控制和健康检查
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"name": "000-platform-admin",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.4.0",
|
||||
"vue-router": "^4.2.0",
|
||||
"pinia": "^2.1.0",
|
||||
"axios": "^1.6.0",
|
||||
"element-plus": "^2.5.0",
|
||||
"@element-plus/icons-vue": "^2.3.0",
|
||||
"echarts": "^5.4.0",
|
||||
"dayjs": "^1.11.0",
|
||||
"monaco-editor": "^0.45.0",
|
||||
"@monaco-editor/loader": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.0.0",
|
||||
"vite": "^5.0.0",
|
||||
"sass": "^1.69.0"
|
||||
}
|
||||
}
|
||||
{
|
||||
"name": "000-platform-admin",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.4.0",
|
||||
"vue-router": "^4.2.0",
|
||||
"pinia": "^2.1.0",
|
||||
"axios": "^1.6.0",
|
||||
"element-plus": "^2.5.0",
|
||||
"@element-plus/icons-vue": "^2.3.0",
|
||||
"echarts": "^5.4.0",
|
||||
"dayjs": "^1.11.0",
|
||||
"monaco-editor": "^0.45.0",
|
||||
"@monaco-editor/loader": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.0.0",
|
||||
"vite": "^5.0.0",
|
||||
"sass": "^1.69.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import router from '@/router'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '',
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
/**
|
||||
* 解析 API 错误响应
|
||||
*/
|
||||
function parseApiError(error) {
|
||||
const result = {
|
||||
code: 'UNKNOWN_ERROR',
|
||||
message: '发生了未知错误',
|
||||
traceId: '',
|
||||
status: 500
|
||||
}
|
||||
|
||||
// 网络错误(后端未启动、网络断开等)
|
||||
if (!error.response) {
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
result.code = 'TIMEOUT_ERROR'
|
||||
result.message = '请求超时,请稍后重试'
|
||||
result.status = 0
|
||||
} else if (error.message?.includes('Network Error')) {
|
||||
result.code = 'SERVICE_UNAVAILABLE'
|
||||
result.message = '服务暂时不可用,请稍后重试'
|
||||
result.status = 503
|
||||
} else {
|
||||
result.code = 'NETWORK_ERROR'
|
||||
result.message = '网络连接失败,请检查网络后重试'
|
||||
result.status = 0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const { status, data, headers } = error.response
|
||||
result.status = status
|
||||
result.traceId = headers['x-trace-id'] || headers['X-Trace-ID'] || ''
|
||||
|
||||
if (data && data.error) {
|
||||
result.code = data.error.code || result.code
|
||||
result.message = data.error.message || result.message
|
||||
result.traceId = data.error.trace_id || result.traceId
|
||||
} else if (data && data.detail) {
|
||||
result.message = typeof data.detail === 'string' ? data.detail : JSON.stringify(data.detail)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到错误页面(使用 sessionStorage + replace,不影响浏览器历史)
|
||||
*/
|
||||
function navigateToErrorPage(errorInfo) {
|
||||
// 记录当前页面路径(用于返回)
|
||||
sessionStorage.setItem('errorFromPath', router.currentRoute.value.fullPath)
|
||||
|
||||
// 保存错误信息到 sessionStorage(不会显示在 URL 中)
|
||||
sessionStorage.setItem('errorInfo', JSON.stringify({
|
||||
code: errorInfo.code,
|
||||
message: errorInfo.message,
|
||||
traceId: errorInfo.traceId,
|
||||
status: errorInfo.status,
|
||||
timestamp: Date.now()
|
||||
}))
|
||||
|
||||
// 使用 replace 而不是 push,这样浏览器返回时不会停留在错误页
|
||||
router.replace({ name: 'Error' })
|
||||
}
|
||||
|
||||
// 请求拦截器
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
)
|
||||
|
||||
// 响应拦截器(集成 TraceID 追踪)
|
||||
api.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
const errorInfo = parseApiError(error)
|
||||
const traceLog = errorInfo.traceId ? ` (trace: ${errorInfo.traceId})` : ''
|
||||
|
||||
console.error(`[API Error] ${errorInfo.code}: ${errorInfo.message}${traceLog}`)
|
||||
|
||||
// 严重错误列表(跳转错误页)
|
||||
const criticalErrors = [
|
||||
'INTERNAL_ERROR',
|
||||
'SERVICE_UNAVAILABLE',
|
||||
'GATEWAY_ERROR',
|
||||
'NETWORK_ERROR',
|
||||
'TIMEOUT_ERROR'
|
||||
]
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
router.push('/login')
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
} else if (error.response?.status === 403) {
|
||||
ElMessage.error('没有权限执行此操作')
|
||||
} else if (criticalErrors.includes(errorInfo.code)) {
|
||||
// 严重错误(包括网络错误、服务不可用)跳转到错误页面
|
||||
navigateToErrorPage(errorInfo)
|
||||
} else {
|
||||
// 普通错误显示消息
|
||||
ElMessage.error(errorInfo.message)
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default api
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import router from '@/router'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '',
|
||||
timeout: 30000
|
||||
})
|
||||
|
||||
/**
|
||||
* 解析 API 错误响应
|
||||
*/
|
||||
function parseApiError(error) {
|
||||
const result = {
|
||||
code: 'UNKNOWN_ERROR',
|
||||
message: '发生了未知错误',
|
||||
traceId: '',
|
||||
status: 500
|
||||
}
|
||||
|
||||
// 网络错误(后端未启动、网络断开等)
|
||||
if (!error.response) {
|
||||
if (error.code === 'ECONNABORTED') {
|
||||
result.code = 'TIMEOUT_ERROR'
|
||||
result.message = '请求超时,请稍后重试'
|
||||
result.status = 0
|
||||
} else if (error.message?.includes('Network Error')) {
|
||||
result.code = 'SERVICE_UNAVAILABLE'
|
||||
result.message = '服务暂时不可用,请稍后重试'
|
||||
result.status = 503
|
||||
} else {
|
||||
result.code = 'NETWORK_ERROR'
|
||||
result.message = '网络连接失败,请检查网络后重试'
|
||||
result.status = 0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const { status, data, headers } = error.response
|
||||
result.status = status
|
||||
result.traceId = headers['x-trace-id'] || headers['X-Trace-ID'] || ''
|
||||
|
||||
if (data && data.error) {
|
||||
result.code = data.error.code || result.code
|
||||
result.message = data.error.message || result.message
|
||||
result.traceId = data.error.trace_id || result.traceId
|
||||
} else if (data && data.detail) {
|
||||
result.message = typeof data.detail === 'string' ? data.detail : JSON.stringify(data.detail)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转到错误页面(使用 sessionStorage + replace,不影响浏览器历史)
|
||||
*/
|
||||
function navigateToErrorPage(errorInfo) {
|
||||
// 记录当前页面路径(用于返回)
|
||||
sessionStorage.setItem('errorFromPath', router.currentRoute.value.fullPath)
|
||||
|
||||
// 保存错误信息到 sessionStorage(不会显示在 URL 中)
|
||||
sessionStorage.setItem('errorInfo', JSON.stringify({
|
||||
code: errorInfo.code,
|
||||
message: errorInfo.message,
|
||||
traceId: errorInfo.traceId,
|
||||
status: errorInfo.status,
|
||||
timestamp: Date.now()
|
||||
}))
|
||||
|
||||
// 使用 replace 而不是 push,这样浏览器返回时不会停留在错误页
|
||||
router.replace({ name: 'Error' })
|
||||
}
|
||||
|
||||
// 请求拦截器
|
||||
api.interceptors.request.use(
|
||||
config => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
)
|
||||
|
||||
// 响应拦截器(集成 TraceID 追踪)
|
||||
api.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
const errorInfo = parseApiError(error)
|
||||
const traceLog = errorInfo.traceId ? ` (trace: ${errorInfo.traceId})` : ''
|
||||
|
||||
console.error(`[API Error] ${errorInfo.code}: ${errorInfo.message}${traceLog}`)
|
||||
|
||||
// 严重错误列表(跳转错误页)
|
||||
const criticalErrors = [
|
||||
'INTERNAL_ERROR',
|
||||
'SERVICE_UNAVAILABLE',
|
||||
'GATEWAY_ERROR',
|
||||
'NETWORK_ERROR',
|
||||
'TIMEOUT_ERROR'
|
||||
]
|
||||
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
router.push('/login')
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
} else if (error.response?.status === 403) {
|
||||
ElMessage.error('没有权限执行此操作')
|
||||
} else if (criticalErrors.includes(errorInfo.code)) {
|
||||
// 严重错误(包括网络错误、服务不可用)跳转到错误页面
|
||||
navigateToErrorPage(errorInfo)
|
||||
} else {
|
||||
// 普通错误显示消息
|
||||
ElMessage.error(errorInfo.message)
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default api
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// 菜单项
|
||||
const menuItems = computed(() => {
|
||||
const items = [
|
||||
{ path: '/dashboard', title: '仪表盘', icon: 'Odometer' },
|
||||
{ path: '/tenants', title: '租户管理', icon: 'OfficeBuilding' },
|
||||
{ path: '/apps', title: '应用管理', icon: 'Grid' },
|
||||
{ path: '/tenant-wechat-apps', title: '企微应用', icon: 'ChatDotRound' },
|
||||
{ path: '/app-config', title: '租户订阅', icon: 'Setting' },
|
||||
{ path: '/stats', title: '统计分析', icon: 'TrendCharts' },
|
||||
{ path: '/logs', title: '日志查看', icon: 'Document' },
|
||||
{ path: '/scheduled-tasks', title: '定时任务', icon: 'Clock' },
|
||||
{ path: '/notification-channels', title: '通知渠道', icon: 'Bell' }
|
||||
]
|
||||
|
||||
// 管理员才能看到用户管理
|
||||
if (authStore.isAdmin) {
|
||||
items.push({ path: '/users', title: '用户管理', icon: 'User' })
|
||||
}
|
||||
|
||||
return items
|
||||
})
|
||||
|
||||
const activeMenu = computed(() => route.path)
|
||||
|
||||
function handleMenuSelect(path) {
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
function handleLogout() {
|
||||
ElMessageBox.confirm('确定要退出登录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
authStore.logout()
|
||||
router.push('/login')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="layout">
|
||||
<!-- 侧边栏 -->
|
||||
<aside class="sidebar">
|
||||
<div class="logo">
|
||||
<el-icon><Platform /></el-icon>
|
||||
<span style="margin-left: 8px">平台管理</span>
|
||||
</div>
|
||||
|
||||
<el-menu
|
||||
:default-active="activeMenu"
|
||||
background-color="transparent"
|
||||
text-color="rgba(255,255,255,0.7)"
|
||||
active-text-color="#fff"
|
||||
@select="handleMenuSelect"
|
||||
>
|
||||
<el-menu-item v-for="item in menuItems" :key="item.path" :index="item.path">
|
||||
<el-icon><component :is="item.icon" /></el-icon>
|
||||
<span>{{ item.title }}</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<div class="main-container">
|
||||
<!-- 顶部栏 -->
|
||||
<header class="header">
|
||||
<div class="breadcrumb">
|
||||
<el-breadcrumb separator="/">
|
||||
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
|
||||
<el-breadcrumb-item v-if="route.meta.title">{{ route.meta.title }}</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
</div>
|
||||
|
||||
<div class="user-info">
|
||||
<span class="username">{{ authStore.user?.nickname || authStore.user?.username }}</span>
|
||||
<el-dropdown trigger="click">
|
||||
<el-avatar :size="32">
|
||||
{{ (authStore.user?.nickname || authStore.user?.username || 'U')[0].toUpperCase() }}
|
||||
</el-avatar>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="handleLogout">
|
||||
<el-icon><SwitchButton /></el-icon>
|
||||
退出登录
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<main class="main-content">
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// 菜单项
|
||||
const menuItems = computed(() => {
|
||||
const items = [
|
||||
{ path: '/dashboard', title: '仪表盘', icon: 'Odometer' },
|
||||
{ path: '/tenants', title: '租户管理', icon: 'OfficeBuilding' },
|
||||
{ path: '/apps', title: '应用管理', icon: 'Grid' },
|
||||
{ path: '/tenant-wechat-apps', title: '企微应用', icon: 'ChatDotRound' },
|
||||
{ path: '/app-config', title: '租户订阅', icon: 'Setting' },
|
||||
{ path: '/stats', title: '统计分析', icon: 'TrendCharts' },
|
||||
{ path: '/logs', title: '日志查看', icon: 'Document' },
|
||||
{ path: '/scheduled-tasks', title: '定时任务', icon: 'Clock' },
|
||||
{ path: '/notification-channels', title: '通知渠道', icon: 'Bell' }
|
||||
]
|
||||
|
||||
// 管理员才能看到用户管理
|
||||
if (authStore.isAdmin) {
|
||||
items.push({ path: '/users', title: '用户管理', icon: 'User' })
|
||||
}
|
||||
|
||||
return items
|
||||
})
|
||||
|
||||
const activeMenu = computed(() => route.path)
|
||||
|
||||
function handleMenuSelect(path) {
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
function handleLogout() {
|
||||
ElMessageBox.confirm('确定要退出登录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
authStore.logout()
|
||||
router.push('/login')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="layout">
|
||||
<!-- 侧边栏 -->
|
||||
<aside class="sidebar">
|
||||
<div class="logo">
|
||||
<el-icon><Platform /></el-icon>
|
||||
<span style="margin-left: 8px">平台管理</span>
|
||||
</div>
|
||||
|
||||
<el-menu
|
||||
:default-active="activeMenu"
|
||||
background-color="transparent"
|
||||
text-color="rgba(255,255,255,0.7)"
|
||||
active-text-color="#fff"
|
||||
@select="handleMenuSelect"
|
||||
>
|
||||
<el-menu-item v-for="item in menuItems" :key="item.path" :index="item.path">
|
||||
<el-icon><component :is="item.icon" /></el-icon>
|
||||
<span>{{ item.title }}</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</aside>
|
||||
|
||||
<!-- 主内容区 -->
|
||||
<div class="main-container">
|
||||
<!-- 顶部栏 -->
|
||||
<header class="header">
|
||||
<div class="breadcrumb">
|
||||
<el-breadcrumb separator="/">
|
||||
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
|
||||
<el-breadcrumb-item v-if="route.meta.title">{{ route.meta.title }}</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
</div>
|
||||
|
||||
<div class="user-info">
|
||||
<span class="username">{{ authStore.user?.nickname || authStore.user?.username }}</span>
|
||||
<el-dropdown trigger="click">
|
||||
<el-avatar :size="32">
|
||||
{{ (authStore.user?.nickname || authStore.user?.username || 'U')[0].toUpperCase() }}
|
||||
</el-avatar>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="handleLogout">
|
||||
<el-icon><SwitchButton /></el-icon>
|
||||
退出登录
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<main class="main-content">
|
||||
<router-view />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,223 +1,223 @@
|
||||
<script setup>
|
||||
/**
|
||||
* 统一错误页面
|
||||
* - 从 sessionStorage 读取错误信息,不污染 URL
|
||||
* - 使用 replace 跳转,支持浏览器返回
|
||||
*/
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElButton, ElMessage } from 'element-plus'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 错误信息
|
||||
const errorCode = ref('UNKNOWN_ERROR')
|
||||
const errorMessage = ref('发生了未知错误')
|
||||
const traceId = ref('')
|
||||
const statusCode = ref('500')
|
||||
const copied = ref(false)
|
||||
|
||||
// 记录来源页面(用于返回)
|
||||
const fromPath = ref('')
|
||||
|
||||
// 错误类型配置
|
||||
const errorConfigs = {
|
||||
'UNAUTHORIZED': { icon: 'Lock', title: '访问受限', color: '#e67e22' },
|
||||
'FORBIDDEN': { icon: 'CircleClose', title: '权限不足', color: '#e74c3c' },
|
||||
'NOT_FOUND': { icon: 'Search', title: '页面未找到', color: '#3498db' },
|
||||
'VALIDATION_ERROR': { icon: 'Warning', title: '请求参数错误', color: '#f39c12' },
|
||||
'INTERNAL_ERROR': { icon: 'Close', title: '服务器错误', color: '#e74c3c' },
|
||||
'SERVICE_UNAVAILABLE': { icon: 'Tools', title: '服务暂时不可用', color: '#9b59b6' },
|
||||
'NETWORK_ERROR': { icon: 'Connection', title: '网络连接失败', color: '#95a5a6' },
|
||||
'TIMEOUT_ERROR': { icon: 'Timer', title: '请求超时', color: '#95a5a6' },
|
||||
'UNKNOWN_ERROR': { icon: 'QuestionFilled', title: '未知错误', color: '#7f8c8d' }
|
||||
}
|
||||
|
||||
const errorConfig = ref(errorConfigs['UNKNOWN_ERROR'])
|
||||
|
||||
onMounted(() => {
|
||||
// 从 sessionStorage 读取错误信息
|
||||
const stored = sessionStorage.getItem('errorInfo')
|
||||
if (stored) {
|
||||
try {
|
||||
const info = JSON.parse(stored)
|
||||
// 检查时效性(5分钟内有效)
|
||||
if (Date.now() - info.timestamp < 5 * 60 * 1000) {
|
||||
errorCode.value = info.code || 'UNKNOWN_ERROR'
|
||||
errorMessage.value = info.message || '发生了未知错误'
|
||||
traceId.value = info.traceId || ''
|
||||
statusCode.value = String(info.status || 500)
|
||||
errorConfig.value = errorConfigs[errorCode.value] || errorConfigs['UNKNOWN_ERROR']
|
||||
}
|
||||
// 读取后清除(避免刷新时重复显示旧错误)
|
||||
sessionStorage.removeItem('errorInfo')
|
||||
} catch (e) {
|
||||
console.error('Failed to parse error info', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 记录来源页面
|
||||
fromPath.value = sessionStorage.getItem('errorFromPath') || '/dashboard'
|
||||
sessionStorage.removeItem('errorFromPath')
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// 确保清理
|
||||
sessionStorage.removeItem('errorInfo')
|
||||
})
|
||||
|
||||
const copyTraceId = async () => {
|
||||
if (!traceId.value) return
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(traceId.value)
|
||||
copied.value = true
|
||||
ElMessage.success('追踪码已复制')
|
||||
setTimeout(() => { copied.value = false }, 2000)
|
||||
} catch {
|
||||
ElMessage.error('复制失败')
|
||||
}
|
||||
}
|
||||
|
||||
const goHome = () => router.push('/dashboard')
|
||||
|
||||
// 返回之前的页面
|
||||
const goBack = () => {
|
||||
if (fromPath.value && fromPath.value !== '/error') {
|
||||
router.push(fromPath.value)
|
||||
} else {
|
||||
router.push('/dashboard')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="error-page">
|
||||
<div class="error-container">
|
||||
<div class="error-icon-wrapper" :style="{ background: errorConfig.color + '20', color: errorConfig.color }">
|
||||
<el-icon :size="48">
|
||||
<component :is="errorConfig.icon" />
|
||||
</el-icon>
|
||||
</div>
|
||||
|
||||
<h1 class="error-title">{{ errorConfig.title }}</h1>
|
||||
<div class="status-code">HTTP {{ statusCode }}</div>
|
||||
<p class="error-message">{{ errorMessage }}</p>
|
||||
|
||||
<div class="trace-section" v-if="traceId">
|
||||
<div class="trace-label">问题追踪码</div>
|
||||
<div class="trace-id-box" @click="copyTraceId">
|
||||
<code class="trace-id">{{ traceId }}</code>
|
||||
<el-button type="primary" link size="small">
|
||||
{{ copied ? '已复制' : '复制' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<p class="trace-tip">如需技术支持,请提供此追踪码</p>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons">
|
||||
<el-button type="primary" @click="goBack">返回</el-button>
|
||||
<el-button @click="goHome">返回首页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.error-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f5f7fa;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.error-container {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 48px;
|
||||
max-width: 480px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.error-icon-wrapper {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 24px;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px 0;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.status-code {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
font-size: 15px;
|
||||
color: #606266;
|
||||
margin: 0 0 24px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.trace-section {
|
||||
background: #f5f7fa;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.trace-label {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.trace-id-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: white;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.trace-id-box:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.trace-id {
|
||||
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.trace-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin: 8px 0 0 0;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
<script setup>
|
||||
/**
|
||||
* 统一错误页面
|
||||
* - 从 sessionStorage 读取错误信息,不污染 URL
|
||||
* - 使用 replace 跳转,支持浏览器返回
|
||||
*/
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElButton, ElMessage } from 'element-plus'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
// 错误信息
|
||||
const errorCode = ref('UNKNOWN_ERROR')
|
||||
const errorMessage = ref('发生了未知错误')
|
||||
const traceId = ref('')
|
||||
const statusCode = ref('500')
|
||||
const copied = ref(false)
|
||||
|
||||
// 记录来源页面(用于返回)
|
||||
const fromPath = ref('')
|
||||
|
||||
// 错误类型配置
|
||||
const errorConfigs = {
|
||||
'UNAUTHORIZED': { icon: 'Lock', title: '访问受限', color: '#e67e22' },
|
||||
'FORBIDDEN': { icon: 'CircleClose', title: '权限不足', color: '#e74c3c' },
|
||||
'NOT_FOUND': { icon: 'Search', title: '页面未找到', color: '#3498db' },
|
||||
'VALIDATION_ERROR': { icon: 'Warning', title: '请求参数错误', color: '#f39c12' },
|
||||
'INTERNAL_ERROR': { icon: 'Close', title: '服务器错误', color: '#e74c3c' },
|
||||
'SERVICE_UNAVAILABLE': { icon: 'Tools', title: '服务暂时不可用', color: '#9b59b6' },
|
||||
'NETWORK_ERROR': { icon: 'Connection', title: '网络连接失败', color: '#95a5a6' },
|
||||
'TIMEOUT_ERROR': { icon: 'Timer', title: '请求超时', color: '#95a5a6' },
|
||||
'UNKNOWN_ERROR': { icon: 'QuestionFilled', title: '未知错误', color: '#7f8c8d' }
|
||||
}
|
||||
|
||||
const errorConfig = ref(errorConfigs['UNKNOWN_ERROR'])
|
||||
|
||||
onMounted(() => {
|
||||
// 从 sessionStorage 读取错误信息
|
||||
const stored = sessionStorage.getItem('errorInfo')
|
||||
if (stored) {
|
||||
try {
|
||||
const info = JSON.parse(stored)
|
||||
// 检查时效性(5分钟内有效)
|
||||
if (Date.now() - info.timestamp < 5 * 60 * 1000) {
|
||||
errorCode.value = info.code || 'UNKNOWN_ERROR'
|
||||
errorMessage.value = info.message || '发生了未知错误'
|
||||
traceId.value = info.traceId || ''
|
||||
statusCode.value = String(info.status || 500)
|
||||
errorConfig.value = errorConfigs[errorCode.value] || errorConfigs['UNKNOWN_ERROR']
|
||||
}
|
||||
// 读取后清除(避免刷新时重复显示旧错误)
|
||||
sessionStorage.removeItem('errorInfo')
|
||||
} catch (e) {
|
||||
console.error('Failed to parse error info', e)
|
||||
}
|
||||
}
|
||||
|
||||
// 记录来源页面
|
||||
fromPath.value = sessionStorage.getItem('errorFromPath') || '/dashboard'
|
||||
sessionStorage.removeItem('errorFromPath')
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// 确保清理
|
||||
sessionStorage.removeItem('errorInfo')
|
||||
})
|
||||
|
||||
const copyTraceId = async () => {
|
||||
if (!traceId.value) return
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(traceId.value)
|
||||
copied.value = true
|
||||
ElMessage.success('追踪码已复制')
|
||||
setTimeout(() => { copied.value = false }, 2000)
|
||||
} catch {
|
||||
ElMessage.error('复制失败')
|
||||
}
|
||||
}
|
||||
|
||||
const goHome = () => router.push('/dashboard')
|
||||
|
||||
// 返回之前的页面
|
||||
const goBack = () => {
|
||||
if (fromPath.value && fromPath.value !== '/error') {
|
||||
router.push(fromPath.value)
|
||||
} else {
|
||||
router.push('/dashboard')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="error-page">
|
||||
<div class="error-container">
|
||||
<div class="error-icon-wrapper" :style="{ background: errorConfig.color + '20', color: errorConfig.color }">
|
||||
<el-icon :size="48">
|
||||
<component :is="errorConfig.icon" />
|
||||
</el-icon>
|
||||
</div>
|
||||
|
||||
<h1 class="error-title">{{ errorConfig.title }}</h1>
|
||||
<div class="status-code">HTTP {{ statusCode }}</div>
|
||||
<p class="error-message">{{ errorMessage }}</p>
|
||||
|
||||
<div class="trace-section" v-if="traceId">
|
||||
<div class="trace-label">问题追踪码</div>
|
||||
<div class="trace-id-box" @click="copyTraceId">
|
||||
<code class="trace-id">{{ traceId }}</code>
|
||||
<el-button type="primary" link size="small">
|
||||
{{ copied ? '已复制' : '复制' }}
|
||||
</el-button>
|
||||
</div>
|
||||
<p class="trace-tip">如需技术支持,请提供此追踪码</p>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons">
|
||||
<el-button type="primary" @click="goBack">返回</el-button>
|
||||
<el-button @click="goHome">返回首页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.error-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f5f7fa;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.error-container {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
padding: 48px;
|
||||
max-width: 480px;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.error-icon-wrapper {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 0 auto 24px;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px 0;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.status-code {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
font-size: 15px;
|
||||
color: #606266;
|
||||
margin: 0 0 24px 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.trace-section {
|
||||
background: #f5f7fa;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.trace-label {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.trace-id-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
padding: 8px 12px;
|
||||
background: white;
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.trace-id-box:hover {
|
||||
border-color: #409eff;
|
||||
}
|
||||
|
||||
.trace-id {
|
||||
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
|
||||
font-size: 13px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.trace-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin: 8px 0 0 0;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,317 +1,317 @@
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import api from '@/api'
|
||||
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
const total = ref(0)
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
size: 50,
|
||||
tenant_id: ''
|
||||
})
|
||||
|
||||
// 租户列表
|
||||
const tenants = ref([])
|
||||
|
||||
// 对话框
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const editingId = ref(null)
|
||||
const formRef = ref(null)
|
||||
const form = reactive({
|
||||
tenant_id: '',
|
||||
channel_name: '',
|
||||
channel_type: 'dingtalk_bot',
|
||||
webhook_url: '',
|
||||
sign_secret: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
tenant_id: [{ required: true, message: '请选择租户', trigger: 'change' }],
|
||||
channel_name: [{ required: true, message: '请输入渠道名称', trigger: 'blur' }],
|
||||
channel_type: [{ required: true, message: '请选择渠道类型', trigger: 'change' }],
|
||||
webhook_url: [{ required: true, message: '请输入 Webhook 地址', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const channelTypes = [
|
||||
{ value: 'dingtalk_bot', label: '钉钉机器人' },
|
||||
{ value: 'wecom_bot', label: '企微机器人' }
|
||||
]
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = { ...query }
|
||||
if (!params.tenant_id) delete params.tenant_id
|
||||
|
||||
const res = await api.get('/api/notification-channels', { params })
|
||||
tableData.value = res.data.items || []
|
||||
total.value = res.data.total || 0
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchTenants() {
|
||||
try {
|
||||
const res = await api.get('/api/tenants', { params: { size: 1000 } })
|
||||
tenants.value = res.data.items || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
query.page = 1
|
||||
fetchList()
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
editingId.value = null
|
||||
dialogTitle.value = '新建通知渠道'
|
||||
Object.assign(form, {
|
||||
tenant_id: '',
|
||||
channel_name: '',
|
||||
channel_type: 'dingtalk_bot',
|
||||
webhook_url: '',
|
||||
sign_secret: '',
|
||||
description: ''
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function handleEdit(row) {
|
||||
editingId.value = row.id
|
||||
dialogTitle.value = '编辑通知渠道'
|
||||
Object.assign(form, {
|
||||
tenant_id: row.tenant_id,
|
||||
channel_name: row.channel_name,
|
||||
channel_type: row.channel_type,
|
||||
webhook_url: row.webhook_url,
|
||||
sign_secret: row.sign_secret || '',
|
||||
description: row.description || ''
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
await formRef.value.validate()
|
||||
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await api.put(`/api/notification-channels/${editingId.value}`, form)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await api.post('/api/notification-channels', form)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row) {
|
||||
await ElMessageBox.confirm(`确定删除渠道 "${row.channel_name}" 吗?`, '提示', {
|
||||
type: 'warning'
|
||||
})
|
||||
|
||||
try {
|
||||
await api.delete(`/api/notification-channels/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggle(row) {
|
||||
try {
|
||||
await api.put(`/api/notification-channels/${row.id}`, {
|
||||
is_enabled: !row.is_enabled
|
||||
})
|
||||
ElMessage.success(row.is_enabled ? '已禁用' : '已启用')
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTest(row) {
|
||||
try {
|
||||
ElMessage.info('发送测试消息中...')
|
||||
const res = await api.post(`/api/notification-channels/${row.id}/test`)
|
||||
if (res.data.success) {
|
||||
ElMessage.success('测试消息发送成功')
|
||||
} else {
|
||||
ElMessage.error(`发送失败: ${res.data.message}`)
|
||||
}
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
function getTenantName(tenantId) {
|
||||
const tenant = tenants.value.find(t => t.code === tenantId)
|
||||
return tenant ? tenant.name : tenantId
|
||||
}
|
||||
|
||||
function getChannelTypeName(type) {
|
||||
const item = channelTypes.find(t => t.value === type)
|
||||
return item ? item.label : type
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchList()
|
||||
fetchTenants()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<div class="page-header">
|
||||
<div class="title">通知渠道管理</div>
|
||||
<el-button type="primary" @click="handleCreate">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新建渠道
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="page-tip">
|
||||
<el-alert type="info" :closable="false">
|
||||
通知渠道用于定时任务执行后发送消息。支持钉钉机器人和企微机器人。
|
||||
脚本中设置 <code>result = {'content': '消息内容', 'title': '标题'}</code> 变量,任务执行后会自动发送到配置的渠道。
|
||||
</el-alert>
|
||||
</div>
|
||||
|
||||
<!-- 筛选 -->
|
||||
<div class="filter-bar">
|
||||
<el-select v-model="query.tenant_id" placeholder="全部租户" clearable style="width: 180px">
|
||||
<el-option v-for="t in tenants" :key="t.code" :label="t.name" :value="t.code" />
|
||||
</el-select>
|
||||
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-table v-loading="loading" :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="id" label="ID" width="60" />
|
||||
<el-table-column label="租户" width="120">
|
||||
<template #default="{ row }">
|
||||
{{ getTenantName(row.tenant_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="channel_name" label="渠道名称" min-width="150" />
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.channel_type === 'dingtalk_bot' ? 'primary' : 'success'" size="small">
|
||||
{{ getChannelTypeName(row.channel_type) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="webhook_url" label="Webhook" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_enabled ? 'success' : 'info'" size="small">
|
||||
{{ row.is_enabled ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="info" link size="small" @click="handleTest(row)">测试</el-button>
|
||||
<el-button :type="row.is_enabled ? 'warning' : 'success'" link size="small" @click="handleToggle(row)">
|
||||
{{ row.is_enabled ? '禁用' : '启用' }}
|
||||
</el-button>
|
||||
<el-button type="danger" link size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 编辑对话框 -->
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="550px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="所属租户" prop="tenant_id">
|
||||
<el-select v-model="form.tenant_id" placeholder="选择租户" style="width: 100%">
|
||||
<el-option v-for="t in tenants" :key="t.code" :label="t.name" :value="t.code" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="渠道名称" prop="channel_name">
|
||||
<el-input v-model="form.channel_name" placeholder="如: 销售群机器人" />
|
||||
</el-form-item>
|
||||
<el-form-item label="渠道类型" prop="channel_type">
|
||||
<el-select v-model="form.channel_type" style="width: 100%">
|
||||
<el-option v-for="t in channelTypes" :key="t.value" :label="t.label" :value="t.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="Webhook" prop="webhook_url">
|
||||
<el-input v-model="form.webhook_url" placeholder="机器人 Webhook 地址" />
|
||||
<div class="form-tip">
|
||||
<template v-if="form.channel_type === 'dingtalk_bot'">
|
||||
钉钉机器人 Webhook 格式: https://oapi.dingtalk.com/robot/send?access_token=xxx
|
||||
</template>
|
||||
<template v-else>
|
||||
企微机器人 Webhook 格式: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx
|
||||
</template>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.channel_type === 'dingtalk_bot'" label="加签密钥">
|
||||
<el-input v-model="form.sign_secret" placeholder="SEC开头的密钥(可选)" />
|
||||
<div class="form-tip">
|
||||
如果创建机器人时选择了「加签」安全设置,请填写密钥(以 SEC 开头)
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="form.description" type="textarea" :rows="2" placeholder="渠道描述(可选)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.page-header .title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-tip {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.page-tip code {
|
||||
background: #f5f7fa;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import api from '@/api'
|
||||
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
const total = ref(0)
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
size: 50,
|
||||
tenant_id: ''
|
||||
})
|
||||
|
||||
// 租户列表
|
||||
const tenants = ref([])
|
||||
|
||||
// 对话框
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const editingId = ref(null)
|
||||
const formRef = ref(null)
|
||||
const form = reactive({
|
||||
tenant_id: '',
|
||||
channel_name: '',
|
||||
channel_type: 'dingtalk_bot',
|
||||
webhook_url: '',
|
||||
sign_secret: '',
|
||||
description: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
tenant_id: [{ required: true, message: '请选择租户', trigger: 'change' }],
|
||||
channel_name: [{ required: true, message: '请输入渠道名称', trigger: 'blur' }],
|
||||
channel_type: [{ required: true, message: '请选择渠道类型', trigger: 'change' }],
|
||||
webhook_url: [{ required: true, message: '请输入 Webhook 地址', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const channelTypes = [
|
||||
{ value: 'dingtalk_bot', label: '钉钉机器人' },
|
||||
{ value: 'wecom_bot', label: '企微机器人' }
|
||||
]
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = { ...query }
|
||||
if (!params.tenant_id) delete params.tenant_id
|
||||
|
||||
const res = await api.get('/api/notification-channels', { params })
|
||||
tableData.value = res.data.items || []
|
||||
total.value = res.data.total || 0
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchTenants() {
|
||||
try {
|
||||
const res = await api.get('/api/tenants', { params: { size: 1000 } })
|
||||
tenants.value = res.data.items || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
query.page = 1
|
||||
fetchList()
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
editingId.value = null
|
||||
dialogTitle.value = '新建通知渠道'
|
||||
Object.assign(form, {
|
||||
tenant_id: '',
|
||||
channel_name: '',
|
||||
channel_type: 'dingtalk_bot',
|
||||
webhook_url: '',
|
||||
sign_secret: '',
|
||||
description: ''
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function handleEdit(row) {
|
||||
editingId.value = row.id
|
||||
dialogTitle.value = '编辑通知渠道'
|
||||
Object.assign(form, {
|
||||
tenant_id: row.tenant_id,
|
||||
channel_name: row.channel_name,
|
||||
channel_type: row.channel_type,
|
||||
webhook_url: row.webhook_url,
|
||||
sign_secret: row.sign_secret || '',
|
||||
description: row.description || ''
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
await formRef.value.validate()
|
||||
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await api.put(`/api/notification-channels/${editingId.value}`, form)
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
await api.post('/api/notification-channels', form)
|
||||
ElMessage.success('创建成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row) {
|
||||
await ElMessageBox.confirm(`确定删除渠道 "${row.channel_name}" 吗?`, '提示', {
|
||||
type: 'warning'
|
||||
})
|
||||
|
||||
try {
|
||||
await api.delete(`/api/notification-channels/${row.id}`)
|
||||
ElMessage.success('删除成功')
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggle(row) {
|
||||
try {
|
||||
await api.put(`/api/notification-channels/${row.id}`, {
|
||||
is_enabled: !row.is_enabled
|
||||
})
|
||||
ElMessage.success(row.is_enabled ? '已禁用' : '已启用')
|
||||
fetchList()
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
async function handleTest(row) {
|
||||
try {
|
||||
ElMessage.info('发送测试消息中...')
|
||||
const res = await api.post(`/api/notification-channels/${row.id}/test`)
|
||||
if (res.data.success) {
|
||||
ElMessage.success('测试消息发送成功')
|
||||
} else {
|
||||
ElMessage.error(`发送失败: ${res.data.message}`)
|
||||
}
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
function getTenantName(tenantId) {
|
||||
const tenant = tenants.value.find(t => t.code === tenantId)
|
||||
return tenant ? tenant.name : tenantId
|
||||
}
|
||||
|
||||
function getChannelTypeName(type) {
|
||||
const item = channelTypes.find(t => t.value === type)
|
||||
return item ? item.label : type
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchList()
|
||||
fetchTenants()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<div class="page-header">
|
||||
<div class="title">通知渠道管理</div>
|
||||
<el-button type="primary" @click="handleCreate">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新建渠道
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div class="page-tip">
|
||||
<el-alert type="info" :closable="false">
|
||||
通知渠道用于定时任务执行后发送消息。支持钉钉机器人和企微机器人。
|
||||
脚本中设置 <code>result = {'content': '消息内容', 'title': '标题'}</code> 变量,任务执行后会自动发送到配置的渠道。
|
||||
</el-alert>
|
||||
</div>
|
||||
|
||||
<!-- 筛选 -->
|
||||
<div class="filter-bar">
|
||||
<el-select v-model="query.tenant_id" placeholder="全部租户" clearable style="width: 180px">
|
||||
<el-option v-for="t in tenants" :key="t.code" :label="t.name" :value="t.code" />
|
||||
</el-select>
|
||||
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-table v-loading="loading" :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="id" label="ID" width="60" />
|
||||
<el-table-column label="租户" width="120">
|
||||
<template #default="{ row }">
|
||||
{{ getTenantName(row.tenant_id) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="channel_name" label="渠道名称" min-width="150" />
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.channel_type === 'dingtalk_bot' ? 'primary' : 'success'" size="small">
|
||||
{{ getChannelTypeName(row.channel_type) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="webhook_url" label="Webhook" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_enabled ? 'success' : 'info'" size="small">
|
||||
{{ row.is_enabled ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="info" link size="small" @click="handleTest(row)">测试</el-button>
|
||||
<el-button :type="row.is_enabled ? 'warning' : 'success'" link size="small" @click="handleToggle(row)">
|
||||
{{ row.is_enabled ? '禁用' : '启用' }}
|
||||
</el-button>
|
||||
<el-button type="danger" link size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 编辑对话框 -->
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="550px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="所属租户" prop="tenant_id">
|
||||
<el-select v-model="form.tenant_id" placeholder="选择租户" style="width: 100%">
|
||||
<el-option v-for="t in tenants" :key="t.code" :label="t.name" :value="t.code" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="渠道名称" prop="channel_name">
|
||||
<el-input v-model="form.channel_name" placeholder="如: 销售群机器人" />
|
||||
</el-form-item>
|
||||
<el-form-item label="渠道类型" prop="channel_type">
|
||||
<el-select v-model="form.channel_type" style="width: 100%">
|
||||
<el-option v-for="t in channelTypes" :key="t.value" :label="t.label" :value="t.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="Webhook" prop="webhook_url">
|
||||
<el-input v-model="form.webhook_url" placeholder="机器人 Webhook 地址" />
|
||||
<div class="form-tip">
|
||||
<template v-if="form.channel_type === 'dingtalk_bot'">
|
||||
钉钉机器人 Webhook 格式: https://oapi.dingtalk.com/robot/send?access_token=xxx
|
||||
</template>
|
||||
<template v-else>
|
||||
企微机器人 Webhook 格式: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx
|
||||
</template>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.channel_type === 'dingtalk_bot'" label="加签密钥">
|
||||
<el-input v-model="form.sign_secret" placeholder="SEC开头的密钥(可选)" />
|
||||
<div class="form-tip">
|
||||
如果创建机器人时选择了「加签」安全设置,请填写密钥(以 SEC 开头)
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述">
|
||||
<el-input v-model="form.description" type="textarea" :rows="2" placeholder="渠道描述(可选)" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.page-header .title {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-tip {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.page-tip code {
|
||||
background: #f5f7fa;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-tip {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user