@qy_better_lib/hooks 0.2.5 → 0.2.7

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.
@@ -1,7 +1,80 @@
1
1
  import { onUnmounted } from "vue";
2
- import { deep_assign, deep_clone } from "@qy_better_lib/core";
3
- import { destroy_chart, auto_size, 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
- import options from "./use-chart/config.js";
2
+ import { auto_size, deep_assign, deep_clone } from "@qy_better_lib/core";
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 "@qy_better_lib/core/echarts";
4
+ const options = {
5
+ textStyle: {
6
+ fontSize: auto_size(12),
7
+ fontFamily: "Helvetica Neue, Arial, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif"
8
+ },
9
+ color: [],
10
+ title: {
11
+ textStyle: {
12
+ fontSize: auto_size(14)
13
+ }
14
+ },
15
+ legend: {
16
+ icon: "rect",
17
+ itemHeight: auto_size(12),
18
+ itemWidth: auto_size(12),
19
+ textStyle: { color: "#606266", fontSize: auto_size(12) },
20
+ itemStyle: {
21
+ shadowColor: "rgba(161, 163, 170, 0.25)",
22
+ shadowBlur: auto_size(4),
23
+ shadowOffsetX: auto_size(4),
24
+ shadowOffsetY: auto_size(4)
25
+ }
26
+ },
27
+ tooltip: {
28
+ trigger: "axis",
29
+ axisPointer: {
30
+ lineStyle: {
31
+ color: "#D4D9E2",
32
+ width: auto_size(1)
33
+ }
34
+ },
35
+ backgroundColor: "rgba(0,0,0,0.6)",
36
+ textStyle: {
37
+ color: "#fff",
38
+ fontWeight: 400,
39
+ width: auto_size(10),
40
+ height: auto_size(10),
41
+ fontSize: auto_size(12)
42
+ },
43
+ borderWidth: 0,
44
+ padding: [auto_size(8), auto_size(16)],
45
+ formatter: "{a}<br/>{b}: {c}"
46
+ },
47
+ xAxis: {
48
+ axisLine: {
49
+ lineStyle: { color: "#D4D9E2", width: auto_size(1) }
50
+ },
51
+ axisLabel: { color: "#606266", fontSize: auto_size(12) },
52
+ nameTextStyle: { color: "#606266", fontSize: auto_size(12) },
53
+ splitLine: {
54
+ show: false,
55
+ lineStyle: {
56
+ color: "#EBECEF",
57
+ type: "dashed",
58
+ width: auto_size(1)
59
+ }
60
+ }
61
+ },
62
+ yAxis: {
63
+ axisLine: {
64
+ show: false,
65
+ lineStyle: { color: "#D4D9E2", width: auto_size(1) }
66
+ },
67
+ axisLabel: { color: "#606266", fontSize: auto_size(12) },
68
+ nameTextStyle: { color: "#606266", fontSize: auto_size(12) },
69
+ splitLine: {
70
+ lineStyle: {
71
+ color: "#EBECEF",
72
+ type: "dashed",
73
+ width: auto_size(1)
74
+ }
75
+ }
76
+ }
77
+ };
5
78
  function get_chart_theme(theme) {
6
79
  {
7
80
  return {
@@ -188,8 +261,7 @@ function use_chart(options$1 = {}) {
188
261
  get_chart_gradient_color,
189
262
  export_chart_image: export_chart_image_wrapper,
190
263
  add_chart_listener: add_chart_listener_wrapper,
191
- remove_chart_listener: remove_chart_listener_wrapper,
192
- auto_size
264
+ remove_chart_listener: remove_chart_listener_wrapper
193
265
  };
194
266
  }
195
267
  export {
@@ -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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qy_better_lib/hooks",
3
3
  "private": false,
4
- "version": "0.2.5",
4
+ "version": "0.2.7",
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.5",
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",
@@ -97,5 +97,8 @@
97
97
  "@qy_better_lib/core": {
98
98
  "optional": false
99
99
  }
100
+ },
101
+ "dependencies": {
102
+ "@qy_better_lib/hooks": "^0.2.6"
100
103
  }
101
104
  }
package/lib/index.js DELETED
@@ -1,16 +0,0 @@
1
- import { use_emit } from "./use-emit/index.js";
2
- import { use_print } from "./use-print/index.js";
3
- import { use_water_mark } from "./use-watermark/index.js";
4
- import { use_web_socket } from "./use-websocket/index.js";
5
- import { use_image } from "./use-image/index.js";
6
- import { use_fullscreen } from "./use-fullscreen/index.js";
7
- import { EImageType } from "./use-image/type.js";
8
- export {
9
- EImageType,
10
- use_emit,
11
- use_fullscreen,
12
- use_image,
13
- use_print,
14
- use_water_mark,
15
- use_web_socket
16
- };
@@ -1,166 +0,0 @@
1
- function auto_size(size, deflate_width = 1920) {
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
- }
7
- function get_chart_gradient_color(type, start_color, end_color) {
8
- return {
9
- type: "linear",
10
- x: 0,
11
- y: 0,
12
- x2: type === "v" ? 0 : 1,
13
- y2: type === "v" ? 1 : 0,
14
- colorStops: [
15
- {
16
- offset: 0,
17
- color: start_color
18
- // 0% 处的颜色
19
- },
20
- {
21
- offset: 1,
22
- color: end_color
23
- // 100% 处的颜色
24
- }
25
- ]
26
- };
27
- }
28
- function init_chart(container, options, renderer = "canvas", theme) {
29
- const load_echarts = async () => {
30
- try {
31
- let echarts;
32
- if (typeof window !== "undefined" && window.echarts) {
33
- echarts = window.echarts;
34
- } else {
35
- const imported = await import("echarts");
36
- echarts = imported.default || imported;
37
- }
38
- const chart_dom = typeof container === "string" ? document.getElementById(container) : container;
39
- if (!chart_dom) {
40
- console.error("ECharts DOM容器未找到");
41
- return null;
42
- }
43
- const chart = echarts.init(chart_dom, theme, {
44
- renderer
45
- });
46
- if (options) {
47
- chart.setOption(options);
48
- }
49
- return chart;
50
- } catch (error) {
51
- console.error("加载 ECharts 失败:", error);
52
- return null;
53
- }
54
- };
55
- return load_echarts();
56
- }
57
- function destroy_chart(chart) {
58
- if (chart && typeof chart.dispose === "function") {
59
- chart.dispose();
60
- }
61
- }
62
- function update_chart(chart, options) {
63
- if (chart && typeof chart.setOption === "function") {
64
- chart.setOption(options);
65
- }
66
- }
67
- function resize_chart(chart) {
68
- if (chart && typeof chart.resize === "function") {
69
- chart.resize();
70
- }
71
- }
72
- function make_chart_responsive(chart, debounce_time = 200) {
73
- if (!chart) return;
74
- let resize_timer;
75
- const resize_handler = () => {
76
- clearTimeout(resize_timer);
77
- resize_timer = setTimeout(() => {
78
- resize_chart(chart);
79
- }, debounce_time);
80
- };
81
- window.addEventListener("resize", resize_handler);
82
- return () => {
83
- window.removeEventListener("resize", resize_handler);
84
- clearTimeout(resize_timer);
85
- };
86
- }
87
- function generate_chart_colors(count, base_colors) {
88
- const default_colors = [
89
- "#5470c6",
90
- "#91cc75",
91
- "#fac858",
92
- "#ee6666",
93
- "#73c0de",
94
- "#3ba272",
95
- "#fc8452",
96
- "#9a60b4",
97
- "#ea7ccc",
98
- "#67c23a"
99
- ];
100
- const colors = base_colors || default_colors;
101
- const result = [];
102
- for (let i = 0; i < count; i++) {
103
- result.push(colors[i % colors.length]);
104
- }
105
- return result;
106
- }
107
- function merge_chart_options(defaultOption, customOption) {
108
- return {
109
- ...defaultOption,
110
- ...customOption,
111
- // 特殊处理数组类型的配置
112
- series: customOption.series || defaultOption.series,
113
- xAxis: customOption.xAxis || defaultOption.xAxis,
114
- yAxis: customOption.yAxis || defaultOption.yAxis,
115
- legend: customOption.legend || defaultOption.legend,
116
- tooltip: customOption.tooltip || defaultOption.tooltip,
117
- title: customOption.title || defaultOption.title
118
- };
119
- }
120
- function add_chart_listener(chart, eventName, handler) {
121
- if (chart && typeof chart.on === "function") {
122
- chart.on(eventName, handler);
123
- }
124
- }
125
- function remove_chart_listener(chart, eventName, handler) {
126
- if (chart && typeof chart.off === "function") {
127
- chart.off(eventName, handler);
128
- }
129
- }
130
- function export_chart_image(chart, options = {}) {
131
- if (!chart || typeof chart.getDataURL !== "function") {
132
- return null;
133
- }
134
- const {
135
- type = "png",
136
- pixel_ratio = 2,
137
- background_color = "#fff",
138
- exclude_components = [],
139
- file_name = "echarts-image"
140
- } = options;
141
- const data_url = chart.getDataURL({
142
- type,
143
- pixelRatio: pixel_ratio,
144
- backgroundColor: background_color,
145
- excludeComponents: exclude_components
146
- });
147
- const link = document.createElement("a");
148
- link.download = `${file_name}.${type}`;
149
- link.href = data_url;
150
- link.click();
151
- return data_url;
152
- }
153
- export {
154
- add_chart_listener,
155
- auto_size,
156
- destroy_chart,
157
- export_chart_image,
158
- generate_chart_colors,
159
- get_chart_gradient_color,
160
- init_chart,
161
- make_chart_responsive,
162
- merge_chart_options,
163
- remove_chart_listener,
164
- resize_chart,
165
- update_chart
166
- };
@@ -1,78 +0,0 @@
1
- import { auto_size } from "../node_modules/@qy_better_lib/core/lib/utils/echarts.js";
2
- const options = {
3
- textStyle: {
4
- fontSize: auto_size(12),
5
- fontFamily: "Helvetica Neue, Arial, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, sans-serif"
6
- },
7
- color: [],
8
- title: {
9
- textStyle: {
10
- fontSize: auto_size(14)
11
- }
12
- },
13
- legend: {
14
- icon: "rect",
15
- itemHeight: auto_size(12),
16
- itemWidth: auto_size(12),
17
- textStyle: { color: "#606266", fontSize: auto_size(12) },
18
- itemStyle: {
19
- shadowColor: "rgba(161, 163, 170, 0.25)",
20
- shadowBlur: auto_size(4),
21
- shadowOffsetX: auto_size(4),
22
- shadowOffsetY: auto_size(4)
23
- }
24
- },
25
- tooltip: {
26
- trigger: "axis",
27
- axisPointer: {
28
- lineStyle: {
29
- color: "#D4D9E2",
30
- width: auto_size(1)
31
- }
32
- },
33
- backgroundColor: "rgba(0,0,0,0.6)",
34
- textStyle: {
35
- color: "#fff",
36
- fontWeight: 400,
37
- width: auto_size(10),
38
- height: auto_size(10),
39
- fontSize: auto_size(12)
40
- },
41
- borderWidth: 0,
42
- padding: [auto_size(8), auto_size(16)],
43
- formatter: "{a}<br/>{b}: {c}"
44
- },
45
- xAxis: {
46
- axisLine: {
47
- lineStyle: { color: "#D4D9E2", width: auto_size(1) }
48
- },
49
- axisLabel: { color: "#606266", fontSize: auto_size(12) },
50
- nameTextStyle: { color: "#606266", fontSize: auto_size(12) },
51
- splitLine: {
52
- show: false,
53
- lineStyle: {
54
- color: "#EBECEF",
55
- type: "dashed",
56
- width: auto_size(1)
57
- }
58
- }
59
- },
60
- yAxis: {
61
- axisLine: {
62
- show: false,
63
- lineStyle: { color: "#D4D9E2", width: auto_size(1) }
64
- },
65
- axisLabel: { color: "#606266", fontSize: auto_size(12) },
66
- nameTextStyle: { color: "#606266", fontSize: auto_size(12) },
67
- splitLine: {
68
- lineStyle: {
69
- color: "#EBECEF",
70
- type: "dashed",
71
- width: auto_size(1)
72
- }
73
- }
74
- }
75
- };
76
- export {
77
- options as default
78
- };
@@ -1,42 +0,0 @@
1
- import mitt from "mitt";
2
- function createAsyncEmitter() {
3
- if (typeof mitt === "undefined") {
4
- return {};
5
- }
6
- const emitter = mitt();
7
- emitter.emitAsync = async function(type, ...args) {
8
- const handlers = this.all?.get(type);
9
- if (!handlers || handlers.length === 0) {
10
- return [];
11
- }
12
- const promises = handlers.map((handler) => {
13
- try {
14
- const result = handler(...args);
15
- return result instanceof Promise ? result : Promise.resolve(result);
16
- } catch (error) {
17
- return Promise.reject(error);
18
- }
19
- });
20
- return Promise.all(promises);
21
- };
22
- emitter.emit;
23
- emitter.emit = function(type, ...args) {
24
- const handlers = this.all?.get(type);
25
- if (!handlers || handlers.length === 0) {
26
- return void 0;
27
- }
28
- let lastResult;
29
- handlers.forEach((handler) => {
30
- try {
31
- lastResult = handler(...args);
32
- } catch (error) {
33
- console.error(`Error in event handler for ${type}:`, error);
34
- }
35
- });
36
- return lastResult;
37
- };
38
- return emitter;
39
- }
40
- export {
41
- createAsyncEmitter
42
- };
@@ -1,27 +0,0 @@
1
- import mitt from "mitt";
2
- import { onMounted, onUnmounted } from "vue";
3
- import { createAsyncEmitter } from "./extend.js";
4
- const emitter = createAsyncEmitter();
5
- function use_emit(event_list) {
6
- if (typeof mitt === "undefined") return { emitter: {} };
7
- onMounted(() => {
8
- if (event_list && event_list.length > 0) {
9
- for (const event of event_list) {
10
- emitter.on(event.key, event.value);
11
- }
12
- }
13
- });
14
- onUnmounted(() => {
15
- if (event_list && event_list.length > 0) {
16
- for (const event of event_list) {
17
- emitter.off(event.key, event.value);
18
- }
19
- }
20
- });
21
- return {
22
- emitter
23
- };
24
- }
25
- export {
26
- use_emit
27
- };
@@ -1,51 +0,0 @@
1
- import { ref, shallowRef, onMounted, onUnmounted } from "vue";
2
- import { get_element, on, off } from "@qy_better_lib/core";
3
- function use_fullscreen(selector) {
4
- const full = ref(false);
5
- const container = shallowRef(null);
6
- function fullscreen_change() {
7
- full.value = document.fullscreenElement === container.value;
8
- }
9
- onMounted(() => {
10
- container.value = get_element(selector);
11
- if (container.value) {
12
- on(container.value, "fullscreenchange", fullscreen_change);
13
- }
14
- });
15
- onUnmounted(() => {
16
- if (container.value) {
17
- off(container.value, "fullscreenchange", fullscreen_change);
18
- }
19
- });
20
- function enter_fullscreen() {
21
- if (!full.value && container.value?.requestFullscreen) {
22
- container.value.requestFullscreen().catch((error) => {
23
- console.error("进入全屏失败:", error);
24
- });
25
- }
26
- }
27
- function exit_fullscreen() {
28
- if (document.exitFullscreen) {
29
- document.exitFullscreen().catch((error) => {
30
- console.error("退出全屏失败:", error);
31
- });
32
- }
33
- }
34
- function toggle_fullscreen() {
35
- if (full.value) {
36
- exit_fullscreen();
37
- } else {
38
- enter_fullscreen();
39
- }
40
- }
41
- return {
42
- container,
43
- full,
44
- toggle_fullscreen,
45
- enter_fullscreen,
46
- exit_fullscreen
47
- };
48
- }
49
- export {
50
- use_fullscreen
51
- };