Skip to content

Commit db326b8

Browse files
committed
fix(playground): update dependencies and refactor ID generation to use uuid library
1 parent e0e8e05 commit db326b8

3 files changed

Lines changed: 47 additions & 23 deletions

File tree

pnpm-lock.yaml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sites/playground/web/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
"@opentiny/tiny-robot-kit": "0.3.3",
1818
"@opentiny/tiny-robot-svgs": "0.3.3",
1919
"@opentiny/vue": "^3.28.0",
20-
"@opentiny/vue-renderless": "^3.28.2",
2120
"@opentiny/vue-directive": "^3.28.0",
2221
"@opentiny/vue-icon": "^3.28.0",
22+
"@opentiny/vue-renderless": "^3.28.2",
2323
"@opentiny/vue-theme": "^3.28.0",
24+
"ai": "6.0.116",
2425
"clipboard-copy": "^4.0.1",
2526
"monaco-editor-vue3": "^1.0.4",
2627
"schema-renderer-ng-adpater": "workspace:*",
28+
"uuid": "11.1.0",
2729
"vite-commit-hash-plugin": "workspace:*",
28-
"vue": "^3.5.18",
29-
"ai": "6.0.116"
30+
"vue": "^3.5.18"
3031
},
3132
"devDependencies": {
3233
"@vitejs/plugin-vue": "^6.0.1",
Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1+
import { v4 as uuidv4 } from 'uuid';
12
/**
23
* 通用 ID 生成函数
34
*
4-
* 策略优先级:
5-
* 1. crypto.randomUUID() — 安全上下文(HTTPS / localhost / Node.js)
6-
* 2. Date.now() + random — 带时间戳,有序,适合日志/排序场景
7-
*
85
* @param length 截取长度,默认 16
96
* @param prefix 可选前缀,如 'user_', 'order_'
107
*/
118
export function generateId(length: number = 16, prefix: string = ''): string {
129
let id: string;
13-
14-
// 策略 1:crypto.randomUUID(最安全,需安全上下文)
15-
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
16-
let raw = '';
17-
while (raw.length < length) {
18-
raw += crypto.randomUUID().replace(/-/g, '');
19-
}
20-
id = raw.substring(0, length);
21-
} else {
22-
// 兜底策略
23-
const timePart = Date.now ? Date.now().toString(36) : '';
24-
let raw = timePart;
25-
while (raw.length < length) {
26-
raw += Math.random().toString(36).slice(2);
27-
}
28-
id = raw.substring(0, length);
10+
let raw = '';
11+
while (raw.length < length) {
12+
raw += uuidv4().replace(/-/g, '');
2913
}
14+
id = raw.substring(0, length);
3015

3116
return prefix + id;
3217
}

0 commit comments

Comments
 (0)