48 lines
1.3 KiB
Dart
48 lines
1.3 KiB
Dart
import 'dart:math';
|
|
import 'package:crypto/crypto.dart';
|
|
import 'dart:convert';
|
|
|
|
class CommonUtil {
|
|
static String generateMd5(String input) {
|
|
List<int> bytes = utf8.encode(input); // 将字符串转换为字节码
|
|
Digest md5Hash = md5.convert(bytes); // 对字节码进行MD5加密
|
|
String encryptedString = md5Hash.toString(); // 获取加密后的字符串
|
|
return encryptedString;
|
|
}
|
|
|
|
static String generateTicketNumber() {
|
|
Random random = Random();
|
|
|
|
int randomTwoDigitNumber = random.nextInt(99);
|
|
String twoDigitNumber = randomTwoDigitNumber.toString().padLeft(2, '0');
|
|
|
|
// 格式化数字串
|
|
String formattedNumber =
|
|
'${random.nextInt(9999999).toString().padLeft(7, '0')}${random.nextInt(9999999).toString().padLeft(7, '0')}-$twoDigitNumber';
|
|
|
|
return formattedNumber;
|
|
}
|
|
|
|
static String firstUppercase(String text) {
|
|
return '${text[0].toUpperCase()}${text.substring(1)}';
|
|
}
|
|
|
|
static List<T> flattenTree<T extends TreeNode>(List<T> children) {
|
|
List<T> result = children;
|
|
for (T child in children) {
|
|
if (child.children != null) {
|
|
result.addAll(flattenTree(child.children as List<T>));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static String toNumberWithout0(num num) {
|
|
return num.toStringAsFixed(num.truncateToDouble() == num ? 0 : 2);
|
|
}
|
|
}
|
|
|
|
class TreeNode<T> {
|
|
List<T>? children;
|
|
}
|