|
@@ -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;
|