Browse Source

platfrom library

main
hulei 3 weeks ago
parent
commit
a340344ab1

+ 109
- 0
ant-design-pro-vue3/src/views/front/platfrom/library/MsgHelper.ts View File

@@ -0,0 +1,109 @@
1
+
2
+// 假设 IPage 接口的定义
3
+interface IPage {
4
+    // 这里可以根据实际情况添加 IPage 接口的成员
5
+}
6
+
7
+// 假设 MessageBoxButton、MessageBoxImage、MessageBoxResult 的枚举定义
8
+enum MessageBoxButton {
9
+    OK,
10
+    YesNo
11
+}
12
+
13
+enum MessageBoxImage {
14
+    Information,
15
+    Error,
16
+    Question,
17
+    Warning,
18
+    Exclamation
19
+}
20
+
21
+enum MessageBoxResult {
22
+    None,
23
+    OK,
24
+    Yes,
25
+    No
26
+}
27
+
28
+// 假设 Key 类型的定义
29
+type Key = string;
30
+
31
+// 假设 PageMessageBox、PageMessageBoxExt、PageMessageBoxSimple、PageMessageBoxMetro 类的模拟实现
32
+class PageMessageBox {
33
+    show(target: IPage, content: object, caption: string, messageBoxButton: MessageBoxButton, messageBoxImage: MessageBoxImage, defaultResult: MessageBoxResult): MessageBoxResult {
34
+        // 这里实现显示消息框的逻辑,返回用户点击的结果
35
+        return MessageBoxResult.None;
36
+    }
37
+}
38
+
39
+class PageMessageBoxExt {
40
+    constructor(target: IPage, messageBoxText: string, content: { [key: string]: string }, defaultFocus: Key) {
41
+        // 这里实现初始化逻辑
42
+    }
43
+
44
+    get MessageDialogMode(): Key {
45
+        // 这里返回用户点击的按钮对应的键
46
+        return "";
47
+    }
48
+}
49
+
50
+class PageMessageBoxSimple {
51
+    constructor(target: IPage, messageBoxText: string, defaultButton?: string, ...buttonConent: string[]) {
52
+        // 这里实现初始化逻辑
53
+    }
54
+
55
+    get MessageDialogResult(): string {
56
+        // 这里返回用户点击按钮的结果
57
+        return "";
58
+    }
59
+}
60
+
61
+class PageMessageBoxMetro {
62
+    constructor(target: IPage, messagecontnt: object, caption: string, image: any, direction: number, isreverse: boolean, iscoverall: boolean, animationEnable: boolean, defaultButton: string, ...buttonConent: string[]) {
63
+        // 这里实现初始化逻辑
64
+    }
65
+
66
+    get MessageDialogResult(): string {
67
+        // 这里返回用户点击按钮的结果
68
+        return "";
69
+    }
70
+}
71
+
72
+// MsgHelper 类的 TypeScript 实现
73
+export class MsgHelper {
74
+    static ShowMessageBox(target: IPage, content: object, caption: string = "", messageBoxButton: MessageBoxButton = MessageBoxButton.OK, messageBoxImage: MessageBoxImage = MessageBoxImage.Information, defaultResult: MessageBoxResult = MessageBoxResult.None): MessageBoxResult {
75
+        const pageMessageBox = new PageMessageBox();
76
+        return pageMessageBox.show(target, content, caption, messageBoxButton, messageBoxImage, defaultResult);
77
+    }
78
+
79
+    static ShowInfoMessageBox(target: IPage, content: object): MessageBoxResult {
80
+        return this.ShowMessageBox(target, content, "Information", MessageBoxButton.OK, MessageBoxImage.Exclamation);
81
+    }
82
+
83
+    static ShowErrorMessageBox(target: IPage, content: object): MessageBoxResult {
84
+        return this.ShowMessageBox(target, content, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
85
+    }
86
+
87
+    static ShowQuestionMessageBox(target: IPage, content: object): MessageBoxResult {
88
+        return this.ShowMessageBox(target, content, "Question", MessageBoxButton.YesNo, MessageBoxImage.Question);
89
+    }
90
+
91
+    static ShowWarnMessageBox(target: IPage, content: object): MessageBoxResult {
92
+        return this.ShowMessageBox(target, content, "Warn", MessageBoxButton.OK, MessageBoxImage.Warning);
93
+    }
94
+
95
+    static ShowPageMessageBoxExt(target: IPage, messageBoxText: string, content: { [key: string]: string }, defaultFocus: Key = ""): Key {
96
+        const pageMessageBoxExt = new PageMessageBoxExt(target, messageBoxText, content, defaultFocus);
97
+        return pageMessageBoxExt.MessageDialogMode;
98
+    }
99
+
100
+    static ShowPageMessageBoxSimple(target: IPage, messageBoxText: string, defaultButton?: string, ...buttonConent: string[]): string {
101
+        const dialog = new PageMessageBoxSimple(target, messageBoxText, defaultButton, ...buttonConent);
102
+        return dialog.MessageDialogResult;
103
+    }
104
+
105
+    static ShowPageMessageBoxMetro(target: IPage, messagecontnt: object, caption: string, image: any, defaultButton: string, direction: number = 0, isreverse: boolean = true, iscoverall: boolean = true, animationEnable: boolean = true, ...buttonConent: string[]): string {
106
+        const dialog = new PageMessageBoxMetro(target, messagecontnt, caption, image, direction, isreverse, iscoverall, animationEnable, defaultButton, ...buttonConent);
107
+        return dialog.MessageDialogResult;
108
+    }
109
+}

+ 831
- 0
ant-design-pro-vue3/src/views/front/platfrom/library/ScriptFunction.ts View File

@@ -0,0 +1,831 @@
1
+// 假设 CommonParames 和 TradeLogger 等类在其他文件中定义
2
+// 这里简单模拟一下
3
+class CommonParames {
4
+    static Coding = 'utf-8';
5
+    static MsgErrorMap: { [key: string]: string } = {};
6
+}
7
+
8
+class TradeLogger {
9
+    static Error(error: any) {
10
+        console.error(error);
11
+    }
12
+}
13
+
14
+// 假设 IPage 接口在其他文件中定义
15
+interface IPage {}
16
+
17
+// 假设 FilesHandle 类在其他文件中定义
18
+class FilesHandle {
19
+    static GetFileData(fileName: string): Uint8Array {
20
+        // 这里只是模拟实现,实际需要根据具体情况实现
21
+        return new Uint8Array();
22
+    }
23
+    static SaveFileData(fileName: string, fileData: Uint8Array, append: boolean): boolean {
24
+        // 这里只是模拟实现,实际需要根据具体情况实现
25
+        return true;
26
+    }
27
+}
28
+
29
+// 假设 ComboBox 类在其他文件中定义
30
+class ComboBox {
31
+    SetItems(dict: { [key: string]: string }) {}
32
+    FontSize = 12;
33
+    MinWidth = 0;
34
+}
35
+
36
+// 定义 ScriptFunction 类
37
+class ScriptFunction {
38
+    // 字符串数字处理类
39
+
40
+    /**
41
+     * 将数字串转换成整数
42
+     * @param number 数字串
43
+     * @returns 整数
44
+     */
45
+    static Atoi(number: string): number {
46
+        return parseInt(number, 10);
47
+    }
48
+
49
+    /**
50
+     * 将数字串转换成整数
51
+     * @param target 
52
+     * @param number 数字串
53
+     * @returns 整数
54
+     */
55
+    static AtoiPage(target: IPage, number: string): number {
56
+        return ScriptFunction.Atoi(number);
57
+    }
58
+
59
+    /**
60
+     * 将数字按指定格式格式化为字符串 暂时支持%d %f这两大类
61
+     * @param number 数字
62
+     * @param format 格式
63
+     * @returns 格式化后的字符串
64
+     */
65
+    static Itoa(number: number, format: string): string {
66
+        const rgx = /^%{1}(-)?(([0-9]*)[dD]{1})|(([0-9]*)(.)?([0-9]*)[fF]{1})$/;
67
+        if (!rgx.test(format)) {
68
+            throw new Error('不支持该格式转换!');
69
+        }
70
+
71
+        let outdata = '';
72
+        let width = -1;
73
+        let sindex = 0;
74
+        let eindex = 0;
75
+        let signindex = format.includes('-') ? format.indexOf('-') : -1;
76
+        let dotindex = -1;
77
+        let formatparse = format;
78
+        let hasZero = false;
79
+
80
+        if (signindex === -1) {
81
+            if (format.substring(1, 2) === '0') {
82
+                formatparse = format.substring(0, 1) + format.substring(2);
83
+                hasZero = true;
84
+            }
85
+        } else {
86
+            if (format.substring(2, 3) === '0') {
87
+                formatparse = format.substring(0, 2) + format.substring(3);
88
+                hasZero = true;
89
+            }
90
+        }
91
+
92
+        if (formatparse === '' || formatparse.includes('d') || formatparse.includes('D')) {
93
+            eindex = formatparse.includes('d') ? formatparse.indexOf('d') : formatparse.indexOf('D');
94
+            outdata = number.toFixed(0);
95
+        }
96
+
97
+        if (formatparse.includes('f') || formatparse.includes('F')) {
98
+            dotindex = formatparse.indexOf('.');
99
+            eindex = formatparse.includes('f') ? formatparse.indexOf('f') : formatparse.indexOf('F');
100
+
101
+            if (dotindex === -1) {
102
+                outdata = number.toFixed(0);
103
+            } else {
104
+                if (eindex - dotindex === 1) {
105
+                    outdata = number.toFixed(0);
106
+                } else {
107
+                    outdata = number.toFixed(parseInt(formatparse.substring(dotindex + 1, eindex), 10));
108
+                }
109
+            }
110
+        }
111
+
112
+        if (dotindex === -1) {
113
+            if (signindex === -1) {
114
+                width = eindex - sindex === 1 ? -1 : parseInt(formatparse.substring(sindex + 1, eindex), 10);
115
+            } else {
116
+                width = eindex - signindex === 1 ? -1 : parseInt(formatparse.substring(signindex + 1, eindex), 10);
117
+            }
118
+        } else {
119
+            if (signindex === -1) {
120
+                width = dotindex - sindex === 1 ? -1 : parseInt(formatparse.substring(sindex + 1, dotindex), 10);
121
+            } else {
122
+                width = dotindex - signindex === 1 ? -1 : parseInt(formatparse.substring(signindex + 1, dotindex), 10);
123
+            }
124
+        }
125
+
126
+        if (width === -1) {
127
+            return outdata;
128
+        } else {
129
+            if (outdata.length >= width) {
130
+                return outdata;
131
+            } else {
132
+                if (signindex === -1) {
133
+                    if (hasZero) {
134
+                        return outdata.padStart(width, '0');
135
+                    } else {
136
+                        return outdata.padStart(width);
137
+                    }
138
+                } else {
139
+                    if (hasZero) {
140
+                        return outdata.padEnd(width, '0');
141
+                    } else {
142
+                        return outdata.padEnd(width);
143
+                    }
144
+                }
145
+            }
146
+        }
147
+    }
148
+
149
+    /**
150
+     * 将数字按指定格式格式化为字符串 暂时支持%d %f这两大类
151
+     * @param target 
152
+     * @param number 数字
153
+     * @param format 格式
154
+     * @returns 格式化后的字符串
155
+     */
156
+    static ItoaPage(target: IPage, number: number, format: string): string {
157
+        return ScriptFunction.Itoa(number, format);
158
+    }
159
+
160
+    /**
161
+     * 截取子字符串
162
+     * @param sourceData 源字符串
163
+     * @param start 起始index
164
+     * @param length 截取长度
165
+     * @returns 截取后的字符串
166
+     */
167
+    static SubStr(sourceData: string, start: number, length: number): string {
168
+        const dataBytes = new TextEncoder().encode(sourceData);
169
+        if (length > dataBytes.length - start) {
170
+            length = dataBytes.length - start;
171
+        }
172
+        const tmpBytes = dataBytes.slice(start, start + length);
173
+        return new TextDecoder(CommonParames.Coding).decode(tmpBytes);
174
+    }
175
+
176
+    /**
177
+     * 截取子字符串
178
+     * @param target 
179
+     * @param sourceData 源字符串
180
+     * @param start 起始
181
+     * @param length 截取长度
182
+     * @returns 截取后的字符串
183
+     */
184
+    static SubStrPage(target: IPage, sourceData: string, start: number, length: number): string {
185
+        return ScriptFunction.SubStr(sourceData, start, length);
186
+    }
187
+
188
+    /**
189
+     * 内部函数,取得字符串长度
190
+     * @param sourceData 源字符串
191
+     * @returns 字符串长度
192
+     */
193
+    static Len(sourceData: string): number {
194
+        return new TextEncoder().encode(sourceData).length;
195
+    }
196
+
197
+    /**
198
+     * 取得字符串长度
199
+     * @param target 
200
+     * @param sourceData 源数据
201
+     * @returns 长度
202
+     */
203
+    static LenPage(target: IPage, sourceData: string): number {
204
+        return ScriptFunction.Len(sourceData);
205
+    }
206
+
207
+    /**
208
+     * 将ASCII码值转换为字符串
209
+     * @param number ASCII码值
210
+     * @returns 字符串
211
+     */
212
+    static Chr(number: number): string {
213
+        return String.fromCharCode(number);
214
+    }
215
+
216
+    /**
217
+     * 将ASCII码值转换为字符串
218
+     * @param target 
219
+     * @param number ASCII码值
220
+     * @returns 字符串
221
+     */
222
+    static ChrPage(target: IPage, number: number): string {
223
+        return ScriptFunction.Chr(number);
224
+    }
225
+
226
+    /**
227
+     * 求两个整数的余
228
+     * @param number1 被除数
229
+     * @param number2 除数
230
+     * @returns 余数
231
+     */
232
+    static Mod(number1: number, number2: number): number {
233
+        return number1 % number2;
234
+    }
235
+
236
+    /**
237
+     * 求两个整数的余
238
+     * @param target 
239
+     * @param number1 被除数
240
+     * @param number2 除数
241
+     * @returns 余数
242
+     */
243
+    static ModPage(target: IPage, number1: number, number2: number): number {
244
+        return ScriptFunction.Mod(number1, number2);
245
+    }
246
+
247
+    /**
248
+     * 将数字串转换成千分位方式显示
249
+     * @param sourceData 处理前数据
250
+     * @param length 指定长度
251
+     * @returns 处理后数据
252
+     */
253
+    static Comma(sourceData: string, length: number): string {
254
+        let result: number;
255
+        if (!Number.isNaN(result = parseFloat(sourceData))) {
256
+            const exception = new Error(
257
+                `Comma函数执行出错![${sourceData}]不是有效的数字类型!`
258
+            );
259
+            TradeLogger.Error(exception);
260
+            throw exception;
261
+        }
262
+        return result.toLocaleString('zh-CN', { style: 'currency', currency: 'CNY' }).padStart(length);
263
+    }
264
+
265
+    /**
266
+     * 将数字串转换成千分位方式显示
267
+     * @param target 
268
+     * @param sourceData 处理前数据
269
+     * @param length 指定长度
270
+     * @returns 处理后数据
271
+     */
272
+    static CommaPage(target: IPage, sourceData: string, length: number): string {
273
+        return ScriptFunction.Comma(sourceData, length);
274
+    }
275
+
276
+    /**
277
+     * 左补齐参数字符
278
+     * @param sourcedata 源字符串
279
+     * @param length 补齐长度
280
+     * @param var 参数字符
281
+     * @returns 补齐后的字符串
282
+     */
283
+    static PadLeft(sourcedata: string, length: number, varChar = ' '): string {
284
+        const data = new TextEncoder().encode(sourcedata);
285
+        const len = length - data.length;
286
+        if (len > 0) {
287
+            return sourcedata.padStart(sourcedata.length + len, varChar);
288
+        }
289
+        return sourcedata;
290
+    }
291
+
292
+    /**
293
+     * 左补齐参数字符
294
+     * @param target 
295
+     * @param sourcedata 源字符串
296
+     * @param length 补齐长度
297
+     * @param var 参数字符
298
+     * @returns 补齐后的字符串
299
+     */
300
+    static PadLeftPage(target: IPage, sourcedata: string, length: number, varChar = ' '): string {
301
+        return ScriptFunction.PadLeft(sourcedata, length, varChar);
302
+    }
303
+
304
+    /**
305
+     * 右补齐参数字符
306
+     * @param sourcedata 源字符串
307
+     * @param length 补齐长度
308
+     * @param var 参数字符
309
+     * @returns 补齐后的字符串
310
+     */
311
+    static PadRight(sourcedata: string, length: number, varChar = ' '): string {
312
+        const data = new TextEncoder().encode(sourcedata);
313
+        const len = length - data.length;
314
+        if (len > 0) {
315
+            return sourcedata.padEnd(sourcedata.length + len, varChar);
316
+        }
317
+        return sourcedata;
318
+    }
319
+
320
+    /**
321
+     * 右补齐参数字符
322
+     * @param target 
323
+     * @param sourcedata 源字符串
324
+     * @param length 补齐长度
325
+     * @param var 参数字符
326
+     * @returns 补齐后的字符串
327
+     */
328
+    static PadRightPage(target: IPage, sourcedata: string, length: number, varChar = ' '): string {
329
+        return ScriptFunction.PadRight(sourcedata, length, varChar);
330
+    }
331
+
332
+    /**
333
+     * 数字串(十进制或十六进制)与权重相乘
334
+     * @param sourceData 数字串
335
+     * @param weight 权重
336
+     * @returns 结果
337
+     */
338
+    static Val(sourceData: string, weight: number): number {
339
+        let result: number;
340
+        if (!Number.isNaN(result = parseFloat(sourceData))) {
341
+            const exception = new Error(
342
+                `Val函数执行出错![${sourceData}]不是有效的数字类型!`
343
+            );
344
+            TradeLogger.Error(exception);
345
+            throw exception;
346
+        }
347
+        return result * weight;
348
+    }
349
+
350
+    /**
351
+     * 数字串(十进制或十六进制)与权重相乘
352
+     * @param target 
353
+     * @param sourceData 数字串
354
+     * @param weight 权重
355
+     * @returns 结果
356
+     */
357
+    static ValPage(target: IPage, sourceData: string, weight: number): number {
358
+        return ScriptFunction.Val(sourceData, weight);
359
+    }
360
+
361
+    /**
362
+     * 去除字符串后面空格
363
+     * @param sourceData 源数据
364
+     * @returns 处理后数据
365
+     */
366
+    static RTrim(sourceData: string): string {
367
+        return sourceData.trimEnd();
368
+    }
369
+
370
+    /**
371
+     * 去除字符串后面空格
372
+     * @param target 
373
+     * @param sourceData 源数据
374
+     * @returns 处理后数据
375
+     */
376
+    static RTrimPage(target: IPage, sourceData: string): string {
377
+        return ScriptFunction.RTrim(sourceData);
378
+    }
379
+
380
+    /**
381
+     * 去除字符串开始空格
382
+     * @param sourceData 源数据
383
+     * @returns 处理后数据
384
+     */
385
+    static LTrim(sourceData: string): string {
386
+        return sourceData.trimStart();
387
+    }
388
+
389
+    /**
390
+     * 去除字符串开始空格
391
+     * @param target 
392
+     * @param sourceData 源数据
393
+     * @returns 处理后数据
394
+     */
395
+    static LTrimPage(target: IPage, sourceData: string): string {
396
+        return ScriptFunction.LTrim(sourceData);
397
+    }
398
+
399
+    /**
400
+     * 以某个字符构建某长度的字符串
401
+     * @param lenght 长度
402
+     * @param c 字符
403
+     * @returns 构建后的字符串
404
+     */
405
+    static Space(lenght: number, c = ' '): string {
406
+        return new Array(lenght).fill(c).join('');
407
+    }
408
+
409
+    /**
410
+     * 以某个字符构建某长度的字符串
411
+     * @param target 
412
+     * @param lenght 长度
413
+     * @param c 字符
414
+     * @returns 构建后的字符串
415
+     */
416
+    static SpacePage(target: IPage, lenght: number, c = ' '): string {
417
+        return ScriptFunction.Space(lenght, c);
418
+    }
419
+
420
+    /**
421
+     * 内部函数,去掉空格
422
+     * @param sourceData 源数据
423
+     * @returns 处理后数据
424
+     */
425
+    static Delspace(sourceData: string): string {
426
+        return sourceData.trim().replace(/\0/g, '').replace(/ /g, '');
427
+    }
428
+
429
+    /**
430
+     * 去掉字符串中的空格、\0
431
+     * @param target 
432
+     * @param sourceData 源数据
433
+     * @returns 处理后数据
434
+     */
435
+    static DelspacePage(target: IPage, sourceData: string): string {
436
+        return ScriptFunction.Delspace(sourceData);
437
+    }
438
+
439
+    /**
440
+     * 计算分隔符分开的字段的个数
441
+     * @param sourceData 源数据
442
+     * @param separator 分隔字符
443
+     * @returns 字段个数
444
+     */
445
+    static StrFldCnt(sourceData: string, separator: string): number {
446
+        return sourceData.split(separator).length;
447
+    }
448
+
449
+    /**
450
+     * 计算分隔符分开的字段的个数
451
+     * @param target 
452
+     * @param sourceData 源数据
453
+     * @param separator 分隔字符
454
+     * @returns 字段个数
455
+     */
456
+    static StrFldCntPage(target: IPage, sourceData: string, separator: string): number {
457
+        return ScriptFunction.StrFldCnt(sourceData, separator);
458
+    }
459
+
460
+    /**
461
+     * 按索引取由分隔符分开的某个字段
462
+     * @param sourceData 源数据
463
+     * @param separator 分隔符
464
+     * @param index 索引值
465
+     * @returns 字段值
466
+     */
467
+    static StrFld(sourceData: string, separator: string, index: number): string {
468
+        const array = sourceData.split(separator);
469
+        return array[index];
470
+    }
471
+
472
+    /**
473
+     * 按索引取由分隔符分开的某个字段
474
+     * @param target 
475
+     * @param sourceData 源数据
476
+     * @param separator 分隔符
477
+     * @param index 索引值
478
+     * @returns 字段值
479
+     */
480
+    static StrFldPage(target: IPage, sourceData: string, separator: string, index: number): string {
481
+        return ScriptFunction.StrFld(sourceData, separator, index);
482
+    }
483
+
484
+    /**
485
+     * 计算两个日期之间的绝对差值(天数)
486
+     * @param fDate 起始日期
487
+     * @param sDate 终止日期
488
+     * @returns 相距天数
489
+     */
490
+    static Func(fDate: string, sDate: string): number {
491
+        const startDate = new Date(parseInt(fDate.substring(0, 4)), parseInt(fDate.substring(4, 2)) - 1, parseInt(fDate.substring(6)));
492
+        const endDate = new Date(parseInt(sDate.substring(0, 4)), parseInt(sDate.substring(4, 2)) - 1, parseInt(sDate.substring(6)));
493
+        const timeSpan = endDate.getTime() - startDate.getTime();
494
+        return Math.floor(timeSpan / (1000 * 60 * 60 * 24));
495
+    }
496
+
497
+    /**
498
+     * 计算两个日期之间的绝对差值(天数)
499
+     * @param target 
500
+     * @param fDate 起始日期
501
+     * @param sDate 终止日期
502
+     * @returns 相距天数
503
+     */
504
+    static FuncPage(target: IPage, fDate: string, sDate: string): number {
505
+        return ScriptFunction.Func(fDate, sDate);
506
+    }
507
+
508
+    /**
509
+     * 将数字类型转换成大写金额字符串
510
+     * @param num 数字
511
+     * @returns 大写金额字符串
512
+     */
513
+    static ChangeToCNY(num: number): string {
514
+        const str1 = "零壹贰叁肆伍陆柒捌玖";
515
+        const str2 = "万仟佰拾亿仟佰拾万仟佰拾元角分";
516
+        let str3 = "";
517
+        let str4 = "";
518
+        let str5 = "";
519
+        let i = 0;
520
+        let j = 0;
521
+        let ch1 = "";
522
+        let ch2 = "";
523
+        let nzero = 0;
524
+        let temp = 0;
525
+
526
+        num = Math.round(Math.abs(num) * 100) / 100;
527
+        str4 = (Math.floor(num * 100)).toString();
528
+        j = str4.length;
529
+        if (j > 15) {
530
+            return '';
531
+        }
532
+
533
+        const str2Sub = str2.substring(15 - j);
534
+
535
+        for (i = 0; i < j; i++) {
536
+            str3 = str4.substring(i, i + 1);
537
+            temp = parseInt(str3, 10);
538
+            if (i !== (j - 3) && i !== (j - 7) && i !== (j - 11) && i !== (j - 15)) {
539
+                if (str3 === "0") {
540
+                    ch1 = "";
541
+                    ch2 = "";
542
+                    nzero = nzero + 1;
543
+                } else {
544
+                    if (str3 !== "0" && nzero !== 0) {
545
+                        ch1 = "零" + str1[temp];
546
+                        ch2 = str2Sub[i];
547
+                        nzero = 0;
548
+                    } else {
549
+                        ch1 = str1[temp];
550
+                        ch2 = str2Sub[i];
551
+                        nzero = 0;
552
+                    }
553
+                }
554
+            } else {
555
+                if (str3 !== "0" && nzero !== 0) {
556
+                    ch1 = "零" + str1[temp];
557
+                    ch2 = str2Sub[i];
558
+                    nzero = 0;
559
+                } else {
560
+                    if (str3 !== "0" && nzero === 0) {
561
+                        ch1 = str1[temp];
562
+                        ch2 = str2Sub[i];
563
+                        nzero = 0;
564
+                    } else {
565
+                        if (str3 === "0" && nzero >= 3) {
566
+                            ch1 = "";
567
+                            ch2 = "";
568
+                            nzero = nzero + 1;
569
+                        } else {
570
+                            if (j >= 11) {
571
+                                ch1 = "";
572
+                                nzero = nzero + 1;
573
+                            } else {
574
+                                ch1 = "";
575
+                                ch2 = str2Sub[i];
576
+                                nzero = nzero + 1;
577
+                            }
578
+                        }
579
+                    }
580
+                }
581
+            }
582
+
583
+            if (i === (j - 11) || i === (j - 3) || (i === (i - 7) && nzero <= 3)) {
584
+                nzero = 0;
585
+                ch2 = str2Sub[i];
586
+            }
587
+            str5 = str5 + ch1 + ch2;
588
+
589
+            if (i === j - 1 && str3 === "0") {
590
+                str5 = str5 + '整';
591
+            }
592
+        }
593
+        if (num === 0) {
594
+            str5 = "零元整";
595
+        }
596
+        return str5;
597
+    }
598
+
599
+    /**
600
+     * 将数字类型转换成大写金额字符串
601
+     * @param target 
602
+     * @param num 数字
603
+     * @returns 大写金额字符串
604
+     */
605
+    static ChangeToCNYPage(target: IPage, num: number): string {
606
+        return ScriptFunction.ChangeToCNY(num);
607
+    }
608
+
609
+    /**
610
+     * 按格式解析返回字串,给combox添加项
611
+     * @param comboBox combox对象
612
+     * @param fileData 源数据
613
+     * @param formatString 赋值格式
614
+     * @returns 是否成功
615
+     */
616
+    static SetSel(comboBox: ComboBox, fileData: string, formatString: string): boolean {
617
+        if (comboBox === null || fileData === '' || formatString === '') {
618
+            return false;
619
+        }
620
+
621
+        const lengths = formatString.toLowerCase().split(/[otv]/);
622
+        let cellLength = 0;
623
+        let titleIndex = 0;
624
+        let titleLength = 0;
625
+        let valueIndex = 0;
626
+        let valueLength = 0;
627
+        let counter = 0;
628
+
629
+        for (let i = 1; i < lengths.length; i++) {
630
+            const length = parseInt(lengths[i], 10);
631
+            switch (formatString[counter]) {
632
+                case 't':
633
+                    titleIndex = cellLength;
634
+                    titleLength = length;
635
+                    break;
636
+                case 'v':
637
+                    valueIndex = cellLength;
638
+                    valueLength = length;
639
+                    break;
640
+                case 'o':
641
+                    break;
642
+                default:
643
+                    TradeLogger.Error(
644
+                        `SetSel函数执行出错!formatString参数[${formatString}]格式解析异常!`
645
+                    );
646
+                    return false;
647
+            }
648
+            counter++;
649
+            counter += lengths[i].length;
650
+            cellLength += length;
651
+        }
652
+
653
+        const data = new TextEncoder().encode(fileData);
654
+        const count = Math.floor(data.length / cellLength);
655
+        let titleMaxLength = 0;
656
+        const dict: { [key: string]: string } = {};
657
+
658
+        for (let i = 0; i < count; i++) {
659
+            const btempTitle = data.slice(titleIndex + i * cellLength, titleIndex + i * cellLength + titleLength);
660
+            const title = new TextDecoder(CommonParames.Coding).decode(btempTitle).trim();
661
+
662
+            const btempValue = data.slice(valueIndex + i * cellLength, valueIndex + i * cellLength + valueLength);
663
+            const varValue = new TextDecoder(CommonParames.Coding).decode(btempValue);
664
+
665
+            dict[title] = varValue;
666
+
667
+            if (title.length > titleMaxLength) {
668
+                titleMaxLength = title.length;
669
+            }
670
+        }
671
+
672
+        comboBox.SetItems(dict);
673
+        comboBox.MinWidth = titleMaxLength * comboBox.FontSize;
674
+        return true;
675
+    }
676
+
677
+    /**
678
+     * 按格式解析返回字串,给combox添加项
679
+     * @param target 
680
+     * @param comboBox combox对象
681
+     * @param fileData 源数据
682
+     * @param formatString 赋值格式
683
+     * @returns 是否成功
684
+     */
685
+    static SetSelPage(target: IPage, comboBox: ComboBox, fileData: string, formatString: string): boolean {
686
+        return ScriptFunction.SetSel(comboBox, fileData, formatString);
687
+    }
688
+
689
+    /**
690
+     * 格式化Title字符串
691
+     * @param title 待格式化的Title字符串
692
+     * @returns 格式化后的Title字符串
693
+     */
694
+    static FormatTitle(title: string): string {
695
+        let i = 0;
696
+        for (i = 0; i < title.length; i++) {
697
+            if (title[i] === '.') {
698
+                i++;
699
+                break;
700
+            }
701
+            if (ScriptFunction.IsChinese(title[i])) {
702
+                break;
703
+            }
704
+        }
705
+        if (i < title.length) {
706
+            title = title.substring(i);
707
+        }
708
+        return ScriptFunction.Delspace(title);
709
+    }
710
+
711
+    /**
712
+     * 判断是否为中文字符
713
+     * @param c 待判断的字符
714
+     * @returns 是否为中文字符
715
+     */
716
+    static IsChinese(c: string): boolean {
717
+        const code = c.charCodeAt(0);
718
+        return code >= 0x4E00 && code <= 0x9FA5;
719
+    }
720
+
721
+    // 控制相关
722
+
723
+    /**
724
+     * 返回错误编号对应的错误信息
725
+     * @param errorNo 错误信息编号
726
+     * @returns 错误信息
727
+     */
728
+    static GetError(errorNo: string): string {
729
+        // TODO:调用web服务初始化信息
730
+        // InitializeHandle.InitErrorMap();
731
+        const errorMessage = CommonParames.MsgErrorMap[errorNo] || "未知的错误代码";
732
+        return `[${errorNo}]${errorMessage}`;
733
+    }
734
+
735
+    /**
736
+     * 返回错误编号对应的错误信息
737
+     * @param target 
738
+     * @param errorNo 错误信息编号
739
+     * @returns 错误信息
740
+     */
741
+    static GetErrorPage(target: IPage, errorNo: string): string {
742
+        return ScriptFunction.GetError(errorNo);
743
+    }
744
+
745
+    /**
746
+     * 返回错误编号对应的错误信息
747
+     * @param target 
748
+     * @param errorNo 错误信息编号
749
+     * @param errorExt 额外的错误信息
750
+     * @returns 错误信息
751
+     */
752
+    static GetErrorPageWithExt(target: IPage, errorNo: string, errorExt: string): string {
753
+        if (errorExt === '') {
754
+            return ScriptFunction.GetError(errorNo);
755
+        } else {
756
+            return `${ScriptFunction.GetError(errorNo)},${errorExt}!`;
757
+        }
758
+    }
759
+
760
+    /**
761
+     * 取得当前机器的IPv4地址
762
+     * @returns IP地址
763
+     */
764
+    static async GetIPv4Addresses(): Promise<string[]> {
765
+        try {
766
+            const response = await fetch('https://api.ipify.org?format=json');
767
+            const data = await response.json();
768
+            return [data.ip];
769
+        } catch (error) {
770
+            TradeLogger.Error(error);
771
+            return [];
772
+        }
773
+    }
774
+
775
+    /**
776
+     * 取得当前机器的IPv4地址
777
+     * @param target 
778
+     * @returns IPv4字符串组
779
+     */
780
+    static async GetIPv4AddressesPage(target: IPage): Promise<string[]> {
781
+        return ScriptFunction.GetIPv4Addresses();
782
+    }
783
+
784
+    // 文件操作相关
785
+
786
+    /**
787
+     * 获取服务端文件
788
+     * @param fileName 文件名
789
+     * @returns 文件内容
790
+     */
791
+    static async Getfiletxt(fileName: string): Promise<string> {
792
+        const fileData = FilesHandle.GetFileData(fileName);
793
+        return new TextDecoder(CommonParames.Coding).decode(fileData);
794
+    }
795
+
796
+    /**
797
+     * 获取服务端文件
798
+     * @param target 
799
+     * @param fileName 文件名
800
+     * @returns 文件内容
801
+     */
802
+    static async GetfiletxtPage(target: IPage, fileName: string): Promise<string> {
803
+        return ScriptFunction.Getfiletxt(fileName);
804
+    }
805
+
806
+    /**
807
+     * 往服务端保存文件
808
+     * @param fileName 文件名
809
+     * @param fileContent 文件内容
810
+     * @param append 是否append追加方式
811
+     * @returns 是否保存成功
812
+     */
813
+    static async Savefiletxt(fileName: string, fileContent: string, append: boolean): Promise<boolean> {
814
+        const fileData = new TextEncoder().encode(fileContent);
815
+        return FilesHandle.SaveFileData(fileName, fileData, append);
816
+    }
817
+
818
+    /**
819
+     * 往服务端保存文件
820
+     * @param target 
821
+     * @param fileName 文件名
822
+     * @param fileContent 文件内容
823
+     * @param append 是否append追加方式
824
+     * @returns 是否保存成功
825
+     */
826
+    static async SavefiletxtPage(target: IPage, fileName: string, fileContent: string, append: boolean): Promise<boolean> {
827
+        return ScriptFunction.Savefiletxt(fileName, fileContent, append);
828
+    }
829
+}
830
+
831
+export default ScriptFunction;

+ 177
- 0
ant-design-pro-vue3/src/views/front/platfrom/library/TradeLogger.ts View File

@@ -0,0 +1,177 @@
1
+// 模拟 CommonParames.TradeLog
2
+const TradeLog = 'TradeLogger';
3
+
4
+class Log {
5
+    private name: string;
6
+
7
+    constructor(name: string) {
8
+        this.name = name;
9
+    }
10
+
11
+    debug(message: any, exception?: Error) {
12
+        if (exception) {
13
+            console.debug(`[${this.name}] ${message}`, exception);
14
+        } else {
15
+            console.debug(`[${this.name}] ${message}`);
16
+        }
17
+    }
18
+
19
+    debugFormat(format: string, ...args: any[]) {
20
+        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
21
+            return typeof args[index] !== 'undefined' ? args[index] : match;
22
+        });
23
+        console.debug(`[${this.name}] ${formattedMessage}`);
24
+    }
25
+
26
+    error(message: any, exception?: Error) {
27
+        if (exception) {
28
+            console.error(`[${this.name}] ${message}`, exception);
29
+        } else {
30
+            console.error(`[${this.name}] ${message}`);
31
+        }
32
+    }
33
+
34
+    errorFormat(format: string, ...args: any[]) {
35
+        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
36
+            return typeof args[index] !== 'undefined' ? args[index] : match;
37
+        });
38
+        console.error(`[${this.name}] ${formattedMessage}`);
39
+    }
40
+
41
+    fatal(message: any, exception?: Error) {
42
+        if (exception) {
43
+            console.error(`[${this.name}] FATAL: ${message}`, exception);
44
+        } else {
45
+            console.error(`[${this.name}] FATAL: ${message}`);
46
+        }
47
+    }
48
+
49
+    fatalFormat(format: string, ...args: any[]) {
50
+        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
51
+            return typeof args[index] !== 'undefined' ? args[index] : match;
52
+        });
53
+        console.error(`[${this.name}] FATAL: ${formattedMessage}`);
54
+    }
55
+
56
+    info(message: any, exception?: Error) {
57
+        if (exception) {
58
+            console.info(`[${this.name}] ${message}`, exception);
59
+        } else {
60
+            console.info(`[${this.name}] ${message}`);
61
+        }
62
+    }
63
+
64
+    infoFormat(format: string, ...args: any[]) {
65
+        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
66
+            return typeof args[index] !== 'undefined' ? args[index] : match;
67
+        });
68
+        console.info(`[${this.name}] ${formattedMessage}`);
69
+    }
70
+
71
+    warn(message: any, exception?: Error) {
72
+        if (exception) {
73
+            console.warn(`[${this.name}] ${message}`, exception);
74
+        } else {
75
+            console.warn(`[${this.name}] ${message}`);
76
+        }
77
+    }
78
+
79
+    warnFormat(format: string, ...args: any[]) {
80
+        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
81
+            return typeof args[index] !== 'undefined' ? args[index] : match;
82
+        });
83
+        console.warn(`[${this.name}] ${formattedMessage}`);
84
+    }
85
+
86
+    get isDebugEnabled() {
87
+        return true; // 简单模拟,实际可根据配置调整
88
+    }
89
+
90
+    get isErrorEnabled() {
91
+        return true; // 简单模拟,实际可根据配置调整
92
+    }
93
+
94
+    get isFatalEnabled() {
95
+        return true; // 简单模拟,实际可根据配置调整
96
+    }
97
+
98
+    get isInfoEnabled() {
99
+        return true; // 简单模拟,实际可根据配置调整
100
+    }
101
+
102
+    get isWarnEnabled() {
103
+        return true; // 简单模拟,实际可根据配置调整
104
+    }
105
+
106
+    get logger() {
107
+        return this;
108
+    }
109
+}
110
+
111
+const LogInstance = new Log(TradeLog);
112
+
113
+export class TradeLogger {
114
+    static debug(message: any, exception?: Error) {
115
+        LogInstance.debug(message, exception);
116
+    }
117
+
118
+    static debugFormat(format: string, ...args: any[]) {
119
+        LogInstance.debugFormat(format, ...args);
120
+    }
121
+
122
+    static error(message: any, exception?: Error) {
123
+        LogInstance.error(message, exception);
124
+    }
125
+
126
+    static errorFormat(format: string, ...args: any[]) {
127
+        LogInstance.errorFormat(format, ...args);
128
+    }
129
+
130
+    static fatal(message: any, exception?: Error) {
131
+        LogInstance.fatal(message, exception);
132
+    }
133
+
134
+    static fatalFormat(format: string, ...args: any[]) {
135
+        LogInstance.fatalFormat(format, ...args);
136
+    }
137
+
138
+    static info(message: any, exception?: Error) {
139
+        LogInstance.info(message, exception);
140
+    }
141
+
142
+    static infoFormat(format: string, ...args: any[]) {
143
+        LogInstance.infoFormat(format, ...args);
144
+    }
145
+
146
+    static warn(message: any, exception?: Error) {
147
+        LogInstance.warn(message, exception);
148
+    }
149
+
150
+    static warnFormat(format: string, ...args: any[]) {
151
+        LogInstance.warnFormat(format, ...args);
152
+    }
153
+
154
+    static get isDebugEnabled() {
155
+        return LogInstance.isDebugEnabled;
156
+    }
157
+
158
+    static get isErrorEnabled() {
159
+        return LogInstance.isErrorEnabled;
160
+    }
161
+
162
+    static get isFatalEnabled() {
163
+        return LogInstance.isFatalEnabled;
164
+    }
165
+
166
+    static get isInfoEnabled() {
167
+        return LogInstance.isInfoEnabled;
168
+    }
169
+
170
+    static get isWarnEnabled() {
171
+        return LogInstance.isWarnEnabled;
172
+    }
173
+
174
+    static get Logger() {
175
+        return LogInstance.logger;
176
+    }
177
+}

+ 528
- 0
ant-design-pro-vue3/src/views/front/platfrom/library/TradePageExtension.ts View File

@@ -0,0 +1,528 @@
1
+// 假设 IPage 接口定义如下
2
+interface IPage {
3
+    // 可根据实际情况添加其他方法
4
+}
5
+
6
+// 假设 PrintContainer 类定义如下
7
+class PrintContainer {
8
+    // 可根据实际情况添加属性和方法
9
+    Device: string;
10
+    ActualWidth: number;
11
+    ActualHeight: number;
12
+    PrintToXps(): FileInfo;
13
+    Content: any;
14
+    DocumentName: string;
15
+}
16
+
17
+// 假设 FileInfo 类定义如下
18
+class FileInfo {
19
+    FullName: string;
20
+}
21
+
22
+// 假设 TradeForms 类定义如下
23
+class TradeForms {
24
+    formid: string;
25
+    formname: string;
26
+    isenabled: number;
27
+    rolecount: number;
28
+}
29
+
30
+// 假设 PrintHandle 类定义如下
31
+class PrintHandle {
32
+    static GetTradeFormsByTradecode(tradeCode: string): TradeForms[] {
33
+        // 实现获取交易相关的表单项配置信息的逻辑
34
+        return [];
35
+    }
36
+}
37
+
38
+// 假设 TellerSys.ServiceProxy.PrintService.TPrintData 类定义如下
39
+class TPrintData {
40
+    formid: string;
41
+    formName: string;
42
+    businessId: string;
43
+    rolecount: number;
44
+    formdata: Uint8Array;
45
+}
46
+
47
+// 假设 TellerSys.ServiceProxy.ServiceHelper 类定义如下
48
+class ServiceHelper {
49
+    static AddPrintData(data: TPrintData): string {
50
+        // 实现添加打印数据的逻辑
51
+        return "";
52
+    }
53
+    static AddPrintHistory(id: string, tellerNo: string, empty: string): void {
54
+        // 实现记录打印历史的逻辑
55
+    }
56
+}
57
+
58
+// 假设 PrintPreviewWindow 类定义如下
59
+class PrintPreviewWindow {
60
+    Owner: any;
61
+    IsPrinted: boolean;
62
+    constructor(xpsFile: FileInfo, device: string) {
63
+        // 实现构造函数逻辑
64
+    }
65
+    DoPrint(): void {
66
+        // 实现打印操作的逻辑
67
+    }
68
+    ShowDialog(): void {
69
+        // 实现显示对话框的逻辑
70
+    }
71
+}
72
+
73
+// 假设 FrameworkElement 类定义如下
74
+class FrameworkElement {
75
+    // 可根据实际情况添加属性和方法
76
+    ActualWidth: number;
77
+    ActualHeight: number;
78
+    Parent: any;
79
+    Name: string;
80
+    Children: any[];
81
+    ItemsSource: any;
82
+    Items: any[];
83
+    SelectedIndex: number;
84
+}
85
+
86
+// 假设 ComboBox 类定义如下
87
+class ComboBox extends FrameworkElement {
88
+    // 可根据实际情况添加属性和方法
89
+}
90
+
91
+// 假设 DataGrid 类定义如下
92
+class DataGrid extends FrameworkElement {
93
+    // 可根据实际情况添加属性和方法
94
+    Columns: any[];
95
+}
96
+
97
+// 假设 DataBox 类定义如下
98
+class DataBox extends FrameworkElement {
99
+    // 可根据实际情况添加属性和方法
100
+}
101
+
102
+// 假设 FocusManager 类定义如下
103
+class FocusManager {
104
+    static GetIsInternalKeyboardControlling(element: any): boolean {
105
+        // 实现获取是否内部键盘控制的逻辑
106
+        return false;
107
+    }
108
+}
109
+
110
+// 假设 XmlDocument 类定义如下
111
+class XmlDocument {
112
+    DocumentElement: any;
113
+    InnerXml: string;
114
+    LoadXml(xml: string): void {
115
+        // 实现加载 XML 的逻辑
116
+    }
117
+    SelectSingleNode(node: string): any {
118
+        // 实现选择单个节点的逻辑
119
+        return null;
120
+    }
121
+    CreateElement(name: string): any {
122
+        // 实现创建元素的逻辑
123
+        return null;
124
+    }
125
+}
126
+
127
+// 假设 XmlNode 类定义如下
128
+class XmlNode {
129
+    Attributes: any;
130
+    ChildNodes: any[];
131
+    AppendChild(node: any): void {
132
+        // 实现追加子节点的逻辑
133
+    }
134
+}
135
+
136
+// 假设 XmlElement 类定义如下
137
+class XmlElement extends XmlNode {
138
+    SetAttribute(name: string, value: string): void {
139
+        // 实现设置属性的逻辑
140
+    }
141
+}
142
+
143
+// 假设 XmlReader 类定义如下
144
+class XmlReader {
145
+    static Create(reader: any): XmlReader {
146
+        // 实现创建 XmlReader 的逻辑
147
+        return null;
148
+    }
149
+}
150
+
151
+// 假设 XamlReader 类定义如下
152
+class XamlReader {
153
+    static Load(reader: any): any {
154
+        // 实现加载 XAML 的逻辑
155
+        return null;
156
+    }
157
+}
158
+
159
+// 假设 XamlWriter 类定义如下
160
+class XamlWriter {
161
+    static Save(element: any): string {
162
+        // 实现保存 XAML 的逻辑
163
+        return "";
164
+    }
165
+}
166
+
167
+// 假设 RenderTargetBitmap 类定义如下
168
+class RenderTargetBitmap {
169
+    constructor(width: number, height: number, dpiX: number, dpiY: number, format: any) {
170
+        // 实现构造函数逻辑
171
+    }
172
+    Render(element: any): void {
173
+        // 实现渲染元素的逻辑
174
+    }
175
+}
176
+
177
+// 假设 BitmapSource 类定义如下
178
+class BitmapSource {
179
+    // 可根据实际情况添加属性和方法
180
+}
181
+
182
+// 假设 BitmapImage 类定义如下
183
+class BitmapImage extends BitmapSource {
184
+    BeginInit(): void {
185
+        // 实现开始初始化的逻辑
186
+    }
187
+    StreamSource: any;
188
+    EndInit(): void {
189
+        // 实现结束初始化的逻辑
190
+    }
191
+}
192
+
193
+// 假设 PngBitmapEncoder 类定义如下
194
+class PngBitmapEncoder {
195
+    Frames: any[];
196
+    Add(frame: any): void {
197
+        // 实现添加帧的逻辑
198
+    }
199
+    Save(stream: any): void {
200
+        // 实现保存到流的逻辑
201
+    }
202
+}
203
+
204
+// 假设 MemoryStream 类定义如下
205
+class MemoryStream {
206
+    constructor(buffer?: Uint8Array) {
207
+        // 实现构造函数逻辑
208
+    }
209
+    Position: number;
210
+    Length: number;
211
+    Read(buffer: Uint8Array, offset: number, count: number): number {
212
+        // 实现读取数据的逻辑
213
+        return 0;
214
+    }
215
+    Flush(): void {
216
+        // 实现刷新流的逻辑
217
+    }
218
+    Close(): void {
219
+        // 实现关闭流的逻辑
220
+    }
221
+    ToArray(): Uint8Array {
222
+        // 实现转换为字节数组的逻辑
223
+        return new Uint8Array();
224
+    }
225
+}
226
+
227
+// 假设 IFormatter 类定义如下
228
+class IFormatter {
229
+    Serialize(stream: any, obj: any): void {
230
+        // 实现序列化的逻辑
231
+    }
232
+    Deserialize(stream: any): any {
233
+        // 实现反序列化的逻辑
234
+        return null;
235
+    }
236
+}
237
+
238
+// 假设 BinaryFormatter 类定义如下
239
+class BinaryFormatter extends IFormatter {
240
+    // 可根据实际情况添加属性和方法
241
+}
242
+
243
+// 假设 Image 类定义如下
244
+class Image {
245
+    Source: BitmapSource;
246
+}
247
+
248
+// 假设 Panel 类定义如下
249
+class Panel extends FrameworkElement {
250
+    Children: FrameworkElement[];
251
+    Remove(child: FrameworkElement): void {
252
+        // 实现移除子元素的逻辑
253
+    }
254
+}
255
+
256
+// 假设 ContentControl 类定义如下
257
+class ContentControl extends FrameworkElement {
258
+    Content: any;
259
+}
260
+
261
+// 假设 ItemsControl 类定义如下
262
+class ItemsControl extends FrameworkElement {
263
+    Items: any[];
264
+    Remove(child: any): void {
265
+        // 实现移除子项的逻辑
266
+    }
267
+}
268
+
269
+// 假设 DataTable 类定义如下
270
+class DataTable {
271
+    Columns: any[];
272
+    Rows: any[];
273
+    AddColumn(name: string): void {
274
+        // 实现添加列的逻辑
275
+    }
276
+    AddRow(data: any[]): void {
277
+        // 实现添加行的逻辑
278
+    }
279
+    DefaultView: any;
280
+}
281
+
282
+// 假设 DataRowView 类定义如下
283
+class DataRowView {
284
+    Row: any;
285
+}
286
+
287
+// 假设 DataGridColumn 类定义如下
288
+class DataGridColumn {
289
+    Header: any;
290
+}
291
+
292
+// 假设 Application 类定义如下
293
+class Application {
294
+    static Current: Application;
295
+    MainWindow: any;
296
+}
297
+
298
+// 假设 TradePage 类定义如下
299
+class TradePage {
300
+    Content: any;
301
+    ShowPageMessageBoxExt(message: string, options: { [key: string]: string }, defaultKey: any): any {
302
+        // 实现显示消息框的逻辑
303
+        return null;
304
+    }
305
+}
306
+
307
+// 转换后的 TradePageExtension 类
308
+export class TradePageExtension {
309
+    static SaveTradePage(target: IPage, rootElement: FrameworkElement): Uint8Array {
310
+        const rtb = new RenderTargetBitmap(
311
+            Math.floor(rootElement.ActualWidth),
312
+            Math.floor(rootElement.ActualHeight),
313
+            96,
314
+            96,
315
+            null // 此处需要根据实际情况指定像素格式
316
+        );
317
+        rtb.Render(rootElement);
318
+        return this.BitmapSourceToByte(rtb as unknown as BitmapSource);
319
+    }
320
+
321
+    static RestoreTradePage(target: IPage, tradepagedata: Uint8Array): FrameworkElement {
322
+        const image = new Image();
323
+        image.Source = this.ByteToBitmapSource(tradepagedata);
324
+        return image as unknown as FrameworkElement;
325
+    }
326
+
327
+    private static DealSpecialControl(rootElement: FrameworkElement, pagedata: XmlDocument, specialitems: { [key: string]: any }, flag: number): void {
328
+        const elements = rootElement.Children;
329
+        for (let i = 0; i < elements.length; i++) {
330
+            const element = elements[i] as FrameworkElement;
331
+            if (!element) continue;
332
+
333
+            if (element instanceof ComboBox) {
334
+                if (flag === 0) {
335
+                    if (!specialitems[element.Name]) {
336
+                        const items: { [key: string]: any } = {};
337
+                        for (let j = 0; j < element.Items.length; j++) {
338
+                            const item = element.Items[j];
339
+                            if (item) {
340
+                                items[(j + 1).toString()] = item;
341
+                            }
342
+                        }
343
+                        this.InsertInfoToXml(pagedata, "ComBoxInfo", element.Name, this.Serialize(items), element.SelectedIndex.toString());
344
+                        items["selectedindex"] = element.SelectedIndex;
345
+                        specialitems[element.Name] = items;
346
+                        element.Items = [];
347
+                    }
348
+                } else if (flag === 1) {
349
+                    if (Object.keys(specialitems).length !== 0) {
350
+                        for (const [key, value] of Object.entries(specialitems)) {
351
+                            if (key === element.Name) {
352
+                                const itemObj = value as { [key: string]: any };
353
+                                for (const [itemKey, itemValue] of Object.entries(itemObj)) {
354
+                                    if (itemKey === "selectedindex") {
355
+                                        element.SelectedIndex = itemValue as number;
356
+                                    } else {
357
+                                        element.Items.push(itemValue);
358
+                                    }
359
+                                }
360
+                                break;
361
+                            }
362
+                        }
363
+                    } else {
364
+                        const items = this.Deserialize<{ [key: string]: any }>(this.GetDataFromXml(pagedata, "ComBoxInfo", element.Name, "value"));
365
+                        for (const [key, value] of Object.entries(items)) {
366
+                            element.Items.push(value);
367
+                        }
368
+                        let index = 0;
369
+                        const indexStr = this.GetDataFromXml(pagedata, "ComBoxInfo", element.Name, "selectedindex");
370
+                        if (indexStr) {
371
+                            index = parseInt(indexStr, 10);
372
+                        }
373
+                        element.SelectedIndex = index;
374
+                    }
375
+                }
376
+            } else if (element instanceof DataGrid) {
377
+                if (flag === 0) {
378
+                    if (!specialitems[element.Name]) {
379
+                        specialitems[element.Name] = element.ItemsSource;
380
+                        const items: { [key: string]: any } = {};
381
+                        const colname: any[] = [];
382
+                        for (let j = 0; j < element.Columns.length; j++) {
383
+                            const column = element.Columns[j];
384
+                            colname.push(column.Header);
385
+                        }
386
+                        items["colname"] = colname;
387
+                        for (let j = 0; j < element.Items.length; j++) {
388
+                            const item = element.Items[j] as DataRowView;
389
+                            if (item) {
390
+                                items[(j + 1).toString()] = item.Row.ItemArray;
391
+                            }
392
+                        }
393
+                        this.InsertInfoToXml(pagedata, "DataGrid", element.Name, this.Serialize(items), "");
394
+                        element.ItemsSource = null;
395
+                    }
396
+                } else if (flag === 1) {
397
+                    if (Object.keys(specialitems).length !== 0) {
398
+                        for (const [key, value] of Object.entries(specialitems)) {
399
+                            if (key === element.Name) {
400
+                                element.ItemsSource = value as any;
401
+                                break;
402
+                            }
403
+                        }
404
+                    } else {
405
+                        const items = this.Deserialize<{ [key: string]: any }>(this.GetDataFromXml(pagedata, "DataGrid", element.Name, "value"));
406
+                        const table = new DataTable();
407
+                        for (const [key, value] of Object.entries(items)) {
408
+                            if (key === "colname") {
409
+                                const colnames = value as any[];
410
+                                for (const colname of colnames) {
411
+                                    table.AddColumn(colname.toString());
412
+                                }
413
+                            } else {
414
+                                table.AddRow(value as any[]);
415
+                            }
416
+                        }
417
+                        element.ItemsSource = table.DefaultView;
418
+                    }
419
+                }
420
+            } else if (element instanceof DataBox) {
421
+                const parent = element.Parent as FrameworkElement;
422
+                if (parent instanceof Panel) {
423
+                    parent.Remove(element);
424
+                } else if (parent instanceof ContentControl) {
425
+                    parent.Content = null;
426
+                } else if (parent instanceof ItemsControl) {
427
+                    parent.Items.remove(element);
428
+                }
429
+                this.DealSpecialControl(parent, pagedata, specialitems, flag);
430
+                break;
431
+            }
432
+
433
+            if (element && !FocusManager.GetIsInternalKeyboardControlling(element)) {
434
+                this.DealSpecialControl(element, pagedata, specialitems, flag);
435
+            }
436
+        }
437
+    }
438
+
439
+    private static InsertInfoToXml(pagedataxml: XmlDocument, node: string, name: string, value: string, selectedindex: string): void {
440
+        try {
441
+            if (pagedataxml) {
442
+                const root = pagedataxml.DocumentElement;
443
+                const nodetmp = root.SelectSingleNode(node);
444
+                const xe = pagedataxml.CreateElement("info");
445
+                xe.SetAttribute("name", name);
446
+                xe.SetAttribute("selectedindex", selectedindex);
447
+                xe.SetAttribute("value", value);
448
+                nodetmp.AppendChild(xe);
449
+            }
450
+        } catch (e) {
451
+            throw e;
452
+        }
453
+    }
454
+
455
+    private static GetDataFromXml(pagedataxml: XmlDocument, node: string, name: string, property: string): string {
456
+        let result = null;
457
+        try {
458
+            const root = pagedataxml.DocumentElement;
459
+            const nodetmp = root.SelectSingleNode(node);
460
+            for (const tmp of nodetmp.ChildNodes) {
461
+                if (tmp.Attributes["name"].Value === name) {
462
+                    result = tmp.Attributes[property].Value;
463
+                    break;
464
+                }
465
+            }
466
+        } catch (e) {
467
+            throw e;
468
+        }
469
+        return result;
470
+    }
471
+
472
+    private static Serialize<T>(obj: T): string {
473
+        if (!obj) return null;
474
+        const formatter = new BinaryFormatter();
475
+        const stream = new MemoryStream();
476
+        formatter.Serialize(stream, obj);
477
+        stream.Position = 0;
478
+        const buffer = new Uint8Array(stream.Length);
479
+        stream.Read(buffer, 0, buffer.length);
480
+        stream.Flush();
481
+        stream.Close();
482
+        return btoa(String.fromCharCode.apply(null, Array.from(buffer)));
483
+    }
484
+
485
+    static Serialize<T>(target: IPage, obj: T): string {
486
+        return this.Serialize(obj);
487
+    }
488
+
489
+    static Deserialize<T>(target: IPage, str: string): T {
490
+        return this.Deserialize(str);
491
+    }
492
+
493
+    private static Deserialize<T>(str: string): T {
494
+        let obj: T = null;
495
+        const formatter = new BinaryFormatter();
496
+        const buffer = Uint8Array.from(atob(str).split('').map(c => c.charCodeAt(0)));
497
+        const stream = new MemoryStream(buffer);
498
+        obj = formatter.Deserialize(stream) as T;
499
+        stream.Flush();
500
+        stream.Close();
501
+        return obj;
502
+    }
503
+
504
+    static PrintCertificate(target: IPage, tradeCode: string, businessId: string, forms: PrintContainer[]): void {
505
+        const tradeForms = PrintHandle.GetTradeFormsByTradecode(tradeCode);
506
+        for (const print of forms) {
507
+            let xpsFile: FileInfo = null;
508
+            // 此处省略了原代码中复杂的打印逻辑,需要根据实际情况实现
509
+        }
510
+    }
511
+
512
+    static BitmapSourceToByte(bitmapSource: BitmapSource): Uint8Array {
513
+        const encoder = new PngBitmapEncoder();
514
+        encoder.Frames = [];
515
+        encoder.Add(BitmapFrame.Create(bitmapSource));
516
+        const ms = new MemoryStream();
517
+        encoder.Save(ms);
518
+        return ms.ToArray();
519
+    }
520
+
521
+    static ByteToBitmapSource(byteData: Uint8Array): BitmapSource {
522
+        const bi = new BitmapImage();
523
+        bi.BeginInit();
524
+        bi.StreamSource = new MemoryStream(byteData);
525
+        bi.EndInit();
526
+        return bi;
527
+    }
528
+}

Loading…
Cancel
Save