scanonweb 1.0.1

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/src/index.d.ts ADDED
@@ -0,0 +1,266 @@
1
+ /**
2
+ * ScanOnWeb - 扫描控件 JavaScript SDK
3
+ * TypeScript 定义文件
4
+ */
5
+
6
+ /**
7
+ * 扫描配置参数接口
8
+ */
9
+ export interface ScanConfig {
10
+ /** 是否显示扫描控件工作界面 */
11
+ showUI: boolean;
12
+ /** DPI 分辨率 X */
13
+ dpi_x: number;
14
+ /** DPI 分辨率 Y */
15
+ dpi_y: number;
16
+ /** 选中的扫描仪硬件设备id索引 */
17
+ deviceIndex: number;
18
+ /** 是否显示设备内置对话框 */
19
+ showDialog: boolean;
20
+ /** 是否使用自动进纸器 */
21
+ autoFeedEnable: boolean;
22
+ /** 是否自动装填纸张 */
23
+ autoFeed: boolean;
24
+ /** 是否使用双面扫描模式 */
25
+ dupxMode: boolean;
26
+ /** 是否使用自动纠偏模式 */
27
+ autoDeskew: boolean;
28
+ /** 是否使用自动边框检测 */
29
+ autoBorderDetection: boolean;
30
+ /** 色彩模式 */
31
+ colorMode: 'RGB' | 'BW' | 'GRAY';
32
+ /** 数据传输模式 */
33
+ transMode: 'memory' | 'file' | 'native';
34
+ }
35
+
36
+ /**
37
+ * WebSocket 消息接口
38
+ */
39
+ export interface WebSocketMessage {
40
+ /** 命令类型 */
41
+ cmd_type: string;
42
+ /** 图像数量 */
43
+ imageCount?: number;
44
+ /** 当前设备索引 */
45
+ currentIndex?: number;
46
+ /** 其他属性 */
47
+ [key: string]: any;
48
+ }
49
+
50
+ /**
51
+ * 扫描控件类
52
+ */
53
+ export default class ScanOnWeb {
54
+ /** 扫描配置参数 */
55
+ scaner_work_config: ScanConfig;
56
+
57
+ /** WebSocket 连接对象 */
58
+ h5socket: WebSocket | null;
59
+
60
+ /** 扫描结果图像总数 */
61
+ imageCount: number;
62
+
63
+ // 事件回调函数(可选)
64
+ onGetDevicesListEvent?: (msg: WebSocketMessage) => void;
65
+ onScanFinishedEvent?: (msg: WebSocketMessage) => void;
66
+ onSelectScanDeviceEvent?: (msg: WebSocketMessage) => void;
67
+ onGetImageCountEvent?: (msg: WebSocketMessage) => void;
68
+ onGetAllImageEvent?: (msg: WebSocketMessage) => void;
69
+ onGetImageByIdEvent?: (msg: WebSocketMessage) => void;
70
+ onLoadImageFromUrlEvent?: (msg: WebSocketMessage) => void;
71
+ onRotateImageEvent?: (msg: WebSocketMessage) => void;
72
+ onGetImageSizeEvent?: (msg: WebSocketMessage) => void;
73
+ onUploadAllImageAsPdfToUrlEvent?: (msg: WebSocketMessage) => void;
74
+ onUploadAllImageAsTiffToUrlEvent?: (msg: WebSocketMessage) => void;
75
+ onUploadJpgImageByIndexEvent?: (msg: WebSocketMessage) => void;
76
+ onUploadEvent?: (msg: WebSocketMessage) => void;
77
+ onImageEditedEvent?: (msg: WebSocketMessage) => void;
78
+ onImageDrapEvent?: (msg: WebSocketMessage) => void;
79
+
80
+ /**
81
+ * 构造函数
82
+ */
83
+ constructor();
84
+
85
+ /**
86
+ * 通过连接多个websocket server端口返回一个可用的websocket连接对象
87
+ * @param wssUrls WebSocket服务器URL数组
88
+ * @returns WebSocket连接Promise
89
+ */
90
+ getConnectedServer(wssUrls: string[]): Promise<WebSocket>;
91
+
92
+ /**
93
+ * 尝试检测websocket哪个端口可以成功连接
94
+ */
95
+ tryConnect(): void;
96
+
97
+ /**
98
+ * 初始化websocket相关的函数绑定
99
+ * @param server WebSocket服务器实例
100
+ */
101
+ initWebsocketCallback(server: WebSocket): void;
102
+
103
+ /**
104
+ * WebSocket错误处理
105
+ * @param event 错误事件
106
+ */
107
+ onSocketError(event: Event): void;
108
+
109
+ /**
110
+ * 判断回调函数是否存在
111
+ * @param f 要检查的函数
112
+ * @returns 函数是否存在且为函数类型
113
+ */
114
+ isCallbackExist(f: any): f is Function;
115
+
116
+ /**
117
+ * WebSocket消息处理
118
+ * @param event WebSocket消息事件
119
+ */
120
+ onSocketMessage(event: MessageEvent): void;
121
+
122
+ /**
123
+ * 通过websocket发送数据给webscoket服务端
124
+ * @param commandData 要发送的命令数据
125
+ */
126
+ sendWebSocketCommand(commandData: object): void;
127
+
128
+ /**
129
+ * 设置授权信息
130
+ * @param licenseMode 授权模式
131
+ * @param key1 授权密钥1
132
+ * @param key2 授权密钥2
133
+ * @param licenseServerUrl 授权服务器URL
134
+ */
135
+ setLicenseKey(licenseMode: string, key1: string, key2: string, licenseServerUrl: string): void;
136
+
137
+ /**
138
+ * 加载所有可用的扫描设备
139
+ */
140
+ loadDevices(): void;
141
+
142
+ /**
143
+ * 设置当前选中的扫描设备id
144
+ * @param deviceIndex 设备索引
145
+ */
146
+ selectScanDevice(deviceIndex: number): void;
147
+
148
+ /**
149
+ * 开始扫描
150
+ */
151
+ startScan(): void;
152
+
153
+ /**
154
+ * 清除全部扫描结果
155
+ */
156
+ clearAll(): void;
157
+
158
+ /**
159
+ * 获取图像总数
160
+ */
161
+ getImageCount(): void;
162
+
163
+ /**
164
+ * 获取所有图像
165
+ */
166
+ getAllImage(): void;
167
+
168
+ /**
169
+ * 发送指令获取某一页图像到托盘服务
170
+ * @param index 图像索引
171
+ */
172
+ getImageById(index: number): void;
173
+
174
+ /**
175
+ * 发送指令远程加载服务器端的多页图像到托盘服务
176
+ * @param url 图像URL
177
+ */
178
+ loadImageFromUrl(url: string): void;
179
+
180
+ /**
181
+ * 发送指令旋转某一页图像到托盘服务
182
+ * @param index 图像索引
183
+ * @param angle 旋转角度
184
+ */
185
+ rotateImage(index: number, angle: number): void;
186
+
187
+ /**
188
+ * 发送指令获取某一页图像的宽度到托盘服务
189
+ * @param index 图像索引
190
+ */
191
+ getImageSize(index: number): void;
192
+
193
+ /**
194
+ * 发送指令删除某一页图像到托盘服务
195
+ * @param index 图像索引
196
+ */
197
+ deleteImageByIndex(index: number): void;
198
+
199
+ /**
200
+ * 以pdf格式上传全部图像到服务器端
201
+ * @param url 上传URL
202
+ * @param id 标识ID
203
+ * @param desc 描述信息
204
+ */
205
+ uploadAllImageAsPdfToUrl(url: string, id: string, desc: string): void;
206
+
207
+ /**
208
+ * 以tiff格式上传全部图像到服务器端
209
+ * @param url 上传URL
210
+ * @param id 标识ID
211
+ * @param desc 描述信息
212
+ */
213
+ uploadAllImageAsTiffToUrl(url: string, id: string, desc: string): void;
214
+
215
+ /**
216
+ * 以jpg格式上传某一页图像到服务器端
217
+ * @param url 上传URL
218
+ * @param id 标识ID
219
+ * @param desc 描述信息
220
+ * @param index 图像索引
221
+ */
222
+ uploadJpgImageByIndex(url: string, id: string, desc: string, index: number): void;
223
+
224
+ /**
225
+ * 全部图像保存到客户端本地文件
226
+ * @param filename 文件名
227
+ */
228
+ saveAllImageToLocal(filename: string): void;
229
+
230
+ /**
231
+ * 从客户端本地读取图像,通过打开文件对话框选择图像文件
232
+ */
233
+ openClientLocalfile(): void;
234
+
235
+ /**
236
+ * ftp上传全部图像文件到服务器端
237
+ * @param serverIp 服务器IP
238
+ * @param port 端口
239
+ * @param username 用户名
240
+ * @param password 密码
241
+ * @param serverPath 服务器路径
242
+ * @param filename 文件名
243
+ */
244
+ ftpUploadAllImage(serverIp: string, port: number, username: string, password: string, serverPath: string, filename: string): void;
245
+
246
+ /**
247
+ * 设置上传按钮是否可见
248
+ * @param visible 是否可见
249
+ */
250
+ setUploadButtonVisible(visible: boolean): void;
251
+
252
+ /**
253
+ * 设置焦点
254
+ */
255
+ setFocus(): void;
256
+
257
+ /**
258
+ * 隐藏窗口
259
+ */
260
+ hidden(): void;
261
+
262
+ /**
263
+ * 关闭websocket连接
264
+ */
265
+ closeWebSocket(): void;
266
+ }