@qy_better_lib/hooks 0.2.6 → 0.2.8
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 +0 -49
- package/lib/index.mjs +935 -0
- package/lib/{use-chart.js → use-chart/index.mjs} +76 -3
- package/package.json +12 -9
- package/lib/index.js +0 -16
- package/lib/node_modules/@qy_better_lib/core/lib/utils/dom.js +0 -14
- package/lib/node_modules/@qy_better_lib/core/lib/utils/echarts.js +0 -160
- package/lib/use-chart/config.js +0 -78
- package/lib/use-emit/extend.js +0 -42
- package/lib/use-emit/index.js +0 -27
- package/lib/use-fullscreen/index.js +0 -51
- package/lib/use-image/index.js +0 -192
- package/lib/use-image/type.js +0 -9
- package/lib/use-print/index.js +0 -301
- package/lib/use-watermark/index.js +0 -131
- package/lib/use-websocket/index.js +0 -205
- /package/lib/{use-layout-flow.js → use-layout-flow/index.mjs} +0 -0
- /package/lib/{use-mqtt.js → use-mqtt/index.mjs} +0 -0
|
@@ -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, 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 "
|
|
4
|
-
|
|
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 {
|
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.8",
|
|
5
5
|
"description": "qy better lib hooks",
|
|
6
6
|
"author": "luhuiming",
|
|
7
7
|
"license": "MIT",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"test": "vitest run",
|
|
13
13
|
"test:watch": "vitest"
|
|
14
14
|
},
|
|
15
|
-
"main": "lib/index.
|
|
16
|
-
"module": "lib/index.
|
|
15
|
+
"main": "lib/index.mjs",
|
|
16
|
+
"module": "lib/index.mjs",
|
|
17
17
|
"types": "lib/index.d.ts",
|
|
18
18
|
"typesVersions": {
|
|
19
19
|
"*": {
|
|
20
|
-
"lib/index.
|
|
20
|
+
"lib/index.mjs": [
|
|
21
21
|
"lib/index.d.ts"
|
|
22
22
|
],
|
|
23
23
|
"@qy-better-lib/hooks": [
|
|
@@ -34,23 +34,23 @@
|
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
|
-
"import": "./lib/index.
|
|
37
|
+
"import": "./lib/index.mjs",
|
|
38
38
|
"types": "./lib/index.d.ts"
|
|
39
39
|
},
|
|
40
40
|
"./*": {
|
|
41
|
-
"import": "./lib/*/index.
|
|
41
|
+
"import": "./lib/*/index.mjs",
|
|
42
42
|
"types": "./lib/*/index.d.ts"
|
|
43
43
|
},
|
|
44
44
|
"./use-chart": {
|
|
45
|
-
"import": "./lib/use-chart/index.
|
|
45
|
+
"import": "./lib/use-chart/index.mjs",
|
|
46
46
|
"types": "./lib/use-chart/index.d.ts"
|
|
47
47
|
},
|
|
48
48
|
"./use-layout-flow": {
|
|
49
|
-
"import": "./lib/use-layout-flow/index.
|
|
49
|
+
"import": "./lib/use-layout-flow/index.mjs",
|
|
50
50
|
"types": "./lib/use-layout-flow/index.d.ts"
|
|
51
51
|
},
|
|
52
52
|
"./use-mqtt": {
|
|
53
|
-
"import": "./lib/use-mqtt/index.
|
|
53
|
+
"import": "./lib/use-mqtt/index.mjs",
|
|
54
54
|
"types": "./lib/use-mqtt/index.d.ts"
|
|
55
55
|
}
|
|
56
56
|
},
|
|
@@ -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,14 +0,0 @@
|
|
|
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,160 +0,0 @@
|
|
|
1
|
-
import { on, off } from "./dom.js";
|
|
2
|
-
function get_chart_gradient_color(type, start_color, end_color) {
|
|
3
|
-
return {
|
|
4
|
-
type: "linear",
|
|
5
|
-
x: 0,
|
|
6
|
-
y: 0,
|
|
7
|
-
x2: type === "v" ? 0 : 1,
|
|
8
|
-
y2: type === "v" ? 1 : 0,
|
|
9
|
-
colorStops: [
|
|
10
|
-
{
|
|
11
|
-
offset: 0,
|
|
12
|
-
color: start_color
|
|
13
|
-
// 0% 处的颜色
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
offset: 1,
|
|
17
|
-
color: end_color
|
|
18
|
-
// 100% 处的颜色
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function init_chart(container, options, renderer = "canvas", theme) {
|
|
24
|
-
const load_echarts = async () => {
|
|
25
|
-
try {
|
|
26
|
-
let echarts;
|
|
27
|
-
if (typeof window !== "undefined" && window.echarts) {
|
|
28
|
-
echarts = window.echarts;
|
|
29
|
-
} else {
|
|
30
|
-
const imported = await import("echarts");
|
|
31
|
-
echarts = imported.default || imported;
|
|
32
|
-
}
|
|
33
|
-
const chart_dom = typeof container === "string" ? document.getElementById(container) : container;
|
|
34
|
-
if (!chart_dom) {
|
|
35
|
-
console.error("ECharts DOM容器未找到");
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const chart = echarts.init(chart_dom, theme, {
|
|
39
|
-
renderer
|
|
40
|
-
});
|
|
41
|
-
if (options) {
|
|
42
|
-
chart.setOption(options);
|
|
43
|
-
}
|
|
44
|
-
return chart;
|
|
45
|
-
} catch (error) {
|
|
46
|
-
console.error("加载 ECharts 失败:", error);
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return load_echarts();
|
|
51
|
-
}
|
|
52
|
-
function destroy_chart(chart) {
|
|
53
|
-
if (chart && typeof chart.dispose === "function") {
|
|
54
|
-
chart.dispose();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function update_chart(chart, options) {
|
|
58
|
-
if (chart && typeof chart.setOption === "function") {
|
|
59
|
-
chart.setOption(options);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function resize_chart(chart) {
|
|
63
|
-
if (chart && typeof chart.resize === "function") {
|
|
64
|
-
chart.resize();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function make_chart_responsive(chart, debounce_time = 200) {
|
|
68
|
-
if (!chart) return;
|
|
69
|
-
let resize_timer;
|
|
70
|
-
const resize_handler = () => {
|
|
71
|
-
clearTimeout(resize_timer);
|
|
72
|
-
resize_timer = setTimeout(() => {
|
|
73
|
-
resize_chart(chart);
|
|
74
|
-
}, debounce_time);
|
|
75
|
-
};
|
|
76
|
-
on(window, "resize", resize_handler);
|
|
77
|
-
return () => {
|
|
78
|
-
off(window, "resize", resize_handler);
|
|
79
|
-
clearTimeout(resize_timer);
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function generate_chart_colors(count, base_colors) {
|
|
83
|
-
const default_colors = [
|
|
84
|
-
"#5470c6",
|
|
85
|
-
"#91cc75",
|
|
86
|
-
"#fac858",
|
|
87
|
-
"#ee6666",
|
|
88
|
-
"#73c0de",
|
|
89
|
-
"#3ba272",
|
|
90
|
-
"#fc8452",
|
|
91
|
-
"#9a60b4",
|
|
92
|
-
"#ea7ccc",
|
|
93
|
-
"#67c23a"
|
|
94
|
-
];
|
|
95
|
-
const colors = base_colors || default_colors;
|
|
96
|
-
const result = [];
|
|
97
|
-
for (let i = 0; i < count; i++) {
|
|
98
|
-
result.push(colors[i % colors.length]);
|
|
99
|
-
}
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
function merge_chart_options(defaultOption, customOption) {
|
|
103
|
-
return {
|
|
104
|
-
...defaultOption,
|
|
105
|
-
...customOption,
|
|
106
|
-
// 特殊处理数组类型的配置
|
|
107
|
-
series: customOption.series || defaultOption.series,
|
|
108
|
-
xAxis: customOption.xAxis || defaultOption.xAxis,
|
|
109
|
-
yAxis: customOption.yAxis || defaultOption.yAxis,
|
|
110
|
-
legend: customOption.legend || defaultOption.legend,
|
|
111
|
-
tooltip: customOption.tooltip || defaultOption.tooltip,
|
|
112
|
-
title: customOption.title || defaultOption.title
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
function add_chart_listener(chart, eventName, handler) {
|
|
116
|
-
if (chart && typeof chart.on === "function") {
|
|
117
|
-
chart.on(eventName, handler);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
function remove_chart_listener(chart, eventName, handler) {
|
|
121
|
-
if (chart && typeof chart.off === "function") {
|
|
122
|
-
chart.off(eventName, handler);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
function export_chart_image(chart, options = {}) {
|
|
126
|
-
if (!chart || typeof chart.getDataURL !== "function") {
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
const {
|
|
130
|
-
type = "png",
|
|
131
|
-
pixel_ratio = 2,
|
|
132
|
-
background_color = "#fff",
|
|
133
|
-
exclude_components = [],
|
|
134
|
-
file_name = "echarts-image"
|
|
135
|
-
} = options;
|
|
136
|
-
const data_url = chart.getDataURL({
|
|
137
|
-
type,
|
|
138
|
-
pixelRatio: pixel_ratio,
|
|
139
|
-
backgroundColor: background_color,
|
|
140
|
-
excludeComponents: exclude_components
|
|
141
|
-
});
|
|
142
|
-
const link = document.createElement("a");
|
|
143
|
-
link.download = `${file_name}.${type}`;
|
|
144
|
-
link.href = data_url;
|
|
145
|
-
link.click();
|
|
146
|
-
return data_url;
|
|
147
|
-
}
|
|
148
|
-
export {
|
|
149
|
-
add_chart_listener,
|
|
150
|
-
destroy_chart,
|
|
151
|
-
export_chart_image,
|
|
152
|
-
generate_chart_colors,
|
|
153
|
-
get_chart_gradient_color,
|
|
154
|
-
init_chart,
|
|
155
|
-
make_chart_responsive,
|
|
156
|
-
merge_chart_options,
|
|
157
|
-
remove_chart_listener,
|
|
158
|
-
resize_chart,
|
|
159
|
-
update_chart
|
|
160
|
-
};
|
package/lib/use-chart/config.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { auto_size } from "@qy_better_lib/core";
|
|
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
|
-
};
|
package/lib/use-emit/extend.js
DELETED
|
@@ -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
|
-
};
|
package/lib/use-emit/index.js
DELETED
|
@@ -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
|
-
};
|