@qy_better_lib/hooks 0.2.5 → 0.2.6
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/DOCUMENTATION.md +18 -12
- package/lib/node_modules/@qy_better_lib/core/lib/utils/dom.js +14 -0
- package/lib/node_modules/@qy_better_lib/core/lib/utils/echarts.js +3 -9
- package/lib/use-chart/config.js +1 -1
- package/lib/use-chart/type.d.ts +0 -7
- package/lib/use-chart.js +2 -3
- package/package.json +2 -2
package/DOCUMENTATION.md
CHANGED
|
@@ -256,6 +256,8 @@ close();
|
|
|
256
256
|
|
|
257
257
|
### 5. use-mqtt - MQTT功能
|
|
258
258
|
|
|
259
|
+
> 注意:MQTT功能现在是可选依赖,需要单独导入
|
|
260
|
+
|
|
259
261
|
#### 功能描述
|
|
260
262
|
适用于需要MQTT通信的场景,支持连接管理、消息订阅和发布。
|
|
261
263
|
|
|
@@ -273,7 +275,7 @@ close();
|
|
|
273
275
|
|
|
274
276
|
#### 示例
|
|
275
277
|
```typescript
|
|
276
|
-
import { use_mqtt } from '@qy_better_lib/hooks';
|
|
278
|
+
import { use_mqtt } from '@qy_better_lib/hooks/use-mqtt';
|
|
277
279
|
|
|
278
280
|
const { connect, close, subscribe, publish } = use_mqtt('mqtt://localhost:1883', {
|
|
279
281
|
clientId: 'test-client',
|
|
@@ -389,6 +391,8 @@ close(() => {
|
|
|
389
391
|
|
|
390
392
|
### 7. use-chart - 图表管理
|
|
391
393
|
|
|
394
|
+
> 注意:图表管理功能现在是可选依赖,需要单独导入
|
|
395
|
+
|
|
392
396
|
#### 功能描述
|
|
393
397
|
适用于需要在前端使用ECharts的场景,支持图表渲染、主题切换、响应式设计等功能。
|
|
394
398
|
|
|
@@ -406,7 +410,7 @@ close(() => {
|
|
|
406
410
|
- **返回类型**: `Promise<any>` - 图表实例
|
|
407
411
|
- **示例**:
|
|
408
412
|
```typescript
|
|
409
|
-
import { use_chart } from '@qy_better_lib/hooks';
|
|
413
|
+
import { use_chart } from '@qy_better_lib/hooks/use-chart';
|
|
410
414
|
|
|
411
415
|
const { render_chart } = use_chart();
|
|
412
416
|
|
|
@@ -437,7 +441,7 @@ close(() => {
|
|
|
437
441
|
- **返回类型**: `boolean` - 是否更新成功
|
|
438
442
|
- **示例**:
|
|
439
443
|
```typescript
|
|
440
|
-
import { use_chart } from '@qy_better_lib/hooks';
|
|
444
|
+
import { use_chart } from '@qy_better_lib/hooks/use-chart';
|
|
441
445
|
|
|
442
446
|
const { update_chart } = use_chart();
|
|
443
447
|
|
|
@@ -457,7 +461,7 @@ close(() => {
|
|
|
457
461
|
- **返回类型**: `boolean` - 是否删除成功
|
|
458
462
|
- **示例**:
|
|
459
463
|
```typescript
|
|
460
|
-
import { use_chart } from '@qy_better_lib/hooks';
|
|
464
|
+
import { use_chart } from '@qy_better_lib/hooks/use-chart';
|
|
461
465
|
|
|
462
466
|
const { remove_chart } = use_chart();
|
|
463
467
|
|
|
@@ -473,7 +477,7 @@ close(() => {
|
|
|
473
477
|
- **返回类型**: `string | null` - 图片URL
|
|
474
478
|
- **示例**:
|
|
475
479
|
```typescript
|
|
476
|
-
import { use_chart } from '@qy_better_lib/hooks';
|
|
480
|
+
import { use_chart } from '@qy_better_lib/hooks/use-chart';
|
|
477
481
|
|
|
478
482
|
const { export_chart_image } = use_chart();
|
|
479
483
|
|
|
@@ -483,6 +487,8 @@ close(() => {
|
|
|
483
487
|
|
|
484
488
|
### 8. use-layout-flow - 流程图布局
|
|
485
489
|
|
|
490
|
+
> 注意:流程图布局功能现在是可选依赖,需要单独导入
|
|
491
|
+
|
|
486
492
|
#### 功能描述
|
|
487
493
|
适用于需要自动布局的流程图场景,支持多种布局方向和自定义元素。
|
|
488
494
|
|
|
@@ -498,7 +504,7 @@ close(() => {
|
|
|
498
504
|
- **返回类型**: `Promise<boolean>` - 是否初始化成功
|
|
499
505
|
- **示例**:
|
|
500
506
|
```typescript
|
|
501
|
-
import { use_layout_flow } from '@qy_better_lib/hooks';
|
|
507
|
+
import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow';
|
|
502
508
|
|
|
503
509
|
const { init } = use_layout_flow({});
|
|
504
510
|
|
|
@@ -515,7 +521,7 @@ close(() => {
|
|
|
515
521
|
- **返回类型**: `Promise<boolean>` - 是否布局成功
|
|
516
522
|
- **示例**:
|
|
517
523
|
```typescript
|
|
518
|
-
import { use_layout_flow } from '@qy_better_lib/hooks';
|
|
524
|
+
import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow';
|
|
519
525
|
|
|
520
526
|
const { layout } = use_layout_flow({});
|
|
521
527
|
|
|
@@ -535,7 +541,7 @@ close(() => {
|
|
|
535
541
|
- **返回类型**: `any[]` - 创建的节点数组
|
|
536
542
|
- **示例**:
|
|
537
543
|
```typescript
|
|
538
|
-
import { use_layout_flow } from '@qy_better_lib/hooks';
|
|
544
|
+
import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow';
|
|
539
545
|
|
|
540
546
|
const { create_nodes } = use_layout_flow({});
|
|
541
547
|
|
|
@@ -567,7 +573,7 @@ close(() => {
|
|
|
567
573
|
- **返回类型**: `any[]` - 创建的边数组
|
|
568
574
|
- **示例**:
|
|
569
575
|
```typescript
|
|
570
|
-
import { use_layout_flow } from '@qy_better_lib/hooks';
|
|
576
|
+
import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow';
|
|
571
577
|
|
|
572
578
|
const { create_edges } = use_layout_flow({});
|
|
573
579
|
|
|
@@ -670,8 +676,8 @@ close();
|
|
|
670
676
|
|
|
671
677
|
## 注意事项
|
|
672
678
|
|
|
673
|
-
1. **use-chart**
|
|
674
|
-
2. **use-layout-flow**
|
|
675
|
-
3. **use-mqtt**
|
|
679
|
+
1. **use-chart** 现在是可选依赖,需要单独导入:`import { use_chart } from '@qy_better_lib/hooks/use-chart'`,并需要安装 ECharts 依赖:`npm install echarts`
|
|
680
|
+
2. **use-layout-flow** 现在是可选依赖,需要单独导入:`import { use_layout_flow } from '@qy_better_lib/hooks/use-layout-flow'`,并需要安装 @antv/x6 和 dagre 依赖:`npm install @antv/x6 dagre`
|
|
681
|
+
3. **use-mqtt** 现在是可选依赖,需要单独导入:`import { use_mqtt } from '@qy_better_lib/hooks/use-mqtt'`,并需要安装 mqtt 依赖:`npm install mqtt`
|
|
676
682
|
4. **use-websocket** 需要确保服务器端支持 WebSocket 协议
|
|
677
683
|
5. **use-print** 在某些浏览器中可能存在兼容性问题,建议在现代浏览器中使用
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function on(element, event, handler, options) {
|
|
2
|
+
if (element) {
|
|
3
|
+
element.addEventListener(event, handler, options);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function off(element, event, handler, options) {
|
|
7
|
+
if (element) {
|
|
8
|
+
element.removeEventListener(event, handler, options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
off,
|
|
13
|
+
on
|
|
14
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
let client_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
3
|
-
if (!client_width) return size;
|
|
4
|
-
let scale = client_width / deflate_width;
|
|
5
|
-
return Number((size * scale).toFixed(3));
|
|
6
|
-
}
|
|
1
|
+
import { on, off } from "./dom.js";
|
|
7
2
|
function get_chart_gradient_color(type, start_color, end_color) {
|
|
8
3
|
return {
|
|
9
4
|
type: "linear",
|
|
@@ -78,9 +73,9 @@ function make_chart_responsive(chart, debounce_time = 200) {
|
|
|
78
73
|
resize_chart(chart);
|
|
79
74
|
}, debounce_time);
|
|
80
75
|
};
|
|
81
|
-
window
|
|
76
|
+
on(window, "resize", resize_handler);
|
|
82
77
|
return () => {
|
|
83
|
-
window
|
|
78
|
+
off(window, "resize", resize_handler);
|
|
84
79
|
clearTimeout(resize_timer);
|
|
85
80
|
};
|
|
86
81
|
}
|
|
@@ -152,7 +147,6 @@ function export_chart_image(chart, options = {}) {
|
|
|
152
147
|
}
|
|
153
148
|
export {
|
|
154
149
|
add_chart_listener,
|
|
155
|
-
auto_size,
|
|
156
150
|
destroy_chart,
|
|
157
151
|
export_chart_image,
|
|
158
152
|
generate_chart_colors,
|
package/lib/use-chart/config.js
CHANGED
package/lib/use-chart/type.d.ts
CHANGED
|
@@ -82,11 +82,4 @@ export interface UseChartReturn {
|
|
|
82
82
|
* @param handler 事件处理函数
|
|
83
83
|
*/
|
|
84
84
|
remove_chart_listener: (dom_id: string, event_name: string, handler: (...args: any[]) => void) => void;
|
|
85
|
-
/**
|
|
86
|
-
* 图表字体、间距自适应
|
|
87
|
-
* @param size 原始尺寸
|
|
88
|
-
* @param deflate_width 基准宽度
|
|
89
|
-
* @returns 自适应后的尺寸
|
|
90
|
-
*/
|
|
91
|
-
auto_size: (size: number, deflate_width?: number) => number;
|
|
92
85
|
}
|
package/lib/use-chart.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { onUnmounted } from "vue";
|
|
2
2
|
import { deep_assign, deep_clone } from "@qy_better_lib/core";
|
|
3
|
-
import { destroy_chart,
|
|
3
|
+
import { destroy_chart, get_chart_gradient_color, generate_chart_colors, remove_chart_listener, add_chart_listener, export_chart_image, resize_chart, merge_chart_options, update_chart, init_chart, make_chart_responsive } from "./node_modules/@qy_better_lib/core/lib/utils/echarts.js";
|
|
4
4
|
import options from "./use-chart/config.js";
|
|
5
5
|
function get_chart_theme(theme) {
|
|
6
6
|
{
|
|
@@ -188,8 +188,7 @@ function use_chart(options$1 = {}) {
|
|
|
188
188
|
get_chart_gradient_color,
|
|
189
189
|
export_chart_image: export_chart_image_wrapper,
|
|
190
190
|
add_chart_listener: add_chart_listener_wrapper,
|
|
191
|
-
remove_chart_listener: remove_chart_listener_wrapper
|
|
192
|
-
auto_size
|
|
191
|
+
remove_chart_listener: remove_chart_listener_wrapper
|
|
193
192
|
};
|
|
194
193
|
}
|
|
195
194
|
export {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qy_better_lib/hooks",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.6",
|
|
5
5
|
"description": "qy better lib hooks",
|
|
6
6
|
"author": "luhuiming",
|
|
7
7
|
"license": "MIT",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@antv/x6": "^2.18.1",
|
|
59
|
-
"@qy_better_lib/core": "^0.2.
|
|
59
|
+
"@qy_better_lib/core": "^0.2.6",
|
|
60
60
|
"@types/dagre": "^0.7.53",
|
|
61
61
|
"@types/node": "^24.5.2",
|
|
62
62
|
"@vitejs/plugin-vue": "^6.0.1",
|