- 新增 platform_tenant_wechat_apps 表(租户企微应用配置) - platform_apps 增加 require_jssdk 字段 - platform_tenant_apps 增加 wechat_app_id 关联字段 - 新增企微应用管理 API 和页面 - 应用管理页面增加 JS-SDK 开关 - 应用配置页面增加企微应用选择
This commit is contained in:
@@ -19,6 +19,10 @@ const query = reactive({
|
||||
// 应用列表(从应用管理获取)
|
||||
const appList = ref([])
|
||||
const appToolsMap = ref({}) // app_code -> tools[]
|
||||
const appRequireJssdk = ref({}) // app_code -> require_jssdk
|
||||
|
||||
// 企微应用列表(按租户)
|
||||
const wechatAppList = ref([]) // 当前表单租户的企微应用列表
|
||||
|
||||
// 对话框
|
||||
const dialogVisible = ref(false)
|
||||
@@ -29,12 +33,15 @@ const form = reactive({
|
||||
tenant_id: '',
|
||||
app_code: 'tools',
|
||||
app_name: '',
|
||||
wechat_corp_id: '',
|
||||
wechat_agent_id: '',
|
||||
wechat_secret: '',
|
||||
wechat_app_id: null, // 关联的企微应用ID
|
||||
allowed_tools: []
|
||||
})
|
||||
|
||||
// 当前选择的应用是否需要 JS-SDK
|
||||
const currentAppRequireJssdk = computed(() => {
|
||||
return appRequireJssdk.value[form.app_code] || false
|
||||
})
|
||||
|
||||
// 根据选择的应用获取工具选项
|
||||
const toolOptions = computed(() => {
|
||||
const tools = appToolsMap.value[form.app_code] || []
|
||||
@@ -66,11 +73,13 @@ const urlInfo = ref({})
|
||||
|
||||
async function fetchApps() {
|
||||
try {
|
||||
const res = await api.get('/api/apps/all')
|
||||
appList.value = res.data || []
|
||||
const res = await api.get('/api/apps', { params: { size: 100 } })
|
||||
const apps = res.data.items || []
|
||||
appList.value = apps.map(a => ({ app_code: a.app_code, app_name: a.app_name }))
|
||||
|
||||
// 获取每个应用的工具列表
|
||||
for (const app of appList.value) {
|
||||
// 获取每个应用的工具列表和 JS-SDK 要求
|
||||
for (const app of apps) {
|
||||
appRequireJssdk.value[app.app_code] = app.require_jssdk || false
|
||||
try {
|
||||
const toolsRes = await api.get(`/api/apps/${app.app_code}/tools`)
|
||||
appToolsMap.value[app.app_code] = toolsRes.data || []
|
||||
@@ -83,6 +92,19 @@ async function fetchApps() {
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchWechatApps(tenantId) {
|
||||
if (!tenantId) {
|
||||
wechatAppList.value = []
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await api.get(`/api/tenant-wechat-apps/by-tenant/${tenantId}`)
|
||||
wechatAppList.value = res.data || []
|
||||
} catch (e) {
|
||||
wechatAppList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -113,37 +135,38 @@ function handleCreate() {
|
||||
tenant_id: '',
|
||||
app_code: 'tools',
|
||||
app_name: '',
|
||||
wechat_corp_id: '',
|
||||
wechat_agent_id: '',
|
||||
wechat_secret: '',
|
||||
wechat_app_id: null,
|
||||
allowed_tools: []
|
||||
})
|
||||
wechatAppList.value = []
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function handleEdit(row) {
|
||||
async function handleEdit(row) {
|
||||
editingId.value = row.id
|
||||
dialogTitle.value = '编辑应用配置'
|
||||
Object.assign(form, {
|
||||
tenant_id: row.tenant_id,
|
||||
app_code: row.app_code,
|
||||
app_name: row.app_name || '',
|
||||
wechat_corp_id: row.wechat_corp_id || '',
|
||||
wechat_agent_id: row.wechat_agent_id || '',
|
||||
wechat_secret: '', // 不回显密钥
|
||||
wechat_app_id: row.wechat_app_id || null,
|
||||
allowed_tools: row.allowed_tools || []
|
||||
})
|
||||
// 获取该租户的企微应用列表
|
||||
await fetchWechatApps(row.tenant_id)
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 租户ID变化时重新获取企微应用列表
|
||||
async function handleTenantChange() {
|
||||
form.wechat_app_id = null
|
||||
await fetchWechatApps(form.tenant_id)
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
await formRef.value.validate()
|
||||
|
||||
const data = { ...form }
|
||||
// 如果没有输入新密钥,不传这个字段
|
||||
if (!data.wechat_secret) {
|
||||
delete data.wechat_secret
|
||||
}
|
||||
|
||||
try {
|
||||
if (editingId.value) {
|
||||
@@ -188,21 +211,6 @@ async function handleRegenerateToken(row) {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleViewSecret(row) {
|
||||
try {
|
||||
const res = await api.get(`/api/tenant-apps/${row.id}/wechat-secret`)
|
||||
if (res.data.wechat_secret) {
|
||||
ElMessageBox.alert(res.data.wechat_secret, '微信 Secret', {
|
||||
confirmButtonText: '关闭'
|
||||
})
|
||||
} else {
|
||||
ElMessage.info('未配置微信 Secret')
|
||||
}
|
||||
} catch (e) {
|
||||
// 错误已在拦截器处理
|
||||
}
|
||||
}
|
||||
|
||||
// 生成链接功能
|
||||
function handleShowUrl(row) {
|
||||
currentRow.value = row
|
||||
@@ -319,12 +327,12 @@ onMounted(() => {
|
||||
<el-table-column prop="tenant_id" label="租户ID" width="120" />
|
||||
<el-table-column prop="app_code" label="应用" width="100" />
|
||||
<el-table-column prop="app_name" label="应用名称" width="150" />
|
||||
<el-table-column prop="wechat_corp_id" label="企业ID" width="150" show-overflow-tooltip />
|
||||
<el-table-column prop="wechat_agent_id" label="应用ID" width="100" />
|
||||
<el-table-column label="微信密钥" width="100">
|
||||
<el-table-column label="企微应用" width="180">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.has_wechat_secret" type="success" size="small">已配置</el-tag>
|
||||
<el-tag v-else type="info" size="small">未配置</el-tag>
|
||||
<template v-if="row.wechat_app">
|
||||
<el-tag type="success" size="small">{{ row.wechat_app.name }}</el-tag>
|
||||
</template>
|
||||
<el-tag v-else type="info" size="small">未关联</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="Access Token" width="120">
|
||||
@@ -341,12 +349,11 @@ onMounted(() => {
|
||||
<span v-if="(row.allowed_tools || []).length > 3">...</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="300" fixed="right">
|
||||
<el-table-column label="操作" width="250" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="success" link size="small" @click="handleShowUrl(row)">生成链接</el-button>
|
||||
<el-button v-if="authStore.isOperator" type="primary" link size="small" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button v-if="authStore.isOperator" type="warning" link size="small" @click="handleViewSecret(row)">密钥</el-button>
|
||||
<el-button v-if="authStore.isOperator" type="info" link size="small" @click="handleRegenerateToken(row)">重置</el-button>
|
||||
<el-button v-if="authStore.isOperator" type="info" link size="small" @click="handleRegenerateToken(row)">重置Token</el-button>
|
||||
<el-button v-if="authStore.isOperator" type="danger" link size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -367,7 +374,12 @@ onMounted(() => {
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="600px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="租户ID" prop="tenant_id">
|
||||
<el-input v-model="form.tenant_id" :disabled="!!editingId" placeholder="如: tenant_001" />
|
||||
<el-input
|
||||
v-model="form.tenant_id"
|
||||
:disabled="!!editingId"
|
||||
placeholder="如: qiqi"
|
||||
@blur="handleTenantChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="应用" prop="app_code">
|
||||
<el-select v-model="form.app_code" :disabled="!!editingId" placeholder="选择应用" style="width: 100%">
|
||||
@@ -379,16 +391,25 @@ onMounted(() => {
|
||||
<el-input v-model="form.app_name" placeholder="显示名称(可选)" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">企业微信配置</el-divider>
|
||||
<el-divider v-if="currentAppRequireJssdk" content-position="left">企业微信关联</el-divider>
|
||||
|
||||
<el-form-item label="企业 ID">
|
||||
<el-input v-model="form.wechat_corp_id" placeholder="ww开头的企业ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="应用 ID">
|
||||
<el-input v-model="form.wechat_agent_id" placeholder="自建应用的 AgentId" />
|
||||
</el-form-item>
|
||||
<el-form-item label="应用 Secret">
|
||||
<el-input v-model="form.wechat_secret" type="password" show-password :placeholder="editingId ? '留空则不修改' : '应用的 Secret'" />
|
||||
<el-form-item v-if="currentAppRequireJssdk" label="关联企微应用">
|
||||
<el-select
|
||||
v-model="form.wechat_app_id"
|
||||
placeholder="选择企微应用"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="wa in wechatAppList"
|
||||
:key="wa.id"
|
||||
:label="`${wa.name} (${wa.corp_id})`"
|
||||
:value="wa.id"
|
||||
/>
|
||||
</el-select>
|
||||
<div v-if="wechatAppList.length === 0 && form.tenant_id" style="color: #909399; font-size: 12px; margin-top: 4px">
|
||||
该租户暂无企微应用,请先在「企微应用」中配置
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">权限配置</el-divider>
|
||||
|
||||
Reference in New Issue
Block a user