{"id":1452,"date":"2024-11-10T11:56:37","date_gmt":"2024-11-10T03:56:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1452\/"},"modified":"2024-11-10T11:56:37","modified_gmt":"2024-11-10T03:56:37","slug":"%e5%a6%82%e4%bd%95%e8%af%86%e5%88%ab%e5%92%8c%e4%bf%ae%e6%ad%a3%e6%96%87%e6%9c%ac%e4%b8%ad%e7%9a%84%e9%94%99%e8%af%af%ef%bc%8c%e5%b9%b6%e4%bd%bf%e7%94%a8%e9%ab%98%e4%ba%ae%e6%98%be%e7%a4%ba%e7%9a%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1452\/","title":{"rendered":"\u5982\u4f55\u8bc6\u522b\u548c\u4fee\u6b63\u6587\u672c\u4e2d\u7684\u9519\u8bef\uff0c\u5e76\u4f7f\u7528\u9ad8\u4eae\u663e\u793a\u7684\u65b9\u5f0f\u5c55\u73b0\u51fa\u6765\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173043810329888.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u8bc6\u522b\u548c\u4fee\u6b63\u6587\u672c\u4e2d\u7684\u9519\u8bef\uff0c\u5e76\u4f7f\u7528\u9ad8\u4eae\u663e\u793a\u7684\u65b9\u5f0f\u5c55\u73b0\u51fa\u6765\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u8bc6\u522b\u548c\u4fee\u6b63\u6587\u672c\u4e2d\u7684\u9519\u8bef\uff0c\u5e76\u4f7f\u7528\u9ad8\u4eae\u663e\u793a\u7684\u65b9\u5f0f\u5c55\u73b0\u51fa\u6765\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u6839\u636e\u7ea0\u9519\u7ed3\u679c\u9ad8\u4eae\u663e\u793a\u6587\u672c\u5185\u5bb9<\/strong><\/p>\n<p>\u8981\u5b9e\u73b0\u6839\u636e\u7ea0\u9519\u8bc6\u522b\u8fd4\u56de\u7ed3\u679c\u9ad8\u4eae\u663e\u793a\u6587\u672c\u5185\u5bb9\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a<\/p>\n<p><strong>1. \u89e3\u6790\u7ea0\u9519\u8bc6\u522b\u7ed3\u679c<\/strong><\/p>\n<p>\u4ece\u7ea0\u9519\u5f15\u64ce\u8fd4\u56de\u7684JSON\u6570\u636e\u4e2d\u63d0\u53d6\u51fa\u7ea0\u9519\u4fe1\u606f\uff0c\u5305\u62ec\u88ab\u7ea0\u6b63\u7684\u8bcd\u8bed\u3001\u7c7b\u578b\u7b49\u3002<\/p>\n<p><strong>2. \u786e\u8ba4\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5206\u522b\u63d0\u4f9b\u5bf9\u5e94\u7684\u6837\u5f0f\u6807\u8bc6<\/strong><\/p>\n<p>\u6839\u636e\u7ea0\u9519\u7c7b\u578b\u7684\u4e0d\u540c\uff0c\u4e3a\u6bcf\u79cd\u7c7b\u578b\u5b9a\u4e49\u5bf9\u5e94\u7684\u6837\u5f0f\u6807\u8bc6\uff0c\u5982\u201cword\u201d\uff08\u9519\u522b\u5b57\uff09\u5bf9\u5e94\u6837\u5f0f\u6807\u8bc6\u201c3\u201d\u7b49\u3002<\/p>\n<p><strong>3. \u5339\u914d\u7ea0\u6b63\u7684\u8bcd\u8bed\uff0c\u66ff\u6362\u6587\u672c\u5185\u5bb9<\/strong><\/p>\n<p>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u51fa\u7ea0\u6b63\u7684\u8bcd\u8bed\uff0c\u5e76\u7528\u5e26\u5bf9\u5e94\u6837\u5f0f\u6807\u8bc6\u7684HTML\u6807\u7b7e\u66ff\u6362\u6389\u539f\u59cb\u6587\u672c\u4e2d\u7684\u8bcd\u8bed\u3002<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>const resp = JSON.parse(`{\"leader\":[],\"org\":[],\"word\": [[37, \"\u4e3b\u610f\", \"\u6ce8\u610f\", \"word\"]], \"char\": [], \"redund\": [[9, \"\u8272\", \"\", \"redund\"]], \"miss\": [[9, \"\u8272\u8272\", \"\u8272\u9ec4\u8272\", \"miss\"]], \"addr\": [[0, \"\u82b8\u5357\u5e02\", \"\u4e30\u5357\u5e02\", \"addr_S\"]], \"name\": []}`);\nconst styleMap = new Map([[\"leader\", \"css1\"], [\"org\", \"css2\"], [\"word\", \"css3\"], [\"char\", \"css4\"], [\"redund\", \"css5\"], [\"miss\", \"css6\"], [\"addr\", \"css7\"], [\"name\", \"css8\"]]);\nlet content = '\u82b8\u5357\u5e02\u6c14\u8c61\u53f0\u66b4\u96e8\u6a59\u8272\u8272\u9884\u8b66\u4fe1\u53f7\uff0c\u76ee\u524d\u964d\u96e8\u4e91\u56e2\u5df2\u4e1c\u5317\u79fb\uff0c\u5bf9\u82b8\u5357\u5e02\u5f71\u54cd\u51cf\u5f31\uff0c\u8bf7\u4e3b\u610f\u9632\u8303\u964d\u6c34\u8fc7\u540e\u53ef\u80fd\u5f15\u53d1\u7684\u6b21\u751f\u707e\u5bb3';\n\nObject.keys(resp).forEach(key =&gt; resp[key].forEach(err =&gt; err[4] = key));\nconst errMap = new Map();\nObject.keys(resp).flatMap(key =&gt; resp[key]).forEach((err) =&gt; {\n  const idx = err[0];\n  if(errMap.has(idx)) {\n    if(errMap.get(idx)[1].length &lt; err[1].length) {\n      errMap.set(idx, err);\n    }\n  } else {\n    errMap.set(idx, err);\n  }\n});\nconsole.log(errMap);\n\n[...errMap.entries()].forEach(([key, value]) =&gt; {\n  content = content.replace(eval(`\/${value[1]}\/g`), `&lt;span style=\"${styleMap.get(value[4])}\"&gt;${value[1]}&lt;\/span&gt;`);\n});\n\nconsole.log(content);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>&lt;span style=\"color: #333;font-weight: 700;background-color: orange;\"&gt;\u82b8\u5357\u5e02&lt;\/span&gt;\u6c14\u8c61\u53f0\u66b4\u96e8\u6a59&lt;span style=\"color: #333;font-weight: 700;background-color: orange;\"&gt;\u8272\u8272&lt;\/span&gt;\u9884\u8b66\u4fe1\u53f7\uff0c\u76ee\u524d\u964d\u96e8\u4e91\u56e2\u5df2\u4e1c\u5317\u79fb\uff0c\u5bf9&lt;span style=\"color: #333;font-weight: 700;background-color: orange;\"&gt;\u82b8\u5357\u5e02&lt;\/span&gt;\u5f71\u54cd\u51cf\u5f31\uff0c\u8bf7&lt;span style=\"color: #333;font-weight: 700;background-color: orange;\"&gt;\u4e3b\u610f&lt;\/span&gt;\u9632\u8303\u964d\u6c34\u8fc7\u540e\u53ef\u80fd\u5f15\u53d1\u7684\u6b21\u751f\u707e\u5bb3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u8bc6\u522b\u548c\u4fee\u6b63\u6587\u672c\u4e2d\u7684\u9519\u8bef\uff0c\u5e76\u4f7f\u7528\u9ad8\u4eae\u663e\u793a\u7684\u65b9\u5f0f\u5c55\u73b0\u51fa\u6765\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6839\u636e\u7ea0\u9519\u7ed3\u679c\u9ad8\u4eae\u663e\u793a\u6587\u672c\u5185\u5bb9 \u8981\u5b9e\u73b0\u6839\u636e\u7ea0\u9519\u8bc6\u522b\u8fd4\u56de\u7ed3\u679c\u9ad8\u4eae\u663e\u793a\u6587\u672c\u5185\u5bb9\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\uff1a 1. \u89e3\u6790\u7ea0\u9519\u8bc6\u522b\u7ed3\u679c \u4ece\u7ea0\u9519\u5f15\u64ce\u8fd4\u56de\u7684JSON\u6570\u636e\u4e2d\u63d0\u53d6\u51fa\u7ea0\u9519\u4fe1\u606f\uff0c\u5305\u62ec\u88ab\u7ea0\u6b63\u7684\u8bcd\u8bed\u3001\u7c7b\u578b\u7b49\u3002 2. \u786e\u8ba4\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u5206\u522b\u63d0\u4f9b\u5bf9\u5e94\u7684\u6837\u5f0f\u6807\u8bc6 \u6839\u636e\u7ea0\u9519\u7c7b\u578b\u7684\u4e0d\u540c\uff0c\u4e3a\u6bcf\u79cd\u7c7b\u578b\u5b9a\u4e49\u5bf9\u5e94\u7684\u6837\u5f0f\u6807\u8bc6\uff0c\u5982\u201cword\u201d\uff08\u9519\u522b\u5b57\uff09\u5bf9\u5e94\u6837\u5f0f\u6807\u8bc6\u201c3\u201d\u7b49\u3002 3. \u5339\u914d\u7ea0\u6b63\u7684\u8bcd\u8bed\uff0c\u66ff\u6362\u6587\u672c\u5185\u5bb9 \u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u51fa\u7ea0\u6b63\u7684\u8bcd\u8bed\uff0c\u5e76\u7528\u5e26\u5bf9\u5e94\u6837\u5f0f\u6807\u8bc6\u7684HTML\u6807\u7b7e\u66ff\u6362\u6389\u539f\u59cb\u6587\u672c\u4e2d\u7684\u8bcd\u8bed\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a const resp = JSON.parse(`{&#8220;leader&#8221;:[],&#8221;org&#8221;:[],&#8221;word&#8221;: [[37, &#8220;\u4e3b\u610f&#8221;, &#8220;\u6ce8\u610f&#8221;, &#8220;word&#8221;]], &#8220;char&#8221;: [], &#8220;redund&#8221;: [[9, &#8220;\u8272&#8221;, &#8220;&#8221;, &#8220;redund&#8221;]], &#8220;miss&#8221;: [[9, &#8220;\u8272\u8272&#8221;, &#8220;\u8272\u9ec4\u8272&#8221;, &#8220;miss&#8221;]], &#8220;addr&#8221;: [[0, &#8220;\u82b8\u5357\u5e02&#8221;, &#8220;\u4e30\u5357\u5e02&#8221;, &#8220;addr_S&#8221;]], &#8220;name&#8221;: []}`); const styleMap = new Map([[&#8220;leader&#8221;, &#8220;css1&#8221;], [&#8220;org&#8221;, &#8220;css2&#8221;], [&#8220;word&#8221;, &#8220;css3&#8221;], [&#8220;char&#8221;, &#8220;css4&#8221;], [&#8220;redund&#8221;, &#8220;css5&#8221;], [&#8220;miss&#8221;, &#8220;css6&#8221;], [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1452","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=1452"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1452\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}