ops-console v1.0.2 (versionCode 8) 源码入库
This commit is contained in:
17
lib/utils/uuid.dart
Normal file
17
lib/utils/uuid.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'dart:math';
|
||||
|
||||
/// 生成与 web 前端一致的 UUID v4 字符串。
|
||||
///
|
||||
/// 模板:`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`
|
||||
String generateUuid() {
|
||||
final random = Random.secure();
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replaceAllMapped(
|
||||
RegExp('[xy]'),
|
||||
(match) {
|
||||
final r = random.nextInt(16);
|
||||
final c = match.group(0)!;
|
||||
final v = c == 'x' ? r : (r & 0x3) | 0x8;
|
||||
return v.toRadixString(16);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user