@donglegeyu/company-ui 1.2.46 → 1.2.48
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/dist/cjs/ai-assistant/AiSessionEngine.d.ts +3 -0
- package/dist/cjs/ai-assistant/AiSessionEngine.js +13 -0
- package/dist/cjs/ai-assistant/MockAiTransport.d.ts +4 -1
- package/dist/cjs/ai-assistant/MockAiTransport.js +14 -2
- package/dist/cjs/ai-assistant/types.d.ts +12 -0
- package/dist/cjs/basic-components/CompanyChart/Chart.d.ts +20 -0
- package/dist/cjs/basic-components/CompanyChart/Chart.js +93 -0
- package/dist/cjs/basic-components/CompanyChart/index.d.ts +3 -0
- package/dist/cjs/basic-components/CompanyChart/index.js +27 -0
- package/dist/cjs/basic-components/CompanyChart/presets.d.ts +102 -0
- package/dist/cjs/basic-components/CompanyChart/presets.js +147 -0
- package/dist/cjs/basic-components/CompanyChart/theme.d.ts +9 -0
- package/dist/cjs/basic-components/CompanyChart/theme.js +45 -0
- package/dist/cjs/basic-components/CompanyChart/utils.d.ts +6 -0
- package/dist/cjs/basic-components/CompanyChart/utils.js +39 -0
- package/dist/cjs/basic-components/index.d.ts +2 -0
- package/dist/cjs/basic-components/index.js +5 -1
- package/dist/cjs/shared-components/CompanyAiAssistant/index.js +12 -1
- package/dist/cjs/shared-components/CompanyAiAssistant/index.scss +12 -0
- package/dist/cjs/sidebar-config.d.ts +2 -0
- package/dist/cjs/sidebar-config.js +23 -0
- package/dist/es/ai-assistant/AiSessionEngine.d.ts +3 -0
- package/dist/es/ai-assistant/AiSessionEngine.js +28 -1
- package/dist/es/ai-assistant/MockAiTransport.d.ts +4 -1
- package/dist/es/ai-assistant/MockAiTransport.js +11 -2
- package/dist/es/ai-assistant/types.d.ts +12 -0
- package/dist/es/basic-components/CompanyChart/Chart.d.ts +20 -0
- package/dist/es/basic-components/CompanyChart/Chart.js +91 -0
- package/dist/es/basic-components/CompanyChart/index.d.ts +3 -0
- package/dist/es/basic-components/CompanyChart/index.js +3 -0
- package/dist/es/basic-components/CompanyChart/presets.d.ts +102 -0
- package/dist/es/basic-components/CompanyChart/presets.js +229 -0
- package/dist/es/basic-components/CompanyChart/theme.d.ts +9 -0
- package/dist/es/basic-components/CompanyChart/theme.js +36 -0
- package/dist/es/basic-components/CompanyChart/utils.d.ts +6 -0
- package/dist/es/basic-components/CompanyChart/utils.js +26 -0
- package/dist/es/basic-components/index.d.ts +2 -0
- package/dist/es/basic-components/index.js +3 -1
- package/dist/es/shared-components/CompanyAiAssistant/index.js +15 -3
- package/dist/es/shared-components/CompanyAiAssistant/index.scss +12 -0
- package/dist/es/sidebar-config.d.ts +2 -0
- package/dist/es/sidebar-config.js +30 -0
- package/package.json +2 -1
|
@@ -31,6 +31,7 @@ __reExport(basic_components_exports, require("./CompanyBubble"), module.exports)
|
|
|
31
31
|
__reExport(basic_components_exports, require("./CompanyButton"), module.exports);
|
|
32
32
|
__reExport(basic_components_exports, require("./CompanyCalendar"), module.exports);
|
|
33
33
|
__reExport(basic_components_exports, require("./CompanyCard"), module.exports);
|
|
34
|
+
__reExport(basic_components_exports, require("./CompanyChart"), module.exports);
|
|
34
35
|
__reExport(basic_components_exports, require("./CompanyCarousel"), module.exports);
|
|
35
36
|
__reExport(basic_components_exports, require("./CompanyCascader"), module.exports);
|
|
36
37
|
__reExport(basic_components_exports, require("./CompanyCheckbox"), module.exports);
|
|
@@ -103,6 +104,7 @@ __reExport(basic_components_exports, require("./CompanyTypography"), module.expo
|
|
|
103
104
|
__reExport(basic_components_exports, require("./CompanyUpload"), module.exports);
|
|
104
105
|
__reExport(basic_components_exports, require("./CompanyWatermark"), module.exports);
|
|
105
106
|
__reExport(basic_components_exports, require("./CompanyWelcome"), module.exports);
|
|
107
|
+
__reExport(basic_components_exports, require("./CompanyXProvider"), module.exports);
|
|
106
108
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
109
|
0 && (module.exports = {
|
|
108
110
|
...require("./CompanyActions"),
|
|
@@ -120,6 +122,7 @@ __reExport(basic_components_exports, require("./CompanyWelcome"), module.exports
|
|
|
120
122
|
...require("./CompanyButton"),
|
|
121
123
|
...require("./CompanyCalendar"),
|
|
122
124
|
...require("./CompanyCard"),
|
|
125
|
+
...require("./CompanyChart"),
|
|
123
126
|
...require("./CompanyCarousel"),
|
|
124
127
|
...require("./CompanyCascader"),
|
|
125
128
|
...require("./CompanyCheckbox"),
|
|
@@ -191,5 +194,6 @@ __reExport(basic_components_exports, require("./CompanyWelcome"), module.exports
|
|
|
191
194
|
...require("./CompanyTypography"),
|
|
192
195
|
...require("./CompanyUpload"),
|
|
193
196
|
...require("./CompanyWatermark"),
|
|
194
|
-
...require("./CompanyWelcome")
|
|
197
|
+
...require("./CompanyWelcome"),
|
|
198
|
+
...require("./CompanyXProvider")
|
|
195
199
|
});
|
|
@@ -264,13 +264,24 @@ function AssistantPanel({
|
|
|
264
264
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: listRef, className: "company-ai-assistant__messages", children: [
|
|
265
265
|
toolCalls && toolCalls.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToolCallChain, { toolCalls }),
|
|
266
266
|
messages.map((message) => {
|
|
267
|
-
const
|
|
267
|
+
const isThinking = streaming && message.role === "assistant" && !message.content;
|
|
268
|
+
const isStreamingTail = isThinking && !message.reasoning && !message.suggestion;
|
|
268
269
|
const messageToolCalls = (toolCalls == null ? void 0 : toolCalls.length) ? void 0 : message.toolCalls;
|
|
269
270
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
270
271
|
"div",
|
|
271
272
|
{
|
|
272
273
|
className: `company-ai-assistant__msg company-ai-assistant__msg--${message.role}`,
|
|
273
274
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "company-ai-assistant__bubble", children: [
|
|
275
|
+
message.reasoning && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
276
|
+
import_basic_components.CompanyThink,
|
|
277
|
+
{
|
|
278
|
+
className: "company-ai-assistant__think",
|
|
279
|
+
title: isThinking ? "思考中" : "已完成思考",
|
|
280
|
+
loading: isThinking,
|
|
281
|
+
defaultExpanded: isThinking,
|
|
282
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "company-ai-assistant__think-body", children: message.reasoning })
|
|
283
|
+
}
|
|
284
|
+
),
|
|
274
285
|
isStreamingTail ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "company-ai-assistant__typing", "aria-label": "正在输入", children: [
|
|
275
286
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", {}),
|
|
276
287
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", {}),
|
|
@@ -122,6 +122,18 @@
|
|
|
122
122
|
word-break: break-word;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// 思考过程区块(CompanyThink):与正文留出间距,正文为浅灰小字
|
|
126
|
+
&__think {
|
|
127
|
+
margin-bottom: 8px;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
&__think-body {
|
|
131
|
+
font-size: 12px;
|
|
132
|
+
line-height: 20px;
|
|
133
|
+
color: rgba(0, 0, 0, 0.65);
|
|
134
|
+
white-space: pre-wrap;
|
|
135
|
+
}
|
|
136
|
+
|
|
125
137
|
// 输入中动画(三个渐现圆点)
|
|
126
138
|
&__typing {
|
|
127
139
|
display: inline-flex;
|
|
@@ -7,4 +7,6 @@ export interface SidebarGroup {
|
|
|
7
7
|
children: SidebarItem[];
|
|
8
8
|
}
|
|
9
9
|
export declare const COMPONENT_GROUPS: SidebarGroup[];
|
|
10
|
+
/** 图表组件(独立 tab):AntV G2 5.0 图表组件,侧边栏单独成组 */
|
|
11
|
+
export declare const CHART_GROUPS: SidebarGroup[];
|
|
10
12
|
export declare const TEMPLATE_GROUPS: SidebarGroup[];
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/sidebar-config.ts
|
|
20
20
|
var sidebar_config_exports = {};
|
|
21
21
|
__export(sidebar_config_exports, {
|
|
22
|
+
CHART_GROUPS: () => CHART_GROUPS,
|
|
22
23
|
COMPONENT_GROUPS: () => COMPONENT_GROUPS,
|
|
23
24
|
TEMPLATE_GROUPS: () => TEMPLATE_GROUPS
|
|
24
25
|
});
|
|
@@ -153,6 +154,27 @@ var COMPONENT_GROUPS = [
|
|
|
153
154
|
]
|
|
154
155
|
}
|
|
155
156
|
];
|
|
157
|
+
var CHART_GROUPS = [
|
|
158
|
+
{
|
|
159
|
+
title: "图表",
|
|
160
|
+
children: [
|
|
161
|
+
{ title: "图表 Chart", link: "/antd-components/charts/companychart" },
|
|
162
|
+
{ title: "折线图 LineChart", link: "/antd-components/charts/companylinechart" },
|
|
163
|
+
{ title: "面积图 AreaChart", link: "/antd-components/charts/companyareachart" },
|
|
164
|
+
{ title: "柱形图 BarChart", link: "/antd-components/charts/companybarchart" },
|
|
165
|
+
{
|
|
166
|
+
title: "分组柱形图 GroupedBarChart",
|
|
167
|
+
link: "/antd-components/charts/companygroupedbarchart"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
title: "堆叠柱形图 StackedBarChart",
|
|
171
|
+
link: "/antd-components/charts/companystackedbarchart"
|
|
172
|
+
},
|
|
173
|
+
{ title: "饼图 PieChart", link: "/antd-components/charts/companypiechart" },
|
|
174
|
+
{ title: "环形图 DonutChart", link: "/antd-components/charts/companydonutchart" }
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
];
|
|
156
178
|
var TEMPLATE_GROUPS = [
|
|
157
179
|
{
|
|
158
180
|
title: "页面级模板",
|
|
@@ -213,6 +235,7 @@ var TEMPLATE_GROUPS = [
|
|
|
213
235
|
];
|
|
214
236
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
237
|
0 && (module.exports = {
|
|
238
|
+
CHART_GROUPS,
|
|
216
239
|
COMPONENT_GROUPS,
|
|
217
240
|
TEMPLATE_GROUPS
|
|
218
241
|
});
|
|
@@ -7,6 +7,8 @@ export interface AiSessionEngineOptions {
|
|
|
7
7
|
getCapability: (tabKey: string) => AiPageCapability | undefined;
|
|
8
8
|
/** 版本栈深度,默认 10(超出丢弃最旧) */
|
|
9
9
|
maxSnapshots?: number;
|
|
10
|
+
/** 随请求发送的对话历史上限条数,默认 20(不含本轮消息) */
|
|
11
|
+
maxHistory?: number;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* 会话引擎:SSE 流式接收、消息历史、草稿版本栈。
|
|
@@ -21,6 +23,7 @@ export declare class AiSessionEngine {
|
|
|
21
23
|
private readonly transport;
|
|
22
24
|
private readonly getCapability;
|
|
23
25
|
private readonly maxSnapshots;
|
|
26
|
+
private readonly maxHistory;
|
|
24
27
|
constructor(options: AiSessionEngineOptions);
|
|
25
28
|
/** 订阅会话表变更(订阅时立即回调一次当前快照) */
|
|
26
29
|
subscribe(listener: (sessions: Record<string, AiSession>) => void): () => void;
|
|
@@ -52,16 +52,18 @@ function safeClone(data) {
|
|
|
52
52
|
*/
|
|
53
53
|
export var AiSessionEngine = /*#__PURE__*/function () {
|
|
54
54
|
function AiSessionEngine(options) {
|
|
55
|
-
var _options$maxSnapshots;
|
|
55
|
+
var _options$maxSnapshots, _options$maxHistory;
|
|
56
56
|
_classCallCheck(this, AiSessionEngine);
|
|
57
57
|
_defineProperty(this, "sessions", new Map());
|
|
58
58
|
_defineProperty(this, "listeners", new Set());
|
|
59
59
|
_defineProperty(this, "transport", void 0);
|
|
60
60
|
_defineProperty(this, "getCapability", void 0);
|
|
61
61
|
_defineProperty(this, "maxSnapshots", void 0);
|
|
62
|
+
_defineProperty(this, "maxHistory", void 0);
|
|
62
63
|
this.transport = options.transport;
|
|
63
64
|
this.getCapability = options.getCapability;
|
|
64
65
|
this.maxSnapshots = (_options$maxSnapshots = options.maxSnapshots) !== null && _options$maxSnapshots !== void 0 ? _options$maxSnapshots : 10;
|
|
66
|
+
this.maxHistory = (_options$maxHistory = options.maxHistory) !== null && _options$maxHistory !== void 0 ? _options$maxHistory : 20;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
/** 订阅会话表变更(订阅时立即回调一次当前快照) */
|
|
@@ -109,6 +111,16 @@ export var AiSessionEngine = /*#__PURE__*/function () {
|
|
|
109
111
|
} catch (_unused3) {
|
|
110
112
|
context = undefined;
|
|
111
113
|
}
|
|
114
|
+
|
|
115
|
+
// 本轮消息之前的对话历史:过滤空内容(流式占位/中断残留),按 maxHistory 截断最近条目
|
|
116
|
+
var history = session.messages.filter(function (item) {
|
|
117
|
+
return item.content.trim().length > 0;
|
|
118
|
+
}).slice(-this.maxHistory).map(function (item) {
|
|
119
|
+
return {
|
|
120
|
+
role: item.role,
|
|
121
|
+
content: item.content
|
|
122
|
+
};
|
|
123
|
+
});
|
|
112
124
|
this.update(tabKey, {
|
|
113
125
|
messages: [].concat(_toConsumableArray(session.messages), [createMessage("user", trimmed), createMessage("assistant", "")]),
|
|
114
126
|
streaming: true
|
|
@@ -132,6 +144,20 @@ export var AiSessionEngine = /*#__PURE__*/function () {
|
|
|
132
144
|
});
|
|
133
145
|
break;
|
|
134
146
|
}
|
|
147
|
+
case "thinking":
|
|
148
|
+
{
|
|
149
|
+
// 思考帧累积到 reasoning,与正文 content 分离渲染
|
|
150
|
+
if (isPlaceholder) {
|
|
151
|
+
var _last$reasoning;
|
|
152
|
+
messages[messages.length - 1] = _objectSpread(_objectSpread({}, last), {}, {
|
|
153
|
+
reasoning: ((_last$reasoning = last.reasoning) !== null && _last$reasoning !== void 0 ? _last$reasoning : "") + event.text
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
_this2.update(tabKey, {
|
|
157
|
+
messages: messages
|
|
158
|
+
});
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
135
161
|
case "action":
|
|
136
162
|
{
|
|
137
163
|
if (isPlaceholder) {
|
|
@@ -213,6 +239,7 @@ export var AiSessionEngine = /*#__PURE__*/function () {
|
|
|
213
239
|
// 无页面契约时为系统级交互,后端按 system 场景路由通用问答
|
|
214
240
|
scene: (_capability$scene = capability === null || capability === void 0 ? void 0 : capability.scene) !== null && _capability$scene !== void 0 ? _capability$scene : "system",
|
|
215
241
|
context: context,
|
|
242
|
+
history: history,
|
|
216
243
|
message: trimmed,
|
|
217
244
|
onEvent: handleEvent
|
|
218
245
|
});
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { AiContext, AiStreamEvent, AiTransport } from "./types";
|
|
1
|
+
import type { AiContext, AiHistoryMessage, AiStreamEvent, AiTransport } from "./types";
|
|
2
2
|
export interface MockAiTransportOptions {
|
|
3
3
|
/** 自定义应答脚本:返回流式帧序列;缺省使用内置通用问答脚本 */
|
|
4
4
|
respond?: (params: {
|
|
5
5
|
scene: string;
|
|
6
6
|
context?: AiContext;
|
|
7
|
+
/** 近 N 轮对话历史(不含本轮 message) */
|
|
8
|
+
history?: AiHistoryMessage[];
|
|
7
9
|
message: string;
|
|
8
10
|
}) => AiStreamEvent[];
|
|
9
11
|
/** 每帧间隔(ms),默认 120 */
|
|
@@ -20,6 +22,7 @@ export declare class MockAiTransport implements AiTransport {
|
|
|
20
22
|
send(params: {
|
|
21
23
|
scene: string;
|
|
22
24
|
context?: AiContext;
|
|
25
|
+
history?: AiHistoryMessage[];
|
|
23
26
|
message: string;
|
|
24
27
|
onEvent: (event: AiStreamEvent) => void;
|
|
25
28
|
}): void;
|
|
@@ -5,11 +5,18 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
5
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
7
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
/**
|
|
8
|
+
/** 内置通用问答脚本:页面未注册能力契约时的兜底回复(含思考过程演示) */
|
|
9
9
|
function defaultRespond(params) {
|
|
10
|
-
var _params$context;
|
|
10
|
+
var _params$context, _params$history$lengt, _params$history;
|
|
11
11
|
var title = (_params$context = params.context) === null || _params$context === void 0 ? void 0 : _params$context.sceneTitle;
|
|
12
|
+
var historyCount = (_params$history$lengt = (_params$history = params.history) === null || _params$history === void 0 ? void 0 : _params$history.length) !== null && _params$history$lengt !== void 0 ? _params$history$lengt : 0;
|
|
12
13
|
return [{
|
|
14
|
+
type: "thinking",
|
|
15
|
+
text: "先理解用户诉求,结合当前页面上下文判断意图。"
|
|
16
|
+
}, {
|
|
17
|
+
type: "thinking",
|
|
18
|
+
text: historyCount > 0 ? "\u7ED3\u5408\u6B64\u524D ".concat(historyCount, " \u8F6E\u5BF9\u8BDD\u5386\u53F2\u4E0E\u9875\u9762\u4FE1\u606F\uFF0C\u7EC4\u7EC7\u672C\u6B21\u56DE\u7B54\u3002") : "本轮暂无对话历史,基于页面上下文组织回答。"
|
|
19
|
+
}, {
|
|
13
20
|
type: "delta",
|
|
14
21
|
text: title ? "\u6536\u5230\uFF0C\u5F53\u524D\u4E3A[".concat(title, "]\u3002") : "收到。"
|
|
15
22
|
}, {
|
|
@@ -44,10 +51,12 @@ export var MockAiTransport = /*#__PURE__*/function () {
|
|
|
44
51
|
var events = (_this$options$respond = (_this$options$respond2 = (_this$options = this.options).respond) === null || _this$options$respond2 === void 0 ? void 0 : _this$options$respond2.call(_this$options, {
|
|
45
52
|
scene: params.scene,
|
|
46
53
|
context: params.context,
|
|
54
|
+
history: params.history,
|
|
47
55
|
message: params.message
|
|
48
56
|
})) !== null && _this$options$respond !== void 0 ? _this$options$respond : defaultRespond({
|
|
49
57
|
scene: params.scene,
|
|
50
58
|
context: params.context,
|
|
59
|
+
history: params.history,
|
|
51
60
|
message: params.message
|
|
52
61
|
});
|
|
53
62
|
var index = 0;
|
|
@@ -95,6 +95,8 @@ export interface AiMessage {
|
|
|
95
95
|
role: AiMessageRole;
|
|
96
96
|
/** 文本内容(流式期间为已累积文本) */
|
|
97
97
|
content: string;
|
|
98
|
+
/** 思考过程文本(thinking 帧累积;仅 assistant 消息,缺省表示本轮无思考内容) */
|
|
99
|
+
reasoning?: string;
|
|
98
100
|
/** 携带的结构化建议(仅 assistant 消息) */
|
|
99
101
|
suggestion?: AiSuggestion;
|
|
100
102
|
/** 建议是否已确认回填(已确认后芯片置为已完成态) */
|
|
@@ -119,10 +121,18 @@ export interface AiSession {
|
|
|
119
121
|
/** 内置版本栈(栈深 maxSnapshots,超出丢弃最旧) */
|
|
120
122
|
snapshots: AiSnapshot[];
|
|
121
123
|
}
|
|
124
|
+
/** 对话历史条目(发送给后端的精简消息结构,不含建议卡片/工具调用等面板专有字段) */
|
|
125
|
+
export interface AiHistoryMessage {
|
|
126
|
+
role: AiMessageRole;
|
|
127
|
+
content: string;
|
|
128
|
+
}
|
|
122
129
|
/** 流式帧(P1 为 mock;P2 与 SSE 网关帧结构对齐) */
|
|
123
130
|
export type AiStreamEvent = {
|
|
124
131
|
type: "delta";
|
|
125
132
|
text: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: "thinking";
|
|
135
|
+
text: string;
|
|
126
136
|
} | {
|
|
127
137
|
type: "action";
|
|
128
138
|
actionType: "backfill";
|
|
@@ -154,6 +164,8 @@ export interface AiTransport {
|
|
|
154
164
|
send(params: {
|
|
155
165
|
scene: string;
|
|
156
166
|
context?: AiContext;
|
|
167
|
+
/** 近 N 轮对话历史(不含本轮 message;引擎按 maxHistory 截断并过滤空内容) */
|
|
168
|
+
history?: AiHistoryMessage[];
|
|
157
169
|
message: string;
|
|
158
170
|
onEvent: (event: AiStreamEvent) => void;
|
|
159
171
|
}): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Chart } from "@antv/g2";
|
|
3
|
+
import type { G2Spec } from "@antv/g2";
|
|
4
|
+
export interface CompanyChartProps {
|
|
5
|
+
/** G2 5.x 图表描述配置(品牌主题已默认注入,可通过 options.theme 覆盖) */
|
|
6
|
+
options: G2Spec;
|
|
7
|
+
/** 容器高度(px),默认 320 */
|
|
8
|
+
height?: number;
|
|
9
|
+
/** 容器类名 */
|
|
10
|
+
className?: string;
|
|
11
|
+
/** 容器样式 */
|
|
12
|
+
style?: React.CSSProperties;
|
|
13
|
+
/** 图表渲染完成回调,返回 G2 Chart 实例(可用于事件绑定、实例方法调用) */
|
|
14
|
+
onReady?: (chart: Chart) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 图表 Chart:基于 AntV G2 5.x 的通用图表容器。
|
|
18
|
+
* 直接传入 G2 spec 即可渲染,品牌色板(category10/20)已默认注入。
|
|
19
|
+
*/
|
|
20
|
+
export declare const CompanyChart: React.ForwardRefExoticComponent<CompanyChartProps & React.RefAttributes<Chart>>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["theme"];
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
+
import React, { useEffect, useImperativeHandle, useRef } from "react";
|
|
11
|
+
import { Chart } from "@antv/g2";
|
|
12
|
+
import { companyChartTheme } from "./theme";
|
|
13
|
+
import { deepMerge } from "./utils";
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
/** 组装最终 spec:默认注入品牌主题,用户 theme 为对象时深度合并、为字符串时整体替换 */
|
|
16
|
+
var buildSpec = function buildSpec(options) {
|
|
17
|
+
var _ref = options,
|
|
18
|
+
theme = _ref.theme,
|
|
19
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
20
|
+
var mergedTheme = companyChartTheme;
|
|
21
|
+
if (typeof theme === "string") {
|
|
22
|
+
mergedTheme = theme;
|
|
23
|
+
} else if (theme) {
|
|
24
|
+
mergedTheme = deepMerge(companyChartTheme, theme);
|
|
25
|
+
}
|
|
26
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
27
|
+
theme: mergedTheme
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 图表 Chart:基于 AntV G2 5.x 的通用图表容器。
|
|
33
|
+
* 直接传入 G2 spec 即可渲染,品牌色板(category10/20)已默认注入。
|
|
34
|
+
*/
|
|
35
|
+
export var CompanyChart = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
36
|
+
var options = props.options,
|
|
37
|
+
_props$height = props.height,
|
|
38
|
+
height = _props$height === void 0 ? 320 : _props$height,
|
|
39
|
+
className = props.className,
|
|
40
|
+
style = props.style,
|
|
41
|
+
onReady = props.onReady;
|
|
42
|
+
var containerRef = useRef(null);
|
|
43
|
+
var chartRef = useRef(null);
|
|
44
|
+
var optionsRef = useRef(options);
|
|
45
|
+
var onReadyRef = useRef(onReady);
|
|
46
|
+
onReadyRef.current = onReady;
|
|
47
|
+
|
|
48
|
+
// 实例生命周期:仅创建与销毁,渲染统一由下方 effect 驱动
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
var container = containerRef.current;
|
|
51
|
+
if (!container) return undefined;
|
|
52
|
+
var chart = new Chart({
|
|
53
|
+
container: container,
|
|
54
|
+
autoFit: true
|
|
55
|
+
});
|
|
56
|
+
chartRef.current = chart;
|
|
57
|
+
return function () {
|
|
58
|
+
chart.destroy();
|
|
59
|
+
chartRef.current = null;
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
63
|
+
// 渲染/更新:依赖 options 变化
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
optionsRef.current = options;
|
|
66
|
+
var chart = chartRef.current;
|
|
67
|
+
if (!chart) return undefined;
|
|
68
|
+
var cancelled = false;
|
|
69
|
+
chart.options(buildSpec(options));
|
|
70
|
+
chart.render().then(function () {
|
|
71
|
+
var _onReadyRef$current;
|
|
72
|
+
if (!cancelled) (_onReadyRef$current = onReadyRef.current) === null || _onReadyRef$current === void 0 || _onReadyRef$current.call(onReadyRef, chart);
|
|
73
|
+
}).catch(function (error) {
|
|
74
|
+
console.error("[CompanyChart] 图表渲染失败:", error);
|
|
75
|
+
});
|
|
76
|
+
return function () {
|
|
77
|
+
cancelled = true;
|
|
78
|
+
};
|
|
79
|
+
}, [options]);
|
|
80
|
+
useImperativeHandle(ref, function () {
|
|
81
|
+
return chartRef.current;
|
|
82
|
+
}, []);
|
|
83
|
+
return /*#__PURE__*/_jsx("div", {
|
|
84
|
+
ref: containerRef,
|
|
85
|
+
className: className,
|
|
86
|
+
style: _objectSpread({
|
|
87
|
+
height: height
|
|
88
|
+
}, style)
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
CompanyChart.displayName = "CompanyChart";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { G2Spec } from "@antv/g2";
|
|
3
|
+
/** 图表数据项 */
|
|
4
|
+
export type CompanyChartDatum = Record<string, unknown>;
|
|
5
|
+
/** 预设图表通用覆盖配置(深度合并到内置 spec,优先级最高) */
|
|
6
|
+
type ChartOverrides = Omit<Partial<G2Spec>, "type" | "data">;
|
|
7
|
+
/** 预设图表通用 Props */
|
|
8
|
+
export interface CompanyPresetChartProps {
|
|
9
|
+
/** 数据源(扁平数组) */
|
|
10
|
+
data: CompanyChartDatum[];
|
|
11
|
+
/** 容器高度(px),默认 320 */
|
|
12
|
+
height?: number;
|
|
13
|
+
/** 容器类名 */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** 容器样式 */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
/** 覆盖 G2 配置(深度合并,优先级高于内置默认) */
|
|
18
|
+
options?: ChartOverrides;
|
|
19
|
+
}
|
|
20
|
+
export interface CompanyLineChartProps extends CompanyPresetChartProps {
|
|
21
|
+
/** x 编码字段 */
|
|
22
|
+
xField: string;
|
|
23
|
+
/** y 编码字段 */
|
|
24
|
+
yField: string;
|
|
25
|
+
/** 系列分组字段(多系列折线时配置) */
|
|
26
|
+
colorField?: string;
|
|
27
|
+
/** 是否平滑曲线,默认 false */
|
|
28
|
+
smooth?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface CompanyAreaChartProps extends CompanyPresetChartProps {
|
|
31
|
+
/** x 编码字段 */
|
|
32
|
+
xField: string;
|
|
33
|
+
/** y 编码字段 */
|
|
34
|
+
yField: string;
|
|
35
|
+
/** 系列分组字段(多系列面积时配置) */
|
|
36
|
+
colorField?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface CompanyBarChartProps extends CompanyPresetChartProps {
|
|
39
|
+
/** x 编码字段(分类轴) */
|
|
40
|
+
xField: string;
|
|
41
|
+
/** y 编码字段(数值轴) */
|
|
42
|
+
yField: string;
|
|
43
|
+
/** 系列分组字段(彩色柱时配置) */
|
|
44
|
+
colorField?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface CompanyGroupedBarChartProps extends CompanyPresetChartProps {
|
|
47
|
+
/** x 编码字段(分类轴) */
|
|
48
|
+
xField: string;
|
|
49
|
+
/** y 编码字段(数值轴) */
|
|
50
|
+
yField: string;
|
|
51
|
+
/** 分组字段(必填,决定柱子分组) */
|
|
52
|
+
colorField: string;
|
|
53
|
+
}
|
|
54
|
+
export interface CompanyStackedBarChartProps extends CompanyPresetChartProps {
|
|
55
|
+
/** x 编码字段(分类轴) */
|
|
56
|
+
xField: string;
|
|
57
|
+
/** y 编码字段(数值轴) */
|
|
58
|
+
yField: string;
|
|
59
|
+
/** 堆叠字段(必填,决定堆叠层级) */
|
|
60
|
+
colorField: string;
|
|
61
|
+
}
|
|
62
|
+
export interface CompanyPieChartProps extends CompanyPresetChartProps {
|
|
63
|
+
/** 分类(扇区名称)字段 */
|
|
64
|
+
colorField: string;
|
|
65
|
+
/** 扇区角度对应的数值字段 */
|
|
66
|
+
angleField: string;
|
|
67
|
+
/** 内半径比例(0~1),饼图默认 0 */
|
|
68
|
+
innerRadius?: number;
|
|
69
|
+
/** 外半径比例(0~1) */
|
|
70
|
+
outerRadius?: number;
|
|
71
|
+
}
|
|
72
|
+
export interface CompanyDonutChartProps extends CompanyPieChartProps {
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 折线图 LineChart
|
|
76
|
+
*/
|
|
77
|
+
export declare const CompanyLineChart: React.FC<CompanyLineChartProps>;
|
|
78
|
+
/**
|
|
79
|
+
* 面积图 AreaChart
|
|
80
|
+
*/
|
|
81
|
+
export declare const CompanyAreaChart: React.FC<CompanyAreaChartProps>;
|
|
82
|
+
/**
|
|
83
|
+
* 柱形图 BarChart
|
|
84
|
+
*/
|
|
85
|
+
export declare const CompanyBarChart: React.FC<CompanyBarChartProps>;
|
|
86
|
+
/**
|
|
87
|
+
* 分组柱形图 GroupedBarChart
|
|
88
|
+
*/
|
|
89
|
+
export declare const CompanyGroupedBarChart: React.FC<CompanyGroupedBarChartProps>;
|
|
90
|
+
/**
|
|
91
|
+
* 堆叠柱形图 StackedBarChart
|
|
92
|
+
*/
|
|
93
|
+
export declare const CompanyStackedBarChart: React.FC<CompanyStackedBarChartProps>;
|
|
94
|
+
/**
|
|
95
|
+
* 饼图 PieChart
|
|
96
|
+
*/
|
|
97
|
+
export declare const CompanyPieChart: React.FC<CompanyPieChartProps>;
|
|
98
|
+
/**
|
|
99
|
+
* 环形图 DonutChart
|
|
100
|
+
*/
|
|
101
|
+
export declare const CompanyDonutChart: React.FC<CompanyDonutChartProps>;
|
|
102
|
+
export {};
|