{"id":1157,"date":"2025-11-15T22:33:22","date_gmt":"2025-11-15T14:33:22","guid":{"rendered":"https:\/\/blog.guguan.us.kg\/?p=1157"},"modified":"2026-04-22T01:40:33","modified_gmt":"2026-04-21T17:40:33","slug":"uuid-%e7%94%9f%e6%88%90%e5%99%a8","status":"publish","type":"post","link":"https:\/\/blog.guguan.us.kg\/?p=1157","title":{"rendered":"UUID \u751f\u6210\u5668"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u751f\u6210\u4e00\u4e2a\u7b26\u5408 RFC4122 \u6807\u51c6\u7684 v4 UUID<\/p>\n\n\n\n<p><textarea id=\"uuid-output\" rows=\"1\" readonly style=\"\n\twidth: 100%;\n\t\/* 1. \u7a84\u5c4f\u6eda\u52a8\u4f18\u5316 *\/\n\toverflow-x: auto;\n\toverflow-y: hidden;\n\twhite-space: nowrap;\n\tresize: none;\n\tpadding: 8px;\n\tbox-sizing: border-box;\n\tfont-family: monospace; \/* \u4f7f\u7528\u7b49\u5bbd\u5b57\u4f53\u66f4\u7f8e\u89c2 *\/\n\tborder: 1px solid #ccc;\n\">\n\u751f\u6210\u7684 UUID \u5c06\u663e\u793a\u5728\u6b64\u5904\u3002\n<\/textarea><\/p>\n\n<p><button onclick=\"generateUUID();\">\u751f\u6210\u65b0\u7684 UUID<\/button><\/p>\n\n<script>\n\t\/**\n\t * @function generateUUID\n\t * @description \u751f\u6210\u4e00\u4e2a\u7b26\u5408 RFC4122 \u6807\u51c6\u7684 v4 UUID \u5e76\u663e\u793a\u5728\u6587\u672c\u57df\u4e2d\u3002\n\t *\/\n\tfunction generateUUID() {\n\t\t\/\/ \u4f7f\u7528\u5185\u7f6e\u7684 crypto.randomUUID() \u65b9\u6cd5\n\t\tlet uuid;\n\t\tif (crypto && crypto.randomUUID) {\n\t\t\tuuid = crypto.randomUUID();\n\t\t} else {\n\t\t\t\/\/ \u517c\u5bb9\u6027\u56de\u9000\n\t\t\tlet d = new Date().getTime();\n\t\t\tif (typeof performance !== 'undefined' && typeof performance.now === 'function'){\n\t\t\t\td += performance.now();\n\t\t\t}\n\t\t\tuuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(\/[xy]\/g, function(c) {\n\t\t\t\tconst r = (d + Math.random() * 16) % 16 | 0;\n\t\t\t\td = Math.floor(d \/ 16);\n\t\t\t\treturn (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);\n\t\t\t});\n\t\t}\n\n\t\tconst outputElement = document.getElementById('uuid-output');\n\t\toutputElement.value = uuid; \/\/ \u8d4b\u503c\u7ed9 textarea \u7684 value \u5c5e\u6027\n\n\t\t\/\/ \u81ea\u52a8\u9009\u4e2d\u65b0\u751f\u6210\u7684\u6587\u672c\uff0c\u65b9\u4fbf\u7528\u6237\u590d\u5236\uff08\u53ef\u9009\uff09\n\t\toutputElement.select();\n\t}\n\n\t\/\/ \u9875\u9762\u52a0\u8f7d\u65f6\u81ea\u52a8\u751f\u6210\u7b2c\u4e00\u4e2a UUID\n\twindow.onload = generateUUID;\n<\/script>\n\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u6210\u4e00\u4e2a\u7b26\u5408 RFC4122 \u6807\u51c6\u7684 v4 UUID \u751f\u6210\u7684 UUID \u5c06\u663e\u793a\u5728\u6b64\u5904\u3002 \u751f\u6210\u65b0\u7684 UUID<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[140],"class_list":["post-1157","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-tools"],"_links":{"self":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1157"}],"version-history":[{"count":2,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1157\/revisions"}],"predecessor-version":[{"id":1159,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1157\/revisions\/1159"}],"wp:attachment":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}