{"id":3504,"date":"2024-05-14T16:01:21","date_gmt":"2024-05-14T08:01:21","guid":{"rendered":"http:\/\/www.yuguoxy.com\/geekhome\/?p=3504"},"modified":"2026-08-18T12:35:36","modified_gmt":"2026-08-18T04:35:36","slug":"%e5%a6%82%e4%bd%95%e6%8e%a7%e5%88%b6%e6%8c%89%e9%92%ae%e6%9d%83%e9%99%90%ef%bc%8c%e7%9c%9f%e5%ae%9e%e6%a1%88%e4%be%8b%e5%b8%a6%e4%bd%a0%e4%b8%80%e6%ad%a5%e4%b8%80%e6%ad%a5%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=3504","title":{"rendered":"&#8220;\u5982\u4f55\u63a7\u5236\u6309\u94ae\u6743\u9650&#8221;\uff0c\u771f\u5b9e\u6848\u4f8b\u5e26\u4f60\u4e00\u6b65\u4e00\u6b65\u5b9e\u73b0\uff01\u8ba9\u9762\u8bd5\u4e0d\u518d\u8e29\u5751\u3002"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\u91cc\uff0c\u83dc\u5355\u6743\u9650\u7ba1\u7684\u662f\u300c\u8fdb\u54ea\u4e2a\u6a21\u5757\u300d\uff1b\u8981\u66f4\u7ec6\u5730\u7ba1\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\u3001\u641c\u7d22\uff0c\u5f97\u7528<strong style=\"color: #4870ac;\">\u6309\u94ae\u6743\u9650<\/strong>\uff1a\u6309\u89d2\u8272\u51b3\u5b9a\u6309\u94ae\u663e\u4e0d\u663e\u793a\u3001\u80fd\u4e0d\u80fd\u70b9\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u9762\u8bd5\u5e38\u8e29\u7684\u5751\u662f\uff1a\u53ea\u85cf\u6309\u94ae\u3001\u63a5\u53e3\u4ecd\u80fd\u8c03\uff1b\u6216\u8005\u4e09\u79cd\u5199\u6cd5\uff08\u51fd\u6570\u3001\u7ec4\u4ef6\u3001\u6307\u4ee4\uff09\u8bb2\u4e0d\u6e05\u3002\u4e0b\u9762\u5148\u770b\u6c47\u667a\u5728\u7ebf\u7684\u771f\u5b9e\u6548\u679c\uff0c\u518d\u62c6\u5b9e\u73b0\uff0c\u6700\u540e\u843d\u5230\u9879\u76ee\u91cc\u7684\u63d2\u4ef6\u5c01\u88c5\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u771f\u5b9e\u573a\u666f\uff1a\u6c47\u667a\u5728\u7ebf<\/h2>\n<p style=\"margin: 1em 0px;\">\u7ed9\u300c\u5546\u57ce\u7528\u6237\u300d\u89d2\u8272\u4e0d\u8bbe\u7f6e\u5546\u54c1\u5220\u9664\u3001banner \u5220\u9664\u3001\u4f1a\u5458\u5220\u9664\u6743\u9650\uff0c\u8be5\u89d2\u8272\u767b\u5f55\u540e\u8fd9\u4e9b\u6309\u94ae\u5c31\u4e0d\u4f1a\u51fa\u73b0\u3002<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1279\" height=\"639\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-2.png\" alt=\"\" class=\"wp-image-3505\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-2.png 1279w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-2-768x384.png 768w\" sizes=\"(max-width: 1279px) 100vw, 1279px\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u5546\u57ce\u7528\u6237\u89d2\u8272\u4e0b\uff0c\u5bf9\u5e94\u5220\u9664\u6743\u9650\u662f\u5173\u6389\u7684\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1262\" height=\"619\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-3.png\" alt=\"\" class=\"wp-image-3506\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-3.png 1262w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-3-768x377.png 768w\" sizes=\"(max-width: 1262px) 100vw, 1262px\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u8d85\u7ea7\u7ba1\u7406\u5458\u89d2\u8272\u6253\u5f00\u5168\u90e8\u6309\u94ae\u64cd\u4f5c\u6743\u9650\u3002\u5468 sir \u4ee5\u8d85\u7ba1\u767b\u5f55\u540e\uff0c\u5546\u54c1\u7ba1\u7406\u91cc\u80fd\u770b\u5230\u5220\u9664\u5546\u54c1\u6309\u94ae\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1309\" height=\"522\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-4.png\" alt=\"\" class=\"wp-image-3507\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-4.png 1309w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-4-768x306.png 768w\" sizes=\"(max-width: 1309px) 100vw, 1309px\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u540c\u4e00\u754c\u9762\uff0c\u5546\u57ce\u7528\u6237\u767b\u5f55\u5219\u6ca1\u6709\u5220\u9664\u6309\u94ae\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1312\" height=\"485\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-5.png\" alt=\"\" class=\"wp-image-3508\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-5.png 1312w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-5-768x284.png 768w\" sizes=\"(max-width: 1312px) 100vw, 1312px\" \/><\/p>\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u8981\u70b9<\/strong>\uff1a\u6743\u9650\u7801\u6765\u81ea\u540e\u7aef\u89d2\u8272\u914d\u7f6e\uff0c\u524d\u7aef\u53ea\u6839\u636e\u5f53\u524d\u7528\u6237\u7684\u8d44\u6e90\u5217\u8868\u51b3\u5b9a\u6e32\u67d3\u3002\u8fd9\u662f\u5c55\u793a\u5c42\u63a7\u5236\uff0c\u63a5\u53e3\u4ecd\u987b\u9274\u6743\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u51fd\u6570\u65b9\u5f0f<\/h2>\n<p style=\"margin: 1em 0px;\">\u7528\u7edf\u4e00\u65b9\u6cd5 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">hasPermission<\/code>\uff0c\u5728\u6a21\u677f\u91cc <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-if<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;a-button v-if=\"hasPermission(['20000', '2000010'])\" color=\"error\" class=\"mx-4\"&gt; \u62e5\u6709[20000,2000010]code\u53ef\u89c1 &lt;\/a-button&gt;\n&lt;\/template&gt;\n&lt;script lang=\"ts\"&gt;\nimport { usePermission } from '\/@\/hooks\/web\/usePermission'\nexport default defineComponent({\n  setup() {\n    const { hasPermission } = usePermission()\n    return { hasPermission }\n  }\n})\n&lt;\/script&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">hasPermission<\/code> \u4ece\u5168\u5c40\u53d6\u51fa\u5f53\u524d\u7528\u6237\u6743\u9650\u7801\uff0c\u5224\u65ad\u6309\u94ae\u9700\u8981\u7684\u7801\u5728\u4e0d\u5728\u91cc\u9762\uff1b\u4f20\u6570\u7ec4\u65f6\uff0c\u547d\u4e2d\u5176\u4e2d\u4e00\u4e2a\u5373\u53ef\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">export function usePermission() {\n  function hasPermission(value, def = true) {\n    \/\/ \u9ed8\u8ba4\u89c6\u4e3a\u6709\u6743\u9650\n    if (!value) {\n      return def\n    }\n    const allCodeList = permissionStore.getPermCodeList\n    if (!isArray(value)) {\n      return allCodeList.includes(value)\n    }\n    \/\/ intersection\u662flodash\u63d0\u4f9b\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7528\u4e8e\u8fd4\u56de\u4e00\u4e2a\u6240\u6709\u7ed9\u5b9a\u6570\u7ec4\u90fd\u5b58\u5728\u7684\u5143\u7d20\u7ec4\u6210\u7684\u6570\u7ec4\n    return intersection(value, allCodeList).length &gt; 0\n    return true\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6700\u540e\u4e00\u884c <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">return true<\/code> \u6c38\u8fdc\u8d70\u4e0d\u5230\uff0c\u5c5e\u4e8e\u6b7b\u4ee3\u7801\uff0c\u9762\u8bd5\u65f6\u4e3b\u52a8\u63d0\u4e00\u53e5\u66f4\u597d\u3002\u591a\u7801\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">intersection<\/code> \u505a\u300c\u6709\u4ea4\u96c6\u5373\u901a\u8fc7\u300d\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e09\u3001\u7ec4\u4ef6\u65b9\u5f0f<\/h2>\n<p style=\"margin: 1em 0px;\">\u4e5f\u53ef\u4ee5\u5305\u4e00\u5c42 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">Authority<\/code>\uff0c\u628a\u6743\u9650\u7801\u901a\u8fc7 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">value<\/code> \u4f20\u5165\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;Authority :value=\"RoleEnum.ADMIN\"&gt; &lt;a-button type=\"primary\" block&gt; \u53ea\u6709admin\u89d2\u8272\u53ef\u89c1 &lt;\/a-button&gt; &lt;\/Authority&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n&lt;script&gt;\nimport { Authority } from '\/@\/components\/Authority'\nimport { defineComponent } from 'vue'\nexport default defineComponent({ components: { Authority } })\n&lt;\/script&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6709\u6743\u9650\u5c31\u539f\u6837\u6e32\u67d3\u63d2\u69fd\uff0c\u6ca1\u6709\u5c31\u4ec0\u4e48\u90fd\u4e0d\u6e32\u67d3\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;script lang=\"ts\"&gt;\nimport { defineComponent } from 'vue'\nimport { usePermission } from '\/@\/hooks\/web\/usePermission'\nimport { getSlot } from '\/@\/utils\/helper\/tsxHelper'\nexport default defineComponent({\n  name: 'Authority',\n  props: { value: { type: [Number, Array, String], default: '' } },\n  setup(props, { slots }) {\n    const { hasPermission } = usePermission()\n    function renderAuth() {\n      const { value } = props\n      if (!value) {\n        return getSlot(slots)\n      }\n      return hasPermission(value) ? getSlot(slots) : null\n    }\n    return () =&gt; {\n      return renderAuth()\n    }\n  }\n})\n&lt;\/script&gt;<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u56db\u3001\u6307\u4ee4\u65b9\u5f0f<\/h2>\n<p style=\"margin: 1em 0px;\">\u6a21\u677f\u66f4\u77ed\uff0c\u5199\u6210 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-auth<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;a-button v-auth=\"'1000'\" type=\"primary\" class=\"mx-4\"&gt; \u62e5\u6709code ['1000']\u6743\u9650\u53ef\u89c1 &lt;\/a-button&gt;<\/code><\/pre>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import { usePermission } from '\/@\/hooks\/web\/usePermission'\nfunction isAuth(el, binding) {\n  const { hasPermission } = usePermission()\n  const value = binding.value\n  if (!value) return\n  if (!hasPermission(value)) {\n    el.parentNode?.removeChild(el)\n  }\n}\nconst mounted = (el, binding) =&gt; {\n  isAuth(el, binding)\n}\nconst authDirective = {\n  \/\/ \u5728\u7ed1\u5b9a\u5143\u7d20\u7684\u7236\u7ec4\u4ef6\n  \/\/ \u53ca\u4ed6\u81ea\u5df1\u7684\u6240\u6709\u5b50\u8282\u70b9\u90fd\u6302\u8f7d\u5b8c\u6210\u540e\u8c03\u7528\n  mounted,\n}\n\/\/ \u6ce8\u518c\u5168\u5c40\u6307\u4ee4\nexport function setupPermissionDirective(app) {\n  app.directive('auth', authDirective)\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u53ea\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">mounted<\/code> \u91cc\u5224\u65ad\uff1a\u6ca1\u6709\u6743\u9650\u5c31\u4ece DOM \u62ff\u6389\u8282\u70b9\u3002\u6743\u9650\u540e\u6765\u53d8\u4e86\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0\uff0c\u8fd9\u662f\u6307\u4ee4\u65b9\u6848\u7684\u5e38\u89c1\u5751\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e94\u3001\u6c47\u667a\u5728\u7ebf\uff1a\u63d2\u4ef6\u5c01\u88c5<\/h2>\n<p style=\"margin: 1em 0px;\">\u5b9e\u9645\u9879\u76ee\u7528\u63d2\u4ef6\u5c01\u88c5\u6307\u4ee4\uff0c\u8026\u5408\u66f4\u5e72\u51c0\uff1a\u6839\u636e\u767b\u5f55\u540e\u5b58\u8fdb store \u7684\u6309\u94ae\u8d44\u6e90\uff0c\u5bf9\u7167\u6307\u4ee4\u4e0a\u7684\u6743\u9650\u503c\uff0c\u51b3\u5b9a\u663e\u793a\u6216\u79fb\u9664\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import { useMenuStore } from '@\/stores\/modules\/menu'\n\nexport const myPlugin = {\n    \/\/ \u63d2\u4ef6\u5c01\u88c5\u5168\u5c40\u7ec4\u4ef6\u3001\u5168\u5c40\u6307\u4ee4\u3001\u5168\u5c40...\n  install(app: any, options: any) {\n    \/\/ \u5b9a\u4e49v-permession\u6307\u4ee4, \u5728 `mounted` \u548c `updated` \u65f6\u90fd\u8c03\u7528\n    app.directive('permession', (el: any, binding: any) =&gt; {\n      \/\/ 1. \u83b7\u53d6\u767b\u5f55\u65f6\u5b58\u50a8store\u4e2d\u7684\u6309\u94ae\u8d44\u6e90\u6570\u636e\n      const menuStore = useMenuStore()\n\n      \/\/ 2. \u83b7\u53d6\u5f53\u524d\u89d2\u8272\u8d44\u6e90\u5217\u8868 [AddProduct,EditProduct...]\n      const resourceList = menuStore.resourceList\n\n      \/\/ 3. \u6309\u94ae\u7ed1\u5b9a\u7684\u6743\u9650\u503c binding.value\n      const value = binding.value\n\n      if (value) {\n        const isHide = resourceList &amp;&amp; resourceList.some(item =&gt; value.includes(item))\n        if (!isHide) {\n          el &amp;&amp; el.remove()\n        } else {\n          console.log('need rols! Like v-perisson =\"AddUser\"')\n        }\n      }\n    })\n  }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u6307\u4ee4\u540d\u6309\u9879\u76ee\u5199\u6210\u4e86 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-permession<\/code>\uff08\u62fc\u5199\u5982\u6b64\uff09\u3002\u5546\u54c1\u5220\u9664\u6309\u94ae\u8fd9\u6837\u7ed1\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;el-button type=\"primary\" size=\"small\" v-permession=\"'DeleteProduct'\"&gt;\u5220\u9664&lt;\/el-button&gt;<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u767b\u5f55\u6210\u529f\u540e\u5e76\u884c\u62c9\u83dc\u5355\u548c\u6309\u94ae\u8d44\u6e90\uff0c\u5199\u5165 store\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1342\" height=\"704\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-6.png\" alt=\"\" class=\"wp-image-3509\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-6.png 1342w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-6-768x403.png 768w\" sizes=\"(max-width: 1342px) 100vw, 1342px\" \/><\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">\/\/ \u8c03\u7528\u83dc\u5355\u8d44\u6e90\u63a5\u53e3\n  let menuPromise = RequestMenu(roleId)\n  \/\/ \u8c03\u7528\u6309\u94ae\u8d44\u6e90\u63a5\u53e3\n  let resourcePromise = RequestReourceAuthor(roleId)\n  \/\/\u591a\u4e2apromise\u5c01\u88c5\u7684\u5f02\u5e38\u64cd\u4f5c\u7528\u4e0a\u4e2a\u65b9\u6cd5\u5b9e\u73b0 Promise.all([promise,promise]) Promise.race([promise,promise])\n  const dataList: any = await Promise.all([\n      menuPromise,\n      resourcePromise,\n  ])\n  const menuData = dataList[0]\n  const resourceData = dataList[1]\n  if (menuData.resultCode === 1) {\n      \/\/ 1.\u4fdd\u5b58\u83dc\u5355\u63a5\u53e3\u6570\u636e\n      this.menuList = menuData.resultInfo\n      \/\/ 2.\u683c\u5f0f\u5316\u83dc\u5355\u6570\u636e\n      let routeMenuList = formateRouterMenu(menuData.resultInfo)\n      \/\/ 3.\u6dfb\u52a0\u52a8\u6001\u8def\u7531,router\u5bf9\u8c61\n      routeMenuList.forEach((route: any) =&gt;\n          router.addRoute(route)\n      )\n  }\n  if (resourceData.resultCode === 1) {\n      \/\/ \u4fdd\u5b58\u6309\u94ae\u8d44\u6e90\u6570\u636e\n      this.resourceList = resourceData.resultInfo.resource\n  }<\/code><\/pre>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5199\u6cd5<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u600e\u4e48\u7528<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u4f18\u70b9<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u9762\u8bd5\u5751<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u51fd\u6570<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-if=\"hasPermission(...)\"<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u903b\u8f91\u96c6\u4e2d\u3001\u597d\u6d4b<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6a21\u677f\u91cc\u5bb9\u6613\u6f0f\u5199 v-if<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7ec4\u4ef6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\"><Authority :value><\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u63d2\u69fd\u8bed\u4e49\u6e05\u695a<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5305\u4e00\u5c42\uff0c\u7b80\u5355\u6309\u94ae\u7565\u91cd<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6307\u4ee4 \/ \u63d2\u4ef6<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-auth<\/code> \/ <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">v-permession<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6a21\u677f\u6700\u77ed<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ea mounted \u65f6\u4e0d\u54cd\u5e94\u6743\u9650\u53d8\u5316\uff1b\u524d\u7aef\u9690\u85cf \u2260 \u63a5\u53e3\u5b89\u5168<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\"><img decoding=\"async\" loading=\"lazy\" width=\"1295\" height=\"525\" src=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-7.png\" alt=\"\" class=\"wp-image-3510\" srcset=\"https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-7.png 1295w, https:\/\/ai.zhousir.top\/wp-content\/uploads\/2024\/05\/image-7-768x311.png 768w\" sizes=\"(max-width: 1295px) 100vw, 1295px\" \/><\/p>\n<p style=\"margin: 1em 0px;\">\u957f\u6309\u4e0a\u56fe\uff0c\u8bc6\u522b\u56fe\u4e2d\u4e8c\u7ef4\u7801\u5373\u53ef\u5173\u6ce8\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u63a8\u8350\u9605\u8bfb\uff1a<\/p>\n<p style=\"margin: 1em 0px;\"><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646768&amp;idx=1&amp;sn=9e9a0e7094fde0d3d1b99f422c09424c&amp;chksm=849fe435b3e86d231b8cd3c58bb406f55685f9f5eb0e85994aa1635ec701084cb81d6554c3bd&amp;scene=21#wechat_redirect\" target=\"_blank\">\u52a8\u6001\u6743\u9650\u83dc\u5355\u662f\u4ec0\u4e48\uff1f<\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646768&amp;idx=1&amp;sn=9e9a0e7094fde0d3d1b99f422c09424c&amp;chksm=849fe435b3e86d231b8cd3c58bb406f55685f9f5eb0e85994aa1635ec701084cb81d6554c3bd&amp;scene=21#wechat_redirect\" target=\"_blank\">\u5c01\u88c5\u9012\u5f52\u7ec4\u4ef6\u8f7b\u677e\u5b9e\u73b0<\/a><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646959&amp;idx=1&amp;sn=2b1c5c9097a72c4ec64fa89d7a6e413a&amp;chksm=849fe4eab3e86dfc4a3695813c8d53e47c5420d991c22754ee482862800475d55d5b1e7cff03&amp;scene=21#wechat_redirect\" target=\"_blank\"><\/a><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646959&amp;idx=1&amp;sn=2b1c5c9097a72c4ec64fa89d7a6e413a&amp;chksm=849fe4eab3e86dfc4a3695813c8d53e47c5420d991c22754ee482862800475d55d5b1e7cff03&amp;scene=21#wechat_redirect\" target=\"_blank\">ElementPlus&nbsp;\u8868\u5355\u7ec4\u4ef6\u4e8c\u6b21\u5c01\u88c5\uff0c\u63d0\u9ad850%\u5f00\u53d1\u6548\u7387<\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646863&amp;idx=1&amp;sn=d318b33d277bbd45641fc91722ac3902&amp;chksm=849fe48ab3e86d9cf8327e3bd241f0d7469caeb11bbe124322f683ffe444868985cd31feb5bd&amp;scene=21#wechat_redirect\" target=\"_blank\"><\/a><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646863&amp;idx=1&amp;sn=d318b33d277bbd45641fc91722ac3902&amp;chksm=849fe48ab3e86d9cf8327e3bd241f0d7469caeb11bbe124322f683ffe444868985cd31feb5bd&amp;scene=21#wechat_redirect\" target=\"_blank\">ElementPlus&nbsp;\u8868\u683c\u7ec4\u4ef6\u4e8c\u6b21\u5c01\u88c5\uff0c\u63d0\u9ad850%\u5f00\u53d1\u6548\u7387<\/a><\/p>\n<p style=\"margin: 1em 0px;\"><a rel=\"noreferrer noopener\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzA5ODU3OTgxOA==&amp;mid=2447646989&amp;idx=1&amp;sn=767190b5fcfa8f53239331caa7238932&amp;chksm=849fe508b3e86c1e4376fcc728269d9d9f51ba601ae48c9269f1acaedd14915d1700e26d3f07&amp;scene=21#wechat_redirect\" target=\"_blank\">token\u662f\u4ec0\u4e48?&nbsp;\u65e0\u611f\u5237\u65b0token\u6280\u672f\u8ba9\u9879\u76ee\u5b89\u5168\u6027\u4e0e\u4f53\u9a8c\u6027\u5b8c\u7f8e\u5e73\u8861<\/a><\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u6309\u94ae\u6743\u9650\u662f\u7528\u89d2\u8272\u8d44\u6e90\u7801\u51b3\u5b9a\u6e32\u67d3\uff1b\u51fd\u6570\u3001\u7ec4\u4ef6\u3001\u6307\u4ee4\u4e09\u79cd\u58f3\uff0c\u6838\u5fc3\u90fd\u662f\u6bd4\u5bf9\u6743\u9650\u7801\uff0c\u5e76\u4e14\u540e\u7aef\u63a5\u53e3\u5fc5\u987b\u518d\u9274\u4e00\u6b21\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\u91cc\uff0c\u83dc\u5355\u6743\u9650\u7ba1\u7684\u662f\u300c\u8fdb\u54ea\u4e2a\u6a21\u5757\u300d\uff1b\u8981\u66f4\u7ec6\u5730\u7ba1\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\u3001\u641c\u7d22\uff0c\u5f97\u7528\u6309\u94ae\u6743\u9650\uff1a\u6309\u89d2\u8272\u51b3\u5b9a\u6309\u94ae\u663e\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[106,105],"tags":[205,140],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3504"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3504"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3504\/revisions"}],"predecessor-version":[{"id":3517,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/3504\/revisions\/3517"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}