@robot-admin/naive-ui-components 0.4.3 → 0.4.4
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/C_ActionBar.cjs +1 -5
- package/dist/C_ActionBar.js +1 -4
- package/dist/C_ActionBar.js.map +1 -0
- package/dist/C_ActionBar2.js +1 -195
- package/dist/C_ActionBar2.js.map +1 -1
- package/dist/C_AntV.cjs +1 -8
- package/dist/C_AntV.js +1 -4
- package/dist/C_AntV.js.map +1 -0
- package/dist/C_AntV2.js +4 -3149
- package/dist/C_AntV2.js.map +1 -1
- package/dist/C_Barcode.cjs +1 -4
- package/dist/C_Barcode.js +1 -3
- package/dist/C_Barcode.js.map +1 -0
- package/dist/C_Barcode2.js +1 -67
- package/dist/C_Barcode2.js.map +1 -1
- package/dist/C_Captcha.cjs +1 -4
- package/dist/C_Captcha.js +1 -3
- package/dist/C_Captcha.js.map +1 -0
- package/dist/C_Captcha2.js +1 -154
- package/dist/C_Captcha2.js.map +1 -1
- package/dist/C_Cascade.cjs +1 -4
- package/dist/C_Cascade.js +1 -3
- package/dist/C_Cascade.js.map +1 -0
- package/dist/C_Cascade2.js +1 -102
- package/dist/C_Cascade2.js.map +1 -1
- package/dist/C_City.cjs +1 -4
- package/dist/C_City.js +1 -3
- package/dist/C_City.js.map +1 -0
- package/dist/C_City2.js +1 -840
- package/dist/C_City2.js.map +1 -1
- package/dist/C_Code.cjs +1 -5
- package/dist/C_Code.js +1 -4
- package/dist/C_Code.js.map +1 -0
- package/dist/C_Code2.js +1 -346
- package/dist/C_Code2.js.map +1 -1
- package/dist/C_CollapsePanel.cjs +1 -6
- package/dist/C_CollapsePanel.js +1 -4
- package/dist/C_CollapsePanel.js.map +1 -0
- package/dist/C_CollapsePanel2.js +1 -318
- package/dist/C_CollapsePanel2.js.map +1 -1
- package/dist/C_Cron.cjs +1 -15
- package/dist/C_Cron.js +1 -4
- package/dist/C_Cron.js.map +1 -0
- package/dist/C_Cron2.js +1 -1209
- package/dist/C_Cron2.js.map +1 -1
- package/dist/C_Date.cjs +1 -4
- package/dist/C_Date.js +1 -3
- package/dist/C_Date.js.map +1 -0
- package/dist/C_Date2.js +1 -218
- package/dist/C_Date2.js.map +1 -1
- package/dist/C_Draggable.cjs +1 -5
- package/dist/C_Draggable.js +1 -3
- package/dist/C_Draggable.js.map +1 -0
- package/dist/C_Draggable2.js +1 -294
- package/dist/C_Draggable2.js.map +1 -1
- package/dist/C_Editor.cjs +1 -4
- package/dist/C_Editor.js +1 -3
- package/dist/C_Editor.js.map +1 -0
- package/dist/C_Editor2.js +1 -159
- package/dist/C_Editor2.js.map +1 -1
- package/dist/C_FilePreview.cjs +1 -7
- package/dist/C_FilePreview.js +1 -4
- package/dist/C_FilePreview.js.map +1 -0
- package/dist/C_FilePreview2.js +1 -1031
- package/dist/C_FilePreview2.js.map +1 -1
- package/dist/C_Form.cjs +1 -16
- package/dist/C_Form.js +1 -5
- package/dist/C_Form.js.map +1 -0
- package/dist/C_Form2.js +1 -2569
- package/dist/C_Form2.js.map +1 -1
- package/dist/C_FormSearch.cjs +1 -6
- package/dist/C_FormSearch.js +1 -3
- package/dist/C_FormSearch.js.map +1 -0
- package/dist/C_FormSearch2.js +1 -355
- package/dist/C_FormSearch2.js.map +1 -1
- package/dist/C_FormulaEditor.cjs +1 -13
- package/dist/C_FormulaEditor.js +1 -4
- package/dist/C_FormulaEditor.js.map +1 -0
- package/dist/C_FormulaEditor2.js +1 -1432
- package/dist/C_FormulaEditor2.js.map +1 -1
- package/dist/C_FullCalendar.cjs +1 -9
- package/dist/C_FullCalendar.js +1 -3
- package/dist/C_FullCalendar.js.map +1 -0
- package/dist/C_FullCalendar2.js +1 -376
- package/dist/C_FullCalendar2.js.map +1 -1
- package/dist/C_GlobalSearch.cjs +1 -5
- package/dist/C_GlobalSearch.js +1 -3
- package/dist/C_GlobalSearch.js.map +1 -0
- package/dist/C_GlobalSearch2.js +1 -335
- package/dist/C_GlobalSearch2.js.map +1 -1
- package/dist/C_Guide.cjs +1 -5
- package/dist/C_Guide.js +1 -4
- package/dist/C_Guide.js.map +1 -0
- package/dist/C_Guide2.js +1 -60
- package/dist/C_Guide2.js.map +1 -1
- package/dist/C_Icon.cjs +1 -4
- package/dist/C_Icon.js +1 -3
- package/dist/C_Icon.js.map +1 -0
- package/dist/C_Icon2.js +1 -285
- package/dist/C_Icon2.js.map +1 -1
- package/dist/C_ImageCropper.cjs +1 -6
- package/dist/C_ImageCropper.js +1 -4
- package/dist/C_ImageCropper.js.map +1 -0
- package/dist/C_ImageCropper2.js +1 -722
- package/dist/C_ImageCropper2.js.map +1 -1
- package/dist/C_Language.cjs +1 -5
- package/dist/C_Language.js +1 -4
- package/dist/C_Language.js.map +1 -0
- package/dist/C_Language2.js +1 -78
- package/dist/C_Language2.js.map +1 -1
- package/dist/C_Map.cjs +1 -7
- package/dist/C_Map.js +1 -3
- package/dist/C_Map.js.map +1 -0
- package/dist/C_Map2.js +1 -198
- package/dist/C_Map2.js.map +1 -1
- package/dist/C_Markdown.cjs +1 -4
- package/dist/C_Markdown.js +1 -3
- package/dist/C_Markdown.js.map +1 -0
- package/dist/C_Markdown2.js +1 -185
- package/dist/C_Markdown2.js.map +1 -1
- package/dist/C_NotificationCenter.cjs +1 -20
- package/dist/C_NotificationCenter.js +1 -4
- package/dist/C_NotificationCenter.js.map +1 -0
- package/dist/C_NotificationCenter2.js +1 -1383
- package/dist/C_NotificationCenter2.js.map +1 -1
- package/dist/C_Progress.cjs +1 -4
- package/dist/C_Progress.js +1 -3
- package/dist/C_Progress.js.map +1 -0
- package/dist/C_Progress2.js +1 -102
- package/dist/C_Progress2.js.map +1 -1
- package/dist/C_QRCode.cjs +1 -5
- package/dist/C_QRCode.js +1 -3
- package/dist/C_QRCode.js.map +1 -0
- package/dist/C_QRCode2.js +1 -217
- package/dist/C_QRCode2.js.map +1 -1
- package/dist/C_Signature.cjs +1 -8
- package/dist/C_Signature.js +1 -4
- package/dist/C_Signature.js.map +1 -0
- package/dist/C_Signature2.js +1 -617
- package/dist/C_Signature2.js.map +1 -1
- package/dist/C_SplitPane.cjs +1 -6
- package/dist/C_SplitPane.js +1 -4
- package/dist/C_SplitPane.js.map +1 -0
- package/dist/C_SplitPane2.js +1 -355
- package/dist/C_SplitPane2.js.map +1 -1
- package/dist/C_Steps.cjs +1 -4
- package/dist/C_Steps.js +1 -3
- package/dist/C_Steps.js.map +1 -0
- package/dist/C_Steps2.js +1 -81
- package/dist/C_Steps2.js.map +1 -1
- package/dist/C_Table.cjs +1 -20
- package/dist/C_Table.js +1 -6
- package/dist/C_Table.js.map +1 -0
- package/dist/C_Table2.js +1 -3023
- package/dist/C_Table2.js.map +1 -1
- package/dist/C_Theme.cjs +1 -5
- package/dist/C_Theme.js +1 -4
- package/dist/C_Theme.js.map +1 -0
- package/dist/C_Theme2.js +1 -63
- package/dist/C_Theme2.js.map +1 -1
- package/dist/C_Time.cjs +1 -5
- package/dist/C_Time.js +1 -3
- package/dist/C_Time.js.map +1 -0
- package/dist/C_Time2.js +1 -198
- package/dist/C_Time2.js.map +1 -1
- package/dist/C_Tree.cjs +1 -7
- package/dist/C_Tree.js +1 -4
- package/dist/C_Tree.js.map +1 -0
- package/dist/C_Tree2.js +1 -440
- package/dist/C_Tree2.js.map +1 -1
- package/dist/C_Upload.cjs +1 -12
- package/dist/C_Upload.js +1 -4
- package/dist/C_Upload.js.map +1 -0
- package/dist/C_Upload2.js +2 -1365
- package/dist/C_Upload2.js.map +1 -1
- package/dist/C_VideoPlayer.cjs +1 -23
- package/dist/C_VideoPlayer.js +1 -3
- package/dist/C_VideoPlayer.js.map +1 -0
- package/dist/C_VideoPlayer2.js +3 -1932
- package/dist/C_VideoPlayer2.js.map +1 -1
- package/dist/C_VtableGantt.cjs +1 -6
- package/dist/C_VtableGantt.js +1 -4
- package/dist/C_VtableGantt.js.map +1 -0
- package/dist/C_VtableGantt2.js +1 -872
- package/dist/C_VtableGantt2.js.map +1 -1
- package/dist/C_WaterFall.cjs +1 -13
- package/dist/C_WaterFall.js +1 -3
- package/dist/C_WaterFall.js.map +1 -0
- package/dist/C_WaterFall2.js +1 -364
- package/dist/C_WaterFall2.js.map +1 -1
- package/dist/C_WorkFlow.cjs +1 -8
- package/dist/C_WorkFlow.js +1 -4
- package/dist/C_WorkFlow.js.map +1 -0
- package/dist/C_WorkFlow2.js +1 -1983
- package/dist/C_WorkFlow2.js.map +1 -1
- package/dist/chunk.js +1 -18
- package/dist/city.js +1 -4816
- package/dist/constants.d.ts +2 -2
- package/dist/constants2.d.ts +3 -3
- package/dist/constants3.d.ts +3 -3
- package/dist/constants4.d.ts +5 -5
- package/dist/constants5.d.ts +2 -2
- package/dist/data.d.ts +1 -1
- package/dist/export-helper.js +1 -9
- package/dist/index.cjs +2 -413
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -231
- package/dist/index.js.map +1 -1
- package/dist/index.vue.d.ts +2 -2
- package/dist/index10.vue.d.ts +5 -5
- package/dist/index12.vue.d.ts +3 -3
- package/dist/index13.vue.d.ts +3 -3
- package/dist/index14.vue.d.ts +3 -3
- package/dist/index16.vue.d.ts +3 -3
- package/dist/index3.vue.d.ts +3 -3
- package/dist/index5.vue.d.ts +1 -1
- package/dist/index7.vue.d.ts +4 -4
- package/dist/index8.vue.d.ts +2 -2
- package/dist/resolver.cjs +2 -89
- package/dist/resolver.cjs.map +1 -0
- package/dist/resolver.js +1 -86
- package/dist/resolver.js.map +1 -1
- package/dist/storage.js +1 -30
- package/dist/storage.js.map +1 -1
- package/dist/useCollapsePanel.d.ts +2 -2
- package/dist/useCropperCore.d.ts +8 -8
- package/dist/useDraggableLayout.d.ts +4 -4
- package/dist/useDynamicFormState.d.ts +7 -7
- package/dist/useEdgeInteraction.d.ts +1 -1
- package/dist/useFullscreen.d.ts +2 -2
- package/dist/useInfiniteScroll.d.ts +1 -1
- package/dist/useModalEdit.d.ts +1 -1
- package/dist/useQRCode.d.ts +3 -3
- package/dist/useSearchState.d.ts +2 -2
- package/dist/useSignatureHistory.d.ts +1 -1
- package/dist/useSplitResize.d.ts +6 -6
- package/dist/useTimeSelection.d.ts +2 -2
- package/dist/useTreeOperations.d.ts +6 -6
- package/dist/useWorkflowValidation.d.ts +4 -4
- package/package.json +1 -2
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants2.d.ts.map +0 -1
- package/dist/constants3.d.ts.map +0 -1
- package/dist/constants4.d.ts.map +0 -1
- package/dist/constants5.d.ts.map +0 -1
- package/dist/data.d.ts.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.vue.d.ts.map +0 -1
- package/dist/index10.vue.d.ts.map +0 -1
- package/dist/index11.vue.d.ts.map +0 -1
- package/dist/index12.vue.d.ts.map +0 -1
- package/dist/index13.vue.d.ts.map +0 -1
- package/dist/index14.vue.d.ts.map +0 -1
- package/dist/index15.vue.d.ts.map +0 -1
- package/dist/index16.vue.d.ts.map +0 -1
- package/dist/index2.vue.d.ts.map +0 -1
- package/dist/index3.vue.d.ts.map +0 -1
- package/dist/index4.vue.d.ts.map +0 -1
- package/dist/index5.vue.d.ts.map +0 -1
- package/dist/index6.vue.d.ts.map +0 -1
- package/dist/index7.vue.d.ts.map +0 -1
- package/dist/index8.vue.d.ts.map +0 -1
- package/dist/index9.vue.d.ts.map +0 -1
- package/dist/resolver.d.cts.map +0 -1
- package/dist/resolver.d.ts.map +0 -1
- package/dist/useCalendarEvents.d.ts.map +0 -1
- package/dist/useCollapsePanel.d.ts.map +0 -1
- package/dist/useCropperCore.d.ts.map +0 -1
- package/dist/useDraggableLayout.d.ts.map +0 -1
- package/dist/useDynamicFormState.d.ts.map +0 -1
- package/dist/useEdgeInteraction.d.ts.map +0 -1
- package/dist/useFullscreen.d.ts.map +0 -1
- package/dist/useGlobalSearch.d.ts.map +0 -1
- package/dist/useInfiniteScroll.d.ts.map +0 -1
- package/dist/useModalEdit.d.ts.map +0 -1
- package/dist/useQRCode.d.ts.map +0 -1
- package/dist/useSearchState.d.ts.map +0 -1
- package/dist/useSignatureHistory.d.ts.map +0 -1
- package/dist/useSplitResize.d.ts.map +0 -1
- package/dist/useTimeSelection.d.ts.map +0 -1
- package/dist/useTreeOperations.d.ts.map +0 -1
- package/dist/useWorkflowValidation.d.ts.map +0 -1
package/dist/C_Signature2.js
CHANGED
|
@@ -1,618 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as export_helper_default } from "./export-helper.js";
|
|
3
|
-
import { NButton, NButtonGroup, NColorPicker, NInputNumber } from "naive-ui";
|
|
4
|
-
import { computed, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, onMounted, onUnmounted, openBlock, reactive, readonly, ref, toRef, unref, withCtx } from "vue";
|
|
5
|
-
|
|
6
|
-
//#region src/components/C_Signature/composables/useSignatureCanvas.ts
|
|
7
|
-
function useSignatureCanvas(options) {
|
|
8
|
-
const { canvasRef, penConfig, mode, disabled, onStrokeComplete, onDrawStart, onDrawing } = options;
|
|
9
|
-
const isDrawing = ref(false);
|
|
10
|
-
const currentStroke = ref([]);
|
|
11
|
-
let ctx = null;
|
|
12
|
-
const initCanvas = () => {
|
|
13
|
-
const canvas = canvasRef.value;
|
|
14
|
-
if (!canvas) return;
|
|
15
|
-
ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
16
|
-
if (!ctx) return;
|
|
17
|
-
const dpr = window.devicePixelRatio || 1;
|
|
18
|
-
const rect = canvas.getBoundingClientRect();
|
|
19
|
-
canvas.width = rect.width * dpr;
|
|
20
|
-
canvas.height = rect.height * dpr;
|
|
21
|
-
canvas.style.width = `${rect.width}px`;
|
|
22
|
-
canvas.style.height = `${rect.height}px`;
|
|
23
|
-
ctx.scale(dpr, dpr);
|
|
24
|
-
ctx.lineCap = "round";
|
|
25
|
-
ctx.lineJoin = "round";
|
|
26
|
-
};
|
|
27
|
-
const getPointFromEvent = (e) => {
|
|
28
|
-
const canvas = canvasRef.value;
|
|
29
|
-
if (!canvas) return {
|
|
30
|
-
x: 0,
|
|
31
|
-
y: 0
|
|
32
|
-
};
|
|
33
|
-
const rect = canvas.getBoundingClientRect();
|
|
34
|
-
let clientX;
|
|
35
|
-
let clientY;
|
|
36
|
-
if ("touches" in e && e.touches.length > 0) ({clientX, clientY} = e.touches[0]);
|
|
37
|
-
else if ("clientX" in e) ({clientX, clientY} = e);
|
|
38
|
-
else return {
|
|
39
|
-
x: 0,
|
|
40
|
-
y: 0
|
|
41
|
-
};
|
|
42
|
-
return {
|
|
43
|
-
x: clientX - rect.left,
|
|
44
|
-
y: clientY - rect.top,
|
|
45
|
-
timestamp: Date.now()
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
const drawStroke = (from, to, config, eraserMode = false) => {
|
|
49
|
-
if (!ctx) return;
|
|
50
|
-
ctx.save();
|
|
51
|
-
if (eraserMode) {
|
|
52
|
-
ctx.globalCompositeOperation = "destination-out";
|
|
53
|
-
ctx.lineWidth = 20;
|
|
54
|
-
} else {
|
|
55
|
-
ctx.globalCompositeOperation = "source-over";
|
|
56
|
-
ctx.strokeStyle = config.color;
|
|
57
|
-
ctx.lineWidth = config.width;
|
|
58
|
-
ctx.globalAlpha = config.opacity;
|
|
59
|
-
}
|
|
60
|
-
ctx.beginPath();
|
|
61
|
-
ctx.moveTo(from.x, from.y);
|
|
62
|
-
ctx.lineTo(to.x, to.y);
|
|
63
|
-
ctx.stroke();
|
|
64
|
-
ctx.restore();
|
|
65
|
-
};
|
|
66
|
-
const startDrawing = (e) => {
|
|
67
|
-
if (disabled.value) return;
|
|
68
|
-
e.preventDefault();
|
|
69
|
-
isDrawing.value = true;
|
|
70
|
-
currentStroke.value = [];
|
|
71
|
-
const point = getPointFromEvent(e);
|
|
72
|
-
currentStroke.value.push(point);
|
|
73
|
-
onDrawStart();
|
|
74
|
-
};
|
|
75
|
-
const draw = (e) => {
|
|
76
|
-
if (!isDrawing.value || disabled.value) return;
|
|
77
|
-
e.preventDefault();
|
|
78
|
-
const point = getPointFromEvent(e);
|
|
79
|
-
const lastPoint = currentStroke.value[currentStroke.value.length - 1];
|
|
80
|
-
if (lastPoint) drawStroke(lastPoint, point, penConfig.value, mode.value === "eraser");
|
|
81
|
-
currentStroke.value.push(point);
|
|
82
|
-
onDrawing(point);
|
|
83
|
-
};
|
|
84
|
-
const endDrawing = (e) => {
|
|
85
|
-
if (!isDrawing.value || disabled.value) return;
|
|
86
|
-
e.preventDefault();
|
|
87
|
-
isDrawing.value = false;
|
|
88
|
-
if (currentStroke.value.length > 0) {
|
|
89
|
-
onStrokeComplete({
|
|
90
|
-
points: [...currentStroke.value],
|
|
91
|
-
color: penConfig.value.color,
|
|
92
|
-
width: penConfig.value.width,
|
|
93
|
-
opacity: penConfig.value.opacity,
|
|
94
|
-
mode: mode.value
|
|
95
|
-
});
|
|
96
|
-
currentStroke.value = [];
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
const redrawStrokes = (strokes) => {
|
|
100
|
-
if (!ctx || !canvasRef.value) return;
|
|
101
|
-
const canvas = canvasRef.value;
|
|
102
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
103
|
-
strokes.forEach((stroke) => {
|
|
104
|
-
for (let i = 1; i < stroke.points.length; i++) drawStroke(stroke.points[i - 1], stroke.points[i], {
|
|
105
|
-
color: stroke.color,
|
|
106
|
-
width: stroke.width,
|
|
107
|
-
opacity: stroke.opacity
|
|
108
|
-
}, stroke.mode === "eraser");
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
const clearCanvas = () => {
|
|
112
|
-
if (!ctx || !canvasRef.value) return;
|
|
113
|
-
ctx.clearRect(0, 0, canvasRef.value.width, canvasRef.value.height);
|
|
114
|
-
};
|
|
115
|
-
const bindEvents = () => {
|
|
116
|
-
const canvas = canvasRef.value;
|
|
117
|
-
if (!canvas) return;
|
|
118
|
-
canvas.addEventListener("mousedown", startDrawing);
|
|
119
|
-
canvas.addEventListener("mousemove", draw);
|
|
120
|
-
canvas.addEventListener("mouseup", endDrawing);
|
|
121
|
-
canvas.addEventListener("mouseleave", endDrawing);
|
|
122
|
-
canvas.addEventListener("touchstart", startDrawing, { passive: false });
|
|
123
|
-
canvas.addEventListener("touchmove", draw, { passive: false });
|
|
124
|
-
canvas.addEventListener("touchend", endDrawing);
|
|
125
|
-
canvas.addEventListener("touchcancel", endDrawing);
|
|
126
|
-
};
|
|
127
|
-
const unbindEvents = () => {
|
|
128
|
-
const canvas = canvasRef.value;
|
|
129
|
-
if (!canvas) return;
|
|
130
|
-
canvas.removeEventListener("mousedown", startDrawing);
|
|
131
|
-
canvas.removeEventListener("mousemove", draw);
|
|
132
|
-
canvas.removeEventListener("mouseup", endDrawing);
|
|
133
|
-
canvas.removeEventListener("mouseleave", endDrawing);
|
|
134
|
-
canvas.removeEventListener("touchstart", startDrawing);
|
|
135
|
-
canvas.removeEventListener("touchmove", draw);
|
|
136
|
-
canvas.removeEventListener("touchend", endDrawing);
|
|
137
|
-
canvas.removeEventListener("touchcancel", endDrawing);
|
|
138
|
-
};
|
|
139
|
-
return {
|
|
140
|
-
isDrawing: readonly(isDrawing),
|
|
141
|
-
initCanvas,
|
|
142
|
-
bindEvents,
|
|
143
|
-
unbindEvents,
|
|
144
|
-
redrawStrokes,
|
|
145
|
-
clearCanvas
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/components/C_Signature/composables/useSignatureHistory.ts
|
|
151
|
-
function useSignatureHistory(options = {}) {
|
|
152
|
-
const { maxHistory = 50, onChange } = options;
|
|
153
|
-
const strokes = ref([]);
|
|
154
|
-
const historyStack = ref([]);
|
|
155
|
-
const historyIndex = ref(-1);
|
|
156
|
-
const canUndo = computed(() => historyIndex.value > 0);
|
|
157
|
-
const canRedo = computed(() => historyIndex.value < historyStack.value.length - 1);
|
|
158
|
-
const addStroke = (stroke) => {
|
|
159
|
-
strokes.value.push(stroke);
|
|
160
|
-
saveToHistory();
|
|
161
|
-
};
|
|
162
|
-
const saveToHistory = () => {
|
|
163
|
-
historyStack.value = historyStack.value.slice(0, historyIndex.value + 1);
|
|
164
|
-
historyStack.value.push([...strokes.value]);
|
|
165
|
-
historyIndex.value++;
|
|
166
|
-
if (historyStack.value.length > maxHistory) {
|
|
167
|
-
historyStack.value.shift();
|
|
168
|
-
historyIndex.value--;
|
|
169
|
-
}
|
|
170
|
-
onChange?.(strokes.value);
|
|
171
|
-
};
|
|
172
|
-
const undo = () => {
|
|
173
|
-
if (!canUndo.value) return false;
|
|
174
|
-
historyIndex.value--;
|
|
175
|
-
strokes.value = [...historyStack.value[historyIndex.value]];
|
|
176
|
-
onChange?.(strokes.value);
|
|
177
|
-
return true;
|
|
178
|
-
};
|
|
179
|
-
const redo = () => {
|
|
180
|
-
if (!canRedo.value) return false;
|
|
181
|
-
historyIndex.value++;
|
|
182
|
-
strokes.value = [...historyStack.value[historyIndex.value]];
|
|
183
|
-
onChange?.(strokes.value);
|
|
184
|
-
return true;
|
|
185
|
-
};
|
|
186
|
-
const clear = () => {
|
|
187
|
-
strokes.value = [];
|
|
188
|
-
historyStack.value = [[]];
|
|
189
|
-
historyIndex.value = 0;
|
|
190
|
-
onChange?.(strokes.value);
|
|
191
|
-
};
|
|
192
|
-
const loadData = (data) => {
|
|
193
|
-
strokes.value = [...data];
|
|
194
|
-
historyStack.value = [[...data]];
|
|
195
|
-
historyIndex.value = 0;
|
|
196
|
-
onChange?.(strokes.value);
|
|
197
|
-
};
|
|
198
|
-
const isEmpty = computed(() => strokes.value.length === 0);
|
|
199
|
-
historyStack.value = [[]];
|
|
200
|
-
historyIndex.value = 0;
|
|
201
|
-
return {
|
|
202
|
-
strokes: readonly(strokes),
|
|
203
|
-
canUndo: readonly(canUndo),
|
|
204
|
-
canRedo: readonly(canRedo),
|
|
205
|
-
isEmpty: readonly(isEmpty),
|
|
206
|
-
addStroke,
|
|
207
|
-
undo,
|
|
208
|
-
redo,
|
|
209
|
-
clear,
|
|
210
|
-
loadData
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
//#endregion
|
|
215
|
-
//#region src/components/C_Signature/composables/useSignatureExport.ts
|
|
216
|
-
function useSignatureExport(options) {
|
|
217
|
-
const { canvasRef, watermark } = options;
|
|
218
|
-
const getWatermarkPosition = (canvas, textWidth, fontSize, position) => {
|
|
219
|
-
const padding = 10;
|
|
220
|
-
const positions = {
|
|
221
|
-
"top-left": {
|
|
222
|
-
x: padding,
|
|
223
|
-
y: fontSize + padding
|
|
224
|
-
},
|
|
225
|
-
"top-right": {
|
|
226
|
-
x: canvas.width - textWidth - padding,
|
|
227
|
-
y: fontSize + padding
|
|
228
|
-
},
|
|
229
|
-
"bottom-left": {
|
|
230
|
-
x: padding,
|
|
231
|
-
y: canvas.height - padding
|
|
232
|
-
},
|
|
233
|
-
"bottom-right": {
|
|
234
|
-
x: canvas.width - textWidth - padding,
|
|
235
|
-
y: canvas.height - padding
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
return positions[position] || positions["bottom-right"];
|
|
239
|
-
};
|
|
240
|
-
const drawWatermark = (canvas, text) => {
|
|
241
|
-
const ctx = canvas.getContext("2d");
|
|
242
|
-
if (!ctx || !watermark?.value?.show) return;
|
|
243
|
-
const config = {
|
|
244
|
-
fontSize: watermark.value.fontSize || 12,
|
|
245
|
-
color: watermark.value.color || "#999999",
|
|
246
|
-
position: watermark.value.position || "bottom-right"
|
|
247
|
-
};
|
|
248
|
-
ctx.save();
|
|
249
|
-
ctx.font = `${config.fontSize}px Arial`;
|
|
250
|
-
ctx.fillStyle = config.color;
|
|
251
|
-
ctx.textBaseline = "bottom";
|
|
252
|
-
const textWidth = ctx.measureText(text).width;
|
|
253
|
-
const { x, y } = getWatermarkPosition(canvas, textWidth, config.fontSize, config.position);
|
|
254
|
-
ctx.fillText(text, x, y);
|
|
255
|
-
ctx.restore();
|
|
256
|
-
};
|
|
257
|
-
const createTempCanvas = (sourceCanvas, includeBackground, backgroundColor) => {
|
|
258
|
-
const tempCanvas = document.createElement("canvas");
|
|
259
|
-
tempCanvas.width = sourceCanvas.width;
|
|
260
|
-
tempCanvas.height = sourceCanvas.height;
|
|
261
|
-
const tempCtx = tempCanvas.getContext("2d");
|
|
262
|
-
if (!tempCtx) throw new Error("无法创建临时 Canvas");
|
|
263
|
-
if (includeBackground) {
|
|
264
|
-
tempCtx.fillStyle = backgroundColor;
|
|
265
|
-
tempCtx.fillRect(0, 0, tempCanvas.width, tempCanvas.height);
|
|
266
|
-
}
|
|
267
|
-
tempCtx.drawImage(sourceCanvas, 0, 0);
|
|
268
|
-
return {
|
|
269
|
-
canvas: tempCanvas,
|
|
270
|
-
ctx: tempCtx
|
|
271
|
-
};
|
|
272
|
-
};
|
|
273
|
-
const prepareExportCanvas = (canvas, options) => {
|
|
274
|
-
const { includeBackground = false, backgroundColor = "#FFFFFF", includeWatermark = false } = options;
|
|
275
|
-
const { canvas: tempCanvas } = createTempCanvas(canvas, includeBackground, backgroundColor);
|
|
276
|
-
if (includeWatermark && watermark?.value?.show && watermark.value.text) drawWatermark(tempCanvas, watermark.value.text);
|
|
277
|
-
return tempCanvas;
|
|
278
|
-
};
|
|
279
|
-
const exportToBlob = (canvas, quality) => {
|
|
280
|
-
return new Promise((resolve, reject) => {
|
|
281
|
-
canvas.toBlob((blob) => blob ? resolve(blob) : reject(/* @__PURE__ */ new Error("导出失败")), "image/png", quality);
|
|
282
|
-
});
|
|
283
|
-
};
|
|
284
|
-
const exportSignature = async (options = {}) => {
|
|
285
|
-
const canvas = canvasRef.value;
|
|
286
|
-
if (!canvas) throw new Error("Canvas 未初始化");
|
|
287
|
-
const { format = "png", quality = .92 } = options;
|
|
288
|
-
if (format === "svg") return "data:image/svg+xml;charset=utf-8,<svg xmlns=\"http://www.w3.org/2000/svg\"><text>SVG export placeholder</text></svg>";
|
|
289
|
-
const tempCanvas = prepareExportCanvas(canvas, options);
|
|
290
|
-
if (format === "blob") return exportToBlob(tempCanvas, quality);
|
|
291
|
-
const mimeType = format === "jpeg" ? "image/jpeg" : "image/png";
|
|
292
|
-
return tempCanvas.toDataURL(mimeType, quality);
|
|
293
|
-
};
|
|
294
|
-
const download = async (filename = "signature", options = {}) => {
|
|
295
|
-
const format = options.format || "png";
|
|
296
|
-
const result = await exportSignature({
|
|
297
|
-
...options,
|
|
298
|
-
format
|
|
299
|
-
});
|
|
300
|
-
if (result instanceof Blob) {
|
|
301
|
-
const url = URL.createObjectURL(result);
|
|
302
|
-
const link = document.createElement("a");
|
|
303
|
-
link.href = url;
|
|
304
|
-
link.download = `${filename}.${format}`;
|
|
305
|
-
link.click();
|
|
306
|
-
URL.revokeObjectURL(url);
|
|
307
|
-
} else if (typeof result === "string") {
|
|
308
|
-
const link = document.createElement("a");
|
|
309
|
-
link.href = result;
|
|
310
|
-
link.download = `${filename}.${format}`;
|
|
311
|
-
link.click();
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
const loadImage = async (imageUrl) => {
|
|
315
|
-
const canvas = canvasRef.value;
|
|
316
|
-
if (!canvas) throw new Error("Canvas 未初始化");
|
|
317
|
-
const ctx = canvas.getContext("2d");
|
|
318
|
-
if (!ctx) throw new Error("无法获取 Canvas 上下文");
|
|
319
|
-
return new Promise((resolve, reject) => {
|
|
320
|
-
const img = new Image();
|
|
321
|
-
img.crossOrigin = "anonymous";
|
|
322
|
-
img.onload = () => {
|
|
323
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
324
|
-
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
325
|
-
resolve();
|
|
326
|
-
};
|
|
327
|
-
img.onerror = () => reject(/* @__PURE__ */ new Error(`图片加载失败: ${imageUrl}`));
|
|
328
|
-
img.src = imageUrl;
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
return {
|
|
332
|
-
exportSignature,
|
|
333
|
-
download,
|
|
334
|
-
loadImage
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/components/C_Signature/data.ts
|
|
340
|
-
const DEFAULT_PEN_CONFIG = {
|
|
341
|
-
color: "#000000",
|
|
342
|
-
width: 2,
|
|
343
|
-
opacity: 1
|
|
344
|
-
};
|
|
345
|
-
const DEFAULT_WATERMARK_CONFIG = {
|
|
346
|
-
show: false,
|
|
347
|
-
text: "",
|
|
348
|
-
fontSize: 12,
|
|
349
|
-
color: "#999999",
|
|
350
|
-
position: "bottom-right"
|
|
351
|
-
};
|
|
352
|
-
const PRESET_COLORS = [
|
|
353
|
-
"#000000",
|
|
354
|
-
"#FF0000",
|
|
355
|
-
"#0000FF",
|
|
356
|
-
"#00AA00",
|
|
357
|
-
"#FF6600",
|
|
358
|
-
"#9900FF"
|
|
359
|
-
];
|
|
360
|
-
|
|
361
|
-
//#endregion
|
|
362
|
-
//#region src/components/C_Signature/index.vue?vue&type=script&setup=true&lang.ts
|
|
363
|
-
const _hoisted_1 = { class: "c-signature" };
|
|
364
|
-
const _hoisted_2 = {
|
|
365
|
-
key: 0,
|
|
366
|
-
class: "signature-toolbar"
|
|
367
|
-
};
|
|
368
|
-
const _hoisted_3 = { class: "toolbar-section" };
|
|
369
|
-
const _hoisted_4 = {
|
|
370
|
-
key: 0,
|
|
371
|
-
class: "toolbar-section"
|
|
372
|
-
};
|
|
373
|
-
const _hoisted_5 = {
|
|
374
|
-
key: 1,
|
|
375
|
-
class: "toolbar-section"
|
|
376
|
-
};
|
|
377
|
-
const _hoisted_6 = { class: "toolbar-section" };
|
|
378
|
-
const _hoisted_7 = { class: "toolbar-section" };
|
|
379
|
-
const _hoisted_8 = {
|
|
380
|
-
key: 0,
|
|
381
|
-
class: "canvas-placeholder"
|
|
382
|
-
};
|
|
383
|
-
var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
384
|
-
name: "C_Signature",
|
|
385
|
-
__name: "index",
|
|
386
|
-
props: {
|
|
387
|
-
width: { default: "100%" },
|
|
388
|
-
height: { default: 300 },
|
|
389
|
-
penConfig: {},
|
|
390
|
-
eraserConfig: {},
|
|
391
|
-
disabled: {
|
|
392
|
-
type: Boolean,
|
|
393
|
-
default: false
|
|
394
|
-
},
|
|
395
|
-
readonly: {
|
|
396
|
-
type: Boolean,
|
|
397
|
-
default: false
|
|
398
|
-
},
|
|
399
|
-
backgroundImage: {},
|
|
400
|
-
backgroundColor: {},
|
|
401
|
-
watermark: {},
|
|
402
|
-
showToolbar: {
|
|
403
|
-
type: Boolean,
|
|
404
|
-
default: true
|
|
405
|
-
},
|
|
406
|
-
maxHistory: { default: 50 }
|
|
407
|
-
},
|
|
408
|
-
emits: [
|
|
409
|
-
"start-draw",
|
|
410
|
-
"drawing",
|
|
411
|
-
"end-draw",
|
|
412
|
-
"clear",
|
|
413
|
-
"undo",
|
|
414
|
-
"redo",
|
|
415
|
-
"change"
|
|
416
|
-
],
|
|
417
|
-
setup(__props, { expose: __expose, emit: __emit }) {
|
|
418
|
-
const props = __props;
|
|
419
|
-
const emit = __emit;
|
|
420
|
-
const canvasRef = ref(null);
|
|
421
|
-
const currentMode = ref("pen");
|
|
422
|
-
const currentPenConfig = reactive({
|
|
423
|
-
...DEFAULT_PEN_CONFIG,
|
|
424
|
-
...props.penConfig
|
|
425
|
-
});
|
|
426
|
-
const currentWatermark = reactive({
|
|
427
|
-
...DEFAULT_WATERMARK_CONFIG,
|
|
428
|
-
...props.watermark
|
|
429
|
-
});
|
|
430
|
-
const { strokes, canUndo, canRedo, isEmpty, addStroke, undo, redo, clear, loadData } = useSignatureHistory({
|
|
431
|
-
maxHistory: props.maxHistory,
|
|
432
|
-
onChange: (data) => {
|
|
433
|
-
canvasInstance.redrawStrokes(data);
|
|
434
|
-
emit("change", data);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
const canvasInstance = useSignatureCanvas({
|
|
438
|
-
canvasRef,
|
|
439
|
-
penConfig: toRef(currentPenConfig),
|
|
440
|
-
mode: currentMode,
|
|
441
|
-
disabled: toRef(props, "disabled"),
|
|
442
|
-
onStrokeComplete: (stroke) => {
|
|
443
|
-
addStroke(stroke);
|
|
444
|
-
emit("end-draw", stroke);
|
|
445
|
-
},
|
|
446
|
-
onDrawStart: () => emit("start-draw"),
|
|
447
|
-
onDrawing: (point) => emit("drawing", point)
|
|
448
|
-
});
|
|
449
|
-
const exportInstance = useSignatureExport({
|
|
450
|
-
canvasRef,
|
|
451
|
-
watermark: toRef(currentWatermark)
|
|
452
|
-
});
|
|
453
|
-
const handleUndo = () => {
|
|
454
|
-
const result = undo();
|
|
455
|
-
if (result) emit("undo");
|
|
456
|
-
return result;
|
|
457
|
-
};
|
|
458
|
-
const handleRedo = () => {
|
|
459
|
-
const result = redo();
|
|
460
|
-
if (result) emit("redo");
|
|
461
|
-
return result;
|
|
462
|
-
};
|
|
463
|
-
const handleClear = () => {
|
|
464
|
-
clear();
|
|
465
|
-
canvasInstance.clearCanvas();
|
|
466
|
-
emit("clear");
|
|
467
|
-
};
|
|
468
|
-
const exportSignature = async (options) => {
|
|
469
|
-
return exportInstance.exportSignature(options);
|
|
470
|
-
};
|
|
471
|
-
const download = async (filename, options) => {
|
|
472
|
-
return exportInstance.download(filename, options);
|
|
473
|
-
};
|
|
474
|
-
const loadImage = async (imageUrl) => {
|
|
475
|
-
await exportInstance.loadImage(imageUrl);
|
|
476
|
-
clear();
|
|
477
|
-
};
|
|
478
|
-
const getSignatureData = () => strokes.value;
|
|
479
|
-
const loadSignatureData = (data) => loadData(data);
|
|
480
|
-
const isSignatureEmpty = () => isEmpty.value;
|
|
481
|
-
onMounted(() => {
|
|
482
|
-
canvasInstance.initCanvas();
|
|
483
|
-
canvasInstance.bindEvents();
|
|
484
|
-
if (props.backgroundImage) loadImage(props.backgroundImage);
|
|
485
|
-
});
|
|
486
|
-
onUnmounted(() => canvasInstance.unbindEvents());
|
|
487
|
-
__expose({
|
|
488
|
-
clear: handleClear,
|
|
489
|
-
undo: handleUndo,
|
|
490
|
-
redo: handleRedo,
|
|
491
|
-
export: exportSignature,
|
|
492
|
-
download,
|
|
493
|
-
loadImage,
|
|
494
|
-
getSignatureData,
|
|
495
|
-
loadSignatureData,
|
|
496
|
-
isEmpty: isSignatureEmpty
|
|
497
|
-
});
|
|
498
|
-
return (_ctx, _cache) => {
|
|
499
|
-
return openBlock(), createElementBlock("div", _hoisted_1, [_ctx.showToolbar ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
|
500
|
-
createElementVNode("div", _hoisted_3, [createVNode(unref(NButtonGroup), null, {
|
|
501
|
-
default: withCtx(() => [createVNode(unref(NButton), {
|
|
502
|
-
type: currentMode.value === "pen" ? "primary" : "default",
|
|
503
|
-
size: "small",
|
|
504
|
-
onClick: _cache[0] || (_cache[0] = ($event) => currentMode.value = "pen")
|
|
505
|
-
}, {
|
|
506
|
-
icon: withCtx(() => [createVNode(C_Icon_default, {
|
|
507
|
-
name: "mdi:draw",
|
|
508
|
-
size: 16,
|
|
509
|
-
color: "currentColor"
|
|
510
|
-
})]),
|
|
511
|
-
default: withCtx(() => [_cache[4] || (_cache[4] = createTextVNode(" 画笔 ", -1))]),
|
|
512
|
-
_: 1,
|
|
513
|
-
__: [4]
|
|
514
|
-
}, 8, ["type"]), createVNode(unref(NButton), {
|
|
515
|
-
type: currentMode.value === "eraser" ? "primary" : "default",
|
|
516
|
-
size: "small",
|
|
517
|
-
onClick: _cache[1] || (_cache[1] = ($event) => currentMode.value = "eraser")
|
|
518
|
-
}, {
|
|
519
|
-
icon: withCtx(() => [createVNode(C_Icon_default, {
|
|
520
|
-
name: "mdi:eraser",
|
|
521
|
-
size: 16,
|
|
522
|
-
color: "currentColor"
|
|
523
|
-
})]),
|
|
524
|
-
default: withCtx(() => [_cache[5] || (_cache[5] = createTextVNode(" 橡皮擦 ", -1))]),
|
|
525
|
-
_: 1,
|
|
526
|
-
__: [5]
|
|
527
|
-
}, 8, ["type"])]),
|
|
528
|
-
_: 1
|
|
529
|
-
})]),
|
|
530
|
-
_cache[11] || (_cache[11] = createElementVNode("div", { class: "toolbar-section divider" }, null, -1)),
|
|
531
|
-
currentMode.value === "pen" ? (openBlock(), createElementBlock("div", _hoisted_4, [_cache[6] || (_cache[6] = createElementVNode("span", { class: "section-label" }, "颜色", -1)), createVNode(unref(NColorPicker), {
|
|
532
|
-
value: currentPenConfig.color,
|
|
533
|
-
"onUpdate:value": _cache[2] || (_cache[2] = ($event) => currentPenConfig.color = $event),
|
|
534
|
-
"show-alpha": false,
|
|
535
|
-
size: "small",
|
|
536
|
-
swatches: unref(PRESET_COLORS)
|
|
537
|
-
}, null, 8, ["value", "swatches"])])) : createCommentVNode("v-if", true),
|
|
538
|
-
currentMode.value === "pen" ? (openBlock(), createElementBlock("div", _hoisted_5, [_cache[7] || (_cache[7] = createElementVNode("span", { class: "section-label" }, "粗细", -1)), createVNode(unref(NInputNumber), {
|
|
539
|
-
value: currentPenConfig.width,
|
|
540
|
-
"onUpdate:value": _cache[3] || (_cache[3] = ($event) => currentPenConfig.width = $event),
|
|
541
|
-
min: 1,
|
|
542
|
-
max: 20,
|
|
543
|
-
size: "small",
|
|
544
|
-
style: { "width": "80px" }
|
|
545
|
-
}, null, 8, ["value"])])) : createCommentVNode("v-if", true),
|
|
546
|
-
_cache[12] || (_cache[12] = createElementVNode("div", { class: "toolbar-section divider" }, null, -1)),
|
|
547
|
-
createElementVNode("div", _hoisted_6, [createVNode(unref(NButton), {
|
|
548
|
-
size: "small",
|
|
549
|
-
disabled: !unref(canUndo),
|
|
550
|
-
onClick: handleUndo
|
|
551
|
-
}, {
|
|
552
|
-
icon: withCtx(() => [createVNode(C_Icon_default, {
|
|
553
|
-
name: "mdi:undo",
|
|
554
|
-
size: 16,
|
|
555
|
-
color: "currentColor"
|
|
556
|
-
})]),
|
|
557
|
-
default: withCtx(() => [_cache[8] || (_cache[8] = createTextVNode(" 撤销 ", -1))]),
|
|
558
|
-
_: 1,
|
|
559
|
-
__: [8]
|
|
560
|
-
}, 8, ["disabled"]), createVNode(unref(NButton), {
|
|
561
|
-
size: "small",
|
|
562
|
-
disabled: !unref(canRedo),
|
|
563
|
-
onClick: handleRedo
|
|
564
|
-
}, {
|
|
565
|
-
icon: withCtx(() => [createVNode(C_Icon_default, {
|
|
566
|
-
name: "mdi:redo",
|
|
567
|
-
size: 16,
|
|
568
|
-
color: "currentColor"
|
|
569
|
-
})]),
|
|
570
|
-
default: withCtx(() => [_cache[9] || (_cache[9] = createTextVNode(" 重做 ", -1))]),
|
|
571
|
-
_: 1,
|
|
572
|
-
__: [9]
|
|
573
|
-
}, 8, ["disabled"])]),
|
|
574
|
-
_cache[13] || (_cache[13] = createElementVNode("div", { class: "toolbar-section divider" }, null, -1)),
|
|
575
|
-
createElementVNode("div", _hoisted_7, [createVNode(unref(NButton), {
|
|
576
|
-
size: "small",
|
|
577
|
-
type: "error",
|
|
578
|
-
disabled: unref(isEmpty),
|
|
579
|
-
onClick: handleClear
|
|
580
|
-
}, {
|
|
581
|
-
icon: withCtx(() => [createVNode(C_Icon_default, {
|
|
582
|
-
name: "mdi:delete-outline",
|
|
583
|
-
size: 16,
|
|
584
|
-
color: "currentColor"
|
|
585
|
-
})]),
|
|
586
|
-
default: withCtx(() => [_cache[10] || (_cache[10] = createTextVNode(" 清空 ", -1))]),
|
|
587
|
-
_: 1,
|
|
588
|
-
__: [10]
|
|
589
|
-
}, 8, ["disabled"])])
|
|
590
|
-
])) : createCommentVNode("v-if", true), createElementVNode("div", {
|
|
591
|
-
class: normalizeClass(["signature-canvas-wrapper", {
|
|
592
|
-
disabled: _ctx.disabled,
|
|
593
|
-
readonly: _ctx.readonly
|
|
594
|
-
}]),
|
|
595
|
-
style: normalizeStyle({
|
|
596
|
-
width: typeof _ctx.width === "number" ? `${_ctx.width}px` : _ctx.width,
|
|
597
|
-
height: typeof _ctx.height === "number" ? `${_ctx.height}px` : _ctx.height,
|
|
598
|
-
backgroundColor: _ctx.backgroundColor || "transparent"
|
|
599
|
-
})
|
|
600
|
-
}, [createElementVNode("canvas", {
|
|
601
|
-
ref_key: "canvasRef",
|
|
602
|
-
ref: canvasRef,
|
|
603
|
-
class: normalizeClass(["signature-canvas", {
|
|
604
|
-
disabled: _ctx.disabled,
|
|
605
|
-
readonly: _ctx.readonly
|
|
606
|
-
}])
|
|
607
|
-
}, null, 2), unref(isEmpty) && !_ctx.disabled && !_ctx.readonly ? (openBlock(), createElementBlock("div", _hoisted_8, " 请在此处签名 ")) : createCommentVNode("v-if", true)], 6)]);
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
//#endregion
|
|
613
|
-
//#region src/components/C_Signature/index.vue
|
|
614
|
-
var C_Signature_default = /* @__PURE__ */ export_helper_default(index_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-1c733bfe"]]);
|
|
615
|
-
|
|
616
|
-
//#endregion
|
|
617
|
-
export { useSignatureCanvas as i, useSignatureExport as n, useSignatureHistory as r, C_Signature_default as t };
|
|
1
|
+
import{t as e}from"./C_Icon2.js";import{t}from"./export-helper.js";import{NButton as n,NButtonGroup as r,NColorPicker as i,NInputNumber as a}from"naive-ui";import{computed as o,createCommentVNode as s,createElementBlock as c,createElementVNode as l,createTextVNode as u,createVNode as d,defineComponent as f,normalizeClass as p,normalizeStyle as m,onMounted as h,onUnmounted as g,openBlock as _,reactive as v,readonly as y,ref as b,toRef as x,unref as S,withCtx as C}from"vue";function w(e){let{canvasRef:t,penConfig:n,mode:r,disabled:i,onStrokeComplete:a,onDrawStart:o,onDrawing:s}=e,c=b(!1),l=b([]),u=null,d=()=>{let e=t.value;if(!e||(u=e.getContext(`2d`,{willReadFrequently:!0}),!u))return;let n=window.devicePixelRatio||1,r=e.getBoundingClientRect();e.width=r.width*n,e.height=r.height*n,e.style.width=`${r.width}px`,e.style.height=`${r.height}px`,u.scale(n,n),u.lineCap=`round`,u.lineJoin=`round`},f=e=>{let n=t.value;if(!n)return{x:0,y:0};let r=n.getBoundingClientRect(),i,a;if(`touches`in e&&e.touches.length>0)({clientX:i,clientY:a}=e.touches[0]);else if(`clientX`in e)({clientX:i,clientY:a}=e);else return{x:0,y:0};return{x:i-r.left,y:a-r.top,timestamp:Date.now()}},p=(e,t,n,r=!1)=>{u&&(u.save(),r?(u.globalCompositeOperation=`destination-out`,u.lineWidth=20):(u.globalCompositeOperation=`source-over`,u.strokeStyle=n.color,u.lineWidth=n.width,u.globalAlpha=n.opacity),u.beginPath(),u.moveTo(e.x,e.y),u.lineTo(t.x,t.y),u.stroke(),u.restore())},m=e=>{if(i.value)return;e.preventDefault(),c.value=!0,l.value=[];let t=f(e);l.value.push(t),o()},h=e=>{if(!c.value||i.value)return;e.preventDefault();let t=f(e),a=l.value[l.value.length-1];a&&p(a,t,n.value,r.value===`eraser`),l.value.push(t),s(t)},g=e=>{!c.value||i.value||(e.preventDefault(),c.value=!1,l.value.length>0&&(a({points:[...l.value],color:n.value.color,width:n.value.width,opacity:n.value.opacity,mode:r.value}),l.value=[]))};return{isDrawing:y(c),initCanvas:d,bindEvents:()=>{let e=t.value;e&&(e.addEventListener(`mousedown`,m),e.addEventListener(`mousemove`,h),e.addEventListener(`mouseup`,g),e.addEventListener(`mouseleave`,g),e.addEventListener(`touchstart`,m,{passive:!1}),e.addEventListener(`touchmove`,h,{passive:!1}),e.addEventListener(`touchend`,g),e.addEventListener(`touchcancel`,g))},unbindEvents:()=>{let e=t.value;e&&(e.removeEventListener(`mousedown`,m),e.removeEventListener(`mousemove`,h),e.removeEventListener(`mouseup`,g),e.removeEventListener(`mouseleave`,g),e.removeEventListener(`touchstart`,m),e.removeEventListener(`touchmove`,h),e.removeEventListener(`touchend`,g),e.removeEventListener(`touchcancel`,g))},redrawStrokes:e=>{if(!u||!t.value)return;let n=t.value;u.clearRect(0,0,n.width,n.height),e.forEach(e=>{for(let t=1;t<e.points.length;t++)p(e.points[t-1],e.points[t],{color:e.color,width:e.width,opacity:e.opacity},e.mode===`eraser`)})},clearCanvas:()=>{!u||!t.value||u.clearRect(0,0,t.value.width,t.value.height)}}}function T(e={}){let{maxHistory:t=50,onChange:n}=e,r=b([]),i=b([]),a=b(-1),s=o(()=>a.value>0),c=o(()=>a.value<i.value.length-1),l=e=>{r.value.push(e),u()},u=()=>{i.value=i.value.slice(0,a.value+1),i.value.push([...r.value]),a.value++,i.value.length>t&&(i.value.shift(),a.value--),n?.(r.value)},d=()=>s.value?(a.value--,r.value=[...i.value[a.value]],n?.(r.value),!0):!1,f=()=>c.value?(a.value++,r.value=[...i.value[a.value]],n?.(r.value),!0):!1,p=()=>{r.value=[],i.value=[[]],a.value=0,n?.(r.value)},m=e=>{r.value=[...e],i.value=[[...e]],a.value=0,n?.(r.value)},h=o(()=>r.value.length===0);return i.value=[[]],a.value=0,{strokes:y(r),canUndo:y(s),canRedo:y(c),isEmpty:y(h),addStroke:l,undo:d,redo:f,clear:p,loadData:m}}function E(e){let{canvasRef:t,watermark:n}=e,r=(e,t,n,r)=>{let i={"top-left":{x:10,y:n+10},"top-right":{x:e.width-t-10,y:n+10},"bottom-left":{x:10,y:e.height-10},"bottom-right":{x:e.width-t-10,y:e.height-10}};return i[r]||i[`bottom-right`]},i=(e,t)=>{let i=e.getContext(`2d`);if(!i||!n?.value?.show)return;let a={fontSize:n.value.fontSize||12,color:n.value.color||`#999999`,position:n.value.position||`bottom-right`};i.save(),i.font=`${a.fontSize}px Arial`,i.fillStyle=a.color,i.textBaseline=`bottom`;let o=i.measureText(t).width,{x:s,y:c}=r(e,o,a.fontSize,a.position);i.fillText(t,s,c),i.restore()},a=(e,t,n)=>{let r=document.createElement(`canvas`);r.width=e.width,r.height=e.height;let i=r.getContext(`2d`);if(!i)throw Error(`无法创建临时 Canvas`);return t&&(i.fillStyle=n,i.fillRect(0,0,r.width,r.height)),i.drawImage(e,0,0),{canvas:r,ctx:i}},o=(e,t)=>{let{includeBackground:r=!1,backgroundColor:o=`#FFFFFF`,includeWatermark:s=!1}=t,{canvas:c}=a(e,r,o);return s&&n?.value?.show&&n.value.text&&i(c,n.value.text),c},s=(e,t)=>new Promise((n,r)=>{e.toBlob(e=>e?n(e):r(Error(`导出失败`)),`image/png`,t)}),c=async(e={})=>{let n=t.value;if(!n)throw Error(`Canvas 未初始化`);let{format:r=`png`,quality:i=.92}=e;if(r===`svg`)return`data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><text>SVG export placeholder</text></svg>`;let a=o(n,e);if(r===`blob`)return s(a,i);let c=r===`jpeg`?`image/jpeg`:`image/png`;return a.toDataURL(c,i)};return{exportSignature:c,download:async(e=`signature`,t={})=>{let n=t.format||`png`,r=await c({...t,format:n});if(r instanceof Blob){let t=URL.createObjectURL(r),i=document.createElement(`a`);i.href=t,i.download=`${e}.${n}`,i.click(),URL.revokeObjectURL(t)}else if(typeof r==`string`){let t=document.createElement(`a`);t.href=r,t.download=`${e}.${n}`,t.click()}},loadImage:async e=>{let n=t.value;if(!n)throw Error(`Canvas 未初始化`);let r=n.getContext(`2d`);if(!r)throw Error(`无法获取 Canvas 上下文`);return new Promise((t,i)=>{let a=new Image;a.crossOrigin=`anonymous`,a.onload=()=>{r.clearRect(0,0,n.width,n.height),r.drawImage(a,0,0,n.width,n.height),t()},a.onerror=()=>i(Error(`图片加载失败: ${e}`)),a.src=e})}}}const ee={color:`#000000`,width:2,opacity:1},te={show:!1,text:``,fontSize:12,color:`#999999`,position:`bottom-right`},D=[`#000000`,`#FF0000`,`#0000FF`,`#00AA00`,`#FF6600`,`#9900FF`],O={class:`c-signature`},k={key:0,class:`signature-toolbar`},A={class:`toolbar-section`},j={key:0,class:`toolbar-section`},M={key:1,class:`toolbar-section`},N={class:`toolbar-section`},ne={class:`toolbar-section`},re={key:0,class:`canvas-placeholder`};var P=t(f({name:`C_Signature`,__name:`index`,props:{width:{default:`100%`},height:{default:300},penConfig:{},eraserConfig:{},disabled:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1},backgroundImage:{},backgroundColor:{},watermark:{},showToolbar:{type:Boolean,default:!0},maxHistory:{default:50}},emits:[`start-draw`,`drawing`,`end-draw`,`clear`,`undo`,`redo`,`change`],setup(t,{expose:o,emit:f}){let y=t,P=f,F=b(null),I=b(`pen`),L=v({...ee,...y.penConfig}),R=v({...te,...y.watermark}),{strokes:z,canUndo:B,canRedo:V,isEmpty:H,addStroke:U,undo:W,redo:G,clear:K,loadData:q}=T({maxHistory:y.maxHistory,onChange:e=>{J.redrawStrokes(e),P(`change`,e)}}),J=w({canvasRef:F,penConfig:x(L),mode:I,disabled:x(y,`disabled`),onStrokeComplete:e=>{U(e),P(`end-draw`,e)},onDrawStart:()=>P(`start-draw`),onDrawing:e=>P(`drawing`,e)}),Y=E({canvasRef:F,watermark:x(R)}),X=()=>{let e=W();return e&&P(`undo`),e},Z=()=>{let e=G();return e&&P(`redo`),e},Q=()=>{K(),J.clearCanvas(),P(`clear`)},ie=async e=>Y.exportSignature(e),ae=async(e,t)=>Y.download(e,t),$=async e=>{await Y.loadImage(e),K()};return h(()=>{J.initCanvas(),J.bindEvents(),y.backgroundImage&&$(y.backgroundImage)}),g(()=>J.unbindEvents()),o({clear:Q,undo:X,redo:Z,export:ie,download:ae,loadImage:$,getSignatureData:()=>z.value,loadSignatureData:e=>q(e),isEmpty:()=>H.value}),(t,o)=>(_(),c(`div`,O,[t.showToolbar?(_(),c(`div`,k,[l(`div`,A,[d(S(r),null,{default:C(()=>[d(S(n),{type:I.value===`pen`?`primary`:`default`,size:`small`,onClick:o[0]||=e=>I.value=`pen`},{icon:C(()=>[d(e,{name:`mdi:draw`,size:16,color:`currentColor`})]),default:C(()=>[o[4]||=u(` 画笔 `,-1)]),_:1,__:[4]},8,[`type`]),d(S(n),{type:I.value===`eraser`?`primary`:`default`,size:`small`,onClick:o[1]||=e=>I.value=`eraser`},{icon:C(()=>[d(e,{name:`mdi:eraser`,size:16,color:`currentColor`})]),default:C(()=>[o[5]||=u(` 橡皮擦 `,-1)]),_:1,__:[5]},8,[`type`])]),_:1})]),o[11]||=l(`div`,{class:`toolbar-section divider`},null,-1),I.value===`pen`?(_(),c(`div`,j,[o[6]||=l(`span`,{class:`section-label`},`颜色`,-1),d(S(i),{value:L.color,"onUpdate:value":o[2]||=e=>L.color=e,"show-alpha":!1,size:`small`,swatches:S(D)},null,8,[`value`,`swatches`])])):s(`v-if`,!0),I.value===`pen`?(_(),c(`div`,M,[o[7]||=l(`span`,{class:`section-label`},`粗细`,-1),d(S(a),{value:L.width,"onUpdate:value":o[3]||=e=>L.width=e,min:1,max:20,size:`small`,style:{width:`80px`}},null,8,[`value`])])):s(`v-if`,!0),o[12]||=l(`div`,{class:`toolbar-section divider`},null,-1),l(`div`,N,[d(S(n),{size:`small`,disabled:!S(B),onClick:X},{icon:C(()=>[d(e,{name:`mdi:undo`,size:16,color:`currentColor`})]),default:C(()=>[o[8]||=u(` 撤销 `,-1)]),_:1,__:[8]},8,[`disabled`]),d(S(n),{size:`small`,disabled:!S(V),onClick:Z},{icon:C(()=>[d(e,{name:`mdi:redo`,size:16,color:`currentColor`})]),default:C(()=>[o[9]||=u(` 重做 `,-1)]),_:1,__:[9]},8,[`disabled`])]),o[13]||=l(`div`,{class:`toolbar-section divider`},null,-1),l(`div`,ne,[d(S(n),{size:`small`,type:`error`,disabled:S(H),onClick:Q},{icon:C(()=>[d(e,{name:`mdi:delete-outline`,size:16,color:`currentColor`})]),default:C(()=>[o[10]||=u(` 清空 `,-1)]),_:1,__:[10]},8,[`disabled`])])])):s(`v-if`,!0),l(`div`,{class:p([`signature-canvas-wrapper`,{disabled:t.disabled,readonly:t.readonly}]),style:m({width:typeof t.width==`number`?`${t.width}px`:t.width,height:typeof t.height==`number`?`${t.height}px`:t.height,backgroundColor:t.backgroundColor||`transparent`})},[l(`canvas`,{ref_key:`canvasRef`,ref:F,class:p([`signature-canvas`,{disabled:t.disabled,readonly:t.readonly}])},null,2),S(H)&&!t.disabled&&!t.readonly?(_(),c(`div`,re,` 请在此处签名 `)):s(`v-if`,!0)],6)]))}}),[[`__scopeId`,`data-v-1c733bfe`]]);export{w as i,E as n,T as r,P as t};
|
|
618
2
|
//# sourceMappingURL=C_Signature2.js.map
|