feat: 钉钉、企业微信webbook
This commit is contained in:
@@ -1,10 +1,233 @@
|
||||
---
|
||||
description:
|
||||
description: 萧康云医管理后台(Vben Admin v5 + Vue 3 + TS + Ant Design Vue)代码规范
|
||||
alwaysApply: true
|
||||
---
|
||||
|
||||
# 基础规范(所有项目通用)
|
||||
|
||||
1. 写代码的时候要补充详细的中文注释(每个方法是干嘛的,为什么要这样写),如果是工作区,则所有项目都适用该规则
|
||||
2. 注意不要生成太多的空行,上一部分代码和下一部分代码中间的空行不要大于2行
|
||||
2. 注意不要生成太多的空行,上一部分代码和下一部分代码中间的空行不要大于 2 行
|
||||
3. 有封装好的方法、组件需要复用,不要重复造轮子
|
||||
4. 小程序端的抽屉全部需要用page-container来防止用户意外退出页面(记得使用v-if而不是v-show)
|
||||
4. 小程序端的抽屉全部需要用 page-container 来防止用户意外退出页面(记得使用 v-if 而不是 v-show)
|
||||
5. 数据库的(created_at、updated_at、deleted_at)统一使用时间戳,不要使用字符串,并且我在查询器中一级格式化成字符串了,无需再次格式化
|
||||
|
||||
# 全局架构规范
|
||||
|
||||
## 目录结构规范
|
||||
|
||||
- 业务页面统一放在 `apps/web-antd/src/views/<端>/<模块>/`(端:system / business / doctor 等)
|
||||
- 标准 CRUD 模块目录结构:
|
||||
|
||||
```
|
||||
views/<端>/<模块>/
|
||||
├── index.vue # 列表页(Page + Grid + Modal)
|
||||
├── api/index.ts # 本模块 API(CRUD)
|
||||
├── config/
|
||||
│ ├── table.ts # vxe-grid 列定义 + proxyConfig
|
||||
│ ├── search.ts # 顶部搜索表单 schema
|
||||
│ └── form.ts # 新增/编辑弹窗 form schema
|
||||
├── components/
|
||||
│ └── modal.vue # 新增/编辑弹窗
|
||||
└── utils/ # 模块工具(可选)
|
||||
```
|
||||
|
||||
- 全局复用组件放 `apps/web-antd/src/components/`
|
||||
- 表单内可用组件放 `apps/web-antd/src/components/form/components/`,文件名 kebab-case,自动注册为 schema 的 `component` 名(PascalCase 引用)
|
||||
|
||||
## 强制复用封装(禁止重复造轮子)
|
||||
|
||||
- 表格统一用 `useVbenVxeGrid`(来自 `#/adapter/vxe-table`),**不要直接 new VxeGrid**
|
||||
- 表单统一用 `useVbenForm`(来自 `#/adapter/form`),**不要直接写 `<Form>` + 手动校验**
|
||||
- 弹窗统一用 `useVbenModal`(来自 `@vben/common-ui`),**不要用原生 `<Modal>`**
|
||||
- 页面外壳统一用 `<Page>` 组件(来自 `@vben/common-ui`)
|
||||
- HTTP 请求统一用 `requestClient`(来自 `#/api/request`),**禁止直接 axios / fetch**
|
||||
- 行操作和工具栏按钮统一用 `<TableAction>` 组件(来自 `#/components/table-action`)
|
||||
- 业务选择器(员工、医生、门店、推广员、地区等)必须复用 `#/components/form/components/*-picker.vue`,不要重写
|
||||
|
||||
## API 层规范
|
||||
|
||||
- API 文件统一放在 `<模块>/api/index.ts`
|
||||
- 函数命名约定:`get{Entity}List` / `get{Entity}Option` / `get{Entity}Info` / `create{Entity}` / `update{Entity}` / `delete{Entity}`
|
||||
- URL 使用 kebab-case,统一前缀变量 `const prefix = 'xxx/'`,**URL 末尾不补 `/`**
|
||||
- GET 用 `params`,POST 用 `data`,例如:
|
||||
|
||||
```ts
|
||||
import { requestClient } from '#/api/request';
|
||||
const prefix = 'oa-robot/';
|
||||
export async function getOaRobotList(data: any) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||||
}
|
||||
```
|
||||
|
||||
## 字段命名对齐后端
|
||||
|
||||
- 数据库字段在前端 schema 的 `field` / `fieldName` 中保持 snake_case(如 `created_at`、`store_id`、`platform_code`),**不要转换为 camelCase**
|
||||
- 时间戳字段(`created_at` 等)后端查询器已格式化为字符串,前端**无需再次格式化**
|
||||
- TS 变量用 camelCase,常量用 UPPER_SNAKE_CASE,类型用 PascalCase
|
||||
|
||||
## 表单校验
|
||||
|
||||
- 必填用字符串规则 `rules: 'required'`(选择项用 `'selectRequired'`),规则定义在 `#/adapter/form.ts` 的 `defineRules`
|
||||
- 校验调用统一用 `formApi.validate().then(e => { if (e.valid) {...} })`
|
||||
- 必填字段在 schema 中加 `rules: 'required'`,禁止散落 `validator` 写法
|
||||
|
||||
## 字典/枚举管理
|
||||
|
||||
- 模块内建 `config/constants.ts`,导出 `{ label, value }[]` 数组,禁止在 schema 中散落字面量
|
||||
- 例如:
|
||||
|
||||
```ts
|
||||
export const OA_MESSAGE_TYPE_OPTIONS = [
|
||||
{ label: '文本', value: 'text' },
|
||||
{ label: 'Markdown', value: 'markdown' },
|
||||
];
|
||||
```
|
||||
|
||||
## 路由规范
|
||||
|
||||
- 业务路由通过后端动态菜单驱动(`xk_menu` 表),**不要在前端 `router/routes/modules/` 静态注册业务路由**
|
||||
- `defineOptions({ name: 'PascalCaseName' })` 必须与 `xk_menu.name` 字段一致
|
||||
|
||||
## Tab 用法
|
||||
|
||||
- 统一用 antd 原生 `Tabs` + `Tabs.TabPane`,**不要找 Vben 自封装的 Tabs**
|
||||
- Tab 选中状态持久化走 `localStorage`(参考 `system-config/index.vue` 的 `TAB_STORAGE_KEY` 模式)
|
||||
|
||||
## 抽屉用法(小程序端,admin 不涉及)
|
||||
|
||||
- 小程序端的抽屉用 `page-container` + `v-if`(不是 `v-show`)防止用户意外退出页面
|
||||
|
||||
## 中文注释
|
||||
|
||||
- 每个 `<script setup>` 顶部说明模块用途
|
||||
- 每个主要函数(特别是有业务逻辑的)必须有中文注释
|
||||
- 复杂的 schema 字段配置要注释意图
|
||||
|
||||
## 空行控制
|
||||
|
||||
- 上一部分代码和下一部分代码中间空行不超过 2 行
|
||||
|
||||
## Vben 组件使用规范
|
||||
|
||||
### VbenModal(来自 @vben/common-ui)
|
||||
|
||||
- 创建弹窗必须用 `useVbenModal`,禁止直接用 antd `Modal` 或原生 `<dialog>`
|
||||
- 抽离弹窗内容到子组件时,外层用 `connectedComponent` 参数连接,内外组件共享 `modalApi`
|
||||
- 底部按钮扩展 slot 优先级:`prepend-footer`(取消按钮左侧)> `center-footer`(取消/确定之间)> `append-footer`(确定右侧)
|
||||
- **严禁覆盖 `#footer` slot**,会丢失默认的取消/确定按钮和 loading 行为
|
||||
- 表单提交 loading 走 `modalApi.setState({ confirmLoading: true })`,禁止自己写 button loading
|
||||
- 提交防抖/防重复用 `modalApi.lock()` / `unlock()`(>5.5.3),禁止手动 disabled
|
||||
- 拖拽开 `draggable: true`,需要拖出可视区时同时开 `overflow: true`
|
||||
- 数据回填走 `modalApi.setData()` + `onOpenChange(isOpen) { const data = modalApi.getData() }`
|
||||
|
||||
### VbenDrawer(来自 @vben/common-ui)
|
||||
|
||||
- 创建抽屉必须用 `useVbenDrawer`,禁止直接用 antd `Drawer`
|
||||
- 底部按钮扩展 slot 与 Modal 一致:`prepend-footer` / `center-footer` / `append-footer`
|
||||
- **同样严禁覆盖 `#footer` slot**
|
||||
- 关闭前校验用 `onBeforeClose`(>5.5.2 支持 Promise),禁止自己拦截
|
||||
- 提交防抖/防重复用 `drawerApi.lock()` / `unlock()`(>5.5.3)
|
||||
- 小程序端的「抽屉」概念与此无关,小程序端按现有规则用 `page-container`
|
||||
|
||||
### VbenVxeTable(来自 #/adapter/vxe-table)
|
||||
|
||||
- 表格必须用 `useVbenVxeGrid`,禁止直接 `new VxeGrid` 或 antd `Table`
|
||||
- 远程数据加载走 `gridOptions.proxyConfig.ajax.query`,**禁止自己 fetch 后 `data = []` 赋值**
|
||||
- query 接口返回结构必须匹配适配器配置:`{ items: [], total: number }`(在 `apps/web-antd/src/adapter/vxe-table.ts` 的 `response` 字段统一配置)
|
||||
- 分页参数从 `{ page }` 解构取:`page.currentPage` / `page.pageSize`,禁止自己读 URL
|
||||
- 刷新表格用 `gridApi.query()`(保留当前页)或 `gridApi.reload()`(回到第一页),禁止整页 `window.location.reload()`
|
||||
- 工具栏按钮插 slot:`toolbar-actions`(标题左侧)、`toolbar-tools`(工具按钮左侧),禁止改 vxe-grid 内部模板
|
||||
- 表格 loading 用 `gridApi.setLoading(bool)`,禁止自己遮罩
|
||||
- 搜索表单由 `formOptions` 配置(底层是 Vben Form),开关走 `gridOptions.toolbarConfig.search = true`
|
||||
- 自定义列渲染走 `slots: { default: 'action' }` + Grid 子组件内 `<template #action="{ row }">`,禁止 column 渲染函数里写 JSX
|
||||
|
||||
### VbenForm(来自 #/adapter/form)
|
||||
|
||||
- 表单必须用 `useVbenForm`,禁止直接 `<form>` 或 antd `Form`
|
||||
- 动态修改 schema 必须用 `formApi.updateSchema([...])`,**vben form 没有 `setComponentProps` 这个方法**(这是已踩过的坑)
|
||||
- 取值/赋值用 `formApi.getValues()` / `formApi.setValues(obj)`,禁止自己 `v-model` 收集
|
||||
- 校验用 `formApi.validate().then(e => { if (e.valid) {...} })` 或 `formApi.validateAndSubmitForm()`
|
||||
- 必填规则用字符串 `'required'` / `'selectRequired'`,规则在 `#/adapter/form.ts` 的 `defineRules` 注册
|
||||
- schema 中字段名(`fieldName`)必须与后端字段 snake_case 对齐,禁止前端 camelCase
|
||||
- 密码/敏感字段用 `VbenInputPassword` 组件,禁止用 `VbenInput` 配 `type="password"`
|
||||
- 单选/多选选项来自接口时,必须在弹窗/页面 `onMounted` 或 `onOpenChange` 里拉取后通过 `updateSchema` 注入,禁止写死常量
|
||||
|
||||
# 专项模块规范
|
||||
|
||||
## OA 通知模块前端规则
|
||||
|
||||
### 组件与封装复用
|
||||
|
||||
- 所有 OA 配置入口(系统配置 tab、CRUD 页面、员工 OA 账号弹窗)必须复用 `Tabs.TabPane`、`useVbenVxeGrid`、`useVbenModal`、`useVbenForm`,禁止用原生 antd 表格/表单
|
||||
|
||||
### 平台动态化(禁止写死)
|
||||
|
||||
- **平台列表必须从接口 `oa-platform/list` 动态拉取**,禁止在前端写死 `['work_wechat', 'dingtalk', 'feishu']` 常量数组
|
||||
- 系统配置 tab 中的平台开关行、机器人表单中的平台下拉、场景表单中的机器人分组,都要走接口动态渲染
|
||||
- 平台编码统一为字符串 snake_case(如 `work_wechat`、`dingtalk`、`feishu`),与后端 `xk_oa_platform.platform_code` 字段对齐
|
||||
|
||||
### 系统配置 tab 交互
|
||||
|
||||
- 系统配置 tab 中的「总开关关闭」必须禁用下方所有平台子开关(视觉上置灰),禁止总开关关闭时仍能切换子开关
|
||||
- 平台子开关切换必须立即调 `oa-platform/update-enabled` 接口,**禁止依赖保存按钮批量提交**(避免总开关与子开关状态不一致)
|
||||
- 系统配置页的总开关走现有 `getSystemConfigList` / `saveSystemConfig` 接口(config_key = `oa_notify_enabled`),**禁止新建专用接口**
|
||||
|
||||
### 表单字段约定
|
||||
|
||||
- @ 人配置必须按平台分组(用 Tabs 或 Collapse 分组),员工必须从 `xk_admin` 表选择(复用员工 picker 组件)
|
||||
- OA 机器人表单中的 webhook、secret 字段必须用密码型输入框(`InputPassword`),禁止明文展示
|
||||
- OA 场景表单中的机器人多选必须按平台分组展示(用 `Tabs` 或 `Collapse` 分组)
|
||||
|
||||
### 消息类型全量支持(数据库驱动 schema)
|
||||
|
||||
- 场景弹窗每个平台 Tab 内的消息类型选项**必须**通过 `GET /oa-scene/message-types` 接口动态拉取,
|
||||
按 `platform_code` 过滤当前平台支持的所有 `message_type`
|
||||
- 每个消息类型对应的 payload 表单**必须**按后端返回的 `payload_schema`(JSON 字符串)动态渲染,
|
||||
禁止前端写死 schema(数据库可启停类型,前端硬编码会不同步)
|
||||
- payload 字段渲染规则(与后端 `payload_schema` 约定):
|
||||
- `Textarea`:多行文本
|
||||
- `Input` / `InputNumber`:单行文本/数字
|
||||
- `RadioGroup` / `Select`:选项组
|
||||
- `GalleryPickLink`:素材库选择器,透传 `props.acceptTypes: number[]` 过滤文件类型
|
||||
- `TemplateCardEditor`:企微模板卡片专用编辑器(用 `views/system/oa-scene/components/template-card-form.vue`)
|
||||
- 提交结构:`message_config: { platform_code: { message_type, payload } }`
|
||||
|
||||
### image-gallery-picker 文件类型过滤
|
||||
|
||||
- `image-gallery-picker.vue` 和 `gallery-pick-link.vue` 都支持 `acceptTypes?: number[]` prop
|
||||
- 取值对应 `xk_file_type.value`:1=图片、2=视频、3=音频、6=文件 等
|
||||
- 不传 `acceptTypes` 时显示全部类型(默认行为,保持向后兼容)
|
||||
- 传数组时只展示匹配类型 tab,且自动锁定到第一个匹配类型
|
||||
- OA 场景中图片字段必须传 `[1]`、语音字段传 `[3]`、文件字段传 `[6]`,避免用户选错类型
|
||||
|
||||
### 通用拖拽可视化编辑器(`components/oa-template-card-editor/`)
|
||||
|
||||
- 任何「左侧组件库 → 右侧画布拖拽组装 → 自动生成 JSON」的需求,**必须复用此通用组件**,禁止重复造轮子
|
||||
- schema 驱动:新增块类型只需扩展 `BlockSchema[]` 配置,禁止改组件内部
|
||||
- SortableJS 用法参照 `views/system/role/components/quick-nav-transfer.vue`(动态 import `sortablejs/modular/sortable.complete.esm.js`)
|
||||
- 双向绑定走 `v-model`(`modelValue` + `update:modelValue`),禁止内部直接修改 props
|
||||
- OA 场景中的企微模板卡片必须用 `views/system/oa-scene/components/template-card-form.vue`(在通用编辑器之上做 OA 封装)
|
||||
|
||||
### 测试发送(全类型循环)
|
||||
|
||||
- OA 机器人 modal 的「测试发送」必须循环跑该平台支持的所有消息类型(单平台最多 8 种)
|
||||
- 后端返回 `results` 数组,前端必须遍历分类型展示成功/失败(不要只展示第一条)
|
||||
- 测试按钮 loading 用独立状态(不要复用 modal 的 `confirmLoading`)
|
||||
- 测试发送结果以列表形式展示在表单下方,每种类型显示状态/耗时/错误信息
|
||||
- 测试发送支持两套入口(共用 `testSendOaRobot` API):
|
||||
- **表单弹窗内测试**(modal.vue):用于「保存前验证密钥」,直接传 webhook_url/secret(不带 id)
|
||||
- **行级测试**(独立组件 `test-send-modal.vue`):用于列表中已有机器人,仅传 `id`,后端自动取已加密密钥
|
||||
- 行级测试弹窗入参:`test_content` + `test_at_all` 开关 + `test_mobiles` 手机号多选
|
||||
- 飞书 webhook 不支持手机号 @,前端必须在飞书平台下隐藏手机号字段并提示用户(仅 @all 有效)
|
||||
|
||||
### 群聊绑定(按平台过滤的 N:N 多选)
|
||||
|
||||
- 「OA群聊管理」是独立菜单(pid=232 OA 通知父级下,菜单 id=233,路由 `/system/oa-chat`)
|
||||
- 群聊管理页结构必须与 `oa-robot` 一致:`index.vue + api/index.ts + config/{table,search,form}.ts + components/modal.vue`
|
||||
- 机器人表单中的「绑定群聊」字段必须用 `Checkbox.Group`:
|
||||
- 群聊列表通过 `getOaChatListByPlatform()` 一次性拉取全量(按平台分组的对象)
|
||||
- 前端按当前 `platform_code` 过滤展示(平台切换时自动过滤掉不属于当前平台的勾选)
|
||||
- 平台切换通过 `componentProps.onChange` 监听(vben form 字段值变化无现成 watch,必须通过 schema 注入 onChange 回调)
|
||||
- 编辑场景下,机器人详情接口返回 `chat_ids: number[]`,前端 `selectedChatIds` 直接回显
|
||||
- 提交时把 `chat_ids` 数组合并到 payload(后端 `OaRobotController::notRequest` 已包含该字段)
|
||||
- 列表展示用后端拼接好的 `chat_names` 字符串(按「、」拼接),详情接口才返回 `chat_ids` 数组
|
||||
|
||||
@@ -61,6 +61,7 @@ export type ComponentType =
|
||||
| 'DatePicker'
|
||||
| 'DefaultButton'
|
||||
| 'Divider'
|
||||
| 'GalleryPickLink' // OA 场景表单的图片/文件素材选择(透传 acceptTypes 过滤类型)
|
||||
| 'IconPicker'
|
||||
| 'Input'
|
||||
| 'InputNumber'
|
||||
|
||||
@@ -8,11 +8,17 @@ const props = withDefaults(
|
||||
multiple?: boolean;
|
||||
maxCount?: number;
|
||||
disabled?: boolean;
|
||||
/**
|
||||
* 限制可选择的文件类型(透传给 image-gallery-picker,按 xk_file_type.value 过滤)
|
||||
* 例如图片:[1];文件:[6];语音:[3]
|
||||
*/
|
||||
acceptTypes?: number[];
|
||||
}>(),
|
||||
{
|
||||
multiple: false,
|
||||
maxCount: 1,
|
||||
disabled: false,
|
||||
acceptTypes: () => [] as number[],
|
||||
},
|
||||
);
|
||||
|
||||
@@ -41,6 +47,7 @@ function onSelect(urls: string[]) {
|
||||
v-model:open="galleryOpen"
|
||||
:multiple="multiple"
|
||||
:max-count="maxCount"
|
||||
:accept-types="acceptTypes"
|
||||
@select="onSelect"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Empty, Input, Modal, Pagination, Spin, Tabs } from 'ant-design-vue';
|
||||
|
||||
@@ -14,10 +14,18 @@ const props = withDefaults(
|
||||
open: boolean;
|
||||
multiple?: boolean;
|
||||
maxCount?: number;
|
||||
/**
|
||||
* 限制可选择的文件类型(按 xk_file_type.value 过滤)
|
||||
* - 不传:显示全部类型(默认行为,保持向后兼容)
|
||||
* - 传数组:只展示指定类型 tab,且自动锁定到第一个匹配的类型
|
||||
* 例如图片:[1];图片+视频:[1, 2];文件:[6]
|
||||
*/
|
||||
acceptTypes?: number[];
|
||||
}>(),
|
||||
{
|
||||
multiple: false,
|
||||
maxCount: 1,
|
||||
acceptTypes: () => [] as number[],
|
||||
},
|
||||
);
|
||||
|
||||
@@ -44,6 +52,39 @@ const {
|
||||
typesLoading,
|
||||
} = useFileGalleryFilter('file-picker-active-type');
|
||||
|
||||
/**
|
||||
* 实际渲染的 tabs(按 acceptTypes 过滤)
|
||||
* - acceptTypes 为空:返回 tabs 原始值(含「全部」+ 所有类型)
|
||||
* - acceptTypes 非空:只保留匹配的类型 tab(不含「全部」,强制选具体类型)
|
||||
*/
|
||||
const visibleTabs = computed(() => {
|
||||
if (!props.acceptTypes || props.acceptTypes.length === 0) {
|
||||
return tabs.value;
|
||||
}
|
||||
return tabs.value.filter(
|
||||
(tab) => tab.value !== -1 && props.acceptTypes.includes(Number(tab.value)),
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* acceptTypes 变化时锁定到第一个匹配的类型(避免停留在「全部」导致看到非目标类型文件)
|
||||
*/
|
||||
watch(
|
||||
() => props.acceptTypes,
|
||||
(arr) => {
|
||||
if (!arr || arr.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (arr.includes(activeType.value)) {
|
||||
return;
|
||||
}
|
||||
setActiveType(arr[0]!);
|
||||
page.value = 1;
|
||||
void load();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
async function load() {
|
||||
@@ -155,7 +196,7 @@ function itemIcon(item: FileGalleryItem) {
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Tabs :active-key="String(activeType)" size="small" @change="onTabChange">
|
||||
<Tabs.TabPane v-for="tab in tabs" :key="String(tab.value)">
|
||||
<Tabs.TabPane v-for="tab in visibleTabs" :key="String(tab.value)">
|
||||
<template #tab>
|
||||
<span class="tab-label">
|
||||
<MIcon v-if="tab.icon" :icon="tab.icon" size="12" />
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
<script setup lang="ts">
|
||||
import type { BlockSchema } from './types';
|
||||
|
||||
import MIcon from '#/components/icon/icon.vue';
|
||||
|
||||
/**
|
||||
* 左侧组件库:渲染所有可拖拽块类型
|
||||
* 用户从这里拖动到中间画布(SortableJS 用 pull:clone 模式,左侧库不会减少)
|
||||
*/
|
||||
defineProps<{
|
||||
/** 所有可拖拽块定义 */
|
||||
blocks: BlockSchema[];
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="block-library">
|
||||
<div class="panel-header">
|
||||
<span class="title">组件库</span>
|
||||
<span class="hint">拖入画布</span>
|
||||
</div>
|
||||
<div class="block-list">
|
||||
<div
|
||||
v-for="block in blocks"
|
||||
:key="block.type"
|
||||
class="block-item"
|
||||
:data-block-type="block.type"
|
||||
>
|
||||
<MIcon v-if="block.icon" :icon="block.icon" size="16" />
|
||||
<span class="block-label">{{ block.label }}</span>
|
||||
</div>
|
||||
<div v-if="blocks.length === 0" class="empty-hint">暂无可拖入组件</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.block-library {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 200px;
|
||||
height: 100%;
|
||||
border-right: 1px solid #e5e6eb;
|
||||
background: #fafbfc;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e5e6eb;
|
||||
font-size: 13px;
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #86909c;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px 8px;
|
||||
}
|
||||
|
||||
.block-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 6px;
|
||||
border: 1px dashed #c9cdd4;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
font-size: 13px;
|
||||
color: #4e5969;
|
||||
cursor: grab;
|
||||
user-select: none;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: #165dff;
|
||||
color: #165dff;
|
||||
background: #f2f7ff;
|
||||
}
|
||||
|
||||
&:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.block-label {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
padding: 24px 12px;
|
||||
text-align: center;
|
||||
color: #c9cdd4;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.dark {
|
||||
.block-library {
|
||||
background: #1f1f1f;
|
||||
border-right-color: #374151;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
border-bottom-color: #374151;
|
||||
|
||||
.title {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
|
||||
.block-item {
|
||||
background: #374151;
|
||||
border-color: #4b5563;
|
||||
color: #d1d5db;
|
||||
|
||||
&:hover {
|
||||
border-color: #60a5fa;
|
||||
color: #60a5fa;
|
||||
background: rgba(96, 165, 250, 0.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
337
apps/web-antd/src/components/oa-template-card-editor/Canvas.vue
Normal file
337
apps/web-antd/src/components/oa-template-card-editor/Canvas.vue
Normal file
@@ -0,0 +1,337 @@
|
||||
<script setup lang="ts">
|
||||
import type { BlockInstance, BlockSchema } from './types';
|
||||
|
||||
import { computed } from 'vue';
|
||||
|
||||
import MIcon from '#/components/icon/icon.vue';
|
||||
|
||||
/**
|
||||
* 中间画布:按 targetArrayPath 分组渲染块实例
|
||||
* 每个分组是一个 SortableJS 接收区,可拖入、排序、删除
|
||||
*/
|
||||
const props = defineProps<{
|
||||
/** 所有块定义(按 type 查找对应 schema) */
|
||||
blockSchemas: BlockSchema[];
|
||||
/** 所有块实例(已拖入画布的) */
|
||||
instances: BlockInstance[];
|
||||
/** 当前选中的块实例 ID(高亮显示) */
|
||||
selectedInstanceId?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 选中块实例(点击时触发) */
|
||||
select: [instanceId: string];
|
||||
/** 删除块实例 */
|
||||
remove: [instanceId: string];
|
||||
}>();
|
||||
|
||||
/**
|
||||
* 按 targetArrayPath 分组的渲染结构
|
||||
* 每个分组对应一个 SortableJS 接收区
|
||||
*/
|
||||
const groupedRender = computed(() => {
|
||||
// 收集所有出现的 targetArrayPath,按 blockSchemas 顺序排序
|
||||
const orderedPaths: string[] = [];
|
||||
const labelMap: Record<string, { label: string; maxCount?: number }> = {};
|
||||
for (const schema of props.blockSchemas) {
|
||||
if (!orderedPaths.includes(schema.targetArrayPath)) {
|
||||
orderedPaths.push(schema.targetArrayPath);
|
||||
labelMap[schema.targetArrayPath] = {
|
||||
label: schema.targetArrayPath,
|
||||
maxCount: schema.maxCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 把 instances 按目标路径分组
|
||||
const grouped: Record<string, BlockInstance[]> = {};
|
||||
for (const inst of props.instances) {
|
||||
const schema = props.blockSchemas.find((s) => s.type === inst.type);
|
||||
if (!schema) continue;
|
||||
const path = schema.targetArrayPath;
|
||||
if (!grouped[path]) grouped[path] = [];
|
||||
grouped[path].push(inst);
|
||||
}
|
||||
|
||||
return orderedPaths.map((path) => ({
|
||||
path,
|
||||
label: labelMap[path]?.label ?? path,
|
||||
maxCount: labelMap[path]?.maxCount,
|
||||
items: grouped[path] ?? [],
|
||||
}));
|
||||
});
|
||||
|
||||
/**
|
||||
* 获取块实例的 schema 定义
|
||||
*/
|
||||
function getSchema(type: string): BlockSchema | undefined {
|
||||
return props.blockSchemas.find((s) => s.type === type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取块实例的简要描述(属性面板编辑的字段值预览)
|
||||
*/
|
||||
function getInstanceSummary(inst: BlockInstance): string {
|
||||
const schema = getSchema(inst.type);
|
||||
if (!schema) return '';
|
||||
const firstField = schema.fields[0];
|
||||
if (!firstField) return '';
|
||||
// 嵌套路径取最末级
|
||||
const path = firstField.name.split('.');
|
||||
let value: any = inst.data;
|
||||
for (const key of path) {
|
||||
value = value?.[key];
|
||||
}
|
||||
return value ? String(value) : '(未填写)';
|
||||
}
|
||||
|
||||
function handleClick(instanceId: string) {
|
||||
emit('select', instanceId);
|
||||
}
|
||||
|
||||
function handleRemove(instanceId: string) {
|
||||
emit('remove', instanceId);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="canvas">
|
||||
<div class="panel-header">
|
||||
<span class="title">画布</span>
|
||||
<span class="hint">拖入 / 排序 / 点击编辑属性</span>
|
||||
</div>
|
||||
<div class="canvas-body">
|
||||
<div
|
||||
v-for="group in groupedRender"
|
||||
:key="group.path"
|
||||
class="canvas-group"
|
||||
>
|
||||
<div class="group-header">
|
||||
<span class="group-label">{{ group.label }}</span>
|
||||
<span class="group-count">
|
||||
{{ group.items.length }}{{ group.maxCount ? `/${group.maxCount}` : '' }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="group-dropzone"
|
||||
:data-target-array-path="group.path"
|
||||
>
|
||||
<div
|
||||
v-for="inst in group.items"
|
||||
:key="inst.id"
|
||||
class="instance-item"
|
||||
:class="{ selected: inst.id === selectedInstanceId }"
|
||||
:data-instance-id="inst.id"
|
||||
@click.stop="handleClick(inst.id)"
|
||||
>
|
||||
<div class="instance-info">
|
||||
<MIcon
|
||||
v-if="getSchema(inst.type)?.icon"
|
||||
:icon="getSchema(inst.type)!.icon"
|
||||
size="14"
|
||||
/>
|
||||
<div class="instance-text">
|
||||
<div class="instance-label">{{ getSchema(inst.type)?.label }}</div>
|
||||
<div class="instance-summary">{{ getInstanceSummary(inst) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="instance-remove"
|
||||
title="删除"
|
||||
@click.stop="handleRemove(inst.id)"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="group.items.length === 0" class="empty-dropzone">
|
||||
拖入组件
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.canvas {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e5e6eb;
|
||||
font-size: 13px;
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #86909c;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
.canvas-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.canvas-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.group-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
font-size: 12px;
|
||||
|
||||
.group-label {
|
||||
color: #4e5969;
|
||||
font-weight: 500;
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
}
|
||||
|
||||
.group-count {
|
||||
color: #86909c;
|
||||
}
|
||||
}
|
||||
|
||||
.group-dropzone {
|
||||
min-height: 60px;
|
||||
padding: 8px;
|
||||
border: 2px dashed #d9d9d9;
|
||||
border-radius: 6px;
|
||||
background: #fafbfc;
|
||||
}
|
||||
|
||||
.empty-dropzone {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 44px;
|
||||
color: #c9cdd4;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.instance-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 10px;
|
||||
margin-bottom: 6px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: #165dff;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #165dff;
|
||||
background: #f2f7ff;
|
||||
box-shadow: 0 0 0 2px rgba(22, 93, 255, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
.instance-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.instance-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.instance-label {
|
||||
font-size: 13px;
|
||||
color: #1d2129;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.instance-summary {
|
||||
font-size: 11px;
|
||||
color: #86909c;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.instance-remove {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
background: transparent;
|
||||
color: #86909c;
|
||||
font-size: 16px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&:hover {
|
||||
background: #f53f3f;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.dark {
|
||||
.canvas {
|
||||
background: #1f1f1f;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
border-bottom-color: #374151;
|
||||
|
||||
.title {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
|
||||
.group-dropzone {
|
||||
background: #1f1f1f;
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.instance-item {
|
||||
background: #374151;
|
||||
border-color: #4b5563;
|
||||
|
||||
&:hover {
|
||||
border-color: #60a5fa;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #60a5fa;
|
||||
background: rgba(96, 165, 250, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.instance-label {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,118 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
/**
|
||||
* JSON 实时预览面板
|
||||
* - 显示最终生成的 JSON 字符串(语法高亮,简单的 key/string 高亮)
|
||||
* - 提供「复制 JSON」按钮(一键拷贝到剪贴板)
|
||||
*/
|
||||
const props = defineProps<{
|
||||
/** 最终生成的 JSON 数据 */
|
||||
value: Record<string, any>;
|
||||
}>();
|
||||
|
||||
const formattedJson = computed(() => {
|
||||
try {
|
||||
return JSON.stringify(props.value, null, 2);
|
||||
} catch {
|
||||
return '// JSON 序列化失败';
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 简单的 JSON 语法高亮
|
||||
* 匹配 key / string / number / boolean 并套用不同颜色 span
|
||||
*/
|
||||
const highlightedHtml = computed(() => {
|
||||
const escape = (s: string) =>
|
||||
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
||||
const json = escape(formattedJson.value);
|
||||
return json
|
||||
.replace(
|
||||
/("(?:\\.|[^"\\])*")(\s*:)/g,
|
||||
'<span class="json-key">$1</span>$2',
|
||||
)
|
||||
.replace(
|
||||
/:\s*("(?:\\.|[^"\\])*")/g,
|
||||
': <span class="json-string">$1</span>',
|
||||
)
|
||||
.replace(/:\s*(-?\d+(?:\.\d+)?)/g, ': <span class="json-number">$1</span>')
|
||||
.replace(/:\s*(true|false|null)/g, ': <span class="json-bool">$1</span>');
|
||||
});
|
||||
|
||||
async function handleCopy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(formattedJson.value);
|
||||
message.success('JSON 已复制');
|
||||
} catch {
|
||||
message.error('复制失败,请手动选择');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="json-preview">
|
||||
<div class="panel-header">
|
||||
<span class="title">JSON 预览</span>
|
||||
<Button size="small" type="link" @click="handleCopy">复制 JSON</Button>
|
||||
</div>
|
||||
<pre class="json-body" v-html="highlightedHtml" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.json-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 280px;
|
||||
height: 100%;
|
||||
border-left: 1px solid #e5e6eb;
|
||||
background: #1e1e1e;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #374151;
|
||||
font-size: 13px;
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
|
||||
.json-body {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
padding: 12px;
|
||||
overflow: auto;
|
||||
font-family: 'JetBrains Mono', 'Fira Code', monospace;
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
color: #d4d4d4;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* JSON 语法高亮颜色 */
|
||||
:deep(.json-key) {
|
||||
color: #9cdcfe;
|
||||
}
|
||||
|
||||
:deep(.json-string) {
|
||||
color: #ce9178;
|
||||
}
|
||||
|
||||
:deep(.json-number) {
|
||||
color: #b5cea8;
|
||||
}
|
||||
|
||||
:deep(.json-bool) {
|
||||
color: #569cd6;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,372 @@
|
||||
<script setup lang="ts">
|
||||
import type { BlockInstance, BlockSchema, FixedField, FormFieldSchema } from './types';
|
||||
|
||||
import { computed, watch } from 'vue';
|
||||
|
||||
import { Empty, Input, InputNumber, Radio, RadioGroup, Select, Textarea } from 'ant-design-vue';
|
||||
|
||||
import GalleryPickLink from '#/components/form/components/gallery-pick-link.vue';
|
||||
|
||||
/**
|
||||
* 右侧属性面板:根据选中块的字段 schema 渲染表单
|
||||
* - 顶层固定字段(fixedFields):渲染在顶部,不可删除
|
||||
* - 选中块的 fields:渲染在下方
|
||||
* - 图片类型字段用 GalleryPickLink(透传 acceptTypes)
|
||||
*/
|
||||
const props = defineProps<{
|
||||
/** 顶层固定字段定义 */
|
||||
fixedFields?: FixedField[];
|
||||
/** 顶层固定字段当前值 */
|
||||
fixedValues?: Record<string, any>;
|
||||
/** 当前选中的块定义(可能为空) */
|
||||
selectedBlockSchema?: BlockSchema;
|
||||
/** 当前选中的块实例(可能为空) */
|
||||
selectedInstance?: BlockInstance;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 顶层固定字段值变化 */
|
||||
'update:fixedValues': [value: Record<string, any>];
|
||||
/** 选中块实例数据变化 */
|
||||
'update:instance': [instance: BlockInstance];
|
||||
}>();
|
||||
|
||||
/**
|
||||
* 设置顶层固定字段的值
|
||||
* 支持 a.b.c 嵌套路径
|
||||
*/
|
||||
function setFixedValue(path: string, value: any) {
|
||||
const next = { ...(props.fixedValues || {}) };
|
||||
setByPath(next, path, value);
|
||||
emit('update:fixedValues', next);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置选中块实例的字段值
|
||||
*/
|
||||
function setInstanceValue(path: string, value: any) {
|
||||
if (!props.selectedInstance) return;
|
||||
const nextData = { ...props.selectedInstance.data };
|
||||
setByPath(nextData, path, value);
|
||||
emit('update:instance', {
|
||||
...props.selectedInstance,
|
||||
data: nextData,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 a.b.c 路径设置对象嵌套属性(不可变更新)
|
||||
*/
|
||||
function setByPath(obj: Record<string, any>, path: string, value: any) {
|
||||
const keys = path.split('.');
|
||||
let cursor: any = obj;
|
||||
for (let i = 0; i < keys.length - 1; i++) {
|
||||
const k = keys[i]!;
|
||||
if (!cursor[k] || typeof cursor[k] !== 'object') {
|
||||
cursor[k] = {};
|
||||
} else {
|
||||
cursor[k] = { ...cursor[k] };
|
||||
}
|
||||
cursor = cursor[k];
|
||||
}
|
||||
cursor[keys[keys.length - 1]!] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 a.b.c 路径读取对象嵌套属性
|
||||
*/
|
||||
function getByPath(obj: Record<string, any> | undefined, path: string): any {
|
||||
if (!obj) return undefined;
|
||||
const keys = path.split('.');
|
||||
let cursor: any = obj;
|
||||
for (const k of keys) {
|
||||
if (cursor == null) return undefined;
|
||||
cursor = cursor[k];
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
const hasAnyField = computed(() => {
|
||||
return (
|
||||
(props.fixedFields && props.fixedFields.length > 0) ||
|
||||
(props.selectedBlockSchema && props.selectedBlockSchema.fields.length > 0)
|
||||
);
|
||||
});
|
||||
|
||||
// 当选中的块变化时,触发 watch 让父级感知(用于属性面板切换的动画/数据初始化)
|
||||
watch(
|
||||
() => props.selectedInstance?.id,
|
||||
() => {
|
||||
// 仅做依赖追踪,实际更新在用户交互时通过 emit 触发
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="property-panel">
|
||||
<div class="panel-header">
|
||||
<span class="title">属性</span>
|
||||
<span v-if="selectedBlockSchema" class="hint">{{ selectedBlockSchema.label }}</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<!-- 顶层固定字段 -->
|
||||
<div v-if="fixedFields && fixedFields.length > 0" class="field-section">
|
||||
<div class="section-title">基础信息</div>
|
||||
<div
|
||||
v-for="field in fixedFields"
|
||||
:key="field.name"
|
||||
class="form-row"
|
||||
>
|
||||
<label class="form-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<!-- 文本 -->
|
||||
<Input
|
||||
v-if="!field.type || field.type === 'string' || field.type === 'url'"
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
allow-clear
|
||||
size="small"
|
||||
@update:value="setFixedValue(field.name, $event)"
|
||||
/>
|
||||
<!-- 数字 -->
|
||||
<InputNumber
|
||||
v-else-if="field.type === 'number'"
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
size="small"
|
||||
style="width: 100%"
|
||||
@update:value="setFixedValue(field.name, $event)"
|
||||
/>
|
||||
<!-- 多行文本 -->
|
||||
<Textarea
|
||||
v-else-if="field.type === 'textarea'"
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
:rows="3"
|
||||
size="small"
|
||||
@update:value="setFixedValue(field.name, $event)"
|
||||
/>
|
||||
<!-- 下拉选择 -->
|
||||
<Select
|
||||
v-else-if="field.type === 'select'"
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
:options="field.options"
|
||||
:placeholder="field.placeholder"
|
||||
size="small"
|
||||
@update:value="setFixedValue(field.name, $event)"
|
||||
/>
|
||||
<!-- 单选 -->
|
||||
<RadioGroup
|
||||
v-else-if="field.type === 'radio'"
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
size="small"
|
||||
@update:value="setFixedValue(field.name, $event)"
|
||||
>
|
||||
<Radio
|
||||
v-for="opt in field.options"
|
||||
:key="String(opt.value)"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
<!-- 图片素材 -->
|
||||
<div v-else-if="field.type === 'image'" class="image-picker-row">
|
||||
<Input
|
||||
:value="getByPath(fixedValues, field.name)"
|
||||
:placeholder="field.placeholder || '从素材库选择图片'"
|
||||
size="small"
|
||||
read-only
|
||||
/>
|
||||
<GalleryPickLink
|
||||
:accept-types="field.acceptTypes || [1]"
|
||||
@select="(urls) => setFixedValue(field.name, urls[0] || '')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 选中块的属性字段 -->
|
||||
<div v-if="selectedBlockSchema && selectedInstance" class="field-section">
|
||||
<div class="section-title">{{ selectedBlockSchema.label }}属性</div>
|
||||
<div
|
||||
v-for="field in selectedBlockSchema.fields"
|
||||
:key="field.name"
|
||||
class="form-row"
|
||||
>
|
||||
<label class="form-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<Input
|
||||
v-if="!field.type || field.type === 'string' || field.type === 'url'"
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
allow-clear
|
||||
size="small"
|
||||
@update:value="setInstanceValue(field.name, $event)"
|
||||
/>
|
||||
<InputNumber
|
||||
v-else-if="field.type === 'number'"
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
size="small"
|
||||
style="width: 100%"
|
||||
@update:value="setInstanceValue(field.name, $event)"
|
||||
/>
|
||||
<Textarea
|
||||
v-else-if="field.type === 'textarea'"
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
:placeholder="field.placeholder"
|
||||
:rows="3"
|
||||
size="small"
|
||||
@update:value="setInstanceValue(field.name, $event)"
|
||||
/>
|
||||
<Select
|
||||
v-else-if="field.type === 'select'"
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
:options="field.options"
|
||||
:placeholder="field.placeholder"
|
||||
size="small"
|
||||
@update:value="setInstanceValue(field.name, $event)"
|
||||
/>
|
||||
<RadioGroup
|
||||
v-else-if="field.type === 'radio'"
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
size="small"
|
||||
@update:value="setInstanceValue(field.name, $event)"
|
||||
>
|
||||
<Radio
|
||||
v-for="opt in field.options"
|
||||
:key="String(opt.value)"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
<div v-else-if="field.type === 'image'" class="image-picker-row">
|
||||
<Input
|
||||
:value="getByPath(selectedInstance.data, field.name)"
|
||||
:placeholder="field.placeholder || '从素材库选择图片'"
|
||||
size="small"
|
||||
read-only
|
||||
/>
|
||||
<GalleryPickLink
|
||||
:accept-types="field.acceptTypes || [1]"
|
||||
@select="(urls) => setInstanceValue(field.name, urls[0] || '')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 未选中任何块时的提示 -->
|
||||
<Empty
|
||||
v-if="!hasAnyField"
|
||||
description="点击画布中的块以编辑属性"
|
||||
:image-style="{ height: '60px' }"
|
||||
style="margin-top: 60px"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.property-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 280px;
|
||||
height: 100%;
|
||||
border-left: 1px solid #e5e6eb;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e5e6eb;
|
||||
font-size: 13px;
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.hint {
|
||||
color: #86909c;
|
||||
font-size: 11px;
|
||||
max-width: 120px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.panel-body {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.field-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 6px;
|
||||
border-bottom: 1px solid #f2f3f5;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #4e5969;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
font-size: 12px;
|
||||
color: #4e5969;
|
||||
|
||||
.required {
|
||||
margin-left: 2px;
|
||||
color: #f53f3f;
|
||||
}
|
||||
}
|
||||
|
||||
.image-picker-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.dark {
|
||||
.property-panel {
|
||||
background: #1f1f1f;
|
||||
border-left-color: #374151;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
border-bottom-color: #374151;
|
||||
|
||||
.title {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
|
||||
.section-title {
|
||||
border-bottom-color: #374151;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
color: #d1d5db;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
538
apps/web-antd/src/components/oa-template-card-editor/index.vue
Normal file
538
apps/web-antd/src/components/oa-template-card-editor/index.vue
Normal file
@@ -0,0 +1,538 @@
|
||||
<script setup lang="ts">
|
||||
import type { BlockInstance, BlockSchema, FixedField } from './types';
|
||||
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
import type Sortable from 'sortablejs';
|
||||
import type { SortableOptions } from 'sortablejs';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import BlockLibrary from './BlockLibrary.vue';
|
||||
import Canvas from './Canvas.vue';
|
||||
import JsonPreview from './JsonPreview.vue';
|
||||
import PropertyPanel from './PropertyPanel.vue';
|
||||
|
||||
/**
|
||||
* 通用拖拽式可视化编辑器
|
||||
*
|
||||
* 用途:把「左侧组件库 → 中间画布拖拽组装 → 右侧属性面板 → 自动生成 JSON」
|
||||
* 做成 schema 驱动的通用组件,未来 OA / 工单 / 通知等任何场景需要可视化拼装 JSON 都能复用。
|
||||
*
|
||||
* 核心机制:
|
||||
* - 左侧库 + 画布各分组共用同一个 SortableJS group(pull:clone 模式:左侧库克隆到画布)
|
||||
* - 拖入 / 排序 / 删除时同步内部 instances 状态
|
||||
* - 通过 computed 把「fixedFields 值 + 各 targetArrayPath 数组」合并成最终 JSON,emit 给父级
|
||||
*
|
||||
* SortableJS 用法参照项目内 views/system/role/components/quick-nav-transfer.vue
|
||||
*/
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 双向绑定的 JSON 数据 */
|
||||
modelValue: Record<string, any>;
|
||||
/** 块定义 schema(决定左侧能拖入哪些块、各自有哪些字段) */
|
||||
schema: BlockSchema[];
|
||||
/** 是否显示 JSON 预览面板 */
|
||||
showJsonPreview?: boolean;
|
||||
/** 顶层固定字段(不可拖拽,固定显示在属性面板顶部) */
|
||||
fixedFields?: FixedField[];
|
||||
}>(),
|
||||
{
|
||||
showJsonPreview: true,
|
||||
fixedFields: () => [] as FixedField[],
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: Record<string, any>];
|
||||
}>();
|
||||
|
||||
// ====== 内部状态 ======
|
||||
|
||||
/** 所有块实例(按拖入顺序) */
|
||||
const instances = ref<BlockInstance[]>([]);
|
||||
/** 当前选中的块实例 ID */
|
||||
const selectedInstanceId = ref<string>('');
|
||||
/** 顶层固定字段值 */
|
||||
const fixedValues = ref<Record<string, any>>({});
|
||||
/** 顶层固定字段 + 块数组组装后的最终 JSON(双向同步给父级) */
|
||||
const assembledJson = computed<Record<string, any>>(() => {
|
||||
const result: Record<string, any> = { ...fixedValues.value };
|
||||
// 按 targetArrayPath 收集块实例数据
|
||||
for (const schema of props.schema) {
|
||||
const path = schema.targetArrayPath;
|
||||
const items = instances.value
|
||||
.filter((inst) => inst.type === schema.type)
|
||||
.map((inst) => {
|
||||
// 深拷贝避免引用问题
|
||||
const data = JSON.parse(JSON.stringify(inst.data));
|
||||
// 移除内部使用的 id 字段(如果有)
|
||||
delete data._blockType;
|
||||
return data;
|
||||
});
|
||||
if (items.length > 0) {
|
||||
// 设置嵌套路径
|
||||
setByPath(result, path, items);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
/** 当前选中的块实例对象 */
|
||||
const selectedInstance = computed<BlockInstance | undefined>(() => {
|
||||
return instances.value.find((i) => i.id === selectedInstanceId.value);
|
||||
});
|
||||
|
||||
/** 当前选中的块 schema */
|
||||
const selectedBlockSchema = computed<BlockSchema | undefined>(() => {
|
||||
if (!selectedInstance.value) return undefined;
|
||||
return props.schema.find((s) => s.type === selectedInstance.value!.type);
|
||||
});
|
||||
|
||||
// ====== SortableJS 实例管理 ======
|
||||
|
||||
const editorRootRef = ref<HTMLElement>();
|
||||
const libraryRef = ref<HTMLElement>();
|
||||
/** 画布中各分组的 dropzone DOM 引用(key = targetArrayPath) */
|
||||
const dropzoneRefs = ref<Record<string, HTMLElement>>({});
|
||||
const librarySortable = ref<Sortable | null>(null);
|
||||
const dropzoneSortables = ref<Record<string, Sortable>>({});
|
||||
|
||||
/**
|
||||
* 动态导入 SortableJS(参照 quick-nav-transfer.vue 模式)
|
||||
*/
|
||||
async function createSortable(
|
||||
el: HTMLElement,
|
||||
options: SortableOptions = {},
|
||||
): Promise<Sortable> {
|
||||
const mod = await import(
|
||||
// @ts-expect-error sortablejs modular esm path
|
||||
'sortablejs/modular/sortable.complete.esm.js'
|
||||
);
|
||||
return mod.default.create(el, {
|
||||
animation: 200,
|
||||
...options,
|
||||
}) as Sortable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 SortableJS 实例
|
||||
* 1. 左侧组件库:pull:clone 模式(拖出后元素保留)
|
||||
* 2. 画布各分组:pull:clone/put,跨组可移动
|
||||
*/
|
||||
async function initSortables() {
|
||||
destroySortables();
|
||||
await nextTick();
|
||||
|
||||
if (libraryRef.value) {
|
||||
librarySortable.value = await createSortable(libraryRef.value, {
|
||||
group: {
|
||||
name: 'template-editor',
|
||||
pull: 'clone',
|
||||
put: false, // 左侧库不接受拖入
|
||||
},
|
||||
sort: false, // 左侧库不排序
|
||||
onEnd: handleLibraryDragEnd,
|
||||
});
|
||||
}
|
||||
|
||||
// 通过 querySelector 直接查询画布中的所有 dropzone DOM(避免父子组件 DOM 引用传递)
|
||||
const editorRoot = editorRootRef.value;
|
||||
const dropzoneEls = editorRoot?.querySelectorAll('.group-dropzone[data-target-array-path]') ?? [];
|
||||
dropzoneEls.forEach((el) => {
|
||||
const path = el.getAttribute('data-target-array-path');
|
||||
if (!path) return;
|
||||
dropzoneRefs.value[path] = el as HTMLElement;
|
||||
void createSortable(el as HTMLElement, {
|
||||
group: {
|
||||
name: 'template-editor',
|
||||
pull: true,
|
||||
put: true,
|
||||
},
|
||||
onAdd: (evt) => handleDropzoneAdd(evt, path),
|
||||
onRemove: (evt) => handleDropzoneRemove(evt, path),
|
||||
onUpdate: (evt) => handleDropzoneUpdate(evt, path),
|
||||
}).then((s) => {
|
||||
dropzoneSortables.value[path] = s;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function destroySortables() {
|
||||
librarySortable.value?.destroy();
|
||||
librarySortable.value = null;
|
||||
for (const sortable of Object.values(dropzoneSortables.value)) {
|
||||
sortable.destroy();
|
||||
}
|
||||
dropzoneRefs.value = {};
|
||||
dropzoneSortables.value = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 dropzone DOM 引用(Canvas 子组件通过回调注入)
|
||||
*/
|
||||
function setDropzoneRef(path: string, el: HTMLElement | null) {
|
||||
if (el) {
|
||||
dropzoneRefs.value[path] = el;
|
||||
} else {
|
||||
delete dropzoneRefs.value[path];
|
||||
}
|
||||
}
|
||||
|
||||
// ====== 拖拽事件处理(在 SortableJS 修改 DOM 后,同步到 Vue 状态) ======
|
||||
|
||||
/**
|
||||
* 左侧库 → 画布的拖拽结束回调
|
||||
* SortableJS 会把左侧库的元素 clone 一份移到画布 DOM,我们要:
|
||||
* 1. 移除 DOM 中被克隆过去的元素(由 Vue 重新渲染)
|
||||
* 2. 在 instances 中追加新块
|
||||
*/
|
||||
function handleLibraryDragEnd(evt: any) {
|
||||
// 如果只是库内拖动(没拖到画布),不做处理
|
||||
if (!evt.to || !evt.to.classList.contains('group-dropzone')) {
|
||||
return;
|
||||
}
|
||||
const blockType = evt.item?.dataset?.blockType;
|
||||
if (!blockType) return;
|
||||
|
||||
// 检查 maxCount 限制
|
||||
const schema = props.schema.find((s) => s.type === blockType);
|
||||
if (!schema) return;
|
||||
|
||||
const targetPath = schema.targetArrayPath;
|
||||
const currentCount = instances.value.filter(
|
||||
(i) => props.schema.find((s) => s.type === i.type)?.targetArrayPath === targetPath,
|
||||
).length;
|
||||
if (schema.maxCount && currentCount >= schema.maxCount) {
|
||||
// 移除 SortableJS 已经克隆到画布 DOM 的元素
|
||||
evt.item?.remove();
|
||||
message.warning(`「${schema.label}」最多 ${schema.maxCount} 项`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除 SortableJS 已经克隆到画布 DOM 的元素(Vue 会重新渲染)
|
||||
evt.item?.remove();
|
||||
|
||||
// 根据 SortableJS 在画布 DOM 中的位置,计算插入位置
|
||||
// 简化处理:直接追加到末尾(实现严格的位置同步太复杂,先保留追加行为)
|
||||
const newInstance: BlockInstance = {
|
||||
id: generateId(),
|
||||
type: blockType,
|
||||
data: schema.defaultValue ? JSON.parse(JSON.stringify(schema.defaultValue)) : {},
|
||||
};
|
||||
instances.value = [...instances.value, newInstance];
|
||||
selectedInstanceId.value = newInstance.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 画布分组间或分组内的添加事件(块从其他分组拖入)
|
||||
*/
|
||||
function handleDropzoneAdd(_evt: any, _path: string) {
|
||||
// SortableJS 自动处理 DOM 顺序,但因为 Vue 控制渲染,需要同步状态
|
||||
syncInstancesFromDom();
|
||||
}
|
||||
|
||||
function handleDropzoneRemove(_evt: any, _path: string) {
|
||||
syncInstancesFromDom();
|
||||
}
|
||||
|
||||
function handleDropzoneUpdate(_evt: any, _path: string) {
|
||||
syncInstancesFromDom();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从画布 DOM 同步块实例状态
|
||||
* SortableJS 修改了 DOM 后,从 DOM 重新读取 instanceId 顺序
|
||||
*/
|
||||
function syncInstancesFromDom() {
|
||||
const newInstances: BlockInstance[] = [];
|
||||
for (const path of Object.keys(dropzoneRefs.value)) {
|
||||
const el = dropzoneRefs.value[path];
|
||||
if (!el) continue;
|
||||
const items = el.querySelectorAll('[data-instance-id]');
|
||||
items.forEach((item) => {
|
||||
const id = item.getAttribute('data-instance-id');
|
||||
if (!id) return;
|
||||
const existing = instances.value.find((i) => i.id === id);
|
||||
if (existing) {
|
||||
newInstances.push(existing);
|
||||
}
|
||||
});
|
||||
}
|
||||
instances.value = newInstances;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除块实例
|
||||
*/
|
||||
function removeInstance(id: string) {
|
||||
instances.value = instances.value.filter((i) => i.id !== id);
|
||||
if (selectedInstanceId.value === id) {
|
||||
selectedInstanceId.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中块实例
|
||||
*/
|
||||
function selectInstance(id: string) {
|
||||
selectedInstanceId.value = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新顶层固定字段值(PropertyPanel 触发)
|
||||
*/
|
||||
function updateFixedValues(values: Record<string, any>) {
|
||||
fixedValues.value = values;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新块实例数据(PropertyPanel 触发)
|
||||
*/
|
||||
function updateInstance(updated: BlockInstance) {
|
||||
instances.value = instances.value.map((i) =>
|
||||
i.id === updated.id ? updated : i,
|
||||
);
|
||||
}
|
||||
|
||||
// ====== 工具函数 ======
|
||||
|
||||
function generateId(): string {
|
||||
return `inst_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 a.b.c 路径设置对象嵌套属性(不可变更新)
|
||||
*/
|
||||
function setByPath(obj: Record<string, any>, path: string, value: any) {
|
||||
const keys = path.split('.');
|
||||
let cursor: any = obj;
|
||||
for (let i = 0; i < keys.length - 1; i++) {
|
||||
const k = keys[i]!;
|
||||
if (!cursor[k]) cursor[k] = {};
|
||||
cursor = cursor[k];
|
||||
}
|
||||
cursor[keys[keys.length - 1]!] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 a.b.c 路径读取对象嵌套属性
|
||||
*/
|
||||
function getByPath(obj: Record<string, any> | undefined, path: string): any {
|
||||
if (!obj) return undefined;
|
||||
const keys = path.split('.');
|
||||
let cursor: any = obj;
|
||||
for (const k of keys) {
|
||||
if (cursor == null) return undefined;
|
||||
cursor = cursor[k];
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
// ====== modelValue 双向同步 ======
|
||||
|
||||
/**
|
||||
* 监听 modelValue 变化,反向初始化内部状态(用于编辑场景回显)
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
if (!val || Object.keys(val).length === 0) {
|
||||
// 重置
|
||||
instances.value = [];
|
||||
fixedValues.value = {};
|
||||
selectedInstanceId.value = '';
|
||||
return;
|
||||
}
|
||||
// 简化处理:只在 modelValue 引用变化时才反解析(避免无限循环)
|
||||
// 从 modelValue 还原 fixedValues 和 instances
|
||||
const newFixed: Record<string, any> = {};
|
||||
for (const field of props.fixedFields || []) {
|
||||
const v = getByPath(val, field.name);
|
||||
if (v !== undefined) {
|
||||
setByPath(newFixed, field.name, v);
|
||||
}
|
||||
}
|
||||
fixedValues.value = newFixed;
|
||||
|
||||
// 从各 targetArrayPath 还原 instances
|
||||
const newInstances: BlockInstance[] = [];
|
||||
for (const schema of props.schema) {
|
||||
const arr = getByPath(val, schema.targetArrayPath);
|
||||
if (Array.isArray(arr)) {
|
||||
for (const item of arr) {
|
||||
newInstances.push({
|
||||
id: generateId(),
|
||||
type: schema.type,
|
||||
data: JSON.parse(JSON.stringify(item)),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
instances.value = newInstances;
|
||||
},
|
||||
{ immediate: false, deep: false },
|
||||
);
|
||||
|
||||
/**
|
||||
* 监听 assembledJson 变化,emit 给父级
|
||||
*/
|
||||
watch(
|
||||
assembledJson,
|
||||
(val) => {
|
||||
// 浅比较避免不必要的 emit
|
||||
const current = JSON.stringify(props.modelValue || {});
|
||||
const next = JSON.stringify(val);
|
||||
if (current !== next) {
|
||||
emit('update:modelValue', val);
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 监听 schema 变化时重置 SortableJS(画布 DOM 可能重建)
|
||||
watch(
|
||||
() => props.schema,
|
||||
() => {
|
||||
void nextTick(() => initSortables());
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
// 初始化 fixedValues(从 props.fixedFields 的 defaultValue)
|
||||
for (const field of props.fixedFields || []) {
|
||||
if (field.defaultValue !== undefined) {
|
||||
setByPath(fixedValues.value, field.name, field.defaultValue);
|
||||
}
|
||||
}
|
||||
// 从 modelValue 回显数据
|
||||
if (props.modelValue && Object.keys(props.modelValue).length > 0) {
|
||||
for (const field of props.fixedFields || []) {
|
||||
const v = getByPath(props.modelValue, field.name);
|
||||
if (v !== undefined) {
|
||||
setByPath(fixedValues.value, field.name, v);
|
||||
}
|
||||
}
|
||||
for (const schema of props.schema) {
|
||||
const arr = getByPath(props.modelValue, schema.targetArrayPath);
|
||||
if (Array.isArray(arr)) {
|
||||
for (const item of arr) {
|
||||
instances.value.push({
|
||||
id: generateId(),
|
||||
type: schema.type,
|
||||
data: JSON.parse(JSON.stringify(item)),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await nextTick();
|
||||
await initSortables();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
destroySortables();
|
||||
});
|
||||
|
||||
// 暴露给父组件
|
||||
defineExpose({
|
||||
initSortables,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="editorRootRef" class="template-editor">
|
||||
<div class="editor-toolbar">
|
||||
<span class="title">模板编辑器</span>
|
||||
<Button
|
||||
size="small"
|
||||
type="link"
|
||||
@click="initSortables"
|
||||
>
|
||||
重置拖拽
|
||||
</Button>
|
||||
</div>
|
||||
<div class="editor-main">
|
||||
<!-- 左侧:组件库(用 ref 暴露给 SortableJS 初始化) -->
|
||||
<div ref="libraryRef">
|
||||
<BlockLibrary :blocks="schema" />
|
||||
</div>
|
||||
|
||||
<!-- 中间:画布 -->
|
||||
<Canvas
|
||||
:block-schemas="schema"
|
||||
:instances="instances"
|
||||
:selected-instance-id="selectedInstanceId"
|
||||
@select="selectInstance"
|
||||
@remove="removeInstance"
|
||||
/>
|
||||
|
||||
<!-- 右侧:属性面板 -->
|
||||
<PropertyPanel
|
||||
:fixed-fields="fixedFields"
|
||||
:fixed-values="fixedValues"
|
||||
:selected-block-schema="selectedBlockSchema"
|
||||
:selected-instance="selectedInstance"
|
||||
@update:fixed-values="updateFixedValues"
|
||||
@update:instance="updateInstance"
|
||||
/>
|
||||
|
||||
<!-- 最右侧:JSON 预览(可选) -->
|
||||
<JsonPreview
|
||||
v-if="showJsonPreview"
|
||||
:value="assembledJson"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.template-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
height: 480px;
|
||||
border: 1px solid #e5e6eb;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.editor-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid #e5e6eb;
|
||||
background: #fafbfc;
|
||||
font-size: 13px;
|
||||
|
||||
.title {
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
}
|
||||
|
||||
.editor-main {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.dark {
|
||||
.template-editor {
|
||||
background: #1f1f1f;
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.editor-toolbar {
|
||||
background: #1f1f1f;
|
||||
border-bottom-color: #374151;
|
||||
|
||||
.title {
|
||||
color: #e5e7eb;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 通用拖拽式可视化编辑器类型定义
|
||||
*
|
||||
* 设计目标:把「左侧组件库 → 中间画布拖拽 → 右侧属性面板 → 自动生成 JSON」
|
||||
* 做成 schema 驱动的通用编辑器,未来任何需要拼装 JSON 结构的场景都能复用。
|
||||
*
|
||||
* 核心概念:
|
||||
* - BlockSchema:可拖拽块定义(左侧组件库中展示,决定属性面板渲染什么字段)
|
||||
* - FormFieldSchema:单个字段定义(驱动右侧属性面板表单渲染)
|
||||
* - 块的 instances 按 targetArrayPath 分组存到画布,每组数量不超过 maxCount
|
||||
*/
|
||||
|
||||
/**
|
||||
* 字段类型枚举
|
||||
* - string:单行文本
|
||||
* - number:数字
|
||||
* - textarea:多行文本
|
||||
* - select:下拉选择
|
||||
* - radio:单选按钮组
|
||||
* - image:图片素材选择(用 GalleryPickLink,acceptTypes 限定图片)
|
||||
* - url:URL 链接
|
||||
*/
|
||||
export type FormFieldType =
|
||||
| 'image'
|
||||
| 'number'
|
||||
| 'radio'
|
||||
| 'select'
|
||||
| 'string'
|
||||
| 'textarea'
|
||||
| 'url';
|
||||
|
||||
/**
|
||||
* 单个字段定义(驱动属性面板表单渲染)
|
||||
*/
|
||||
export interface FormFieldSchema {
|
||||
/** 字段名(在 payload 对象中的 key,支持 a.b.c 嵌套路径) */
|
||||
name: string;
|
||||
/** 中文标签 */
|
||||
label: string;
|
||||
/** 字段类型 */
|
||||
type: FormFieldType;
|
||||
/** 占位提示 */
|
||||
placeholder?: string;
|
||||
/** 是否必填 */
|
||||
required?: boolean;
|
||||
/** select / radio 类型的选项列表 */
|
||||
options?: { label: string; value: any }[];
|
||||
/** 图片字段:限定素材库文件类型(如 [1] 只显示图片) */
|
||||
acceptTypes?: number[];
|
||||
/** 最大长度 */
|
||||
maxLength?: number;
|
||||
/** 默认值 */
|
||||
defaultValue?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可拖拽块定义(左侧组件库中展示,决定画布上能放什么块、各块有哪些字段)
|
||||
*/
|
||||
export interface BlockSchema {
|
||||
/** 块类型标识(唯一) */
|
||||
type: string;
|
||||
/** 块显示名(如「二级标题+文本项」「跳转链接项」) */
|
||||
label: string;
|
||||
/** 块图标(Iconify) */
|
||||
icon: string;
|
||||
/** 该块的字段定义(驱动右侧属性面板表单渲染) */
|
||||
fields: FormFieldSchema[];
|
||||
/**
|
||||
* 该块在最终 JSON 中放到的数组路径
|
||||
* 例如 'horizontal_content_list' 表示拖入的块实例会被收集到 result.horizontal_content_list 数组
|
||||
* 多个块共用同一个 targetArrayPath 即被收集到同一数组
|
||||
*/
|
||||
targetArrayPath: string;
|
||||
/** 该数组路径下最多允许的块数量(如企微 jump_list 最多 3 项) */
|
||||
maxCount?: number;
|
||||
/** 块实例的默认值(拖入时初始化) */
|
||||
defaultValue?: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 画布中的块实例(拖入后生成的实际数据)
|
||||
*/
|
||||
export interface BlockInstance {
|
||||
/** 块实例唯一 ID(用于 SortableJS 拖拽排序追踪) */
|
||||
id: string;
|
||||
/** 关联的块类型(对应 BlockSchema.type) */
|
||||
type: string;
|
||||
/** 块实例的当前数据(属性面板编辑后会更新这里) */
|
||||
data: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 顶层固定字段(不可拖拽删除,固定显示在属性面板顶部)
|
||||
* 用于 card_type / main_title / source 等必填顶层字段
|
||||
*/
|
||||
export interface FixedField extends FormFieldSchema {
|
||||
/** 字段在最终 JSON 中的路径(支持 a.b.c 嵌套,如 'main_title.title') */
|
||||
name: string;
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import { createAdminGridOptions } from './table-config';
|
||||
import { getRoleMeta } from './role-meta';
|
||||
import DoctorCardModal from '#/views/doctor/doctor/components/DoctorCardModal.vue';
|
||||
import PromoterInfoCard from '#/components/promoter/PromoterInfoCard.vue';
|
||||
import OaAccountModal from '#/views/system/admin/_shared/components/oa-account-modal.vue';
|
||||
import { resolveAvatarUrl } from '#/views/system/store-input/utils/inputUser';
|
||||
|
||||
function formatAdminRegion(row: {
|
||||
@@ -121,6 +122,20 @@ const openDoctorCard = (row: { doctor_id?: number }) => {
|
||||
DoctorCardModalApi.open();
|
||||
};
|
||||
|
||||
/** 员工 OA 账号弹窗:每个员工可配置各平台的 @ 标识 */
|
||||
const [OaAccountModals, OaAccountModalApi] = useVbenModal({
|
||||
connectedComponent: OaAccountModal,
|
||||
});
|
||||
|
||||
/** 打开员工 OA 账号弹窗 */
|
||||
const openOaAccount = (row: { id: number; nick_name?: string; name?: string }) => {
|
||||
OaAccountModalApi.setData({
|
||||
id: row.id,
|
||||
name: row.nick_name || row.name,
|
||||
});
|
||||
OaAccountModalApi.open();
|
||||
};
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
@@ -210,6 +225,7 @@ const copyToClipboard = async (text: string) => {
|
||||
<Form />
|
||||
</Modal>
|
||||
<DoctorCardModals />
|
||||
<OaAccountModals />
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
@@ -368,6 +384,13 @@ const copyToClipboard = async (text: string) => {
|
||||
confirm: resetPasswordApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'OA 账号',
|
||||
type: 'link',
|
||||
icon: 'ant-design:notification-outlined',
|
||||
size: 'small',
|
||||
onClick: openOaAccount.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, Empty, message, Spin, Tabs } from 'ant-design-vue';
|
||||
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
import {
|
||||
getAdminOaAccounts,
|
||||
saveAdminOaAccounts,
|
||||
} from '#/views/system/admin/_shared/oa-account/api';
|
||||
|
||||
/**
|
||||
* 员工 OA 账号管理弹窗
|
||||
*
|
||||
* 用途:在员工管理页的「更多操作」中点击「OA 账号」打开,
|
||||
* 为该员工配置每个平台的 @ 标识(企业微信 userid、钉钉 userid、飞书 open_id 等)。
|
||||
*
|
||||
* 设计要点:
|
||||
* - 每个启用平台一个 Tab,Tab 内可以添加多条账号(一个员工在一个平台可有多个账号)
|
||||
* - 账号标识和昵称两个输入框:account_id 用于 @,account_name 仅用于展示
|
||||
* - 保存时全量覆盖该员工的所有账号(先软删旧的,再插入新的)
|
||||
*/
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const platforms = ref<any[]>([]);
|
||||
const activeTab = ref('');
|
||||
const adminId = ref(0);
|
||||
const adminName = ref('');
|
||||
|
||||
/** 按平台分组的账号列表:[platform_code => [{account_id, account_name, key}]] */
|
||||
const accountsByPlatform = ref<Record<string, Array<{ account_id: string; account_name: string; key: number }>>>({});
|
||||
|
||||
let keyCounter = 0;
|
||||
function genKey() {
|
||||
keyCounter += 1;
|
||||
return keyCounter;
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
if (!adminId.value) {
|
||||
message.error('员工 ID 不能为空');
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
// 提交时去除 key 字段(后端不需要),过滤空 account_id
|
||||
const payload: Record<string, any[]> = {};
|
||||
for (const [platformCode, accounts] of Object.entries(accountsByPlatform.value)) {
|
||||
const filtered = accounts
|
||||
.filter((a) => a.account_id.trim() !== '')
|
||||
.map((a) => ({
|
||||
account_id: a.account_id.trim(),
|
||||
account_name: a.account_name,
|
||||
}));
|
||||
if (filtered.length > 0) {
|
||||
payload[platformCode] = filtered;
|
||||
}
|
||||
}
|
||||
await saveAdminOaAccounts(adminId.value, payload);
|
||||
message.success('保存成功');
|
||||
modalApi.close();
|
||||
} catch (e: any) {
|
||||
message.error(e.message || '保存失败');
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (isOpen) {
|
||||
const data = modalApi.getData<{ id: number; name?: string }>();
|
||||
adminId.value = data?.id || 0;
|
||||
adminName.value = data?.name || '';
|
||||
loadData();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载平台列表 + 该员工的已有账号
|
||||
*/
|
||||
async function loadData() {
|
||||
if (!adminId.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const [platformList, accountList] = await Promise.all([
|
||||
getOaPlatformList(),
|
||||
getAdminOaAccounts(adminId.value),
|
||||
]);
|
||||
const platformRows: any[] = Array.isArray(platformList)
|
||||
? platformList
|
||||
: platformList?.data || [];
|
||||
platforms.value = platformRows.sort(
|
||||
(a: any, b: any) => (b.sort || 0) - (a.sort || 0),
|
||||
);
|
||||
activeTab.value = platforms.value[0]?.platform_code || '';
|
||||
|
||||
// 把后端返回的按平台分组的账号填充到表单
|
||||
const grouped: typeof accountsByPlatform.value = {};
|
||||
for (const platform of platforms.value) {
|
||||
const code = platform.platform_code;
|
||||
const accounts: any[] = (accountList?.[code] || accountList?.data?.[code]) || [];
|
||||
grouped[code] = accounts.map((a) => ({
|
||||
account_id: String(a.account_id || ''),
|
||||
account_name: String(a.account_name || ''),
|
||||
key: genKey(),
|
||||
}));
|
||||
// 至少留一条空行,便于新增
|
||||
if (grouped[code].length === 0) {
|
||||
grouped[code] = [{ account_id: '', account_name: '', key: genKey() }];
|
||||
}
|
||||
}
|
||||
accountsByPlatform.value = grouped;
|
||||
} catch (e: any) {
|
||||
message.error(e.message || '加载数据失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一行账号输入框
|
||||
*/
|
||||
function addAccount(platformCode: string) {
|
||||
if (!accountsByPlatform.value[platformCode]) {
|
||||
accountsByPlatform.value[platformCode] = [];
|
||||
}
|
||||
accountsByPlatform.value[platformCode].push({
|
||||
account_id: '',
|
||||
account_name: '',
|
||||
key: genKey(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一行账号
|
||||
*/
|
||||
function removeAccount(platformCode: string, key: number) {
|
||||
accountsByPlatform.value[platformCode] = (
|
||||
accountsByPlatform.value[platformCode] || []
|
||||
).filter((a) => a.key !== key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台编码 → 显示名
|
||||
*/
|
||||
function platformName(code: string): string {
|
||||
return platforms.value.find((p) => p.platform_code === code)?.name || code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台编码 → 该平台 @ 标识的提示文案
|
||||
*/
|
||||
function platformTip(code: string): string {
|
||||
if (code === 'work_wechat') return '企业微信 userid(在通讯录中查看,组织内唯一)';
|
||||
if (code === 'dingtalk') return '钉钉 userid(管理后台 → 通讯录 → 成员详情)';
|
||||
if (code === 'feishu') return '飞书 open_id(ou_ 开头)';
|
||||
return '该平台的账号标识';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:title="`员工 OA 账号 - ${adminName || `#${adminId}`}`"
|
||||
class="w-[50%]"
|
||||
>
|
||||
<Spin :spinning="loading || saving">
|
||||
<div v-if="platforms.length === 0 && !loading" class="py-6">
|
||||
<Empty description="暂无启用的 OA 平台" />
|
||||
</div>
|
||||
<Tabs v-else v-model:active-key="activeTab">
|
||||
<Tabs.TabPane
|
||||
v-for="platform in platforms"
|
||||
:key="platform.platform_code"
|
||||
:tab="platform.name"
|
||||
>
|
||||
<div class="oa-account-tab">
|
||||
<div class="mb-3 text-sm text-gray-500">
|
||||
{{ platformTip(platform.platform_code) }}
|
||||
</div>
|
||||
<div
|
||||
v-for="account in accountsByPlatform[platform.platform_code] || []"
|
||||
:key="account.key"
|
||||
class="mb-2 flex items-center gap-2"
|
||||
>
|
||||
<input
|
||||
v-model="account.account_id"
|
||||
class="ant-input ant-input-sm flex-1"
|
||||
placeholder="账号标识(用于 @)"
|
||||
/>
|
||||
<input
|
||||
v-model="account.account_name"
|
||||
class="ant-input ant-input-sm flex-1"
|
||||
placeholder="账号昵称(仅用于展示,可选)"
|
||||
/>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
danger
|
||||
@click="removeAccount(platform.platform_code, account.key)"
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
type="dashed"
|
||||
size="small"
|
||||
block
|
||||
@click="addAccount(platform.platform_code)"
|
||||
>
|
||||
+ 添加{{ platformName(platform.platform_code) }}账号
|
||||
</Button>
|
||||
</div>
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.oa-account-tab {
|
||||
padding: 8px;
|
||||
max-height: 360px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 员工 OA 账号管理 API
|
||||
* 路由前缀:admin-oa-account/
|
||||
*/
|
||||
const prefix = 'admin-oa-account/';
|
||||
|
||||
/**
|
||||
* 获取指定员工的所有 OA 账号(按平台分组)
|
||||
* 返回结构:['work_wechat' => [{id, account_id, account_name}, ...], ...]
|
||||
*/
|
||||
export async function getAdminOaAccounts(adminId: number) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: { admin_id: adminId } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存员工的 OA 账号配置(全量同步)
|
||||
* accounts 结构:{ platform_code: [{account_id, account_name}, ...] }
|
||||
*/
|
||||
export async function saveAdminOaAccounts(adminId: number, accounts: Record<string, any[]>) {
|
||||
return requestClient.post<any>(`${prefix}save`, { admin_id: adminId, accounts });
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export const modalFormProps: VbenFormProps = {
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'VbenTextarea',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入内容',
|
||||
rows: 4,
|
||||
|
||||
62
apps/web-antd/src/views/system/oa-chat/api/index.ts
Normal file
62
apps/web-antd/src/views/system/oa-chat/api/index.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* OA 群聊管理 API
|
||||
*
|
||||
* 群聊用于机器人维度的推送分组(N:N 绑定),按平台区分。
|
||||
* 路由前缀:oa-chat/
|
||||
*
|
||||
* 后端约定:
|
||||
* - 标准 CRUD(list/detail/create/update/delete)由 BaseController 通过反射自动注册
|
||||
* - 额外接口 listByPlatform:按平台分组的群聊列表(机器人表单按平台多选时使用)
|
||||
*/
|
||||
const prefix = 'oa-chat/';
|
||||
|
||||
/**
|
||||
* 分页查询群聊列表
|
||||
*/
|
||||
export async function getOaChatList(data: any) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取群聊详情
|
||||
*/
|
||||
export async function getOaChatInfo(id: number) {
|
||||
return requestClient.get<any>(`${prefix}detail`, { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增群聊
|
||||
*/
|
||||
export async function createOaChat(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}create`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑群聊
|
||||
*/
|
||||
export async function updateOaChat(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}update`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除群聊(支持批量)
|
||||
*/
|
||||
export async function deleteOaChat(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}delete`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按平台分组的群聊列表(机器人表单选群聊用)
|
||||
*
|
||||
* 返回结构示例:
|
||||
* {
|
||||
* work_wechat: [{ id: 1, name: '财务群' }, ...],
|
||||
* dingtalk: [{ id: 2, name: '运营群' }, ...],
|
||||
* feishu: [{ id: 3, name: '产品群' }, ...],
|
||||
* }
|
||||
*/
|
||||
export async function getOaChatListByPlatform() {
|
||||
return requestClient.get<any>(`${prefix}list-by-platform`);
|
||||
}
|
||||
99
apps/web-antd/src/views/system/oa-chat/components/modal.vue
Normal file
99
apps/web-antd/src/views/system/oa-chat/components/modal.vue
Normal file
@@ -0,0 +1,99 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createOaChat,
|
||||
updateOaChat,
|
||||
} from '#/views/system/oa-chat/api';
|
||||
import { modalFormProps } from '#/views/system/oa-chat/config/form';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
|
||||
/**
|
||||
* OA 群聊新增/编辑弹窗
|
||||
*
|
||||
* 关键交互:
|
||||
* - 打开弹窗时动态拉取平台选项注入 platform_code 单选按钮组
|
||||
* - 已禁用平台在 label 上加后缀标记并禁用选择(保持与机器人弹窗一致)
|
||||
* - external_id / sort / status 为选填字段,留空时由后端取默认值
|
||||
*/
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const gridApi = ref();
|
||||
|
||||
const [Form, formApi] = useVbenForm(modalFormProps);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
formApi.validate().then(async (e: any) => {
|
||||
if (e.valid) {
|
||||
const values = await formApi.getValues();
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
const submitApi = isUpdate.value ? updateOaChat : createOaChat;
|
||||
submitApi(values)
|
||||
.then(() => {
|
||||
message.success('保存成功');
|
||||
gridApi.value?.reload();
|
||||
modalApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
});
|
||||
}
|
||||
});
|
||||
await formApi.validateAndSubmitForm();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
gridApi.value = isOpen ? modalApi.getData()?.gridApi : null;
|
||||
if (isOpen) {
|
||||
const { values, update } = modalApi.getData<Record<string, any>>();
|
||||
if (values) {
|
||||
isUpdate.value = update;
|
||||
formApi.setValues(values);
|
||||
}
|
||||
// 每次打开都重新拉取平台列表,保证平台启用状态最新
|
||||
loadPlatformOptions();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 拉取平台列表并注入到表单的 platform_code 单选按钮组
|
||||
* - 显示全部平台(含已禁用的,便于历史数据回显)
|
||||
* - 已禁用平台在 label 上加后缀标记并禁用选择
|
||||
*/
|
||||
async function loadPlatformOptions() {
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
const options = rows.map((item) => ({
|
||||
label: item.enabled === 1 ? item.name : `${item.name}(已禁用)`,
|
||||
value: item.platform_code,
|
||||
disabled: item.enabled !== 1,
|
||||
}));
|
||||
formApi.updateSchema([
|
||||
{
|
||||
fieldName: 'platform_code',
|
||||
componentProps: { options },
|
||||
},
|
||||
]);
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="`${isUpdate === true ? '编辑' : '新增'}群聊`" class="w-[40%]">
|
||||
<Form />
|
||||
</Modal>
|
||||
</template>
|
||||
85
apps/web-antd/src/views/system/oa-chat/config/form.ts
Normal file
85
apps/web-antd/src/views/system/oa-chat/config/form.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 群聊新增/编辑弹窗表单配置
|
||||
*
|
||||
* 关键字段:
|
||||
* - platform_code:所属平台(RadioGroup 单选,选项由弹窗组件 onOpenChange 时动态注入)
|
||||
* - name:群聊名称(用户可读,便于识别)
|
||||
* - external_id:平台原生群聊 ID(选填,预留后期接入获取群成员接口时使用)
|
||||
* - sort:排序值(数字越大越靠前)
|
||||
* - status:启用/禁用
|
||||
*/
|
||||
export const modalFormProps: VbenFormProps = {
|
||||
wrapperClass: 'grid-cols-12',
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-12',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
formItemClass: 'col-span-6',
|
||||
dependencies: {
|
||||
show: false,
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
// 平台数量有限(企业微信/钉钉/飞书),用单选按钮比下拉更直观
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
// 选项由弹窗组件 onOpenChange 时通过 formApi.updateSchema 动态注入
|
||||
options: [],
|
||||
},
|
||||
fieldName: 'platform_code',
|
||||
label: '所属平台',
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入群聊名称(便于识别,如:财务群-企业微信)',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '群聊名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '选填,预留后期接入「获取群成员」接口时填入',
|
||||
},
|
||||
fieldName: 'external_id',
|
||||
label: '平台原生群聊 ID',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '数字越大越靠前',
|
||||
min: 0,
|
||||
},
|
||||
defaultValue: 0,
|
||||
fieldName: 'sort',
|
||||
label: '排序',
|
||||
},
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: 1,
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: false,
|
||||
};
|
||||
52
apps/web-antd/src/views/system/oa-chat/config/search.ts
Normal file
52
apps/web-antd/src/views/system/oa-chat/config/search.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 群聊搜索表单配置
|
||||
*
|
||||
* 关键字段:
|
||||
* - platform_code:平台编码精确匹配
|
||||
* - name:群聊名称模糊匹配
|
||||
* - status:启用/禁用
|
||||
*/
|
||||
export const formOptions: VbenFormProps = {
|
||||
collapsed: false,
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入群聊名称',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'name',
|
||||
label: '群聊名称',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入平台编码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'platform_code',
|
||||
label: '平台编码',
|
||||
},
|
||||
{
|
||||
component: 'VbenSelect',
|
||||
componentProps: {
|
||||
placeholder: '选择状态',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: false,
|
||||
};
|
||||
89
apps/web-antd/src/views/system/oa-chat/config/table.ts
Normal file
89
apps/web-antd/src/views/system/oa-chat/config/table.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getOaChatList } from '#/views/system/oa-chat/api';
|
||||
|
||||
interface RowType {
|
||||
id: number;
|
||||
platform_code: string;
|
||||
name: string;
|
||||
external_id: string;
|
||||
icon: string;
|
||||
sort: number;
|
||||
status: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 群聊列表表格配置
|
||||
* 列表展示:ID、平台(slot 渲染中文名)、群聊名称、外部 ID、排序、状态、创建时间、操作
|
||||
*/
|
||||
export const gridOptions: VxeGridProps<RowType> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: '',
|
||||
},
|
||||
columnConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
rowConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
columns: [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 80 },
|
||||
{
|
||||
field: 'platform_code',
|
||||
align: 'left',
|
||||
title: '平台',
|
||||
width: 120,
|
||||
slots: { default: 'platform_code' },
|
||||
},
|
||||
{ field: 'name', align: 'left', title: '群聊名称' },
|
||||
{ field: 'external_id', align: 'left', title: '外部群 ID', width: 200 },
|
||||
{ field: 'sort', align: 'left', title: '排序', width: 80 },
|
||||
{
|
||||
field: 'status',
|
||||
align: 'left',
|
||||
title: '状态',
|
||||
width: 100,
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{ field: 'created_at', align: 'left', title: '创建时间', width: 180 },
|
||||
{
|
||||
type: 'html',
|
||||
title: '操作',
|
||||
slots: { default: 'action' },
|
||||
width: 200,
|
||||
fixed: 'right',
|
||||
},
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOaChatList({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
height: 'auto',
|
||||
border: false,
|
||||
toolbarConfig: {
|
||||
search: true,
|
||||
refresh: true,
|
||||
print: false,
|
||||
export: false,
|
||||
zoom: true,
|
||||
slots: {
|
||||
buttons: 'toolbar-buttons',
|
||||
},
|
||||
custom: {
|
||||
icon: 'vxe-icon-menu',
|
||||
},
|
||||
},
|
||||
showOverflow: false,
|
||||
};
|
||||
168
apps/web-antd/src/views/system/oa-chat/index.vue
Normal file
168
apps/web-antd/src/views/system/oa-chat/index.vue
Normal file
@@ -0,0 +1,168 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
|
||||
import { deleteOaChat } from './api';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
|
||||
/**
|
||||
* OA 群聊管理列表页
|
||||
* 顶部支持按名称/平台编码/状态搜索
|
||||
* 操作:新增、编辑、删除(单个/批量)
|
||||
*/
|
||||
defineOptions({ name: 'OaChat' });
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
|
||||
/** 平台编码 → 显示名映射,用于表格中渲染平台列 */
|
||||
const platformMap = ref<Record<string, any>>({});
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents,
|
||||
});
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: FormModalDemo,
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
*/
|
||||
const showModal = (data = {}, isUpdate = false) => {
|
||||
formModalApi.setData({
|
||||
values: data,
|
||||
update: isUpdate,
|
||||
gridApi,
|
||||
});
|
||||
formModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除群聊(支持单个和批量)
|
||||
*/
|
||||
const deleteApi = (row: any) => {
|
||||
let ids: any[] = [];
|
||||
if (row) {
|
||||
ids.push(row);
|
||||
} else {
|
||||
ids = gridApi.grid.getCheckboxRecords().map((item: any) => item.id);
|
||||
}
|
||||
deleteOaChat({ ids }).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载平台列表(用于表格中 platform_code 列展示成中文名)
|
||||
*/
|
||||
async function loadPlatforms() {
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
platformMap.value = rows.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.platform_code] = item;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any>,
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
loadPlatforms();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="OA 群聊管理">
|
||||
<FormModal />
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: showModal.bind(null),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '批量删除',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
ifShow: hasTopTableDropDownActions,
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, false),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<!-- 平台列:渲染成中文平台名 -->
|
||||
<template #platform_code="{ row }">
|
||||
<Tag v-if="platformMap[row.platform_code]" color="processing">
|
||||
{{ platformMap[row.platform_code].name }}
|
||||
</Tag>
|
||||
<span v-else>{{ row.platform_code }}</span>
|
||||
</template>
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }">
|
||||
<Tag :color="row.status === 1 ? 'success' : 'default'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
type: 'link',
|
||||
icon: 'uil:edit',
|
||||
size: 'small',
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
21
apps/web-antd/src/views/system/oa-notify-log/api/index.ts
Normal file
21
apps/web-antd/src/views/system/oa-notify-log/api/index.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* OA 通知发送日志 API(只读)
|
||||
* 路由前缀:oa-notify-log/
|
||||
*/
|
||||
const prefix = 'oa-notify-log/';
|
||||
|
||||
/**
|
||||
* 分页查询日志列表
|
||||
*/
|
||||
export async function getOaNotifyLogList(data: any) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日志详情
|
||||
*/
|
||||
export async function getOaNotifyLogInfo(id: number) {
|
||||
return requestClient.get<any>(`${prefix}detail`, { params: { id } });
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 日志搜索表单配置
|
||||
*/
|
||||
export const formOptions: VbenFormProps = {
|
||||
collapsed: false,
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入场景编码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'scene_code',
|
||||
label: '场景编码',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入平台编码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'platform_code',
|
||||
label: '平台编码',
|
||||
},
|
||||
{
|
||||
component: 'VbenSelect',
|
||||
componentProps: {
|
||||
placeholder: '选择状态',
|
||||
options: [
|
||||
{ label: '成功', value: 1 },
|
||||
{ label: '失败', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
{
|
||||
// 发送类型筛选:normal 业务正常发送 / test 机器人测试发送
|
||||
component: 'VbenSelect',
|
||||
componentProps: {
|
||||
placeholder: '选择发送类型',
|
||||
options: [
|
||||
{ label: '正常发送', value: 'normal' },
|
||||
{ label: '测试发送', value: 'test' },
|
||||
],
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'send_type',
|
||||
label: '发送类型',
|
||||
},
|
||||
],
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: false,
|
||||
};
|
||||
78
apps/web-antd/src/views/system/oa-notify-log/config/table.ts
Normal file
78
apps/web-antd/src/views/system/oa-notify-log/config/table.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getOaNotifyLogList } from '#/views/system/oa-notify-log/api';
|
||||
|
||||
interface RowType {
|
||||
id: number;
|
||||
scene_id: number;
|
||||
scene_code: string;
|
||||
robot_id: number;
|
||||
platform_code: string;
|
||||
message_type: string;
|
||||
send_type: string;
|
||||
request_payload: string;
|
||||
response_payload: string;
|
||||
status: number;
|
||||
error_msg: string;
|
||||
cost_ms: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志列表表格配置(只读,无操作列)
|
||||
*/
|
||||
export const gridOptions: VxeGridProps<RowType> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: '',
|
||||
},
|
||||
columnConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
rowConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
columns: [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 100 },
|
||||
{ field: 'scene_code', align: 'left', title: '场景编码', width: 180 },
|
||||
{ field: 'platform_code', align: 'left', title: '平台', width: 120, slots: { default: 'platform_code' } },
|
||||
{ field: 'robot_id', align: 'left', title: '机器人ID', width: 100 },
|
||||
{ field: 'message_type', align: 'left', title: '消息类型', width: 100, slots: { default: 'message_type' } },
|
||||
{ field: 'send_type', align: 'left', title: '发送类型', width: 100, slots: { default: 'send_type' } },
|
||||
{ field: 'request_payload', align: 'left', title: '请求体', slots: { default: 'request_payload' } },
|
||||
{ field: 'status', align: 'left', title: '状态', width: 100, slots: { default: 'status' } },
|
||||
{ field: 'error_msg', align: 'left', title: '错误信息', slots: { default: 'error_msg' } },
|
||||
{ field: 'cost_ms', align: 'left', title: '耗时(ms)', width: 100 },
|
||||
{ field: 'created_at', align: 'left', title: '发送时间', width: 180 },
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOaNotifyLogList({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
height: 'auto',
|
||||
border: false,
|
||||
toolbarConfig: {
|
||||
search: true,
|
||||
refresh: true,
|
||||
print: false,
|
||||
export: false,
|
||||
zoom: true,
|
||||
slots: {
|
||||
buttons: 'toolbar-buttons',
|
||||
},
|
||||
custom: {
|
||||
icon: 'vxe-icon-menu',
|
||||
},
|
||||
},
|
||||
showOverflow: false,
|
||||
};
|
||||
144
apps/web-antd/src/views/system/oa-notify-log/index.vue
Normal file
144
apps/web-antd/src/views/system/oa-notify-log/index.vue
Normal file
@@ -0,0 +1,144 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { Tag, Tooltip } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
|
||||
/**
|
||||
* OA 通知发送日志列表(只读,仅查看)
|
||||
*/
|
||||
defineOptions({ name: 'OaNotifyLog' });
|
||||
|
||||
/** 平台编码 → 显示名映射 */
|
||||
const platformMap = ref<Record<string, string>>({});
|
||||
|
||||
/**
|
||||
* 消息类型 → {名称, Tag 颜色} 映射
|
||||
* 顺带补全现有 slot 只处理 text/markdown 两类的不足,覆盖所有 OA 支持的消息类型
|
||||
*/
|
||||
const MESSAGE_TYPE_MAP: Record<string, { name: string; color: string }> = {
|
||||
text: { name: '文本', color: 'processing' },
|
||||
markdown: { name: 'MD', color: 'warning' },
|
||||
image: { name: '图片', color: 'cyan' },
|
||||
news: { name: '图文', color: 'gold' },
|
||||
template_card: { name: '卡片', color: 'purple' },
|
||||
link: { name: '链接', color: 'blue' },
|
||||
action_card: { name: '动作卡', color: 'magenta' },
|
||||
actionCard: { name: '动作卡', color: 'magenta' },
|
||||
interactive: { name: '交互', color: 'geekblue' },
|
||||
feed_card: { name: '流式', color: 'volcano' },
|
||||
};
|
||||
|
||||
/**
|
||||
* 取消息类型展示信息(未命中时回退为「未知」+ 灰色 Tag)
|
||||
*/
|
||||
function getMessageTypeInfo(type: string): { name: string; color: string } {
|
||||
return MESSAGE_TYPE_MAP[type] ?? { name: type || '未知', color: 'default' };
|
||||
}
|
||||
|
||||
const [Grid] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载平台列表用于列展示
|
||||
*/
|
||||
async function loadPlatforms() {
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
platformMap.value = rows.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.platform_code] = item.name;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
loadPlatforms();
|
||||
|
||||
/**
|
||||
* 解析 JSON 字符串便于展示
|
||||
*/
|
||||
function formatPayload(raw: any): string {
|
||||
if (!raw) return '';
|
||||
if (typeof raw === 'object') {
|
||||
return JSON.stringify(raw, null, 2);
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(String(raw));
|
||||
return JSON.stringify(parsed, null, 2);
|
||||
} catch {
|
||||
return String(raw);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="OA 通知发送日志">
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<span class="text-xs text-gray-400">
|
||||
日志为只读,记录每次 OA 通知发送的请求和响应(含成功和失败)
|
||||
</span>
|
||||
</template>
|
||||
<template #platform_code="{ row }">
|
||||
<Tag v-if="platformMap[row.platform_code]" color="processing">
|
||||
{{ platformMap[row.platform_code] }}
|
||||
</Tag>
|
||||
<span v-else>{{ row.platform_code }}</span>
|
||||
</template>
|
||||
<!-- 消息类型:按 MESSAGE_TYPE_MAP 映射,覆盖所有 OA 支持的类型 -->
|
||||
<template #message_type="{ row }">
|
||||
<Tag :color="getMessageTypeInfo(row.message_type).color">
|
||||
{{ getMessageTypeInfo(row.message_type).name }}
|
||||
</Tag>
|
||||
</template>
|
||||
<!-- 发送类型:normal 正常业务发送 / test 测试发送 -->
|
||||
<template #send_type="{ row }">
|
||||
<Tag :color="row.send_type === 'test' ? 'warning' : 'processing'">
|
||||
{{ row.send_type === 'test' ? '测试' : '正常' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #request_payload="{ row }">
|
||||
<Tooltip>
|
||||
<template #title>
|
||||
<pre class="max-w-[400px] overflow-auto text-xs">{{
|
||||
formatPayload(row.request_payload)
|
||||
}}</pre>
|
||||
</template>
|
||||
<span class="cursor-pointer text-blue-500">查看请求体</span>
|
||||
</Tooltip>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag :color="row.status === 1 ? 'success' : 'error'">
|
||||
{{ row.status === 1 ? '成功' : '失败' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #error_msg="{ row }">
|
||||
<Tooltip v-if="row.error_msg">
|
||||
<template #title>
|
||||
<span class="max-w-[400px] inline-block">{{ row.error_msg }}</span>
|
||||
</template>
|
||||
<span class="cursor-pointer text-red-500 line-clamp-1">
|
||||
{{ row.error_msg }}
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
24
apps/web-antd/src/views/system/oa-platform/api/index.ts
Normal file
24
apps/web-antd/src/views/system/oa-platform/api/index.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* OA 平台元信息 API(多个模块共用:机器人下拉、场景 @ 人分组、系统配置 tab)
|
||||
*
|
||||
* 平台列表必须从接口动态拉取,禁止在前端写死常量数组。
|
||||
* 路由前缀:oa-platform/
|
||||
*/
|
||||
const prefix = 'oa-platform/';
|
||||
|
||||
/**
|
||||
* 获取所有平台列表(不分页,前端动态渲染用)
|
||||
* 返回值含未启用平台,前端根据 enabled 字段决定显示样式
|
||||
*/
|
||||
export async function getOaPlatformList() {
|
||||
return requestClient.get<any>(`${prefix}list`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换平台启用状态(系统配置 tab 中点击开关立即调用)
|
||||
*/
|
||||
export async function updateOaPlatformEnabled(id: number, enabled: number) {
|
||||
return requestClient.post<any>(`${prefix}update-enabled`, { id, enabled });
|
||||
}
|
||||
88
apps/web-antd/src/views/system/oa-robot/api/index.ts
Normal file
88
apps/web-antd/src/views/system/oa-robot/api/index.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* OA 通知模块 API
|
||||
* 路由前缀统一为 oa-robot/、oa-scene/、oa-platform/、oa-notify-log/、admin-oa-account/
|
||||
* 命名规范:get{Entity}List / get{Entity}Option / get{Entity}Info / create{Entity} / update{Entity} / delete{Entity}
|
||||
*/
|
||||
const prefix = 'oa-robot/';
|
||||
|
||||
/**
|
||||
* 分页查询机器人列表
|
||||
*/
|
||||
export async function getOaRobotList(data: any) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机器人详情(含解密后的 webhook_url 和 secret,用于编辑回显)
|
||||
*/
|
||||
export async function getOaRobotInfo(id: number) {
|
||||
return requestClient.get<any>(`${prefix}detail`, { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增机器人
|
||||
*/
|
||||
export async function createOaRobot(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}create`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑机器人
|
||||
*/
|
||||
export async function updateOaRobot(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}update`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除机器人(支持批量)
|
||||
*/
|
||||
export async function deleteOaRobot(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}delete`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试发送(验证密钥是否正确,不依赖机器人表)
|
||||
*
|
||||
* 入参说明:
|
||||
* - id:行级测试时传入,后端按 id 自动取已加密的 webhook_url/secret(webhook_url/secret 仍可显式传,用于表单内测试)
|
||||
* - test_at_all:是否 @ 全员(按平台自动适配:企微/钉钉走 atMobiles,飞书走 atUserIds)
|
||||
* - test_mobiles:要 @ 的手机号列表(企微/钉钉有效,飞书 webhook 不支持手机号 @)
|
||||
*/
|
||||
export async function testSendOaRobot(data: {
|
||||
id?: number;
|
||||
platform_code: string;
|
||||
webhook_url?: string;
|
||||
secret?: string;
|
||||
test_content?: string;
|
||||
test_at_all?: boolean;
|
||||
test_mobiles?: string[];
|
||||
}) {
|
||||
return requestClient.post<any>(`${prefix}test-send`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅同步机器人-群聊绑定关系(用于「未绑定」link 入口和「绑定群聊」按钮)
|
||||
* 与 updateOaRobot 区分:本接口不动 name / status / remark 等基础信息
|
||||
*/
|
||||
export async function updateOaRobotChatBind(data: {
|
||||
id: number;
|
||||
chat_ids: number[];
|
||||
}) {
|
||||
return requestClient.post<any>(`${prefix}bind-chats`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅更新 webhook_url 和 secret(用于「改地址」入口)
|
||||
* 与 updateOaRobot 区分:本接口不动任何其他字段
|
||||
* - webhook_url 必填(非空、不允许 mask)
|
||||
* - secret 可选,传空字符串表示清空加签
|
||||
*/
|
||||
export async function updateOaRobotWebhook(data: {
|
||||
id: number;
|
||||
webhook_url: string;
|
||||
secret?: string;
|
||||
}) {
|
||||
return requestClient.post<any>(`${prefix}update-webhook`, data);
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Checkbox,
|
||||
message,
|
||||
TypographyText,
|
||||
TypographyTitle,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getOaChatListByPlatform } from '#/views/system/oa-chat/api';
|
||||
import { updateOaRobotChatBind } from '#/views/system/oa-robot/api';
|
||||
|
||||
/**
|
||||
* OA 机器人「单独绑定群聊」独立弹窗
|
||||
*
|
||||
* 与编辑弹窗的区别:本弹窗只同步群聊绑定关系,不动其他字段
|
||||
* 入口场景:
|
||||
* - 列表「chat_names」列的「未绑定」link 按钮(专为未绑定机器人提供)
|
||||
* - 也可被列表操作列「绑定群聊」按钮复用(如有需要)
|
||||
*/
|
||||
interface ChatOption {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface RobotRow {
|
||||
id: number;
|
||||
platform_code: string;
|
||||
name: string;
|
||||
chat_ids?: number[];
|
||||
}
|
||||
|
||||
/** 当前操作的机器人(由列表行传入) */
|
||||
const currentRobot = ref<RobotRow | null>(null);
|
||||
/** 按平台分组的群聊列表(结构:{ platform_code: [{ id, name }, ...] }) */
|
||||
const chatsByPlatform = ref<Record<string, ChatOption[]>>({});
|
||||
/** 当前已勾选的群聊 ID 列表(回显 + 提交用) */
|
||||
const selectedChatIds = ref<number[]>([]);
|
||||
/** 当前机器人所属平台(弹窗内只读展示,不允许跨平台改) */
|
||||
const currentPlatformCode = ref('');
|
||||
|
||||
/** 当前平台下可绑定的群聊列表 */
|
||||
const chatsOfCurrentPlatform = computed<ChatOption[]>(() => {
|
||||
return chatsByPlatform.value[currentPlatformCode.value] ?? [];
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
if (!currentRobot.value?.id) {
|
||||
message.warning('机器人信息缺失');
|
||||
return;
|
||||
}
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await updateOaRobotChatBind({
|
||||
id: currentRobot.value.id,
|
||||
chat_ids: selectedChatIds.value,
|
||||
});
|
||||
message.success('绑定成功');
|
||||
const grid = modalApi.getData<{ gridApi?: any }>()?.gridApi;
|
||||
grid?.query?.();
|
||||
modalApi.close();
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (isOpen) {
|
||||
const data = modalApi.getData<{ row: RobotRow; gridApi?: any }>();
|
||||
currentRobot.value = data?.row ?? null;
|
||||
// 回显已绑定的群聊
|
||||
const row = currentRobot.value;
|
||||
currentPlatformCode.value = String(row?.platform_code ?? '');
|
||||
selectedChatIds.value = Array.isArray(row?.chat_ids)
|
||||
? row!.chat_ids!.map((id) => Number(id))
|
||||
: [];
|
||||
// 动态设置标题,让用户看到正在为哪个机器人绑定
|
||||
if (row) {
|
||||
modalApi.setState({
|
||||
title: `绑定群聊 - ${row.name}`,
|
||||
confirmLoading: false,
|
||||
});
|
||||
}
|
||||
// 拉取群聊列表
|
||||
loadChatsByPlatform();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 拉取所有平台下的群聊列表(一次拉全量,前端按 platform_code 过滤)
|
||||
*/
|
||||
async function loadChatsByPlatform() {
|
||||
try {
|
||||
const data = await getOaChatListByPlatform();
|
||||
chatsByPlatform.value = data ?? {};
|
||||
} catch (e) {
|
||||
console.error('加载群聊列表失败', e);
|
||||
chatsByPlatform.value = {};
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="绑定群聊" class="w-[40%]">
|
||||
<!-- 提示:当前机器人所属平台 + 平台锁定说明(不允许跨平台改) -->
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
message="平台已锁定,仅展示当前机器人所属平台下的群聊"
|
||||
:description="`机器人所属平台:${currentPlatformCode || '-'}(如需更换平台,请走「编辑」入口)`"
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
|
||||
<!--
|
||||
绑定群聊:去掉自定义背景块改为简单分区(与 modal.vue 保持一致)
|
||||
全部走 antd 原生样式,暗色一致性由 antd 保证
|
||||
必须用具名导入 TypographyTitle/TypographyText,不要用 Typography.Title 命名空间写法
|
||||
-->
|
||||
<div class="chat-bind-section">
|
||||
<TypographyTitle :level="5" class="chat-bind-title">
|
||||
绑定群聊
|
||||
</TypographyTitle>
|
||||
<TypographyText type="secondary" class="chat-bind-hint">
|
||||
仅展示「{{ currentPlatformCode || '请先选平台' }}」平台下的群聊
|
||||
</TypographyText>
|
||||
<TypographyText
|
||||
v-if="chatsOfCurrentPlatform.length === 0"
|
||||
type="secondary"
|
||||
class="chat-empty"
|
||||
>
|
||||
当前平台下暂无群聊,可先到「OA群聊管理」中新增
|
||||
</TypographyText>
|
||||
<Checkbox.Group
|
||||
v-else
|
||||
v-model:value="selectedChatIds"
|
||||
class="chat-checkbox-group"
|
||||
>
|
||||
<Checkbox
|
||||
v-for="chat in chatsOfCurrentPlatform"
|
||||
:key="chat.id"
|
||||
:value="chat.id"
|
||||
>
|
||||
{{ chat.name }}
|
||||
</Checkbox>
|
||||
</Checkbox.Group>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/*
|
||||
* 暗色适配:去掉自定义背景块后,仅保留布局间距相关样式
|
||||
* 颜色全部由 antd 原生组件自动适配
|
||||
*/
|
||||
.chat-bind-section {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.chat-bind-title {
|
||||
margin-bottom: 4px !important;
|
||||
font-size: 14px !important;
|
||||
}
|
||||
|
||||
.chat-bind-hint {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.chat-empty {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.chat-checkbox-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
449
apps/web-antd/src/views/system/oa-robot/components/modal.vue
Normal file
449
apps/web-antd/src/views/system/oa-robot/components/modal.vue
Normal file
@@ -0,0 +1,449 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Checkbox,
|
||||
message,
|
||||
Tag,
|
||||
TypographyText,
|
||||
TypographyTitle,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { getOaChatListByPlatform } from '#/views/system/oa-chat/api';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
import {
|
||||
createOaRobot,
|
||||
testSendOaRobot,
|
||||
updateOaRobot,
|
||||
} from '#/views/system/oa-robot/api';
|
||||
import {
|
||||
createFormSchema,
|
||||
editFormSchema,
|
||||
modalFormProps,
|
||||
} from '#/views/system/oa-robot/config/form';
|
||||
|
||||
/**
|
||||
* OA 机器人新增/编辑弹窗
|
||||
*
|
||||
* 关键交互:
|
||||
* - 打开弹窗时组件内直接调 getOaPlatformList,把 options 合并进 schema 后一次性 setState
|
||||
* (禁止事后 updateSchema,避免与 setState(schema) 竞态导致所属平台选项为空)
|
||||
* - 用 update 标志区分新增/编辑:新增走 createFormSchema(含 webhook/secret),编辑走 editFormSchema
|
||||
* - 「绑定群聊」复选框组:按当前选中的 platform_code 过滤,仅展示该平台下的群聊
|
||||
* - 弹窗内有「测试发送」按钮,循环跑该平台支持的所有消息类型
|
||||
*/
|
||||
|
||||
interface TestResultItem {
|
||||
message_type: string;
|
||||
name: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
response: any;
|
||||
cost_ms: number;
|
||||
}
|
||||
|
||||
interface ChatOption {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const gridApi = ref();
|
||||
/** 测试发送按钮的 loading 状态(与底部「确定」的 confirmLoading 分离,避免互相干扰) */
|
||||
const testing = ref(false);
|
||||
/** 最近一次测试发送的结果列表(按消息类型分别展示) */
|
||||
const testResults = ref<TestResultItem[]>([]);
|
||||
/** 测试发送结果汇总提示 */
|
||||
const testSummary = ref('');
|
||||
/** 按平台分组的群聊列表(结构:{ platform_code: [{ id, name }, ...] }) */
|
||||
const chatsByPlatform = ref<Record<string, ChatOption[]>>({});
|
||||
/** 当前已勾选的群聊 ID 列表(编辑场景下回显用) */
|
||||
const selectedChatIds = ref<number[]>([]);
|
||||
/** 当前选中的平台编码(控制群聊列表过滤) */
|
||||
const currentPlatformCode = ref('');
|
||||
|
||||
const [Form, formApi] = useVbenForm(modalFormProps);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
formApi.validate().then(async (e: any) => {
|
||||
if (e.valid) {
|
||||
const values = await formApi.getValues();
|
||||
// 合并群聊绑定数组到提交载荷(后端 OaRobotController::notRequest 已包含 chat_ids)
|
||||
const payload = { ...values, chat_ids: selectedChatIds.value };
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
const submitApi = isUpdate.value ? updateOaRobot : createOaRobot;
|
||||
submitApi(payload)
|
||||
.then(() => {
|
||||
message.success('保存成功');
|
||||
gridApi.value?.reload();
|
||||
modalApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
});
|
||||
}
|
||||
});
|
||||
await formApi.validateAndSubmitForm();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
gridApi.value = isOpen ? modalApi.getData()?.gridApi : null;
|
||||
if (isOpen) {
|
||||
// 必须用 update 标志区分,不能用 if (values):新增时 values={} 也是 truthy,会误走编辑分支
|
||||
const data = modalApi.getData<Record<string, any>>() ?? {};
|
||||
const values = data.values;
|
||||
isUpdate.value = !!data.update;
|
||||
// 组件内直接拉平台列表,合并进 schema 后再 setState,避免 updateSchema 竞态
|
||||
applySchemaWithPlatforms(isUpdate.value).then(() => {
|
||||
if (isUpdate.value && values && Object.keys(values).length > 0) {
|
||||
formApi.setValues(values);
|
||||
currentPlatformCode.value = String(values.platform_code ?? '');
|
||||
selectedChatIds.value = Array.isArray(values.chat_ids)
|
||||
? values.chat_ids.map((id: any) => Number(id))
|
||||
: [];
|
||||
} else {
|
||||
currentPlatformCode.value = '';
|
||||
selectedChatIds.value = [];
|
||||
}
|
||||
});
|
||||
loadChatsByPlatform();
|
||||
testResults.value = [];
|
||||
testSummary.value = '';
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 当前平台下可绑定的群聊列表
|
||||
* 切换平台时自动过滤,仅展示该平台下的群聊
|
||||
*/
|
||||
const chatsOfCurrentPlatform = computed<ChatOption[]>(() => {
|
||||
return chatsByPlatform.value[currentPlatformCode.value] ?? [];
|
||||
});
|
||||
|
||||
/**
|
||||
* 平台切换处理:清理已不属于当前平台的勾选项(避免提交无效绑定)
|
||||
*/
|
||||
function handlePlatformChange(value: string) {
|
||||
currentPlatformCode.value = value;
|
||||
const allowedIds = new Set(chatsOfCurrentPlatform.value.map((c) => c.id));
|
||||
selectedChatIds.value = selectedChatIds.value.filter((id) =>
|
||||
allowedIds.has(id),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件内直接调 getOaPlatformList,把平台选项合并进 schema 后一次性 setState
|
||||
* - 显示全部平台(含已禁用的,便于历史数据回显)
|
||||
* - 已禁用平台在 label 上加后缀并禁用选择
|
||||
* - 注入 onChange:点选平台时同步 currentPlatformCode 并过滤群聊勾选
|
||||
*
|
||||
* @param isEdit 是否编辑态(决定用 editFormSchema 还是 createFormSchema)
|
||||
*/
|
||||
async function applySchemaWithPlatforms(isEdit: boolean) {
|
||||
let options: { label: string; value: string; disabled: boolean }[] = [];
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
options = rows.map((item) => ({
|
||||
label: item.enabled === 1 ? item.name : `${item.name}(已禁用)`,
|
||||
value: item.platform_code,
|
||||
disabled: item.enabled !== 1,
|
||||
}));
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
const base = isEdit ? editFormSchema : createFormSchema;
|
||||
// 深拷贝字段配置,避免污染导出的静态 schema;把 options/onChange 写进 platform_code
|
||||
const schema = base.map((field: any) => {
|
||||
if (field.fieldName !== 'platform_code') {
|
||||
return { ...field };
|
||||
}
|
||||
return {
|
||||
...field,
|
||||
componentProps: {
|
||||
...(field.componentProps || {}),
|
||||
options,
|
||||
// RadioGroup 的 change 事件(antd 原生):e.target.value 取选中值
|
||||
onChange: (e: any) => {
|
||||
const next = e?.target?.value ?? '';
|
||||
if (typeof next === 'string' && next !== '') {
|
||||
handlePlatformChange(next);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
formApi.setState({ schema });
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取所有平台下的群聊列表(一次拉全量,前端按 platform_code 过滤)
|
||||
*/
|
||||
async function loadChatsByPlatform() {
|
||||
try {
|
||||
const data = await getOaChatListByPlatform();
|
||||
chatsByPlatform.value = data ?? {};
|
||||
} catch (e) {
|
||||
console.error('加载群聊列表失败', e);
|
||||
chatsByPlatform.value = {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试发送:循环跑该平台支持的所有消息类型
|
||||
*
|
||||
* 入参策略(与 webhook 入口分离后的新逻辑):
|
||||
* - 编辑态:webhook_url/secret 已不在表单中,直接用 row.id 走后端兜底取密钥
|
||||
* - 新增态:用表单填写的 webhook_url/secret 走(保存前验证密钥有效性)
|
||||
*
|
||||
* 单平台最多 8 种类型,需并行调用以缩短等待时间(约 10~20s)
|
||||
* 返回的 results 数组按消息类型分别展示成功/失败
|
||||
*/
|
||||
async function handleTestSend() {
|
||||
const values = await formApi.getValues();
|
||||
if (!values.platform_code) {
|
||||
message.warning('请先选择平台');
|
||||
return;
|
||||
}
|
||||
// 新增态校验 webhook_url;编辑态走 id 兜底,不需要表单 webhook_url
|
||||
if (!isUpdate.value && (!values.webhook_url || values.webhook_url === '****')) {
|
||||
message.warning('请填写 webhook 地址');
|
||||
return;
|
||||
}
|
||||
testing.value = true;
|
||||
// 进入测试态时清空旧结果,避免用户误以为是上次结果
|
||||
testResults.value = [];
|
||||
testSummary.value = '正在发送测试消息,请稍候(最多 8 种类型)...';
|
||||
try {
|
||||
const result = await testSendOaRobot(
|
||||
isUpdate.value
|
||||
? {
|
||||
// 编辑态:传 id,后端按 id 自动取已加密密钥
|
||||
id: values.id,
|
||||
platform_code: values.platform_code,
|
||||
test_content: '萧康云医 OA 测试消息',
|
||||
}
|
||||
: {
|
||||
// 新增态:传表单填写的 webhook_url/secret
|
||||
platform_code: values.platform_code,
|
||||
webhook_url: values.webhook_url,
|
||||
secret: values.secret || '',
|
||||
test_content: '萧康云医 OA 测试消息',
|
||||
},
|
||||
);
|
||||
// 兼容后端两种返回结构:单结果(旧)/ 多结果数组(新)
|
||||
if (Array.isArray(result?.results)) {
|
||||
testResults.value = result.results;
|
||||
const total = result.total ?? result.results.length;
|
||||
const succ = result.success_count ?? result.results.filter((r: any) => r.success).length;
|
||||
const fail = total - succ;
|
||||
testSummary.value = `共 ${total} 种类型,成功 ${succ} 种,失败 ${fail} 种`;
|
||||
if (fail === 0) {
|
||||
message.success(testSummary.value);
|
||||
} else if (succ === 0) {
|
||||
message.error(testSummary.value);
|
||||
} else {
|
||||
message.warning(testSummary.value);
|
||||
}
|
||||
} else if (result?.success !== undefined) {
|
||||
// 兼容老接口:单条结果包装为数组
|
||||
testResults.value = [
|
||||
{
|
||||
message_type: 'text',
|
||||
name: '文本消息',
|
||||
success: result.success,
|
||||
message: result.message || '',
|
||||
response: result.response,
|
||||
cost_ms: 0,
|
||||
},
|
||||
];
|
||||
testSummary.value = result.success ? '测试发送成功' : '测试发送失败';
|
||||
}
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:title="`${isUpdate === true ? '编辑' : '新增'}机器人`"
|
||||
class="w-[40%]"
|
||||
>
|
||||
<Form />
|
||||
|
||||
<!--
|
||||
绑定群聊:去掉自定义背景块改为简单分区
|
||||
- 全部走 antd 原生样式,暗色模式下由 antd 自动保证对比度一致性
|
||||
- 标题用 TypographyTitle,提示用 TypographyText type="secondary"
|
||||
- 必须用具名导入(TypographyTitle/TypographyText),不要用 Typography.Title 命名空间写法
|
||||
(script setup 下命名空间子组件可能解析失败导致整块不渲染)
|
||||
-->
|
||||
<div class="chat-bind-section">
|
||||
<TypographyTitle :level="5" class="chat-bind-title">
|
||||
绑定群聊
|
||||
</TypographyTitle>
|
||||
<TypographyText type="secondary" class="chat-bind-hint">
|
||||
仅展示「{{ currentPlatformCode || '请先选平台' }}」平台下的群聊
|
||||
</TypographyText>
|
||||
<TypographyText
|
||||
v-if="chatsOfCurrentPlatform.length === 0"
|
||||
type="secondary"
|
||||
class="chat-empty"
|
||||
>
|
||||
当前平台下暂无群聊,可先到「OA群聊管理」中新增
|
||||
</TypographyText>
|
||||
<Checkbox.Group
|
||||
v-else
|
||||
v-model:value="selectedChatIds"
|
||||
class="chat-checkbox-group"
|
||||
>
|
||||
<Checkbox
|
||||
v-for="chat in chatsOfCurrentPlatform"
|
||||
:key="chat.id"
|
||||
:value="chat.id"
|
||||
>
|
||||
{{ chat.name }}
|
||||
</Checkbox>
|
||||
</Checkbox.Group>
|
||||
</div>
|
||||
|
||||
<!-- 测试发送结果展示区:仅在有过测试时显示 -->
|
||||
<div v-if="testResults.length > 0 || testSummary" class="test-results">
|
||||
<Alert
|
||||
v-if="testSummary"
|
||||
:type="
|
||||
testResults.length === 0
|
||||
? 'info'
|
||||
: testResults.every((r) => r.success)
|
||||
? 'success'
|
||||
: testResults.some((r) => r.success)
|
||||
? 'warning'
|
||||
: 'error'
|
||||
"
|
||||
:message="testSummary"
|
||||
show-icon
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
|
||||
<div v-if="testResults.length > 0" class="result-list">
|
||||
<div
|
||||
v-for="item in testResults"
|
||||
:key="item.message_type"
|
||||
class="result-item"
|
||||
>
|
||||
<div class="result-header">
|
||||
<Tag :color="item.success ? 'success' : 'error'">
|
||||
{{ item.success ? '成功' : '失败' }}
|
||||
</Tag>
|
||||
<span class="result-name">{{ item.name }}</span>
|
||||
<span class="result-type">({{ item.message_type }})</span>
|
||||
<span v-if="item.cost_ms" class="result-cost">{{ item.cost_ms }}ms</span>
|
||||
</div>
|
||||
<div v-if="!item.success && item.message" class="result-error">
|
||||
{{ item.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 测试发送按钮塞在默认「取消/确定」按钮组的左侧 -->
|
||||
<template #prepend-footer>
|
||||
<Button type="default" :loading="testing" @click="handleTestSend">
|
||||
测试发送(全部类型)
|
||||
</Button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/*
|
||||
* 暗色适配:去掉自定义背景块后,仅保留布局间距相关样式
|
||||
* 颜色全部由 antd 原生组件(TypographyTitle / TypographyText / Checkbox)自动适配
|
||||
*/
|
||||
.chat-bind-section {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.chat-bind-title {
|
||||
/* 覆盖 TypographyTitle 默认大字号,让其更紧凑 */
|
||||
margin-bottom: 4px !important;
|
||||
font-size: 14px !important;
|
||||
}
|
||||
|
||||
.chat-bind-hint {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.chat-empty {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.chat-checkbox-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.test-results {
|
||||
margin-top: 16px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px dashed var(--ant-color-border-secondary, #e5e6eb);
|
||||
}
|
||||
|
||||
.result-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
background: var(--ant-color-fill-quaternary, #f7f8fa);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.result-name {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
}
|
||||
|
||||
.result-type {
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.result-cost {
|
||||
margin-left: auto;
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
}
|
||||
|
||||
.result-error {
|
||||
margin-top: 4px;
|
||||
color: var(--ant-color-error, #f53f3f);
|
||||
word-break: break-all;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,291 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Descriptions,
|
||||
DescriptionsItem as DescItem,
|
||||
Tag,
|
||||
Timeline,
|
||||
TimelineItem,
|
||||
TypographyParagraph,
|
||||
TypographyText,
|
||||
TypographyTitle,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
/**
|
||||
* OA 机器人「测试发送结果」独立弹窗
|
||||
*
|
||||
* 设计要点:
|
||||
* - 顶部 Descriptions:全局上下文(机器人、平台、时间、测试内容、@)
|
||||
* - 底部 Timeline:每种消息类型一个节点,展示成功/失败 + 真实请求体 + 响应体
|
||||
* - 请求体来自后端 results[].request(渠道 buildPayload 的真实 HTTP body,已脱敏)
|
||||
* - 暗色模式全部走 antd 原生组件 + CSS 变量
|
||||
*
|
||||
* 数据来源:modalApi.getData(),由 test-send-modal.vue 的 onFinished 注入
|
||||
*/
|
||||
|
||||
interface TestResultItem {
|
||||
message_type: string;
|
||||
name: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
/** 真实 HTTP 请求体(后端脱敏后) */
|
||||
request?: any;
|
||||
response: any;
|
||||
cost_ms: number;
|
||||
}
|
||||
|
||||
/** 测试结果列表(由外部传入) */
|
||||
const testResults = ref<TestResultItem[]>([]);
|
||||
/** 测试汇总提示(由外部传入) */
|
||||
const testSummary = ref('');
|
||||
/** 机器人名称(上下文展示) */
|
||||
const robotName = ref('');
|
||||
/** 机器人 ID(上下文展示) */
|
||||
const robotId = ref<number>();
|
||||
/** 平台编码(上下文展示) */
|
||||
const platformCode = ref('');
|
||||
/** 测试内容(上下文展示) */
|
||||
const testContent = ref('');
|
||||
/** 是否 @ 全员(上下文展示) */
|
||||
const testAtAll = ref(false);
|
||||
/** @ 手机号列表(上下文展示) */
|
||||
const testMobiles = ref<string[]>([]);
|
||||
/** 发送完成时间戳(秒,上下文展示) */
|
||||
const sentAt = ref<number>();
|
||||
|
||||
/**
|
||||
* @ 配置摘要(Descriptions 一行展示用)
|
||||
*/
|
||||
const atSummary = computed(() => {
|
||||
if (testAtAll.value) return '@ 全员';
|
||||
if (testMobiles.value.length === 0) return '无';
|
||||
return testMobiles.value.join('、');
|
||||
});
|
||||
|
||||
/**
|
||||
* 格式化时间戳为可读字符串(秒级 → dayjs)
|
||||
*/
|
||||
function formatTime(ts?: number): string {
|
||||
return ts ? dayjs(ts * 1000).format('YYYY-MM-DD HH:mm:ss') : '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* 把对象格式化为可读 JSON 字符串(空对象显示「无」)
|
||||
* 用于请求体 / 响应体的 <pre> 展示
|
||||
*/
|
||||
function formatJson(data: any): string {
|
||||
if (data === null || data === undefined) return '无';
|
||||
if (typeof data === 'string') {
|
||||
// 后端偶发已是 JSON 字符串,尝试美化
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(data), null, 2);
|
||||
} catch {
|
||||
return data || '无';
|
||||
}
|
||||
}
|
||||
if (typeof data === 'object' && Object.keys(data).length === 0) return '无';
|
||||
try {
|
||||
return JSON.stringify(data, null, 2);
|
||||
} catch {
|
||||
return String(data);
|
||||
}
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
modalApi.close();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (isOpen) {
|
||||
const data = modalApi.getData<any>();
|
||||
testResults.value = data?.results ?? [];
|
||||
testSummary.value = data?.summary ?? '';
|
||||
robotName.value = data?.robotName ?? '';
|
||||
robotId.value = data?.robotId;
|
||||
platformCode.value = data?.platformCode ?? '';
|
||||
testContent.value = data?.testContent ?? '';
|
||||
testAtAll.value = !!data?.testAtAll;
|
||||
testMobiles.value = data?.testMobiles ?? [];
|
||||
sentAt.value = data?.sentAt;
|
||||
const suffix = robotName.value ? ` - ${robotName.value}` : '';
|
||||
modalApi.setState({
|
||||
title: `测试发送结果${suffix}`,
|
||||
confirmText: '知道了',
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="测试发送结果" class="w-[60%]">
|
||||
<!-- 1. 汇总提示 -->
|
||||
<Alert
|
||||
v-if="testSummary"
|
||||
:type="
|
||||
testResults.length === 0
|
||||
? 'info'
|
||||
: testResults.every((r) => r.success)
|
||||
? 'success'
|
||||
: testResults.some((r) => r.success)
|
||||
? 'warning'
|
||||
: 'error'
|
||||
"
|
||||
:message="testSummary"
|
||||
show-icon
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<!-- 2. 发送详情(全局上下文) -->
|
||||
<Descriptions
|
||||
title="发送详情"
|
||||
:column="1"
|
||||
size="small"
|
||||
bordered
|
||||
style="margin-bottom: 16px"
|
||||
>
|
||||
<DescItem label="机器人">
|
||||
{{ robotName || '-' }}
|
||||
<span v-if="robotId" style="color: var(--ant-color-text-tertiary)">
|
||||
(id: {{ robotId }})
|
||||
</span>
|
||||
</DescItem>
|
||||
<DescItem label="平台">
|
||||
<Tag v-if="platformCode" color="processing">{{ platformCode }}</Tag>
|
||||
<span v-else>-</span>
|
||||
</DescItem>
|
||||
<DescItem label="发送时间">{{ formatTime(sentAt) }}</DescItem>
|
||||
<DescItem label="测试内容">
|
||||
<TypographyParagraph
|
||||
style="margin: 0; white-space: pre-wrap; word-break: break-all"
|
||||
>
|
||||
{{ testContent || '-' }}
|
||||
</TypographyParagraph>
|
||||
</DescItem>
|
||||
<DescItem label="@ 配置">{{ atSummary }}</DescItem>
|
||||
</Descriptions>
|
||||
|
||||
<!-- 3. 各类型发送结果(含真实请求体 / 响应体) -->
|
||||
<TypographyTitle :level="5" style="margin-bottom: 12px">
|
||||
消息类型发送结果
|
||||
</TypographyTitle>
|
||||
<Timeline v-if="testResults.length > 0">
|
||||
<TimelineItem
|
||||
v-for="item in testResults"
|
||||
:key="item.message_type"
|
||||
:color="item.success ? 'green' : 'red'"
|
||||
>
|
||||
<!-- 标题行:名称 + 类型 Tag + 成功/失败 Tag + 耗时 -->
|
||||
<div class="timeline-row">
|
||||
<span class="timeline-name">{{ item.name }}</span>
|
||||
<Tag class="timeline-type">{{ item.message_type }}</Tag>
|
||||
<Tag :color="item.success ? 'success' : 'error'">
|
||||
{{ item.success ? '成功' : '失败' }}
|
||||
</Tag>
|
||||
<span v-if="item.cost_ms" class="timeline-cost">
|
||||
{{ item.cost_ms }}ms
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 渠道返回文案(成功 errmsg / 失败原因) -->
|
||||
<div v-if="item.message" class="timeline-msg" :class="{ error: !item.success }">
|
||||
{{ item.message }}
|
||||
</div>
|
||||
|
||||
<!-- 真实请求体(渠道 buildPayload 结果,已脱敏) -->
|
||||
<div class="payload-block">
|
||||
<TypographyText type="secondary" class="payload-label">
|
||||
请求体
|
||||
</TypographyText>
|
||||
<pre class="payload-pre">{{ formatJson(item.request) }}</pre>
|
||||
</div>
|
||||
|
||||
<!-- 第三方响应体 -->
|
||||
<div class="payload-block">
|
||||
<TypographyText type="secondary" class="payload-label">
|
||||
响应体
|
||||
</TypographyText>
|
||||
<pre class="payload-pre">{{ formatJson(item.response) }}</pre>
|
||||
</div>
|
||||
</TimelineItem>
|
||||
</Timeline>
|
||||
<TypographyText v-else type="secondary">
|
||||
无发送结果
|
||||
</TypographyText>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/*
|
||||
* 暗色适配:颜色一律用 antd CSS 变量
|
||||
* pre 限高 + overflow,避免超长 JSON(尤其 image base64 截断前)撑爆弹窗
|
||||
*/
|
||||
.timeline-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.timeline-name {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
}
|
||||
|
||||
.timeline-type {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.timeline-cost {
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.timeline-msg {
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
word-break: break-all;
|
||||
color: var(--ant-color-text-secondary, #4e5969);
|
||||
|
||||
&.error {
|
||||
color: var(--ant-color-error, #f53f3f);
|
||||
}
|
||||
}
|
||||
|
||||
.payload-block {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.payload-label {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.payload-pre {
|
||||
margin: 0;
|
||||
padding: 8px 10px;
|
||||
max-height: 180px;
|
||||
overflow: auto;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--ant-color-border, #d9d9d9);
|
||||
background: var(--ant-color-fill-quaternary, rgba(0, 0, 0, 0.02));
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,260 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Select, Switch, Textarea } from 'ant-design-vue';
|
||||
|
||||
import { testSendOaRobot } from '#/views/system/oa-robot/api';
|
||||
|
||||
/**
|
||||
* OA 机器人「行级测试发送」参数弹窗
|
||||
*
|
||||
* 与 test-result-modal.vue 配合:
|
||||
* - 本弹窗:负责输入测试参数(test_content、@all、mobiles)和发起发送
|
||||
* - 测试发送结果弹窗:发送完成后接管结果展示
|
||||
* - 拆分后两个弹窗职责单一:本弹窗专注参数输入,结果弹窗专注结果展示
|
||||
*
|
||||
* 数据流:
|
||||
* 1. index.vue 的 openTestModal 注入 onFinished 回调
|
||||
* 2. 用户点击「发送测试」→ 后端按平台循环跑所有消息类型
|
||||
* 3. 发送完成后调用 onFinished({ results, summary, robotName })
|
||||
* 4. 本弹窗关闭,index.vue 中 onFinished 打开 test-result-modal.vue
|
||||
*
|
||||
* 与表单弹窗内测试的区别:
|
||||
* - 表单弹窗内测试:用于「保存前验证密钥」(无 id,直接走 webhook_url/secret)
|
||||
* - 本弹窗(行级测试):用于「列表中已有机器人」的快速冒烟测试(有 id,后端自动取已加密密钥)
|
||||
*/
|
||||
|
||||
interface TestResultItem {
|
||||
message_type: string;
|
||||
name: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
response: any;
|
||||
cost_ms: number;
|
||||
}
|
||||
|
||||
interface RobotRow {
|
||||
id: number;
|
||||
platform_code: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** onFinished 回调签名(由 index.vue 注入)
|
||||
*
|
||||
* payload 字段说明:
|
||||
* - results/summary:核心结果数据(必传)
|
||||
* - robotName/robotId/platformCode:机器人上下文(结果弹窗展示用)
|
||||
* - testContent/testAtAll/testMobiles:测试参数(结果弹窗「发送详情」展示用)
|
||||
* - sentAt:发送完成时间戳(秒),结果弹窗「发送时间」展示
|
||||
*/
|
||||
interface OnFinishedPayload {
|
||||
results: TestResultItem[];
|
||||
summary: string;
|
||||
robotName?: string;
|
||||
robotId?: number;
|
||||
platformCode?: string;
|
||||
testContent?: string;
|
||||
testAtAll?: boolean;
|
||||
testMobiles?: string[];
|
||||
sentAt?: number;
|
||||
}
|
||||
|
||||
/** 是否飞书平台(飞书 webhook 不支持手机号 @) */
|
||||
const isFeishu = computed(() => currentRobot.value?.platform_code === 'feishu');
|
||||
|
||||
/** 当前测试的机器人信息(由列表行传入) */
|
||||
const currentRobot = ref<RobotRow | null>(null);
|
||||
/** 测试发送 loading */
|
||||
const testing = ref(false);
|
||||
/** 测试内容(默认值预填,用户可改) */
|
||||
const testContent = ref('萧康云医 OA 测试消息');
|
||||
/** @ 所有人开关 */
|
||||
const testAtAll = ref(false);
|
||||
/** @ 手机号列表(antd Select mode='tags',允许用户输入任意手机号) */
|
||||
const testMobiles = ref<string[]>([]);
|
||||
/** onFinished 回调(由外部注入,发送完成后通知父级打开结果弹窗) */
|
||||
const onFinished = ref<((payload: OnFinishedPayload) => void) | null>(null);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
await handleTestSend();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (isOpen) {
|
||||
const data = modalApi.getData<{
|
||||
row: RobotRow;
|
||||
onFinished?: (payload: OnFinishedPayload) => void;
|
||||
}>();
|
||||
currentRobot.value = data?.row ?? null;
|
||||
onFinished.value = data?.onFinished ?? null;
|
||||
// 每次打开都重置表单,避免上次状态残留
|
||||
testContent.value = '萧康云医 OA 测试消息';
|
||||
testAtAll.value = false;
|
||||
testMobiles.value = [];
|
||||
// 动态设置标题(让用户看到正在测试哪个机器人)
|
||||
if (currentRobot.value) {
|
||||
modalApi.setState({
|
||||
title: `测试发送 - ${currentRobot.value.name}`,
|
||||
confirmLoading: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 发送测试:调用后端 oa-robot/test-send 接口
|
||||
* 后端按 platform_code 循环跑该平台支持的所有消息类型,并注入 @ 配置
|
||||
* 发送完成后调用 onFinished 回调,关闭本弹窗,由父级打开结果弹窗
|
||||
*/
|
||||
async function handleTestSend() {
|
||||
if (!currentRobot.value?.id) {
|
||||
message.warning('机器人信息缺失');
|
||||
return;
|
||||
}
|
||||
if (!testContent.value.trim()) {
|
||||
message.warning('请填写测试内容');
|
||||
return;
|
||||
}
|
||||
testing.value = true;
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
try {
|
||||
const result = await testSendOaRobot({
|
||||
id: currentRobot.value.id,
|
||||
platform_code: currentRobot.value.platform_code,
|
||||
// 行级测试有 id,后端会自动取已加密密钥;webhook_url/secret 不传,避免 mask 字符串覆盖
|
||||
test_content: testContent.value,
|
||||
test_at_all: testAtAll.value,
|
||||
test_mobiles: isFeishu.value ? [] : testMobiles.value,
|
||||
});
|
||||
|
||||
// 构造结果数据
|
||||
let results: TestResultItem[] = [];
|
||||
let summary = '';
|
||||
if (Array.isArray(result?.results)) {
|
||||
results = result.results;
|
||||
const total = result.total ?? result.results.length;
|
||||
const succ =
|
||||
result.success_count ??
|
||||
result.results.filter((r: any) => r.success).length;
|
||||
const fail = total - succ;
|
||||
summary = `共 ${total} 种类型,成功 ${succ} 种,失败 ${fail} 种`;
|
||||
} else if (result?.success !== undefined) {
|
||||
// 兜底兼容老接口结构
|
||||
results = [
|
||||
{
|
||||
message_type: 'text',
|
||||
name: '文本消息',
|
||||
success: result.success,
|
||||
message: result.message || '',
|
||||
response: result.response,
|
||||
cost_ms: 0,
|
||||
},
|
||||
];
|
||||
summary = result.success ? '测试发送成功' : '测试发送失败';
|
||||
}
|
||||
|
||||
// 发送完成:关闭本弹窗,通过 onFinished 回调打开结果弹窗
|
||||
modalApi.close();
|
||||
if (onFinished.value) {
|
||||
onFinished.value({
|
||||
results,
|
||||
summary,
|
||||
// 上下文字段:结果弹窗「发送详情」展示用
|
||||
robotName: currentRobot.value.name,
|
||||
robotId: currentRobot.value.id,
|
||||
platformCode: currentRobot.value.platform_code,
|
||||
testContent: testContent.value,
|
||||
testAtAll: testAtAll.value,
|
||||
testMobiles: isFeishu.value ? [] : testMobiles.value,
|
||||
// 发送完成时间戳(秒)
|
||||
sentAt: Math.floor(Date.now() / 1000),
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
testing.value = false;
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="测试发送" class="w-[40%]">
|
||||
<!-- 测试参数表单(专注于参数输入,结果展示移交 test-result-modal.vue) -->
|
||||
<div class="test-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">测试内容</label>
|
||||
<Textarea
|
||||
v-model:value="testContent"
|
||||
:rows="2"
|
||||
placeholder="请输入测试内容(如:萧康云医 OA 测试消息)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">@ 所有人</label>
|
||||
<Switch v-model:checked="testAtAll" />
|
||||
<span class="form-hint">
|
||||
开启后所有消息类型都按 @ 全员发送
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="!isFeishu" class="form-item">
|
||||
<label class="form-label">@ 手机号</label>
|
||||
<Select
|
||||
v-model:value="testMobiles"
|
||||
mode="tags"
|
||||
:disabled="testAtAll"
|
||||
placeholder="输入手机号后回车添加,可多个(@ 所有人开启时无效)"
|
||||
:token-separators="[',', ' ']"
|
||||
class="w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Alert
|
||||
v-else
|
||||
type="info"
|
||||
show-icon
|
||||
message="飞书 webhook 不支持手机号 @,仅 @ 所有人有效"
|
||||
class="form-alert"
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* 暗色适配:全部走 antd CSS 变量 */
|
||||
.test-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.form-alert {
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,348 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, InputPassword, message, Modal as AModal, Tag } from 'ant-design-vue';
|
||||
|
||||
import { testSendOaRobot, updateOaRobotWebhook } from '#/views/system/oa-robot/api';
|
||||
|
||||
/**
|
||||
* OA 机器人「单独编辑推送地址」独立弹窗
|
||||
*
|
||||
* 设计意图:把 webhook_url 和 secret 的修改从「编辑基础信息」中剥离,
|
||||
* 避免用户在编辑名称/备注时无意中触发 webhook 重新加密写入。
|
||||
*
|
||||
* 关键交互:
|
||||
* - 顶部 Alert 警示:修改后立即生效,影响所有绑定该机器人的 OA 场景
|
||||
* - webhook_url 必填(不允许 mask)
|
||||
* - secret 选填,placeholder 提示「留空 = 清空加签」
|
||||
* - 内置「测试发送」按钮:保存前先用新地址测一次,避免改错导致线上通知失效
|
||||
* - 提交前 Modal.confirm 二次确认,避免误操作
|
||||
*/
|
||||
|
||||
interface TestResultItem {
|
||||
message_type: string;
|
||||
name: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
response: any;
|
||||
cost_ms: number;
|
||||
}
|
||||
|
||||
interface RobotRow {
|
||||
id: number;
|
||||
platform_code: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** 当前操作的机器人(由列表行传入) */
|
||||
const currentRobot = ref<RobotRow | null>(null);
|
||||
/** webhook_url 输入值 */
|
||||
const webhookUrl = ref('');
|
||||
/** secret 输入值(空字符串表示清空) */
|
||||
const secret = ref('');
|
||||
/** 测试发送 loading */
|
||||
const testing = ref(false);
|
||||
/** 最近一次测试发送的结果列表 */
|
||||
const testResults = ref<TestResultItem[]>([]);
|
||||
/** 测试发送结果汇总提示 */
|
||||
const testSummary = ref('');
|
||||
|
||||
/**
|
||||
* 测试发送:用「当前填写」的 webhook_url/secret 临时验证(不依赖数据库)
|
||||
* 与列表「测试」按钮的区别:列表测试用库里已存的密钥;本弹窗用表单新值
|
||||
*/
|
||||
async function handleTestSend() {
|
||||
if (!currentRobot.value?.id) {
|
||||
message.warning('机器人信息缺失');
|
||||
return;
|
||||
}
|
||||
if (!currentRobot.value.platform_code) {
|
||||
message.warning('平台编码缺失');
|
||||
return;
|
||||
}
|
||||
if (!webhookUrl.value || webhookUrl.value === '****') {
|
||||
message.warning('请填写 webhook 地址');
|
||||
return;
|
||||
}
|
||||
testing.value = true;
|
||||
testResults.value = [];
|
||||
testSummary.value = '正在发送测试消息,请稍候(最多 8 种类型)...';
|
||||
try {
|
||||
const result = await testSendOaRobot({
|
||||
// 注意:这里不传 id,强制用表单新值(不走后端兜底取密钥)
|
||||
platform_code: currentRobot.value.platform_code,
|
||||
webhook_url: webhookUrl.value,
|
||||
secret: secret.value || '',
|
||||
test_content: '萧康云医 OA 测试消息',
|
||||
});
|
||||
if (Array.isArray(result?.results)) {
|
||||
testResults.value = result.results;
|
||||
const total = result.total ?? result.results.length;
|
||||
const succ =
|
||||
result.success_count ??
|
||||
result.results.filter((r: any) => r.success).length;
|
||||
const fail = total - succ;
|
||||
testSummary.value = `共 ${total} 种类型,成功 ${succ} 种,失败 ${fail} 种`;
|
||||
if (fail === 0) {
|
||||
message.success(testSummary.value);
|
||||
} else if (succ === 0) {
|
||||
message.error(testSummary.value);
|
||||
} else {
|
||||
message.warning(testSummary.value);
|
||||
}
|
||||
} else if (result?.success !== undefined) {
|
||||
testResults.value = [
|
||||
{
|
||||
message_type: 'text',
|
||||
name: '文本消息',
|
||||
success: result.success,
|
||||
message: result.message || '',
|
||||
response: result.response,
|
||||
cost_ms: 0,
|
||||
},
|
||||
];
|
||||
testSummary.value = result.success ? '测试发送成功' : '测试发送失败';
|
||||
}
|
||||
} finally {
|
||||
testing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
if (!currentRobot.value?.id) {
|
||||
message.warning('机器人信息缺失');
|
||||
return;
|
||||
}
|
||||
if (!webhookUrl.value) {
|
||||
message.warning('请填写 Webhook 地址');
|
||||
return;
|
||||
}
|
||||
if (webhookUrl.value === '****') {
|
||||
message.warning('请填写完整的 Webhook 地址(不允许 mask)');
|
||||
return;
|
||||
}
|
||||
// secret 为 mask 时报错(必须重新输入完整密钥或留空清空)
|
||||
if (secret.value && secret.value === '****') {
|
||||
message.warning('请填写完整的加签密钥或留空以清空');
|
||||
return;
|
||||
}
|
||||
// 二次确认:避免误改导致线上 OA 通知失效
|
||||
AModal.confirm({
|
||||
title: '确认修改推送地址?',
|
||||
content:
|
||||
'修改后将立即生效,会影响所有绑定该机器人的 OA 通知场景。是否继续?',
|
||||
okType: 'danger',
|
||||
onOk: async () => {
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
try {
|
||||
await updateOaRobotWebhook({
|
||||
id: currentRobot.value!.id,
|
||||
webhook_url: webhookUrl.value,
|
||||
secret: secret.value || '',
|
||||
});
|
||||
message.success('修改成功');
|
||||
const grid = modalApi.getData<{ gridApi?: any }>()?.gridApi;
|
||||
grid?.query?.();
|
||||
modalApi.close();
|
||||
} finally {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (isOpen) {
|
||||
const data = modalApi.getData<{ row: RobotRow; gridApi?: any }>();
|
||||
currentRobot.value = data?.row ?? null;
|
||||
// 每次打开都重置表单(不回显原 webhook/secret,强制用户重新输入,避免误操作)
|
||||
webhookUrl.value = '';
|
||||
secret.value = '';
|
||||
testResults.value = [];
|
||||
testSummary.value = '';
|
||||
if (currentRobot.value) {
|
||||
modalApi.setState({
|
||||
title: `编辑推送地址 - ${currentRobot.value.name}`,
|
||||
confirmLoading: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="编辑推送地址" class="w-[40%]">
|
||||
<!-- 顶部警示:修改后立即生效,影响线上 OA 通知 -->
|
||||
<Alert
|
||||
type="warning"
|
||||
show-icon
|
||||
message="修改 Webhook 地址后立即生效"
|
||||
description="会影响所有绑定该机器人的 OA 通知场景。建议先点「测试发送」验证新地址可用后再保存。"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
|
||||
<!-- 表单:webhook_url 必填 + secret 选填 -->
|
||||
<div class="webhook-form">
|
||||
<div class="form-item">
|
||||
<label class="form-label">
|
||||
Webhook 地址 <span class="required-mark">*</span>
|
||||
</label>
|
||||
<InputPassword
|
||||
v-model:value="webhookUrl"
|
||||
placeholder="请粘贴新的 webhook URL"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<div class="form-hint">
|
||||
为防止误操作,编辑时不回显原地址,需完整粘贴新地址
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">加签密钥</label>
|
||||
<InputPassword
|
||||
v-model:value="secret"
|
||||
placeholder="选填,留空表示清空加签密钥"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<div class="form-hint">
|
||||
若原机器人有加签密钥,请重新输入完整密钥;留空则清空原密钥
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 测试结果展示区 -->
|
||||
<div v-if="testResults.length > 0 || testSummary" class="test-results">
|
||||
<Alert
|
||||
v-if="testSummary"
|
||||
:type="
|
||||
testResults.length === 0
|
||||
? 'info'
|
||||
: testResults.every((r) => r.success)
|
||||
? 'success'
|
||||
: testResults.some((r) => r.success)
|
||||
? 'warning'
|
||||
: 'error'
|
||||
"
|
||||
:message="testSummary"
|
||||
show-icon
|
||||
style="margin-bottom: 12px"
|
||||
/>
|
||||
|
||||
<div v-if="testResults.length > 0" class="result-list">
|
||||
<div
|
||||
v-for="item in testResults"
|
||||
:key="item.message_type"
|
||||
class="result-item"
|
||||
>
|
||||
<div class="result-header">
|
||||
<Tag :color="item.success ? 'success' : 'error'">
|
||||
{{ item.success ? '成功' : '失败' }}
|
||||
</Tag>
|
||||
<span class="result-name">{{ item.name }}</span>
|
||||
<span class="result-type">({{ item.message_type }})</span>
|
||||
<span v-if="item.cost_ms" class="result-cost">
|
||||
{{ item.cost_ms }}ms
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="!item.success && item.message" class="result-error">
|
||||
{{ item.message }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部按钮:取消(默认)/ 测试发送(prepend)/ 确定修改(confirm) -->
|
||||
<template #prepend-footer>
|
||||
<Button type="default" :loading="testing" @click="handleTestSend">
|
||||
测试发送(全部类型)
|
||||
</Button>
|
||||
</template>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* 暗色适配:全部走 antd CSS 变量 */
|
||||
.webhook-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.required-mark {
|
||||
color: var(--ant-color-error, #f53f3f);
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-results {
|
||||
margin-top: 16px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px dashed var(--ant-color-border-secondary, #e5e6eb);
|
||||
}
|
||||
|
||||
.result-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
background: var(--ant-color-fill-quaternary, #f7f8fa);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.result-name {
|
||||
font-weight: 500;
|
||||
color: var(--ant-color-text, #1d2129);
|
||||
}
|
||||
|
||||
.result-type {
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
font-family: 'JetBrains Mono', monospace;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.result-cost {
|
||||
margin-left: auto;
|
||||
color: var(--ant-color-text-tertiary, #86909c);
|
||||
}
|
||||
|
||||
.result-error {
|
||||
margin-top: 4px;
|
||||
color: var(--ant-color-error, #f53f3f);
|
||||
word-break: break-all;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
33
apps/web-antd/src/views/system/oa-robot/config/constants.ts
Normal file
33
apps/web-antd/src/views/system/oa-robot/config/constants.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* OA 平台选项类型(前端动态拉取,禁止写死)
|
||||
*/
|
||||
export interface OaPlatformOption {
|
||||
/** 平台 ID */
|
||||
id: number;
|
||||
/** 平台编码(与后端 xk_oa_platform.platform_code 一致) */
|
||||
platform_code: string;
|
||||
/** 平台显示名(如 企业微信) */
|
||||
name: string;
|
||||
/** 平台图标(iconify 图标库) */
|
||||
icon: string;
|
||||
/** 1启用 0禁用 */
|
||||
enabled: number;
|
||||
/** 排序 */
|
||||
sort: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* OA 消息类型选项
|
||||
*/
|
||||
export const OA_MESSAGE_TYPE_OPTIONS = [
|
||||
{ label: '文本', value: 'text' },
|
||||
{ label: 'Markdown', value: 'markdown' },
|
||||
];
|
||||
|
||||
/**
|
||||
* 机器人状态选项
|
||||
*/
|
||||
export const OA_ROBOT_STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
128
apps/web-antd/src/views/system/oa-robot/config/form.ts
Normal file
128
apps/web-antd/src/views/system/oa-robot/config/form.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 机器人表单 Schema 拆分说明(基础信息与 webhook 编辑入口分离)
|
||||
*
|
||||
* - createFormSchema:新增机器人用,包含 webhook_url、secret(创建时必填 webhook)
|
||||
* - editFormSchema:编辑基础信息用,**不含** webhook_url 和 secret(这两个字段由「改地址」入口单独管理)
|
||||
*
|
||||
* 这样能保证:
|
||||
* - 编辑基础信息时不会无意中触发 webhook 重新加密写入
|
||||
* - 老前端代码即便误传 webhook_url/secret,也会被后端 BaseController::checkRequiredFields 过滤
|
||||
*/
|
||||
|
||||
/**
|
||||
* 通用基础字段(id、platform_code、name、status、remark)
|
||||
* 新增和编辑都包含这些字段
|
||||
*/
|
||||
const baseSchema = [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
formItemClass: 'col-span-6',
|
||||
dependencies: {
|
||||
show: false,
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
// 选项由弹窗组件 onOpenChange 时拉取接口后合并进 schema 再 setState
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [],
|
||||
},
|
||||
fieldName: 'platform_code',
|
||||
label: '所属平台',
|
||||
rules: 'selectRequired',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入机器人名称(便于识别)',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '机器人名称',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: 1,
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
{
|
||||
// 注意:项目内 textarea 的 schema 组件名是 'Textarea'(antd 原生组件直接注册)
|
||||
// 不是 'VbenTextarea'(不存在的组件名,会导致字段无法渲染)
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '可选,备注说明(如:财务群-企业微信)',
|
||||
rows: 3,
|
||||
},
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Webhook / Secret 字段(仅新增时使用)
|
||||
* - webhook_url:始终必填
|
||||
* - secret:钉钉必填(加签模式),企微/飞书选填(通过 dependencies 按 platform_code 动态校验)
|
||||
*/
|
||||
const webhookSchema = [
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
componentProps: {
|
||||
placeholder: '请粘贴 webhook URL',
|
||||
autocomplete: 'new-password',
|
||||
},
|
||||
fieldName: 'webhook_url',
|
||||
label: 'Webhook 地址',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
componentProps: {
|
||||
placeholder: '钉钉必填;企微/飞书选填',
|
||||
autocomplete: 'new-password',
|
||||
},
|
||||
fieldName: 'secret',
|
||||
label: '加签密钥',
|
||||
// 钉钉自定义机器人加签模式必须有 secret;其他平台可空
|
||||
dependencies: {
|
||||
triggerFields: ['platform_code'],
|
||||
rules: (values: { platform_code?: string }) => {
|
||||
return values.platform_code === 'dingtalk' ? 'required' : null;
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** 新增机器人 schema(含 webhook_url、secret) */
|
||||
export const createFormSchema = [...baseSchema, ...webhookSchema];
|
||||
|
||||
/** 编辑机器人 schema(仅基础信息,不含 webhook_url、secret) */
|
||||
export const editFormSchema = [...baseSchema];
|
||||
|
||||
/**
|
||||
* 新增机器人的默认表单配置(向后兼容:modal.vue 在新增分支下用此配置)
|
||||
* 编辑分支由 modal.vue 在 onOpenChange 中动态切换 schema
|
||||
*/
|
||||
export const modalFormProps: VbenFormProps = {
|
||||
wrapperClass: 'grid-cols-12',
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-12',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: createFormSchema,
|
||||
showDefaultActions: false,
|
||||
};
|
||||
47
apps/web-antd/src/views/system/oa-robot/config/search.ts
Normal file
47
apps/web-antd/src/views/system/oa-robot/config/search.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 机器人搜索表单配置
|
||||
*/
|
||||
export const formOptions: VbenFormProps = {
|
||||
collapsed: false,
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入机器人名称',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'name',
|
||||
label: '机器人名称',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入平台编码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'platform_code',
|
||||
label: '平台编码',
|
||||
},
|
||||
{
|
||||
component: 'VbenSelect',
|
||||
componentProps: {
|
||||
placeholder: '选择状态',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: false,
|
||||
};
|
||||
76
apps/web-antd/src/views/system/oa-robot/config/table.ts
Normal file
76
apps/web-antd/src/views/system/oa-robot/config/table.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getOaRobotList } from '#/views/system/oa-robot/api';
|
||||
|
||||
interface RowType {
|
||||
id: number;
|
||||
platform_code: string;
|
||||
name: string;
|
||||
webhook_url: string;
|
||||
secret: string;
|
||||
status: number;
|
||||
remark: string;
|
||||
chat_ids: number[];
|
||||
chat_names: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 机器人列表表格配置
|
||||
* 列表中的 webhook_url 和 secret 字段由后端做了 mask('****' 或 ''),不会泄露明文
|
||||
* chat_names:后端按「、」拼接的群聊名称串(展示用),详情接口才返回 chat_ids 数组(编辑回显用)
|
||||
*/
|
||||
export const gridOptions: VxeGridProps<RowType> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: '',
|
||||
},
|
||||
columnConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
rowConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
columns: [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 80 },
|
||||
{ field: 'platform_code', align: 'left', title: '平台', width: 120, slots: { default: 'platform_code' } },
|
||||
{ field: 'name', align: 'left', title: '机器人名称' },
|
||||
{ field: 'chat_names', align: 'left', title: '绑定群聊', slots: { default: 'chat_names' } },
|
||||
{ field: 'webhook_url', align: 'left', title: 'Webhook', width: 120, slots: { default: 'webhook_status' } },
|
||||
{ field: 'secret', align: 'left', title: '加签密钥', width: 120, slots: { default: 'secret_status' } },
|
||||
{ field: 'status', align: 'left', title: '状态', width: 100, slots: { default: 'status' } },
|
||||
{ field: 'remark', align: 'left', title: '备注' },
|
||||
{ field: 'created_at', align: 'left', title: '创建时间', width: 180 },
|
||||
{ type: 'html', title: '操作', slots: { default: 'action' }, width: 300, fixed: 'right' },
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOaRobotList({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
height: 'auto',
|
||||
border: false,
|
||||
toolbarConfig: {
|
||||
search: true,
|
||||
refresh: true,
|
||||
print: false,
|
||||
export: false,
|
||||
zoom: true,
|
||||
slots: {
|
||||
buttons: 'toolbar-buttons',
|
||||
},
|
||||
custom: {
|
||||
icon: 'vxe-icon-menu',
|
||||
},
|
||||
},
|
||||
showOverflow: false,
|
||||
};
|
||||
281
apps/web-antd/src/views/system/oa-robot/index.vue
Normal file
281
apps/web-antd/src/views/system/oa-robot/index.vue
Normal file
@@ -0,0 +1,281 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
|
||||
import { deleteOaRobot } from './api';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
import ChatBindModal from './components/chat-bind-modal.vue';
|
||||
import TestSendModal from './components/test-send-modal.vue';
|
||||
import TestResultModal from './components/test-result-modal.vue';
|
||||
import WebhookModal from './components/webhook-modal.vue';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
|
||||
/**
|
||||
* OA 机器人管理列表页
|
||||
* 顶部支持按名称/平台编码/状态搜索
|
||||
* 操作:新增、编辑(基础信息)、改地址(webhook/secret)、绑定群聊、测试、删除(单个/批量)
|
||||
*/
|
||||
defineOptions({ name: 'OaRobot' });
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
|
||||
/** 平台编码 → 显示名映射,用于表格中渲染平台列 */
|
||||
const platformMap = ref<Record<string, any>>({});
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents,
|
||||
});
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: FormModalDemo,
|
||||
});
|
||||
|
||||
const [TestModal, testModalApi] = useVbenModal({
|
||||
connectedComponent: TestSendModal,
|
||||
});
|
||||
|
||||
const [TestResultEditModal, testResultModalApi] = useVbenModal({
|
||||
connectedComponent: TestResultModal,
|
||||
});
|
||||
|
||||
const [WebhookEditModal, webhookModalApi] = useVbenModal({
|
||||
connectedComponent: WebhookModal,
|
||||
});
|
||||
|
||||
const [ChatBindEditModal, chatBindModalApi] = useVbenModal({
|
||||
connectedComponent: ChatBindModal,
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
*/
|
||||
const showModal = (data = {}, isUpdate = false) => {
|
||||
formModalApi.setData({
|
||||
values: data,
|
||||
update: isUpdate,
|
||||
gridApi,
|
||||
});
|
||||
formModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开行级测试发送弹窗
|
||||
* 传入完整 row(含 id、platform_code、name),后端按 id 自动取已加密密钥
|
||||
* 注入 onFinished 回调:发送完成后关闭参数弹窗,打开结果弹窗
|
||||
*
|
||||
* onFinished payload 字段透传给 test-result-modal.vue 的 setData:
|
||||
* - results / summary:核心结果数据
|
||||
* - robotName / robotId / platformCode:机器人上下文
|
||||
* - testContent / testAtAll / testMobiles:测试参数
|
||||
* - sentAt:发送完成时间戳(秒)
|
||||
*/
|
||||
const openTestModal = (row: any) => {
|
||||
testModalApi.setData({
|
||||
row,
|
||||
onFinished: (payload: any) => {
|
||||
// 参数弹窗会在调用 onFinished 前自行关闭,这里只负责打开结果弹窗
|
||||
testResultModalApi.setData(payload);
|
||||
testResultModalApi.open();
|
||||
},
|
||||
});
|
||||
testModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开「改地址」独立弹窗
|
||||
* 仅修改 webhook_url 和 secret,不动其他字段
|
||||
*/
|
||||
const openWebhookModal = (row: any) => {
|
||||
webhookModalApi.setData({ row, gridApi });
|
||||
webhookModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开「绑定群聊」独立弹窗
|
||||
* 入口:列表「chat_names」列的「未绑定」link 按钮(也支持手动调用)
|
||||
* 仅同步机器人-群聊关系,不动其他字段
|
||||
*/
|
||||
const openChatBindModal = (row: any) => {
|
||||
chatBindModalApi.setData({ row, gridApi });
|
||||
chatBindModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除机器人(支持单个和批量)
|
||||
*/
|
||||
const deleteApi = (row: any) => {
|
||||
let ids: any[] = [];
|
||||
if (row) {
|
||||
ids.push(row);
|
||||
} else {
|
||||
ids = gridApi.grid.getCheckboxRecords().map((item: any) => item.id);
|
||||
}
|
||||
deleteOaRobot({ ids }).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 加载平台列表(用于表格中 platform_code 列展示成中文名)
|
||||
*/
|
||||
async function loadPlatforms() {
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
platformMap.value = rows.reduce(
|
||||
(acc, item) => {
|
||||
acc[item.platform_code] = item;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, any>,
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
loadPlatforms();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="OA 机器人管理">
|
||||
<FormModal />
|
||||
<TestModal />
|
||||
<TestResultEditModal />
|
||||
<WebhookEditModal />
|
||||
<ChatBindEditModal />
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: showModal.bind(null),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '批量删除',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
ifShow: hasTopTableDropDownActions,
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, false),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<!-- 平台列:渲染成中文平台名 + 图标 -->
|
||||
<template #platform_code="{ row }">
|
||||
<Tag v-if="platformMap[row.platform_code]" color="processing">
|
||||
{{ platformMap[row.platform_code].name }}
|
||||
</Tag>
|
||||
<span v-else>{{ row.platform_code }}</span>
|
||||
</template>
|
||||
<!--
|
||||
绑定群聊列:
|
||||
- 有绑定:直接展示后端拼接好的群聊名称串
|
||||
- 未绑定:显示可点击的「未绑定」link 按钮,点击后打开独立绑定弹窗
|
||||
-->
|
||||
<template #chat_names="{ row }">
|
||||
<span v-if="row.chat_names">{{ row.chat_names }}</span>
|
||||
<TableAction
|
||||
v-else
|
||||
:actions="[
|
||||
{
|
||||
label: '未绑定',
|
||||
type: 'link',
|
||||
size: 'small',
|
||||
class: '!px-0',
|
||||
onClick: openChatBindModal.bind(null, row),
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<!-- Webhook 状态列:仅展示已配置/未配置 -->
|
||||
<template #webhook_status="{ row }">
|
||||
<Tag :color="row.has_webhook || row.webhook_url ? 'success' : 'default'">
|
||||
{{ row.has_webhook || row.webhook_url ? '已配置' : '未配置' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<!-- Secret 状态列 -->
|
||||
<template #secret_status="{ row }">
|
||||
<Tag :color="row.has_secret || row.secret ? 'success' : 'default'">
|
||||
{{ row.has_secret || row.secret ? '已配置' : '未配置' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }">
|
||||
<Tag :color="row.status === 1 ? 'success' : 'default'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
type: 'link',
|
||||
icon: 'uil:edit',
|
||||
size: 'small',
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '改地址',
|
||||
type: 'link',
|
||||
icon: 'ant-design:link-outlined',
|
||||
size: 'small',
|
||||
onClick: openWebhookModal.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '测试',
|
||||
type: 'link',
|
||||
icon: 'ant-design:thunderbolt-outlined',
|
||||
size: 'small',
|
||||
onClick: openTestModal.bind(null, row),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
52
apps/web-antd/src/views/system/oa-scene/api/index.ts
Normal file
52
apps/web-antd/src/views/system/oa-scene/api/index.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* OA 场景管理 API
|
||||
* 路由前缀:oa-scene/
|
||||
*/
|
||||
const prefix = 'oa-scene/';
|
||||
|
||||
/**
|
||||
* 分页查询场景列表
|
||||
*/
|
||||
export async function getOaSceneList(data: any) {
|
||||
return requestClient.get<any>(`${prefix}list`, { params: data });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取场景详情(含 robot_ids 和 at_users 字段)
|
||||
*/
|
||||
export async function getOaSceneInfo(id: number) {
|
||||
return requestClient.get<any>(`${prefix}detail`, { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增场景
|
||||
* data 需包含:scene_code、scene_name、message_type、description、status、robot_ids、at_users
|
||||
*/
|
||||
export async function createOaScene(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}create`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑场景(scene_code 不允许修改)
|
||||
*/
|
||||
export async function updateOaScene(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}update`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除场景(支持批量)
|
||||
*/
|
||||
export async function deleteOaScene(data: Record<string, any>) {
|
||||
return requestClient.post<any>(`${prefix}delete`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有平台支持的消息类型列表(含 payload_schema)
|
||||
* 返回结构:{ platform_code: [{ message_type, name, icon, need_media, payload_schema }, ...] }
|
||||
* 前端场景弹窗打开时调用,按平台 Tab 动态渲染消息类型选项 + payload 表单
|
||||
*/
|
||||
export async function getOaMessageTypes() {
|
||||
return requestClient.get<any>(`${prefix}message-types`);
|
||||
}
|
||||
709
apps/web-antd/src/views/system/oa-scene/components/modal.vue
Normal file
709
apps/web-antd/src/views/system/oa-scene/components/modal.vue
Normal file
@@ -0,0 +1,709 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Checkbox,
|
||||
Empty,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Radio,
|
||||
RadioGroup,
|
||||
Select,
|
||||
Spin,
|
||||
Tabs,
|
||||
Textarea,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import GalleryPickLink from '#/components/form/components/gallery-pick-link.vue';
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { getAdminList } from '#/views/system/admin/api';
|
||||
import { getOaPlatformList } from '#/views/system/oa-platform/api';
|
||||
import { getOaRobotList } from '#/views/system/oa-robot/api';
|
||||
import {
|
||||
createOaScene,
|
||||
getOaMessageTypes,
|
||||
updateOaScene,
|
||||
} from '#/views/system/oa-scene/api';
|
||||
import { modalFormProps } from '#/views/system/oa-scene/config/form';
|
||||
import TemplateCardForm from '#/views/system/oa-scene/components/template-card-form.vue';
|
||||
|
||||
/**
|
||||
* OA 场景新增/编辑弹窗(全量消息类型版)
|
||||
*
|
||||
* 结构:
|
||||
* 1. 顶部基础信息表单(场景编码、名称、状态、说明)
|
||||
* 2. 中部:每个启用平台一个 Tab,Tab 内独立配置:
|
||||
* - 消息类型选择(RadioGroup,选项按平台过滤)
|
||||
* - 消息内容表单(按 payload_schema 动态渲染)
|
||||
* - 推送机器人多选 + @ 人多选
|
||||
*
|
||||
* 提交结构:
|
||||
* {
|
||||
* scene_code, scene_name, description, status,
|
||||
* message_config: {
|
||||
* work_wechat: { message_type, payload },
|
||||
* dingtalk: { message_type, payload },
|
||||
* feishu: { message_type, payload }
|
||||
* },
|
||||
* robot_ids: [...], // 所有平台合并
|
||||
* at_users: { work_wechat: [...], dingtalk: [...] }
|
||||
* }
|
||||
*/
|
||||
|
||||
interface MessageTypeOption {
|
||||
message_type: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
need_media: number;
|
||||
payload_schema: string | null;
|
||||
}
|
||||
|
||||
interface PayloadFieldSchema {
|
||||
name: string;
|
||||
label: string;
|
||||
component: string;
|
||||
required?: boolean;
|
||||
props?: Record<string, any>;
|
||||
}
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const gridApi = ref();
|
||||
const loading = ref(false);
|
||||
|
||||
/** 平台列表(仅展示启用的平台) */
|
||||
const platforms = ref<any[]>([]);
|
||||
/** 启用平台下的所有机器人 */
|
||||
const allRobots = ref<any[]>([]);
|
||||
/** 员工列表(用于 @ 人多选) */
|
||||
const adminList = ref<any[]>([]);
|
||||
/** 当前选中的 Tab 平台编码 */
|
||||
const activePlatformTab = ref('');
|
||||
|
||||
/** 各平台支持的消息类型列表(来自 message-types 接口) */
|
||||
const messageTypesMap = ref<Record<string, MessageTypeOption[]>>({});
|
||||
|
||||
/**
|
||||
* 多维状态:
|
||||
* - selectedMessageType: 每个平台选中的消息类型
|
||||
* - payloadValues: 每个平台 payload 字段值(按 message_type 不同字段不同)
|
||||
*/
|
||||
const selectedMessageType = ref<Record<string, string>>({});
|
||||
const payloadValues = ref<Record<string, Record<string, any>>>({});
|
||||
|
||||
/** 机器人勾选(按平台分组) */
|
||||
const selectedRobots = ref<Record<string, number[]>>({});
|
||||
/** @ 人勾选(按平台分组) */
|
||||
const selectedAtUsers = ref<Record<string, number[]>>({});
|
||||
|
||||
const [Form, formApi] = useVbenForm(modalFormProps);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
fullscreenButton: false,
|
||||
draggable: true,
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm: async () => {
|
||||
formApi.validate().then(async (e: any) => {
|
||||
if (e.valid) {
|
||||
const baseValues = await formApi.getValues();
|
||||
|
||||
// 组装 message_config
|
||||
const message_config: Record<string, any> = {};
|
||||
for (const platform of platforms.value) {
|
||||
const code = platform.platform_code;
|
||||
const messageType = selectedMessageType.value[code];
|
||||
if (!messageType) continue;
|
||||
message_config[code] = {
|
||||
message_type: messageType,
|
||||
payload: payloadValues.value[code] || {},
|
||||
};
|
||||
}
|
||||
|
||||
// 合并所有平台的机器人勾选
|
||||
const robot_ids: number[] = [];
|
||||
for (const platformCode of Object.keys(selectedRobots.value)) {
|
||||
robot_ids.push(...(selectedRobots.value[platformCode] || []));
|
||||
}
|
||||
// at_users 按平台分组提交
|
||||
const at_users: Record<string, number[]> = {};
|
||||
for (const platformCode of Object.keys(selectedAtUsers.value)) {
|
||||
const ids = selectedAtUsers.value[platformCode] || [];
|
||||
if (ids.length > 0) {
|
||||
at_users[platformCode] = ids;
|
||||
}
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...baseValues,
|
||||
message_config,
|
||||
robot_ids,
|
||||
at_users,
|
||||
};
|
||||
modalApi.setState({ loading: true, confirmLoading: true });
|
||||
const submitApi = isUpdate.value ? updateOaScene : createOaScene;
|
||||
submitApi(payload)
|
||||
.then(() => {
|
||||
message.success('保存成功');
|
||||
gridApi.value?.reload();
|
||||
modalApi.close();
|
||||
})
|
||||
.finally(() => {
|
||||
modalApi.setState({ loading: false, confirmLoading: false });
|
||||
});
|
||||
}
|
||||
});
|
||||
await formApi.validateAndSubmitForm();
|
||||
},
|
||||
onOpenChange(isOpen: boolean) {
|
||||
gridApi.value = isOpen ? modalApi.getData()?.gridApi : null;
|
||||
if (isOpen) {
|
||||
const { values, update } = modalApi.getData<Record<string, any>>();
|
||||
isUpdate.value = !!update;
|
||||
// 重置内部状态
|
||||
selectedMessageType.value = {};
|
||||
payloadValues.value = {};
|
||||
selectedRobots.value = {};
|
||||
selectedAtUsers.value = {};
|
||||
if (values) {
|
||||
formApi.setValues({
|
||||
...values,
|
||||
// 编辑回显时不带 message_config 进 form(避免被 form schema 当字段处理)
|
||||
message_config: undefined,
|
||||
});
|
||||
// 回显 message_config
|
||||
const config = values.message_config || {};
|
||||
for (const code of Object.keys(config)) {
|
||||
selectedMessageType.value[code] = config[code].message_type || 'text';
|
||||
payloadValues.value[code] = config[code].payload || {};
|
||||
}
|
||||
// 回显已勾选的机器人(需等数据加载后由 groupRobotsByPlatform 重算)
|
||||
// 暂存原始 robot_ids 用于后续回显
|
||||
pendingRobotIds = values.robot_ids || [];
|
||||
selectedAtUsers.value = { ...(values.at_users || {}) };
|
||||
} else {
|
||||
pendingRobotIds = [];
|
||||
}
|
||||
loadData();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// 暂存待回显的 robot_ids(数据加载完后处理)
|
||||
let pendingRobotIds: number[] = [];
|
||||
|
||||
/**
|
||||
* 加载平台、消息类型、机器人、员工列表(并行)
|
||||
*/
|
||||
async function loadData() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const [platformList, typesRes, adminRes] = await Promise.all([
|
||||
getOaPlatformList(),
|
||||
getOaMessageTypes(),
|
||||
getAdminList({ page: 1, pageSize: 500 }),
|
||||
]);
|
||||
|
||||
const platformRows: any[] = Array.isArray(platformList)
|
||||
? platformList
|
||||
: platformList?.data || [];
|
||||
platforms.value = platformRows
|
||||
.filter((p: any) => p.enabled === 1)
|
||||
.sort((a: any, b: any) => (b.sort || 0) - (a.sort || 0));
|
||||
activePlatformTab.value = platforms.value[0]?.platform_code || '';
|
||||
|
||||
// 消息类型按平台分组
|
||||
const typesData = (typesRes as any)?.data ?? typesRes ?? {};
|
||||
messageTypesMap.value = typesData;
|
||||
|
||||
// 机器人列表
|
||||
const robotRes = await getOaRobotList({
|
||||
page: 1,
|
||||
pageSize: 500,
|
||||
status: 1,
|
||||
});
|
||||
const robotRows: any[] = robotRes?.items || robotRes?.data || [];
|
||||
allRobots.value = robotRows.filter((r: any) =>
|
||||
platforms.value.some((p: any) => p.platform_code === r.platform_code),
|
||||
);
|
||||
|
||||
// 员工列表
|
||||
const adminRows: any[] = adminRes?.items || adminRes?.data || [];
|
||||
adminList.value = adminRows.map((a: any) => ({
|
||||
id: a.id,
|
||||
name: a.nick_name || a.name || a.username || `员工${a.id}`,
|
||||
}));
|
||||
|
||||
// 数据加载完后处理回显
|
||||
if (pendingRobotIds.length > 0) {
|
||||
selectedRobots.value = groupRobotsByPlatform(pendingRobotIds);
|
||||
}
|
||||
|
||||
// 初始化每个平台的默认消息类型(如未回显则默认 text)
|
||||
for (const platform of platforms.value) {
|
||||
const code = platform.platform_code;
|
||||
if (!selectedMessageType.value[code]) {
|
||||
const types = messageTypesMap.value[code] || [];
|
||||
const defaultType = types.find((t) => t.message_type === 'text');
|
||||
selectedMessageType.value[code] = defaultType?.message_type || types[0]?.message_type || '';
|
||||
payloadValues.value[code] = {};
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载场景数据失败', e);
|
||||
message.error('加载场景数据失败,请刷新重试');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function groupRobotsByPlatform(robotIds: number[]): Record<string, number[]> {
|
||||
const result: Record<string, number[]> = {};
|
||||
for (const id of robotIds) {
|
||||
const robot = allRobots.value.find((r) => r.id === id);
|
||||
if (robot) {
|
||||
if (!result[robot.platform_code]) {
|
||||
result[robot.platform_code] = [];
|
||||
}
|
||||
result[robot.platform_code].push(id);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function robotsOfPlatform(platformCode: string): any[] {
|
||||
return allRobots.value.filter((r: any) => r.platform_code === platformCode);
|
||||
}
|
||||
|
||||
function checkedRobotsOfPlatform(platformCode: string): number[] {
|
||||
return selectedRobots.value[platformCode] || [];
|
||||
}
|
||||
|
||||
function toggleRobot(platformCode: string, robotId: number, checked: boolean) {
|
||||
const current = new Set(selectedRobots.value[platformCode] || []);
|
||||
if (checked) current.add(robotId);
|
||||
else current.delete(robotId);
|
||||
selectedRobots.value = { ...selectedRobots.value, [platformCode]: Array.from(current) };
|
||||
}
|
||||
|
||||
function toggleAtUser(platformCode: string, adminId: number, checked: boolean) {
|
||||
const current = new Set(selectedAtUsers.value[platformCode] || []);
|
||||
if (checked) current.add(adminId);
|
||||
else current.delete(adminId);
|
||||
selectedAtUsers.value = { ...selectedAtUsers.value, [platformCode]: Array.from(current) };
|
||||
}
|
||||
|
||||
function toggleAllRobots(platformCode: string, e: any) {
|
||||
const checked = (e?.target as HTMLInputElement)?.checked;
|
||||
const robotIds = robotsOfPlatform(platformCode).map((r) => r.id);
|
||||
selectedRobots.value = {
|
||||
...selectedRobots.value,
|
||||
[platformCode]: checked ? robotIds : [],
|
||||
};
|
||||
}
|
||||
|
||||
function toggleAllAtUsers(platformCode: string, e: any) {
|
||||
const checked = (e?.target as HTMLInputElement)?.checked;
|
||||
const adminIds = adminList.value.map((a) => a.id);
|
||||
selectedAtUsers.value = {
|
||||
...selectedAtUsers.value,
|
||||
[platformCode]: checked ? adminIds : [],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定平台当前消息类型对应的 payload_schema(解析 JSON)
|
||||
*/
|
||||
function currentPayloadSchema(platformCode: string): PayloadFieldSchema[] {
|
||||
const messageType = selectedMessageType.value[platformCode];
|
||||
if (!messageType) return [];
|
||||
const types = messageTypesMap.value[platformCode] || [];
|
||||
const typeInfo = types.find((t) => t.message_type === messageType);
|
||||
if (!typeInfo?.payload_schema) return [];
|
||||
try {
|
||||
return JSON.parse(typeInfo.payload_schema);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定平台 payload 字段当前值
|
||||
*/
|
||||
function getPayloadValue(platformCode: string, fieldName: string): any {
|
||||
return payloadValues.value[platformCode]?.[fieldName];
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置指定平台 payload 字段值(不可变更新)
|
||||
*/
|
||||
function setPayloadValue(platformCode: string, fieldName: string, value: any) {
|
||||
const current = payloadValues.value[platformCode] || {};
|
||||
payloadValues.value = {
|
||||
...payloadValues.value,
|
||||
[platformCode]: { ...current, [fieldName]: value },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换平台的消息类型时,清空 payload
|
||||
*/
|
||||
function handleMessageTypeChange(platformCode: string, messageType: string) {
|
||||
selectedMessageType.value = {
|
||||
...selectedMessageType.value,
|
||||
[platformCode]: messageType,
|
||||
};
|
||||
payloadValues.value = {
|
||||
...payloadValues.value,
|
||||
[platformCode]: {},
|
||||
};
|
||||
}
|
||||
|
||||
const isEmpty = computed(() => platforms.value.length === 0);
|
||||
|
||||
watch(
|
||||
() => platforms.value,
|
||||
(list) => {
|
||||
const validCodes = new Set(list.map((p) => p.platform_code));
|
||||
const newRobots: Record<string, number[]> = {};
|
||||
const newAtUsers: Record<string, number[]> = {};
|
||||
for (const code of validCodes) {
|
||||
newRobots[code] = selectedRobots.value[code] || [];
|
||||
newAtUsers[code] = selectedAtUsers.value[code] || [];
|
||||
}
|
||||
selectedRobots.value = newRobots;
|
||||
selectedAtUsers.value = newAtUsers;
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:title="`${isUpdate === true ? '编辑' : '新增'}通知场景`"
|
||||
class="w-[80%]"
|
||||
>
|
||||
<Spin :spinning="loading">
|
||||
<!-- 基础信息表单 -->
|
||||
<Form />
|
||||
|
||||
<!-- 启用平台 Tab -->
|
||||
<div class="mt-4">
|
||||
<div class="mb-2 font-medium">
|
||||
各平台消息配置 + 关联机器人 + @ 人员
|
||||
</div>
|
||||
<div v-if="isEmpty" class="py-4 text-center text-gray-400">
|
||||
暂无启用的平台,请先在「系统配置 → OA 通知」中启用平台
|
||||
</div>
|
||||
<Tabs v-else v-model:active-key="activePlatformTab">
|
||||
<Tabs.TabPane
|
||||
v-for="platform in platforms"
|
||||
:key="platform.platform_code"
|
||||
:tab="platform.name"
|
||||
>
|
||||
<div class="oa-scene-tab">
|
||||
<!-- 1. 消息类型选择 -->
|
||||
<div class="section">
|
||||
<div class="section-title">消息类型</div>
|
||||
<RadioGroup
|
||||
:value="selectedMessageType[platform.platform_code]"
|
||||
size="small"
|
||||
@update:value="
|
||||
(val) => handleMessageTypeChange(platform.platform_code, val)
|
||||
"
|
||||
>
|
||||
<Radio
|
||||
v-for="opt in (messageTypesMap[platform.platform_code] || [])"
|
||||
:key="opt.message_type"
|
||||
:value="opt.message_type"
|
||||
>
|
||||
{{ opt.name }}
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<!-- 2. 消息内容表单(动态 payload_schema) -->
|
||||
<div class="section">
|
||||
<div class="section-title">消息内容</div>
|
||||
<div class="payload-form">
|
||||
<template
|
||||
v-for="field in currentPayloadSchema(platform.platform_code)"
|
||||
:key="field.name"
|
||||
>
|
||||
<!-- 企微模板卡片:用专用编辑器 -->
|
||||
<div
|
||||
v-if="field.component === 'TemplateCardEditor'"
|
||||
class="payload-row"
|
||||
>
|
||||
<label class="payload-label">{{ field.label }}</label>
|
||||
<TemplateCardForm
|
||||
:model-value="getPayloadValue(platform.platform_code, 'template_card') || {}"
|
||||
@update:model-value="
|
||||
(val) => setPayloadValue(platform.platform_code, 'template_card', val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 图片素材选择 -->
|
||||
<div
|
||||
v-else-if="field.component === 'GalleryPickLink'"
|
||||
class="payload-row"
|
||||
>
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<div class="payload-image">
|
||||
<Input
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:placeholder="field.props?.placeholder"
|
||||
size="small"
|
||||
read-only
|
||||
/>
|
||||
<GalleryPickLink
|
||||
:accept-types="field.props?.acceptTypes || [1]"
|
||||
@select="
|
||||
(urls) => setPayloadValue(platform.platform_code, field.name, urls[0] || '')
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文本域 -->
|
||||
<div v-else-if="field.component === 'Textarea'" class="payload-row">
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<Textarea
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:rows="field.props?.rows || 3"
|
||||
:placeholder="field.props?.placeholder"
|
||||
@update:value="
|
||||
(val) => setPayloadValue(platform.platform_code, field.name, val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 单选按钮组 -->
|
||||
<div v-else-if="field.component === 'RadioGroup'" class="payload-row">
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<RadioGroup
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:options="field.props?.options"
|
||||
size="small"
|
||||
@update:value="
|
||||
(val) => setPayloadValue(platform.platform_code, field.name, val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 下拉选择 -->
|
||||
<div v-else-if="field.component === 'Select'" class="payload-row">
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<Select
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:options="field.props?.options"
|
||||
:placeholder="field.props?.placeholder"
|
||||
size="small"
|
||||
@update:value="
|
||||
(val) => setPayloadValue(platform.platform_code, field.name, val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 数字输入 -->
|
||||
<div v-else-if="field.component === 'InputNumber'" class="payload-row">
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<InputNumber
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:placeholder="field.props?.placeholder"
|
||||
size="small"
|
||||
style="width: 100%"
|
||||
@update:value="
|
||||
(val) => setPayloadValue(platform.platform_code, field.name, val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 默认:单行文本 -->
|
||||
<div v-else class="payload-row">
|
||||
<label class="payload-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required">*</span>
|
||||
</label>
|
||||
<Input
|
||||
:value="getPayloadValue(platform.platform_code, field.name)"
|
||||
:placeholder="field.props?.placeholder"
|
||||
size="small"
|
||||
@update:value="
|
||||
(val) => setPayloadValue(platform.platform_code, field.name, val)
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Empty
|
||||
v-if="currentPayloadSchema(platform.platform_code).length === 0"
|
||||
description="该消息类型无需配置内容"
|
||||
:image-style="{ height: '40px' }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 3. 机器人多选 -->
|
||||
<div class="section">
|
||||
<div class="mb-2 flex items-center">
|
||||
<Checkbox
|
||||
:checked="
|
||||
robotsOfPlatform(platform.platform_code).length > 0 &&
|
||||
checkedRobotsOfPlatform(platform.platform_code).length ===
|
||||
robotsOfPlatform(platform.platform_code).length
|
||||
"
|
||||
@change="toggleAllRobots(platform.platform_code, $event)"
|
||||
>
|
||||
<span class="font-medium">推送机器人(全选)</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
<div
|
||||
v-if="robotsOfPlatform(platform.platform_code).length === 0"
|
||||
class="text-gray-400"
|
||||
>
|
||||
该平台暂无启用的机器人
|
||||
</div>
|
||||
<Checkbox.Group
|
||||
v-else
|
||||
:value="checkedRobotsOfPlatform(platform.platform_code)"
|
||||
class="flex flex-wrap gap-2"
|
||||
>
|
||||
<Checkbox
|
||||
v-for="robot in robotsOfPlatform(platform.platform_code)"
|
||||
:key="robot.id"
|
||||
:value="robot.id"
|
||||
:checked="
|
||||
checkedRobotsOfPlatform(platform.platform_code).includes(robot.id)
|
||||
"
|
||||
@change="
|
||||
toggleRobot(
|
||||
platform.platform_code,
|
||||
robot.id,
|
||||
($event.target as HTMLInputElement).checked,
|
||||
)
|
||||
"
|
||||
>
|
||||
{{ robot.name }}
|
||||
</Checkbox>
|
||||
</Checkbox.Group>
|
||||
</div>
|
||||
|
||||
<!-- 4. @ 人多选 -->
|
||||
<div class="section">
|
||||
<div class="mb-2 flex items-center">
|
||||
<Checkbox
|
||||
:checked="
|
||||
adminList.length > 0 &&
|
||||
(selectedAtUsers[platform.platform_code] || []).length === adminList.length
|
||||
"
|
||||
@change="toggleAllAtUsers(platform.platform_code, $event)"
|
||||
>
|
||||
<span class="font-medium">@ 人员(全选)</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
<div v-if="adminList.length === 0" class="text-gray-400">
|
||||
暂无员工可选
|
||||
</div>
|
||||
<Checkbox.Group
|
||||
v-else
|
||||
:value="selectedAtUsers[platform.platform_code] || []"
|
||||
class="flex flex-wrap gap-2"
|
||||
>
|
||||
<Checkbox
|
||||
v-for="admin in adminList"
|
||||
:key="admin.id"
|
||||
:value="admin.id"
|
||||
:checked="
|
||||
(selectedAtUsers[platform.platform_code] || []).includes(admin.id)
|
||||
"
|
||||
@change="
|
||||
toggleAtUser(
|
||||
platform.platform_code,
|
||||
admin.id,
|
||||
($event.target as HTMLInputElement).checked,
|
||||
)
|
||||
"
|
||||
>
|
||||
{{ admin.name }}
|
||||
</Checkbox>
|
||||
</Checkbox.Group>
|
||||
</div>
|
||||
</div>
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
</div>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.oa-scene-tab {
|
||||
max-height: 600px;
|
||||
overflow-y: auto;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px dashed #e5e6eb;
|
||||
}
|
||||
|
||||
.section:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin-bottom: 12px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
.payload-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.payload-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.payload-label {
|
||||
font-size: 12px;
|
||||
color: #4e5969;
|
||||
}
|
||||
|
||||
.payload-label .required {
|
||||
color: #f53f3f;
|
||||
margin-left: 2px;
|
||||
}
|
||||
|
||||
.payload-image {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,313 @@
|
||||
<script setup lang="ts">
|
||||
import type { BlockSchema, FixedField } from '#/components/oa-template-card-editor/types';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Radio, RadioGroup } from 'ant-design-vue';
|
||||
|
||||
import TemplateCardEditor from '#/components/oa-template-card-editor/index.vue';
|
||||
|
||||
/**
|
||||
* OA 场景 - 企业微信模板卡片专用编辑器
|
||||
*
|
||||
* 在通用拖拽编辑器之上做 OA 封装:
|
||||
* - 顶部用 RadioGroup 切换卡片子类型(text_notice / news_notice)
|
||||
* - 根据子类型动态切换 schema(fixedFields + blocks)
|
||||
* - 输出的 JSON 结构与企微官方文档对齐(template_card 子结构)
|
||||
*
|
||||
* 本期支持两种子类型:
|
||||
* - text_notice:文本通知卡片
|
||||
* - news_notice:图文展示卡片(在 text_notice 基础上加 card_image)
|
||||
* 其他子类型(button_interaction/vote_interaction/multiple_interaction)后续扩展
|
||||
*/
|
||||
|
||||
interface Props {
|
||||
/** 双向绑定的 template_card 数据(企微 payload.template_card) */
|
||||
modelValue?: Record<string, any>;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
modelValue: () => ({}),
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: Record<string, any>];
|
||||
}>();
|
||||
|
||||
/** 当前选中的卡片子类型 */
|
||||
const cardType = ref<string>(props.modelValue?.card_type || 'text_notice');
|
||||
|
||||
/** 卡片子类型选项 */
|
||||
const cardTypeOptions = [
|
||||
{ label: '文本通知(text_notice)', value: 'text_notice' },
|
||||
{ label: '图文展示(news_notice)', value: 'news_notice' },
|
||||
];
|
||||
|
||||
/**
|
||||
* 顶层固定字段定义(不可拖拽,固定在属性面板顶部)
|
||||
* 共通字段:card_type、source、main_title、emphasis_content、sub_title_text、card_action
|
||||
*/
|
||||
const commonFixedFields: FixedField[] = [
|
||||
{
|
||||
name: 'card_type',
|
||||
label: '卡片类型',
|
||||
type: 'select',
|
||||
required: true,
|
||||
options: cardTypeOptions,
|
||||
defaultValue: 'text_notice',
|
||||
},
|
||||
{
|
||||
name: 'main_title.title',
|
||||
label: '一级标题',
|
||||
type: 'string',
|
||||
placeholder: '建议不超过 26 个字',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'main_title.desc',
|
||||
label: '标题辅助信息',
|
||||
type: 'string',
|
||||
placeholder: '建议不超过 30 个字',
|
||||
},
|
||||
{
|
||||
name: 'emphasis_content.title',
|
||||
label: '关键数据内容',
|
||||
type: 'string',
|
||||
placeholder: '如「100」,建议不超过 10 个字',
|
||||
},
|
||||
{
|
||||
name: 'emphasis_content.desc',
|
||||
label: '关键数据描述',
|
||||
type: 'string',
|
||||
placeholder: '如「数据含义」,建议不超过 15 个字',
|
||||
},
|
||||
{
|
||||
name: 'sub_title_text',
|
||||
label: '二级普通文本',
|
||||
type: 'textarea',
|
||||
placeholder: '建议不超过 112 个字',
|
||||
},
|
||||
{
|
||||
name: 'card_action.type',
|
||||
label: '整体卡片点击事件',
|
||||
type: 'radio',
|
||||
options: [
|
||||
{ label: '跳转 URL', value: 1 },
|
||||
{ label: '跳转小程序', value: 2 },
|
||||
],
|
||||
defaultValue: 1,
|
||||
},
|
||||
{
|
||||
name: 'card_action.url',
|
||||
label: '卡片点击跳转 URL',
|
||||
type: 'url',
|
||||
placeholder: 'https://...',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* news_notice 特有的字段(图文展示)
|
||||
*/
|
||||
const newsOnlyFields: FixedField[] = [
|
||||
{
|
||||
name: 'card_image.url',
|
||||
label: '卡片图片 URL',
|
||||
type: 'image',
|
||||
acceptTypes: [1],
|
||||
placeholder: '图文展示卡片的主图',
|
||||
},
|
||||
{
|
||||
name: 'card_image.aspect_ratio',
|
||||
label: '图片宽高比',
|
||||
type: 'string',
|
||||
placeholder: '如 2.25(宽/高)',
|
||||
defaultValue: '2.25',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 完整的固定字段列表(根据 cardType 动态组合)
|
||||
*/
|
||||
const fixedFields = computed<FixedField[]>(() => {
|
||||
const list = [...commonFixedFields];
|
||||
if (cardType.value === 'news_notice') {
|
||||
// news_notice 在 main_title 之后插入 card_image 字段
|
||||
const insertIdx = list.findIndex((f) => f.name === 'main_title.desc') + 1;
|
||||
list.splice(insertIdx, 0, ...newsOnlyFields);
|
||||
}
|
||||
return list;
|
||||
});
|
||||
|
||||
/**
|
||||
* 可拖拽块定义
|
||||
* - horizontal_content_list:二级标题+文本列表(最多 6 项)
|
||||
* - jump_list:跳转链接列表(最多 3 项)
|
||||
*/
|
||||
const blockSchemas: BlockSchema[] = [
|
||||
{
|
||||
type: 'horizontal_content_item',
|
||||
label: '二级标题+文本',
|
||||
icon: 'mdi:format-list-bulleted',
|
||||
targetArrayPath: 'horizontal_content_list',
|
||||
maxCount: 6,
|
||||
defaultValue: { keyname: '', value: '' },
|
||||
fields: [
|
||||
{
|
||||
name: 'keyname',
|
||||
label: '二级标题',
|
||||
type: 'string',
|
||||
required: true,
|
||||
placeholder: '建议不超过 5 个字',
|
||||
},
|
||||
{
|
||||
name: 'value',
|
||||
label: '二级文本',
|
||||
type: 'string',
|
||||
placeholder: '二级文本内容',
|
||||
},
|
||||
{
|
||||
name: 'type',
|
||||
label: '类型',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ label: '普通文本(默认)', value: 0 },
|
||||
{ label: 'URL 链接', value: 1 },
|
||||
{ label: '文件附件', value: 2 },
|
||||
{ label: '成员详情', value: 3 },
|
||||
],
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
name: 'url',
|
||||
label: '跳转 URL',
|
||||
type: 'url',
|
||||
placeholder: 'type=1 时必填',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'jump_item',
|
||||
label: '跳转链接',
|
||||
icon: 'mdi:link-variant',
|
||||
targetArrayPath: 'jump_list',
|
||||
maxCount: 3,
|
||||
defaultValue: { title: '', type: 1, url: '' },
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: '跳转文案',
|
||||
type: 'string',
|
||||
required: true,
|
||||
placeholder: '建议不超过 13 个字',
|
||||
},
|
||||
{
|
||||
name: 'type',
|
||||
label: '跳转类型',
|
||||
type: 'radio',
|
||||
options: [
|
||||
{ label: 'URL', value: 1 },
|
||||
{ label: '小程序', value: 2 },
|
||||
],
|
||||
defaultValue: 1,
|
||||
},
|
||||
{
|
||||
name: 'url',
|
||||
label: '跳转 URL',
|
||||
type: 'url',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/** 编辑器输出的 JSON(实时双向同步给父级) */
|
||||
const editorValue = ref<Record<string, any>>({ ...props.modelValue });
|
||||
|
||||
/**
|
||||
* 监听 props.modelValue 变化,同步到内部(编辑场景回显)
|
||||
*/
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
if (val && Object.keys(val).length > 0) {
|
||||
cardType.value = val.card_type || 'text_notice';
|
||||
editorValue.value = { ...val };
|
||||
}
|
||||
},
|
||||
{ immediate: true, deep: false },
|
||||
);
|
||||
|
||||
/**
|
||||
* 切换卡片子类型时,更新 editorValue.card_type 并清空 news_notice 特有字段
|
||||
*/
|
||||
function handleCardTypeChange(val: any) {
|
||||
cardType.value = val;
|
||||
editorValue.value = {
|
||||
...editorValue.value,
|
||||
card_type: val,
|
||||
};
|
||||
if (val !== 'news_notice') {
|
||||
// 切换回 text_notice 时清除 card_image 字段
|
||||
delete editorValue.value.card_image;
|
||||
}
|
||||
emit('update:modelValue', editorValue.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑器值变化时同步给父级
|
||||
*/
|
||||
function handleEditorUpdate(val: Record<string, any>) {
|
||||
editorValue.value = val;
|
||||
emit('update:modelValue', val);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="template-card-form">
|
||||
<div class="card-type-switcher">
|
||||
<label>卡片子类型:</label>
|
||||
<RadioGroup
|
||||
:value="cardType"
|
||||
size="small"
|
||||
@update:value="handleCardTypeChange"
|
||||
>
|
||||
<Radio
|
||||
v-for="opt in cardTypeOptions"
|
||||
:key="opt.value"
|
||||
:value="opt.value"
|
||||
>
|
||||
{{ opt.label }}
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
<TemplateCardEditor
|
||||
:model-value="editorValue"
|
||||
:schema="blockSchemas"
|
||||
:fixed-fields="fixedFields"
|
||||
@update:model-value="handleEditorUpdate"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.template-card-form {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.card-type-switcher {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
background: #f2f7ff;
|
||||
font-size: 13px;
|
||||
|
||||
label {
|
||||
color: #4e5969;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
15
apps/web-antd/src/views/system/oa-scene/config/constants.ts
Normal file
15
apps/web-antd/src/views/system/oa-scene/config/constants.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* OA 消息类型选项
|
||||
*/
|
||||
export const OA_MESSAGE_TYPE_OPTIONS = [
|
||||
{ label: '文本', value: 'text' },
|
||||
{ label: 'Markdown', value: 'markdown' },
|
||||
];
|
||||
|
||||
/**
|
||||
* 场景状态选项
|
||||
*/
|
||||
export const OA_SCENE_STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
77
apps/web-antd/src/views/system/oa-scene/config/form.ts
Normal file
77
apps/web-antd/src/views/system/oa-scene/config/form.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 场景基础信息表单(仅含基础字段,机器人多选和 @ 人在弹窗中用自定义组件实现)
|
||||
*/
|
||||
export const modalFormProps: VbenFormProps = {
|
||||
wrapperClass: 'grid-cols-12',
|
||||
commonConfig: {
|
||||
formItemClass: 'col-span-12',
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
fieldName: 'id',
|
||||
label: 'ID',
|
||||
formItemClass: 'col-span-6',
|
||||
dependencies: {
|
||||
show: false,
|
||||
triggerFields: ['id'],
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '业务方代码中调用 dispatch 时传入的编码,如 order_paid',
|
||||
},
|
||||
fieldName: 'scene_code',
|
||||
label: '场景编码',
|
||||
rules: 'required',
|
||||
// 编辑场景下场景编码不可修改(前端禁用)
|
||||
dependencies: {
|
||||
triggerFields: ['id'],
|
||||
componentProps: (values) => {
|
||||
return { disabled: !!values?.id };
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入场景名称(中文,便于管理)',
|
||||
},
|
||||
fieldName: 'scene_name',
|
||||
label: '场景名称',
|
||||
rules: 'required',
|
||||
},
|
||||
// 消息类型不再放在基础表单中:每个平台支持的消息类型不同,放在弹窗下方的平台 Tab 内独立配置
|
||||
{
|
||||
component: 'RadioGroup',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: 1,
|
||||
fieldName: 'status',
|
||||
label: '场景状态',
|
||||
},
|
||||
{
|
||||
// 注意:项目内 textarea 的 schema 组件名是 'Textarea'(antd 原生组件直接注册)
|
||||
// 不是 'VbenTextarea'(不存在的组件名,会导致字段无法渲染)
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '可选,场景说明(什么业务事件触发,包含哪些信息)',
|
||||
rows: 3,
|
||||
},
|
||||
fieldName: 'description',
|
||||
label: '场景说明',
|
||||
},
|
||||
],
|
||||
showDefaultActions: false,
|
||||
};
|
||||
47
apps/web-antd/src/views/system/oa-scene/config/search.ts
Normal file
47
apps/web-antd/src/views/system/oa-scene/config/search.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
|
||||
/**
|
||||
* 场景搜索表单配置
|
||||
*/
|
||||
export const formOptions: VbenFormProps = {
|
||||
collapsed: false,
|
||||
schema: [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入场景编码',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'scene_code',
|
||||
label: '场景编码',
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '输入场景名称',
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'scene_name',
|
||||
label: '场景名称',
|
||||
},
|
||||
{
|
||||
component: 'VbenSelect',
|
||||
componentProps: {
|
||||
placeholder: '选择状态',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'status',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
content: '查询',
|
||||
},
|
||||
submitOnChange: true,
|
||||
submitOnEnter: false,
|
||||
};
|
||||
69
apps/web-antd/src/views/system/oa-scene/config/table.ts
Normal file
69
apps/web-antd/src/views/system/oa-scene/config/table.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { getOaSceneList } from '#/views/system/oa-scene/api';
|
||||
|
||||
interface RowType {
|
||||
id: number;
|
||||
scene_code: string;
|
||||
scene_name: string;
|
||||
message_type: string;
|
||||
description: string;
|
||||
status: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 场景列表表格配置
|
||||
*/
|
||||
export const gridOptions: VxeGridProps<RowType> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
labelField: '',
|
||||
},
|
||||
columnConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
rowConfig: {
|
||||
useKey: true,
|
||||
},
|
||||
columns: [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{ field: 'id', align: 'left', title: 'ID', width: 80 },
|
||||
{ field: 'scene_code', align: 'left', title: '场景编码', width: 180 },
|
||||
{ field: 'scene_name', align: 'left', title: '场景名称' },
|
||||
{ field: 'message_type', align: 'left', title: '消息类型', width: 120, slots: { default: 'message_type' } },
|
||||
{ field: 'description', align: 'left', title: '说明' },
|
||||
{ field: 'status', align: 'left', title: '状态', width: 100, slots: { default: 'status' } },
|
||||
{ field: 'created_at', align: 'left', title: '创建时间', width: 180 },
|
||||
{ type: 'html', title: '操作', slots: { default: 'action' }, width: 200, fixed: 'right' },
|
||||
],
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
return await getOaSceneList({
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
height: 'auto',
|
||||
border: false,
|
||||
toolbarConfig: {
|
||||
search: true,
|
||||
refresh: true,
|
||||
print: false,
|
||||
export: false,
|
||||
zoom: true,
|
||||
slots: {
|
||||
buttons: 'toolbar-buttons',
|
||||
},
|
||||
custom: {
|
||||
icon: 'vxe-icon-menu',
|
||||
},
|
||||
},
|
||||
showOverflow: false,
|
||||
};
|
||||
146
apps/web-antd/src/views/system/oa-scene/index.vue
Normal file
146
apps/web-antd/src/views/system/oa-scene/index.vue
Normal file
@@ -0,0 +1,146 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridListeners } from '#/adapter/vxe-table';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { TableAction } from '#/components/table-action';
|
||||
|
||||
import { deleteOaScene } from './api';
|
||||
import FormModalDemo from './components/modal.vue';
|
||||
import { formOptions } from './config/search';
|
||||
import { gridOptions } from './config/table';
|
||||
|
||||
/**
|
||||
* OA 通知场景管理列表页
|
||||
*/
|
||||
defineOptions({ name: 'OaScene' });
|
||||
|
||||
const hasTopTableDropDownActions = ref(false);
|
||||
|
||||
const gridEvents: VxeGridListeners<any> = {
|
||||
checkboxChange() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const records = gridApi.grid.getCheckboxRecords();
|
||||
hasTopTableDropDownActions.value = records.length > 0;
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents,
|
||||
});
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: FormModalDemo,
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* 编辑时需要拉取场景详情(含 robot_ids 和 at_users 字段),所以传入 id
|
||||
*/
|
||||
const showModal = async (row: any = {}, isUpdate = false) => {
|
||||
let values: any = {};
|
||||
if (isUpdate && row?.id) {
|
||||
// 编辑场景下,先拉取详情(含 robot_ids 和 at_users 字段)再打开弹窗
|
||||
// 详情接口由弹窗内的 onOpenChange 触发(这里直接传 row,但 row 中没有 robot_ids/at_users)
|
||||
// 为简化,这里直接打开弹窗,让弹窗根据 row.id 重新拉详情
|
||||
values = { ...row, id: row.id };
|
||||
}
|
||||
formModalApi.setData({
|
||||
values,
|
||||
update: isUpdate,
|
||||
gridApi,
|
||||
});
|
||||
formModalApi.open();
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除场景(支持单个和批量)
|
||||
*/
|
||||
const deleteApi = (row: any) => {
|
||||
let ids: any[] = [];
|
||||
if (row) {
|
||||
ids.push(row);
|
||||
} else {
|
||||
ids = gridApi.grid.getCheckboxRecords().map((item: any) => item.id);
|
||||
}
|
||||
deleteOaScene({ ids }).then(() => {
|
||||
message.success('删除成功!');
|
||||
gridApi.query();
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height title="OA 通知场景管理">
|
||||
<FormModal />
|
||||
<Grid>
|
||||
<template #toolbar-buttons>
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '新增',
|
||||
type: 'primary',
|
||||
icon: 'ant-design:plus-outlined',
|
||||
onClick: showModal.bind(null),
|
||||
},
|
||||
]"
|
||||
:drop-down-actions="[
|
||||
{
|
||||
label: '批量删除',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
ifShow: hasTopTableDropDownActions,
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, false),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
<template #message_type="{ row }">
|
||||
<Tag :color="row.message_type === 'markdown' ? 'warning' : 'processing'">
|
||||
{{ row.message_type === 'markdown' ? 'Markdown' : '文本' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #status="{ row }">
|
||||
<Tag :color="row.status === 1 ? 'success' : 'default'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
<template #toolbar-tools></template>
|
||||
<template #action="{ row }">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{
|
||||
label: '编辑',
|
||||
type: 'link',
|
||||
icon: 'uil:edit',
|
||||
size: 'small',
|
||||
onClick: showModal.bind(null, row, true),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
type: 'link',
|
||||
icon: 'ant-design:delete-outlined',
|
||||
size: 'small',
|
||||
popConfirm: {
|
||||
title: '确定删除吗?',
|
||||
confirm: deleteApi.bind(null, row.id),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</Grid>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,188 @@
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
message,
|
||||
Spin,
|
||||
Switch,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
getOaPlatformList,
|
||||
updateOaPlatformEnabled,
|
||||
} from '#/views/system/oa-platform/api';
|
||||
import { getSystemConfigList, saveSystemConfig } from '#/views/system/system-config/api';
|
||||
|
||||
/**
|
||||
* 系统配置 - OA 通知 Tab 内容
|
||||
*
|
||||
* 内容:
|
||||
* 1. 总开关(OA 通知模块开关):保存到 xk_system_config.oa_notify_enabled
|
||||
* 2. 平台子开关列表(动态拉取,从 xk_oa_platform 表读取)
|
||||
*
|
||||
* 关键交互:
|
||||
* - 总开关关闭时,下方所有平台子开关整体置灰禁用
|
||||
* - 平台子开关切换时立即调接口(不等保存按钮)
|
||||
* - 总开关切换走现有 saveSystemConfig 接口
|
||||
*/
|
||||
|
||||
/** 总开关 */
|
||||
const oaEnabled = ref(false);
|
||||
const totalSaving = ref(false);
|
||||
const platformsLoading = ref(false);
|
||||
const platforms = ref<any[]>([]);
|
||||
|
||||
/**
|
||||
* 加载系统配置(取总开关值)
|
||||
*/
|
||||
async function loadSystemConfig() {
|
||||
try {
|
||||
const list = await getSystemConfigList();
|
||||
const rows: any[] = Array.isArray(list) ? list : list?.data || [];
|
||||
const oaRow = rows.find((r) => r.config_key === 'oa_notify_enabled');
|
||||
oaEnabled.value = oaRow
|
||||
? oaRow.config_value === '1' ||
|
||||
oaRow.config_value === 'true' ||
|
||||
oaRow.config_value === true
|
||||
: false;
|
||||
} catch (e) {
|
||||
console.error('加载系统配置失败', e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载平台列表
|
||||
*/
|
||||
async function loadPlatforms() {
|
||||
platformsLoading.value = true;
|
||||
try {
|
||||
const list = await getOaPlatformList();
|
||||
platforms.value = Array.isArray(list) ? list : list?.data || [];
|
||||
} catch (e) {
|
||||
console.error('加载平台列表失败', e);
|
||||
} finally {
|
||||
platformsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换总开关(保存到 xk_system_config)
|
||||
*/
|
||||
async function handleTotalSwitch(checked: boolean) {
|
||||
totalSaving.value = true;
|
||||
try {
|
||||
await saveSystemConfig([
|
||||
{ config_key: 'oa_notify_enabled', config_value: checked ? '1' : '0' },
|
||||
]);
|
||||
oaEnabled.value = checked;
|
||||
message.success(`OA 通知已${checked ? '启用' : '关闭'}`);
|
||||
} catch (e: any) {
|
||||
message.error(e.message || '保存失败');
|
||||
// 失败回滚到原状态
|
||||
oaEnabled.value = !checked;
|
||||
} finally {
|
||||
totalSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换平台子开关(立即调用接口,乐观更新 + 失败回滚)
|
||||
*/
|
||||
async function handlePlatformSwitch(
|
||||
platform: any,
|
||||
checked: boolean,
|
||||
index: number,
|
||||
) {
|
||||
const oldValue = platform.enabled;
|
||||
// 乐观更新:先在前端切换状态
|
||||
platforms.value[index].enabled = checked ? 1 : 0;
|
||||
try {
|
||||
await updateOaPlatformEnabled(platform.id, checked ? 1 : 0);
|
||||
message.success(`${platform.name} 已${checked ? '启用' : '关闭'}`);
|
||||
} catch (e: any) {
|
||||
// 失败回滚
|
||||
platforms.value[index].enabled = oldValue;
|
||||
message.error(e.message || `${platform.name} 切换失败`);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadSystemConfig();
|
||||
loadPlatforms();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="py-4">
|
||||
<!-- 总开关 -->
|
||||
<Card class="mb-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<div class="mb-1 text-base font-medium">OA 通知总开关</div>
|
||||
<div class="text-sm text-gray-500">
|
||||
关闭后,所有场景的 OA 通知都将停止推送(包括所有平台)
|
||||
</div>
|
||||
</div>
|
||||
<Spin :spinning="totalSaving">
|
||||
<Switch
|
||||
:checked="oaEnabled"
|
||||
checked-children="开"
|
||||
un-checked-children="关"
|
||||
@change="handleTotalSwitch"
|
||||
/>
|
||||
</Spin>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<!-- 平台子开关列表(总开关关闭时整体置灰禁用) -->
|
||||
<Card :class="{ 'oa-platform-disabled': !oaEnabled }">
|
||||
<div class="mb-3 text-base font-medium">平台子开关</div>
|
||||
<div class="mb-2 text-sm text-gray-500">
|
||||
每个平台独立开关,关闭后该平台的所有机器人都会跳过发送
|
||||
</div>
|
||||
<Spin :spinning="platformsLoading">
|
||||
<div v-if="platforms.length === 0 && !platformsLoading" class="py-4 text-center text-gray-400">
|
||||
暂无平台数据,请联系开发初始化
|
||||
</div>
|
||||
<div v-else class="space-y-3">
|
||||
<div
|
||||
v-for="(platform, index) in platforms"
|
||||
:key="platform.platform_code"
|
||||
class="flex items-center justify-between rounded border border-gray-100 p-3"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<Icon :icon="platform.icon" class="text-2xl" />
|
||||
<div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium">{{ platform.name }}</span>
|
||||
<Tag>{{ platform.platform_code }}</Tag>
|
||||
</div>
|
||||
<div class="text-xs text-gray-400">
|
||||
排序:{{ platform.sort }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Switch
|
||||
:checked="platform.enabled === 1"
|
||||
:disabled="!oaEnabled"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
@change="(checked: boolean) => handlePlatformSwitch(platform, checked, index)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Spin>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 总开关关闭时,平台子开关区域整体置灰 */
|
||||
.oa-platform-disabled {
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
</style>
|
||||
@@ -9,6 +9,7 @@ import type { QuickDiscountOption } from '#/utils/pricePercentAdjust';
|
||||
|
||||
import FormAvatar from '#/components/form/components/avatar.vue';
|
||||
|
||||
import OaNotifyConfigPanel from './components/oa-notify-config-panel.vue';
|
||||
import { getSystemConfigList, saveSystemConfig } from './api';
|
||||
|
||||
defineOptions({ name: 'SystemConfig' });
|
||||
@@ -34,7 +35,7 @@ const miniprogramEmptyImage = ref('');
|
||||
|
||||
function readStoredTab() {
|
||||
const stored = localStorage.getItem(TAB_STORAGE_KEY);
|
||||
if (stored === 'price_adjust' || stored === 'input_audit' || stored === 'miniprogram') {
|
||||
if (stored === 'price_adjust' || stored === 'input_audit' || stored === 'miniprogram' || stored === 'oa_notify') {
|
||||
activeKey.value = stored;
|
||||
}
|
||||
}
|
||||
@@ -188,6 +189,10 @@ onMounted(() => {
|
||||
<FormAvatar v-model:value="miniprogramEmptyImage" />
|
||||
</div>
|
||||
</Tabs.TabPane>
|
||||
|
||||
<Tabs.TabPane key="oa_notify" tab="OA通知">
|
||||
<OaNotifyConfigPanel />
|
||||
</Tabs.TabPane>
|
||||
</Tabs>
|
||||
|
||||
<div class="mt-4">
|
||||
|
||||
Reference in New Issue
Block a user