@zhin.js/plugin-qrcode 1.1.23 → 1.1.25
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/package.json +15 -7
- package/pages/index/index.js +63 -0
- package/pages/index/index.ts +68 -0
- package/plugin.js +84 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/plugin-qrcode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
4
4
|
"description": "QR code generator & reader plugin for Zhin.js (Plugin Runtime)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"plugin.js",
|
|
17
17
|
"schema.json",
|
|
18
18
|
"commands",
|
|
19
|
+
"pages",
|
|
19
20
|
"src",
|
|
20
21
|
"lib",
|
|
21
22
|
"tools",
|
|
@@ -37,20 +38,23 @@
|
|
|
37
38
|
},
|
|
38
39
|
"license": "MIT",
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@zhin.js/
|
|
41
|
-
"@zhin.js/
|
|
42
|
-
"@zhin.js/
|
|
41
|
+
"@zhin.js/console-contract": "1.1.5",
|
|
42
|
+
"@zhin.js/core": "1.1.60",
|
|
43
|
+
"@zhin.js/page": "1.1.17",
|
|
44
|
+
"@zhin.js/tool": "1.1.18",
|
|
45
|
+
"@zhin.js/skill": "1.1.16"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"typescript": "^6.0.3",
|
|
46
49
|
"vitest": "^4.1.10",
|
|
47
50
|
"zod": "^4.4.3",
|
|
48
|
-
"zhin.js": "1.1.
|
|
51
|
+
"zhin.js": "1.1.25"
|
|
49
52
|
},
|
|
50
53
|
"peerDependencies": {
|
|
51
54
|
"zod": "^4.0.0",
|
|
52
|
-
"@zhin.js/command": "^1.1.
|
|
53
|
-
"zhin.js": "^1.1.
|
|
55
|
+
"@zhin.js/command": "^1.1.17",
|
|
56
|
+
"@zhin.js/page": "^1.1.17",
|
|
57
|
+
"zhin.js": "^1.1.25"
|
|
54
58
|
},
|
|
55
59
|
"peerDependenciesMeta": {
|
|
56
60
|
"@zhin.js/command": {
|
|
@@ -90,6 +94,10 @@
|
|
|
90
94
|
{
|
|
91
95
|
"package": "@zhin.js/skill",
|
|
92
96
|
"api": "^1.0.0"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"package": "@zhin.js/page",
|
|
100
|
+
"api": "^1.0.0"
|
|
93
101
|
}
|
|
94
102
|
],
|
|
95
103
|
"plugins": []
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { definePage, definePageBlueprint } from '@zhin.js/console-contract';
|
|
3
|
+
export const meta = definePage({
|
|
4
|
+
title: '二维码工具',
|
|
5
|
+
titleI18n: { en: 'QR Code' },
|
|
6
|
+
icon: 'QrCode',
|
|
7
|
+
order: 58,
|
|
8
|
+
requiredPermissions: ['qrcode:read'],
|
|
9
|
+
});
|
|
10
|
+
export default definePageBlueprint({
|
|
11
|
+
title: { zh: '二维码工具', en: 'QR Code' },
|
|
12
|
+
description: {
|
|
13
|
+
zh: '在线生成二维码并查看近期生成记录',
|
|
14
|
+
en: 'Generate QR codes online and view recent generation history',
|
|
15
|
+
},
|
|
16
|
+
stats: [
|
|
17
|
+
{
|
|
18
|
+
key: 'recentCount',
|
|
19
|
+
label: { zh: '近期生成数', en: 'Recent Count' },
|
|
20
|
+
value: 'recentCount',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
actions: [
|
|
24
|
+
{
|
|
25
|
+
name: 'generate',
|
|
26
|
+
label: { zh: '生成二维码', en: 'Generate QR Code' },
|
|
27
|
+
variant: 'primary',
|
|
28
|
+
fields: [
|
|
29
|
+
{
|
|
30
|
+
key: 'text',
|
|
31
|
+
label: { zh: '二维码内容', en: 'QR Content' },
|
|
32
|
+
type: 'text',
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: 'width',
|
|
37
|
+
label: { zh: '图片尺寸 (px)', en: 'Width (px)' },
|
|
38
|
+
type: 'number',
|
|
39
|
+
defaultValue: '280',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'clearHistory',
|
|
45
|
+
label: { zh: '清空记录', en: 'Clear History' },
|
|
46
|
+
variant: 'secondary',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
sections: [
|
|
50
|
+
{
|
|
51
|
+
id: 'history',
|
|
52
|
+
layout: 'table',
|
|
53
|
+
title: { zh: '最近生成记录', en: 'Recent Generation History' },
|
|
54
|
+
emptyText: { zh: '暂无二维码生成记录', en: 'No QR code generation history' },
|
|
55
|
+
items: 'history',
|
|
56
|
+
columns: [
|
|
57
|
+
{ key: 'createdAt', label: { zh: '生成时间', en: 'Created At' } },
|
|
58
|
+
{ key: 'content', label: { zh: '内容', en: 'Content' } },
|
|
59
|
+
{ key: 'size', label: { zh: '尺寸', en: 'Size' } },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { definePage, definePageBlueprint } from '@zhin.js/console-contract';
|
|
2
|
+
import type { QrCodeConsoleStatus, QrCodeHistoryItem } from '../../plugin.js';
|
|
3
|
+
|
|
4
|
+
export const meta = definePage({
|
|
5
|
+
title: '二维码工具',
|
|
6
|
+
titleI18n: { en: 'QR Code' },
|
|
7
|
+
icon: 'QrCode',
|
|
8
|
+
order: 58,
|
|
9
|
+
requiredPermissions: ['qrcode:read'],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export default definePageBlueprint<QrCodeConsoleStatus>({
|
|
13
|
+
title: { zh: '二维码工具', en: 'QR Code' },
|
|
14
|
+
description: {
|
|
15
|
+
zh: '在线生成二维码并查看近期生成记录',
|
|
16
|
+
en: 'Generate QR codes online and view recent generation history',
|
|
17
|
+
},
|
|
18
|
+
stats: [
|
|
19
|
+
{
|
|
20
|
+
key: 'recentCount',
|
|
21
|
+
label: { zh: '近期生成数', en: 'Recent Count' },
|
|
22
|
+
value: 'recentCount',
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
actions: [
|
|
26
|
+
{
|
|
27
|
+
name: 'generate',
|
|
28
|
+
label: { zh: '生成二维码', en: 'Generate QR Code' },
|
|
29
|
+
variant: 'primary',
|
|
30
|
+
fields: [
|
|
31
|
+
{
|
|
32
|
+
key: 'text',
|
|
33
|
+
label: { zh: '二维码内容', en: 'QR Content' },
|
|
34
|
+
type: 'text',
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: 'width',
|
|
39
|
+
label: { zh: '图片尺寸 (px)', en: 'Width (px)' },
|
|
40
|
+
type: 'number',
|
|
41
|
+
defaultValue: '280',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'clearHistory',
|
|
47
|
+
label: { zh: '清空记录', en: 'Clear History' },
|
|
48
|
+
variant: 'secondary',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
sections: [
|
|
52
|
+
{
|
|
53
|
+
id: 'history',
|
|
54
|
+
layout: 'table',
|
|
55
|
+
title: { zh: '最近生成记录', en: 'Recent Generation History' },
|
|
56
|
+
emptyText: { zh: '暂无二维码生成记录', en: 'No QR code generation history' },
|
|
57
|
+
items: 'history',
|
|
58
|
+
columns: [
|
|
59
|
+
{ key: 'createdAt', label: { zh: '生成时间', en: 'Created At' } },
|
|
60
|
+
{ key: 'content', label: { zh: '内容', en: 'Content' } },
|
|
61
|
+
{ key: 'size', label: { zh: '尺寸', en: 'Size' } },
|
|
62
|
+
] satisfies readonly {
|
|
63
|
+
readonly key: keyof QrCodeHistoryItem & string;
|
|
64
|
+
readonly label: { readonly zh: string; readonly en: string };
|
|
65
|
+
}[],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
package/plugin.js
CHANGED
|
@@ -1,8 +1,91 @@
|
|
|
1
1
|
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
-
import {
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { definePlugin, definePluginCapabilityGraph, definePluginConsoleRpc, PluginConsoleRpcError, pluginConsoleRpcToken, } from 'zhin.js';
|
|
4
|
+
import { generateQrCode } from 'zhin.js/qrcode';
|
|
5
|
+
const MAX_HISTORY_ITEMS = 20;
|
|
3
6
|
export default definePlugin({
|
|
4
7
|
name: 'qrcode',
|
|
5
8
|
metadata: {
|
|
6
9
|
displayName: 'QR Code',
|
|
7
10
|
},
|
|
11
|
+
capabilityGraph: definePluginCapabilityGraph({
|
|
12
|
+
provides: [pluginConsoleRpcToken],
|
|
13
|
+
features: {
|
|
14
|
+
commands: ['gen', 'scan/[url]'],
|
|
15
|
+
skills: ['qrcode'],
|
|
16
|
+
tools: ['skill/qrcode/qrcode_generate'],
|
|
17
|
+
pages: ['index'],
|
|
18
|
+
},
|
|
19
|
+
}),
|
|
20
|
+
setup() {
|
|
21
|
+
const history = [];
|
|
22
|
+
const rpc = definePluginConsoleRpc({
|
|
23
|
+
status: {
|
|
24
|
+
page: 'index',
|
|
25
|
+
demo: true,
|
|
26
|
+
requiredPermissions: ['qrcode:read'],
|
|
27
|
+
handler() {
|
|
28
|
+
return {
|
|
29
|
+
recentCount: history.length,
|
|
30
|
+
history: [...history],
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
actions: {
|
|
35
|
+
generate: {
|
|
36
|
+
page: 'index',
|
|
37
|
+
requiredPermissions: ['qrcode:write'],
|
|
38
|
+
async handler(input) {
|
|
39
|
+
const rawText = typeof input.text === 'string' ? input.text.trim() : '';
|
|
40
|
+
if (!rawText) {
|
|
41
|
+
throw new PluginConsoleRpcError('invalid_input', '请输入要生成二维码的文本内容');
|
|
42
|
+
}
|
|
43
|
+
const rawWidth = input.width !== undefined && input.width !== null && input.width !== ''
|
|
44
|
+
? Number(input.width)
|
|
45
|
+
: 280;
|
|
46
|
+
const width = Number.isFinite(rawWidth) && rawWidth >= 64 && rawWidth <= 1024
|
|
47
|
+
? Math.round(rawWidth)
|
|
48
|
+
: 280;
|
|
49
|
+
// Generates QR data URL via QRCode.toDataURL(...) under the hood
|
|
50
|
+
const qr = await generateQrCode(rawText, { width });
|
|
51
|
+
const dataUrl = qr.toDataUrl();
|
|
52
|
+
const entry = {
|
|
53
|
+
id: randomUUID(),
|
|
54
|
+
content: rawText,
|
|
55
|
+
size: width,
|
|
56
|
+
createdAt: new Date().toISOString(),
|
|
57
|
+
dataUrl,
|
|
58
|
+
};
|
|
59
|
+
history.unshift(entry);
|
|
60
|
+
if (history.length > MAX_HISTORY_ITEMS) {
|
|
61
|
+
history.length = MAX_HISTORY_ITEMS;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
message: '二维码已生成',
|
|
65
|
+
dataUrl,
|
|
66
|
+
text: rawText,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
'clear-history': {
|
|
71
|
+
page: 'index',
|
|
72
|
+
requiredPermissions: ['qrcode:write'],
|
|
73
|
+
handler() {
|
|
74
|
+
history.length = 0;
|
|
75
|
+
return {
|
|
76
|
+
message: '生成记录已清空',
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const methods = rpc.methods;
|
|
83
|
+
const clearHistoryMethod = methods.get('clear-history');
|
|
84
|
+
if (clearHistoryMethod) {
|
|
85
|
+
methods.set('clearHistory', clearHistoryMethod);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
consoleRpc: rpc,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
8
91
|
});
|