@qiqb/message-domain 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -2
- package/build/components/DefaultMessageReminderRenderer.d.ts +10 -0
- package/build/components/DefaultMessageReminderRenderer.js +29 -0
- package/build/components/MessageNavigation.d.ts +7 -0
- package/build/components/MessageNavigation.js +192 -0
- package/build/components/MessageReminderDisplay.d.ts +21 -0
- package/build/components/MessageReminderDisplay.js +353 -0
- package/build/components/MessageWorkspace.d.ts +14 -0
- package/build/components/MessageWorkspace.js +26 -0
- package/build/components/message-navigation.less +89 -0
- package/build/components/message-reminder-display.less +367 -0
- package/build/components/message-workspace.less +150 -0
- package/build/index.d.ts +20 -0
- package/build/index.js +17 -0
- package/build/pages/inbox/InboxPage.d.ts +2 -0
- package/build/pages/inbox/InboxPage.js +257 -0
- package/build/pages/inbox/inbox.less +293 -0
- package/build/pages/subscription/PersonalSubscriptionPage.d.ts +1 -0
- package/build/pages/subscription/PersonalSubscriptionPage.js +6 -0
- package/build/pages/subscription/RoleSubscriptionPage.d.ts +1 -0
- package/build/pages/subscription/RoleSubscriptionPage.js +5 -0
- package/build/pages/subscription/SubscriptionForm.d.ts +16 -0
- package/build/pages/subscription/SubscriptionForm.js +111 -0
- package/build/pages/subscription/SubscriptionPage.d.ts +5 -0
- package/build/pages/subscription/SubscriptionPage.js +273 -0
- package/build/pages/subscription/subscription-form.less +341 -0
- package/build/pages/subscription/subscription.less +250 -0
- package/build/pages/topic/TopicPage.d.ts +1 -0
- package/build/pages/topic/TopicPage.js +275 -0
- package/build/routes.cjs +38 -0
- package/build/routes.d.cts +22 -0
- package/build/routes.d.ts +22 -0
- package/build/routes.js +34 -0
- package/build/runtime/MessageReminderLayout.d.ts +14 -0
- package/build/runtime/MessageReminderLayout.js +25 -0
- package/build/runtime/MessageReminders.d.ts +16 -0
- package/build/runtime/MessageReminders.js +364 -0
- package/build/runtime/index.d.ts +77 -0
- package/build/runtime/index.js +103 -0
- package/build/runtime/message-reminder-layout.less +40 -0
- package/build/runtime/messageRealtime.d.ts +15 -0
- package/build/runtime/messageRealtime.js +99 -0
- package/build/runtime/reminderEvents.d.ts +18 -0
- package/build/runtime/reminderEvents.js +53 -0
- package/build/runtime/reminderOwnership.d.ts +35 -0
- package/build/runtime/reminderOwnership.js +135 -0
- package/build/runtime/reminderPresentation.d.ts +34 -0
- package/build/runtime/reminderPresentation.js +57 -0
- package/build/runtime/reminderQuery.d.ts +18 -0
- package/build/runtime/reminderQuery.js +33 -0
- package/build/runtime/reminderQueue.d.ts +25 -0
- package/build/runtime/reminderQueue.js +88 -0
- package/build/services/MessageController.d.ts +108 -0
- package/build/services/MessageController.js +42 -0
- package/build/types/index.d.ts +12 -0
- package/build/types/index.js +1 -0
- package/package.json +95 -4
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BellOutlined, InboxOutlined, TeamOutlined, UserOutlined, } from '@ant-design/icons';
|
|
3
|
+
import { Button, Drawer, Form, Input, Select, Switch, Tag, message, } from 'antd';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { useMessageTheme } from '../../components/MessageWorkspace.js';
|
|
6
|
+
import { saveMessageSubscription, showMessageError, } from '../../services/MessageController.js';
|
|
7
|
+
import './subscription-form.less';
|
|
8
|
+
export default function SubscriptionForm({ scope, open, record, topics, roles, metadata, canManage, loading, onClose, onSuccess, }) {
|
|
9
|
+
const [form] = Form.useForm();
|
|
10
|
+
const [saving, setSaving] = useState(false);
|
|
11
|
+
const savingRef = useRef(false);
|
|
12
|
+
const mounted = useRef(true);
|
|
13
|
+
const themeStyle = useMessageTheme();
|
|
14
|
+
const topicCode = Form.useWatch('topicCode', form);
|
|
15
|
+
const topic = topics.find((item) => item.code === topicCode);
|
|
16
|
+
const enabled = Form.useWatch('enabled', form);
|
|
17
|
+
const roleScope = scope === 'ROLE';
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
mounted.current = true;
|
|
20
|
+
return () => {
|
|
21
|
+
mounted.current = false;
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!open)
|
|
26
|
+
return;
|
|
27
|
+
form.resetFields();
|
|
28
|
+
form.setFieldsValue(record || { enabled: true, conditions: [], channels: ['IN_APP'] });
|
|
29
|
+
}, [open, record, form]);
|
|
30
|
+
const save = async () => {
|
|
31
|
+
if (!canManage ||
|
|
32
|
+
!roleScope ||
|
|
33
|
+
loading ||
|
|
34
|
+
!metadata ||
|
|
35
|
+
savingRef.current)
|
|
36
|
+
return;
|
|
37
|
+
// 校验期间同样阻止重复保存;表单尚未渲染 loading 时也不会生成两条订阅。
|
|
38
|
+
savingRef.current = true;
|
|
39
|
+
setSaving(true);
|
|
40
|
+
try {
|
|
41
|
+
const values = await form.validateFields().catch(() => undefined);
|
|
42
|
+
if (!values || !mounted.current)
|
|
43
|
+
return;
|
|
44
|
+
await saveMessageSubscription({
|
|
45
|
+
id: record?.id,
|
|
46
|
+
name: values.name,
|
|
47
|
+
topicCode: values.topicCode,
|
|
48
|
+
// 个人订阅由主题策略生成,本表单只配置角色与主题的绑定关系。
|
|
49
|
+
subjectType: 'ROLE',
|
|
50
|
+
subjectId: values.subjectId,
|
|
51
|
+
enabled: values.enabled,
|
|
52
|
+
// 页面已取消过滤条件,保存时显式清空历史条件,统一接收主题全部消息。
|
|
53
|
+
conditions: [],
|
|
54
|
+
// 本期固定使用站内消息,界面无需让用户选择唯一可用的渠道。
|
|
55
|
+
channels: ['IN_APP'],
|
|
56
|
+
});
|
|
57
|
+
if (!mounted.current)
|
|
58
|
+
return;
|
|
59
|
+
message.success('消息订阅已保存');
|
|
60
|
+
onSuccess();
|
|
61
|
+
onClose();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (mounted.current)
|
|
65
|
+
showMessageError(error, '保存消息订阅失败');
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
savingRef.current = false;
|
|
69
|
+
if (mounted.current)
|
|
70
|
+
setSaving(false);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return (_jsx(Drawer
|
|
74
|
+
// 抽屉渲染到独立 Portal,主题变量和样式入口直接挂在抽屉根节点。
|
|
75
|
+
, {
|
|
76
|
+
// 抽屉渲染到独立 Portal,主题变量和样式入口直接挂在抽屉根节点。
|
|
77
|
+
rootClassName: "qiqb-subscription-drawer", rootStyle: themeStyle, placement: "right", width: "min(600px, 100vw)", open: open, closable: !saving, maskClosable: !saving, keyboard: !saving, onClose: () => {
|
|
78
|
+
if (!saving)
|
|
79
|
+
onClose();
|
|
80
|
+
}, destroyOnHidden: true, title: _jsxs("div", { className: "qiqb-subscription-drawer__heading", children: [_jsxs("div", { className: "qiqb-subscription-drawer__eyebrow", children: [roleScope ? _jsx(TeamOutlined, {}) : _jsx(UserOutlined, {}), _jsx("span", { children: roleScope ? '角色订阅' : '个人订阅' })] }), _jsx("h2", { children: record ? '编辑订阅' : '新建订阅' }), _jsx("p", { children: "\u9009\u62E9\u89D2\u8272\u8BA2\u9605\u6A21\u5F0F\u7684\u4E3B\u9898\uFF0C\u7ED1\u5B9A\u63A5\u6536\u89D2\u8272\u3002" })] }), footer: _jsxs("div", { className: "qiqb-subscription-drawer__footer", children: [_jsx("span", { children: "\u4EC5\u63A5\u6536\u542F\u7528\u540E\u7684\u65B0\u6D88\u606F" }), _jsxs("div", { className: "qiqb-subscription-drawer__actions", children: [_jsx(Button, { disabled: saving, onClick: onClose, children: "\u53D6\u6D88" }), _jsx(Button, { type: "primary", loading: saving, disabled: !canManage ||
|
|
81
|
+
!roleScope ||
|
|
82
|
+
loading ||
|
|
83
|
+
!metadata ||
|
|
84
|
+
(topic !== undefined && topic.subscriptionMode !== 'ROLE'), onClick: save, children: "\u4FDD\u5B58\u8BA2\u9605" })] })] }), children: _jsxs(Form, { form: form, layout: "vertical", disabled: loading || saving, children: [_jsxs("section", { className: "qiqb-subscription-drawer__section", children: [_jsxs("div", { className: "qiqb-subscription-drawer__section-heading", children: [_jsx("span", { className: "qiqb-subscription-drawer__step", children: "01" }), _jsxs("div", { children: [_jsx("h3", { children: "\u57FA\u672C\u8BBE\u7F6E" }), _jsx("p", { children: "\u4E3A\u8BA2\u9605\u547D\u540D\uFF0C\u5E76\u9009\u62E9\u6D88\u606F\u4E3B\u9898\u3002" })] })] }), _jsx(Form.Item, { name: "name", label: "\u8BA2\u9605\u540D\u79F0", rules: [
|
|
85
|
+
{ required: true, whitespace: true, message: '请输入订阅名称' },
|
|
86
|
+
], children: _jsx(Input, { maxLength: 128, placeholder: "\u4F8B\u5982\uFF1A\u5BA1\u6279\u7ED3\u679C\u63D0\u9192" }) }), _jsx(Form.Item, { name: "topicCode", label: "\u6D88\u606F\u4E3B\u9898", rules: [
|
|
87
|
+
{ required: true, message: '请选择消息主题' },
|
|
88
|
+
{
|
|
89
|
+
validator: async (_, value) => {
|
|
90
|
+
if (value &&
|
|
91
|
+
!topics.some((item) => item.code === value && item.subscriptionMode === 'ROLE'))
|
|
92
|
+
throw new Error('请选择角色订阅模式的主题');
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
], children: _jsx(Select, { loading: loading, showSearch: true, optionFilterProp: "label", placeholder: "\u9009\u62E9\u4F60\u5173\u6CE8\u7684\u6D88\u606F\u4E3B\u9898", options: topics.map((item) => ({
|
|
96
|
+
label: `${item.name}(${item.code})`,
|
|
97
|
+
value: item.code,
|
|
98
|
+
disabled: !item.enabled || item.subscriptionMode !== 'ROLE',
|
|
99
|
+
})) }) }), topic && (_jsxs("div", { className: "qiqb-subscription-drawer__topic-info", children: [_jsx(BellOutlined, {}), _jsxs("div", { children: [_jsx("strong", { children: topic.name }), _jsxs("span", { children: ["\u6765\u6E90\u7CFB\u7EDF\uFF1A", topic.sourceSystem] }), topic.description && _jsx("p", { children: topic.description })] })] })), roleScope ? (_jsx(Form.Item, { name: "subjectId", label: "\u8BA2\u9605\u89D2\u8272", extra: record
|
|
100
|
+
? '角色归属已固定。如需更换角色,请新建订阅。'
|
|
101
|
+
: '账户绑定该角色时,会自动生成对应的个人订阅。', rules: [{ required: true, message: '请选择订阅角色' }], children: _jsx(Select
|
|
102
|
+
// 订阅主体创建后不能转移,避免编辑规则时改变既有规则归属。
|
|
103
|
+
, {
|
|
104
|
+
// 订阅主体创建后不能转移,避免编辑规则时改变既有规则归属。
|
|
105
|
+
disabled: !!record, showSearch: true, optionFilterProp: "label", options: roles.map((role) => ({
|
|
106
|
+
value: role.id,
|
|
107
|
+
label: role.code ? `${role.name}(${role.code})` : role.name,
|
|
108
|
+
})), placeholder: "\u9009\u62E9\u63A5\u6536\u6D88\u606F\u7684\u89D2\u8272" }) })) : (_jsxs("div", { className: "qiqb-subscription-drawer__personal-note", children: [_jsx(UserOutlined, {}), _jsx("span", { children: "\u8FD9\u6761\u8BA2\u9605\u4EC5\u5BF9\u5F53\u524D\u8D26\u53F7\u751F\u6548\u3002" })] }))] }), _jsxs("section", { className: "qiqb-subscription-drawer__section qiqb-subscription-drawer__section--last", children: [_jsxs("div", { className: "qiqb-subscription-drawer__section-heading", children: [_jsx("span", { className: "qiqb-subscription-drawer__step", children: "02" }), _jsxs("div", { children: [_jsx("h3", { children: "\u63A5\u6536\u65B9\u5F0F" }), _jsx("p", { children: "\u6D88\u606F\u7EDF\u4E00\u4FDD\u5B58\u5728\u201C\u6211\u7684\u6D88\u606F\u201D\u4E2D\u3002" })] })] }), _jsxs("div", { className: "qiqb-subscription-drawer__delivery", children: [_jsx("span", { className: "qiqb-subscription-drawer__delivery-icon", children: _jsx(InboxOutlined, {}) }), _jsxs("div", { children: [_jsx("strong", { children: "\u7AD9\u5185\u6D88\u606F" }), _jsx("p", { children: "\u968F\u65F6\u5728\u6D88\u606F\u4E2D\u5FC3\u67E5\u770B\u548C\u9605\u8BFB\u3002" })] }), _jsx(Tag, { className: "qiqb-subscription-drawer__channel-tag", children: "\u9ED8\u8BA4\u6E20\u9053" })] }), _jsxs("div", { className: "qiqb-subscription-drawer__status", children: [_jsxs("div", { children: [_jsx("strong", { children: "\u542F\u7528\u8BA2\u9605" }), _jsx("p", { children: enabled === false
|
|
109
|
+
? '已暂停。开启后接收该主题后续发布的消息。'
|
|
110
|
+
: '接收该主题后续发布的消息。' })] }), _jsx(Form.Item, { name: "enabled", valuePropName: "checked", noStyle: true, children: _jsx(Switch, { "aria-label": "\u542F\u7528\u8BA2\u9605" }) })] }), _jsxs("div", { className: "qiqb-subscription-drawer__history-note", children: [_jsx(BellOutlined, {}), _jsx("span", { children: "\u8BA2\u9605\u542F\u7528\u540E\u63A5\u6536\u65B0\u6D88\u606F\uFF0C\u5386\u53F2\u6D88\u606F\u4E0D\u4F1A\u8865\u53D1\u3002" })] })] })] }) }));
|
|
111
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { BellOutlined, DeleteOutlined, EditOutlined, MessageOutlined, PlusOutlined, ReloadOutlined, TeamOutlined, } from '@ant-design/icons';
|
|
3
|
+
import { Alert, Button, Empty, Pagination, Popconfirm, Segmented, Select, Skeleton, Space, Spin, Switch, Tooltip, message, } from 'antd';
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import MessageWorkspace from '../../components/MessageWorkspace.js';
|
|
6
|
+
import { useAccess } from '../../runtime/index.js';
|
|
7
|
+
import { getMessageRoles, getMessageTopics, getSubscriptionMetadata, pageMessageSubscriptions, removeMessageSubscription, setMessageSubscriptionEnabled, showMessageError, } from '../../services/MessageController.js';
|
|
8
|
+
import SubscriptionForm from './SubscriptionForm.js';
|
|
9
|
+
import './subscription.less';
|
|
10
|
+
const initialQuery = {
|
|
11
|
+
current: 1,
|
|
12
|
+
pageSize: 12,
|
|
13
|
+
status: 'ALL',
|
|
14
|
+
};
|
|
15
|
+
export default function SubscriptionPage({ scope, }) {
|
|
16
|
+
const access = useAccess();
|
|
17
|
+
const roleScope = scope === 'ROLE';
|
|
18
|
+
// 个人只调整自己的订阅启停;角色入口查询及所有写操作统一受管理权限保护。
|
|
19
|
+
const canManage = !roleScope ||
|
|
20
|
+
access.verifyElementPermission('MessageRoleSubscriptionManageBtn');
|
|
21
|
+
const canConfigure = roleScope && canManage;
|
|
22
|
+
const [topics, setTopics] = useState([]);
|
|
23
|
+
const [roles, setRoles] = useState([]);
|
|
24
|
+
const [metadata, setMetadata] = useState();
|
|
25
|
+
const [optionsLoading, setOptionsLoading] = useState(true);
|
|
26
|
+
const [optionsFailed, setOptionsFailed] = useState(false);
|
|
27
|
+
const [records, setRecords] = useState([]);
|
|
28
|
+
const [total, setTotal] = useState(0);
|
|
29
|
+
const [recordsLoading, setRecordsLoading] = useState(true);
|
|
30
|
+
const [recordsFailed, setRecordsFailed] = useState(false);
|
|
31
|
+
const [query, setQuery] = useState(initialQuery);
|
|
32
|
+
const [reloadKey, setReloadKey] = useState(0);
|
|
33
|
+
const [open, setOpen] = useState(false);
|
|
34
|
+
const [editing, setEditing] = useState();
|
|
35
|
+
const [busyId, setBusyId] = useState();
|
|
36
|
+
const optionsVersion = useRef(0);
|
|
37
|
+
const recordsVersion = useRef(0);
|
|
38
|
+
const mounted = useRef(true);
|
|
39
|
+
// ref 同步拦住连续点击,避免 React 状态尚未渲染时重复发出写请求。
|
|
40
|
+
const mutationId = useRef();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
mounted.current = true;
|
|
43
|
+
return () => {
|
|
44
|
+
// 离开页面后,已发出的写请求可以完成,但不再提示或触发上一页刷新。
|
|
45
|
+
mounted.current = false;
|
|
46
|
+
};
|
|
47
|
+
}, []);
|
|
48
|
+
const reloadRecords = useCallback(() => {
|
|
49
|
+
recordsVersion.current += 1;
|
|
50
|
+
setReloadKey((key) => key + 1);
|
|
51
|
+
}, []);
|
|
52
|
+
const changeQuery = (changes) => {
|
|
53
|
+
// 筛选改变时即使旧请求马上返回,也不能覆盖新筛选结果。
|
|
54
|
+
recordsVersion.current += 1;
|
|
55
|
+
setQuery((previous) => ({ ...previous, ...changes }));
|
|
56
|
+
};
|
|
57
|
+
const loadOptions = useCallback(async () => {
|
|
58
|
+
const version = ++optionsVersion.current;
|
|
59
|
+
if (roleScope && !canManage) {
|
|
60
|
+
// 角色规则含跨账号信息,没有管理权限时不发起选项及角色查询。
|
|
61
|
+
setOptionsLoading(false);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
setOptionsLoading(true);
|
|
65
|
+
setOptionsFailed(false);
|
|
66
|
+
try {
|
|
67
|
+
const [topicResponse, metadataResponse, roleResponse] = await Promise.all([
|
|
68
|
+
getMessageTopics(),
|
|
69
|
+
getSubscriptionMetadata(),
|
|
70
|
+
roleScope ? getMessageRoles() : Promise.resolve(undefined),
|
|
71
|
+
]);
|
|
72
|
+
if (version !== optionsVersion.current)
|
|
73
|
+
return;
|
|
74
|
+
// 个人订阅由主题策略自动生成;角色配置仅提供角色订阅模式的主题。
|
|
75
|
+
setTopics((topicResponse.data || []).filter((topic) => !roleScope || topic.subscriptionMode === 'ROLE'));
|
|
76
|
+
setMetadata(metadataResponse.data);
|
|
77
|
+
setRoles(roleResponse?.data || []);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
if (version !== optionsVersion.current)
|
|
81
|
+
return;
|
|
82
|
+
setOptionsFailed(true);
|
|
83
|
+
showMessageError(error, '加载订阅选项失败');
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
if (version === optionsVersion.current)
|
|
87
|
+
setOptionsLoading(false);
|
|
88
|
+
}
|
|
89
|
+
}, [roleScope, canManage]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
void loadOptions();
|
|
92
|
+
return () => {
|
|
93
|
+
optionsVersion.current += 1;
|
|
94
|
+
};
|
|
95
|
+
}, [loadOptions]);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
// 个人与角色页面复用组件时,清除上一个入口的筛选、页码和编辑对象。
|
|
98
|
+
recordsVersion.current += 1;
|
|
99
|
+
setQuery(initialQuery);
|
|
100
|
+
setRecords([]);
|
|
101
|
+
setTotal(0);
|
|
102
|
+
setOpen(false);
|
|
103
|
+
setEditing(undefined);
|
|
104
|
+
}, [scope]);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const version = ++recordsVersion.current;
|
|
107
|
+
let active = true;
|
|
108
|
+
if (roleScope && !canManage) {
|
|
109
|
+
setRecords([]);
|
|
110
|
+
setTotal(0);
|
|
111
|
+
setRecordsLoading(false);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
setRecordsLoading(true);
|
|
115
|
+
setRecordsFailed(false);
|
|
116
|
+
void (async () => {
|
|
117
|
+
try {
|
|
118
|
+
const { data } = await pageMessageSubscriptions({
|
|
119
|
+
scope,
|
|
120
|
+
current: query.current,
|
|
121
|
+
pageSize: query.pageSize,
|
|
122
|
+
topicCode: query.topicCode,
|
|
123
|
+
subjectId: roleScope ? query.subjectId : undefined,
|
|
124
|
+
// “全部”不提交 enabled,避免把未选择状态误解释为停用规则。
|
|
125
|
+
enabled: query.status === 'ALL' ? undefined : query.status === 'ENABLED',
|
|
126
|
+
});
|
|
127
|
+
if (!active || version !== recordsVersion.current)
|
|
128
|
+
return;
|
|
129
|
+
const nextTotal = data?.total || 0;
|
|
130
|
+
setTotal(nextTotal);
|
|
131
|
+
const lastPage = Math.max(1, Math.ceil(nextTotal / query.pageSize));
|
|
132
|
+
if (query.current > lastPage) {
|
|
133
|
+
// 删除末页最后一条规则后,依据服务端最新总数退回可用页重新查询。
|
|
134
|
+
recordsVersion.current += 1;
|
|
135
|
+
setQuery((previous) => ({ ...previous, current: lastPage }));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
setRecords(data?.records || []);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
if (!active || version !== recordsVersion.current)
|
|
142
|
+
return;
|
|
143
|
+
setRecordsFailed(true);
|
|
144
|
+
setRecords([]);
|
|
145
|
+
setTotal(0);
|
|
146
|
+
showMessageError(error, '加载消息订阅失败');
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
if (active && version === recordsVersion.current)
|
|
150
|
+
setRecordsLoading(false);
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
return () => {
|
|
154
|
+
active = false;
|
|
155
|
+
};
|
|
156
|
+
}, [scope, roleScope, canManage, query, reloadKey]);
|
|
157
|
+
const changeEnabled = async (record, enabled) => {
|
|
158
|
+
if (!mounted.current || !canManage || mutationId.current)
|
|
159
|
+
return;
|
|
160
|
+
mutationId.current = record.id;
|
|
161
|
+
setBusyId(record.id);
|
|
162
|
+
try {
|
|
163
|
+
await setMessageSubscriptionEnabled(record.id, enabled);
|
|
164
|
+
if (!mounted.current)
|
|
165
|
+
return;
|
|
166
|
+
message.success(enabled ? '订阅已启用' : '订阅已停用');
|
|
167
|
+
reloadRecords();
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
if (mounted.current)
|
|
171
|
+
showMessageError(error, '调整订阅状态失败');
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
mutationId.current = undefined;
|
|
175
|
+
if (mounted.current)
|
|
176
|
+
setBusyId(undefined);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const remove = async (record) => {
|
|
180
|
+
if (!mounted.current || !canConfigure || mutationId.current)
|
|
181
|
+
return;
|
|
182
|
+
mutationId.current = record.id;
|
|
183
|
+
setBusyId(record.id);
|
|
184
|
+
try {
|
|
185
|
+
await removeMessageSubscription(record.id);
|
|
186
|
+
if (!mounted.current)
|
|
187
|
+
return;
|
|
188
|
+
message.success('消息订阅已删除');
|
|
189
|
+
reloadRecords();
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (mounted.current)
|
|
193
|
+
showMessageError(error, '删除消息订阅失败');
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
mutationId.current = undefined;
|
|
197
|
+
if (mounted.current)
|
|
198
|
+
setBusyId(undefined);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const create = () => {
|
|
202
|
+
if (!canConfigure || optionsLoading || optionsFailed || !metadata || busyId)
|
|
203
|
+
return;
|
|
204
|
+
setEditing(undefined);
|
|
205
|
+
setOpen(true);
|
|
206
|
+
};
|
|
207
|
+
const filtersActive = !!query.topicCode || !!query.subjectId || query.status !== 'ALL';
|
|
208
|
+
const title = roleScope ? '角色订阅' : '我的订阅';
|
|
209
|
+
const description = roleScope
|
|
210
|
+
? '为角色配置订阅,账户绑定角色时自动生成个人订阅。'
|
|
211
|
+
: '主题和角色为你自动绑定订阅,可按需启用或停用消息接收。';
|
|
212
|
+
const createDisabled = optionsFailed || !metadata || !!busyId;
|
|
213
|
+
if (roleScope && !canManage) {
|
|
214
|
+
return (_jsx(MessageWorkspace, { icon: _jsx(TeamOutlined, {}), title: title, description: description, children: _jsx(Alert, { type: "warning", showIcon: true, message: "\u6682\u65E0\u89D2\u8272\u8BA2\u9605\u7BA1\u7406\u6743\u9650\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u6388\u6743\u3002" }) }));
|
|
215
|
+
}
|
|
216
|
+
return (_jsxs(MessageWorkspace, { icon: roleScope ? _jsx(TeamOutlined, {}) : _jsx(BellOutlined, {}), title: title, description: description, extra: canConfigure && (_jsx(Button, { type: "primary", icon: _jsx(PlusOutlined, {}), loading: optionsLoading, disabled: createDisabled, onClick: create, children: "\u65B0\u589E\u8BA2\u9605" })), children: [optionsFailed && (_jsx(Alert, { className: "qiqb-message-subscription-alert", type: "error", showIcon: true, message: "\u8BA2\u9605\u9009\u9879\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u540E\u7BA1\u7406\u8BA2\u9605\u3002", action: _jsx(Button, { size: "small", onClick: () => void loadOptions(), children: "\u91CD\u8BD5" }) })), _jsxs("div", { className: "qiqb-message-subscription-toolbar", children: [_jsxs("div", { className: "qiqb-message-subscription-filters", children: [_jsx(Select, { "aria-label": "\u7B5B\u9009\u6D88\u606F\u4E3B\u9898", className: "qiqb-message-subscription-select", allowClear: true, showSearch: true, optionFilterProp: "label", placeholder: "\u5168\u90E8\u4E3B\u9898", value: query.topicCode, loading: optionsLoading, options: topics.map((topic) => ({
|
|
217
|
+
value: topic.code,
|
|
218
|
+
label: topic.name,
|
|
219
|
+
})), onChange: (topicCode) => changeQuery({ topicCode, current: 1 }) }), roleScope && (_jsx(Select, { "aria-label": "\u7B5B\u9009\u8BA2\u9605\u89D2\u8272", className: "qiqb-message-subscription-select", allowClear: true, showSearch: true, optionFilterProp: "label", placeholder: "\u5168\u90E8\u89D2\u8272", value: query.subjectId, loading: optionsLoading, options: roles.map((role) => ({
|
|
220
|
+
value: role.id,
|
|
221
|
+
label: role.name,
|
|
222
|
+
})), onChange: (subjectId) => changeQuery({ subjectId, current: 1 }) })), _jsx(Segmented, { "aria-label": "\u7B5B\u9009\u8BA2\u9605\u72B6\u6001", value: query.status, options: [
|
|
223
|
+
{ label: '全部', value: 'ALL' },
|
|
224
|
+
{ label: '启用', value: 'ENABLED' },
|
|
225
|
+
{ label: '停用', value: 'DISABLED' },
|
|
226
|
+
], onChange: (status) => changeQuery({ status: status, current: 1 }) }), filtersActive && (_jsx(Button, { type: "text", onClick: () => changeQuery({
|
|
227
|
+
topicCode: undefined,
|
|
228
|
+
subjectId: undefined,
|
|
229
|
+
status: 'ALL',
|
|
230
|
+
current: 1,
|
|
231
|
+
}), children: "\u91CD\u7F6E\u7B5B\u9009" }))] }), _jsxs("div", { className: "qiqb-message-subscription-summary", children: [_jsx("span", { children: recordsLoading
|
|
232
|
+
? '正在加载订阅'
|
|
233
|
+
: recordsFailed
|
|
234
|
+
? '数量暂不可用'
|
|
235
|
+
: `共 ${total} 条订阅` }), _jsx(Tooltip, { title: "\u5237\u65B0\u8BA2\u9605", children: _jsx(Button, { type: "text", "aria-label": "\u5237\u65B0\u8BA2\u9605", icon: _jsx(ReloadOutlined, {}), loading: recordsLoading, onClick: reloadRecords }) })] })] }), recordsFailed && (_jsx(Alert, { className: "qiqb-message-subscription-alert", type: "error", showIcon: true, message: "\u6D88\u606F\u8BA2\u9605\u52A0\u8F7D\u5931\u8D25", action: _jsx(Button, { size: "small", onClick: reloadRecords, children: "\u91CD\u65B0\u52A0\u8F7D" }) })), _jsx(Spin, { spinning: recordsLoading && records.length > 0, children: _jsx("div", { className: "qiqb-message-subscription-grid", "aria-busy": recordsLoading, children: recordsLoading && records.length === 0
|
|
236
|
+
? [0, 1, 2].map((key) => (_jsx("div", { className: "qiqb-message-subscription-card", children: _jsx(Skeleton, { active: true, paragraph: { rows: 4 } }) }, key)))
|
|
237
|
+
: records.map((record) => {
|
|
238
|
+
const topicName = record.topicName ||
|
|
239
|
+
topics.find((topic) => topic.code === record.topicCode)
|
|
240
|
+
?.name ||
|
|
241
|
+
record.topicCode;
|
|
242
|
+
const roleName = record.subjectName ||
|
|
243
|
+
roles.find((role) => role.id === record.subjectId)?.name ||
|
|
244
|
+
'角色订阅';
|
|
245
|
+
const disabled = !canManage || !!busyId || recordsLoading || optionsLoading;
|
|
246
|
+
return (_jsxs("article", { className: "qiqb-message-subscription-card", children: [_jsxs("div", { className: "qiqb-message-subscription-card-header", children: [_jsx("span", { className: "qiqb-message-subscription-topic-icon", children: _jsx(BellOutlined, {}) }), _jsxs("div", { className: "qiqb-message-subscription-heading", children: [_jsx("h3", { children: record.name }), _jsx("div", { className: "qiqb-message-subscription-topic", children: topicName })] }), _jsxs("div", { className: "qiqb-message-subscription-state", children: [_jsx("span", { className: record.enabled
|
|
247
|
+
? 'qiqb-message-subscription-status is-enabled'
|
|
248
|
+
: 'qiqb-message-subscription-status', children: record.enabled ? '已启用' : '已停用' }), _jsx(Switch, { size: "small", "aria-label": `${record.name}启用状态`, checked: record.enabled, disabled: disabled, loading: busyId === record.id, onChange: (enabled) => void changeEnabled(record, enabled) })] })] }), roleScope && (_jsxs("div", { className: "qiqb-message-subscription-role", children: [_jsx(TeamOutlined, {}), _jsx("span", { children: roleName })] })), _jsxs("div", { className: "qiqb-message-subscription-conditions", children: [_jsx("div", { className: "qiqb-message-subscription-condition-label", children: "\u63A5\u6536\u8303\u56F4" }), _jsx("div", { className: "qiqb-message-subscription-all", children: "\u8BE5\u4E3B\u9898\u4E0B\u7684\u5168\u90E8\u6D88\u606F" })] }), _jsxs("div", { className: "qiqb-message-subscription-card-footer", children: [_jsxs("div", { className: "qiqb-message-subscription-channels", children: [_jsx(MessageOutlined, {}), _jsx("span", { children: (record.channels || [])
|
|
249
|
+
.map((channel) => metadata?.channels.find((item) => item.code === channel)?.name ||
|
|
250
|
+
(channel === 'IN_APP' ? '站内消息' : channel))
|
|
251
|
+
.join('、') || '未设置渠道' })] }), canConfigure && (_jsxs(Space, { size: 0, children: [_jsx(Button, { type: "text", size: "small", icon: _jsx(EditOutlined, {}), disabled: disabled ||
|
|
252
|
+
optionsFailed ||
|
|
253
|
+
!metadata ||
|
|
254
|
+
!topics.some((topic) => topic.code === record.topicCode), onClick: () => {
|
|
255
|
+
if (!canConfigure || mutationId.current)
|
|
256
|
+
return;
|
|
257
|
+
setEditing(record);
|
|
258
|
+
setOpen(true);
|
|
259
|
+
}, children: "\u7F16\u8F91" }), _jsx(Popconfirm, { title: "\u5220\u9664\u8BE5\u6D88\u606F\u8BA2\u9605\uFF1F", description: "\u5220\u9664\u540E\u5C06\u4E0D\u518D\u901A\u8FC7\u6B64\u89C4\u5219\u63A5\u6536\u65B0\u6D88\u606F\u3002", disabled: disabled, okText: "\u5220\u9664", cancelText: "\u53D6\u6D88", onConfirm: () => remove(record), children: _jsx(Button, { type: "text", size: "small", danger: true, icon: _jsx(DeleteOutlined, {}), disabled: disabled, children: "\u5220\u9664" }) })] }))] })] }, record.id));
|
|
260
|
+
}) }) }), !recordsLoading && !recordsFailed && records.length === 0 && (_jsx("div", { className: "qiqb-message-subscription-empty", children: _jsx(Empty, { image: Empty.PRESENTED_IMAGE_SIMPLE, description: filtersActive ? '没有符合筛选条件的订阅' : '还没有消息订阅', children: filtersActive ? (_jsx(Button, { onClick: () => changeQuery({
|
|
261
|
+
...initialQuery,
|
|
262
|
+
pageSize: query.pageSize,
|
|
263
|
+
// 展开对象不包含可选字段,须显式清除已有主题及角色筛选。
|
|
264
|
+
topicCode: undefined,
|
|
265
|
+
subjectId: undefined,
|
|
266
|
+
}), children: "\u6E05\u9664\u7B5B\u9009" })) : (canConfigure && (_jsx(Button, { type: "primary", icon: _jsx(PlusOutlined, {}), disabled: createDisabled || optionsLoading, onClick: create, children: "\u521B\u5EFA\u7B2C\u4E00\u4E2A\u8BA2\u9605" }))) }) })), total > 0 && (_jsx("div", { className: "qiqb-message-subscription-pagination", children: _jsx(Pagination, { current: query.current, pageSize: query.pageSize, total: total, showSizeChanger: true, pageSizeOptions: [12, 24, 48], disabled: recordsLoading, onChange: (current, pageSize) => changeQuery({
|
|
267
|
+
current: pageSize === query.pageSize ? current : 1,
|
|
268
|
+
pageSize,
|
|
269
|
+
}) }) })), roleScope && (_jsx(SubscriptionForm, { scope: scope, open: open, record: editing, topics: topics, roles: roles, metadata: metadata, canManage: canConfigure, loading: optionsLoading || optionsFailed, onClose: () => {
|
|
270
|
+
setOpen(false);
|
|
271
|
+
setEditing(undefined);
|
|
272
|
+
}, onSuccess: reloadRecords }))] }));
|
|
273
|
+
}
|