浏览代码

refine plugin usage

czhen 3 年之前
父节点
当前提交
e88bb1a2f5
共有 3 个文件被更改,包括 18 次插入14 次删除
  1. 1 1
      client/src/components/icons/Icons.tsx
  2. 15 12
      client/src/components/layout/Layout.tsx
  3. 2 1
      client/src/plugins/system/config.json

+ 1 - 1
client/src/components/icons/Icons.tsx

@@ -36,7 +36,7 @@ import { ReactComponent as SearchEmptyIcon } from '../../assets/icons/search.svg
 import { ReactComponent as CopyIcon } from '../../assets/icons/copy.svg';
 import { ReactComponent as SystemIcon } from '../../assets/icons/system.svg';
 
-const icons: { [x in IconsType]: (props?: any) => React.ReactElement } = {
+const icons: { [key: string]: (props?: any) => React.ReactElement } = {
   search: (props = {}) => <SearchIcon {...props} />,
   add: (props = {}) => <AddIcon {...props} />,
   delete: (props = {}) => <DeleteIcon {...props} />,

+ 15 - 12
client/src/components/layout/Layout.tsx

@@ -93,19 +93,22 @@ const Layout = (props: any) => {
     r.keys().forEach((key: any) => {
       const content = r(key);
       const pathName = content.client?.path;
-      const icon = content.client?.icon || icons.navSystem;
-      const iconActiveClass =
-        content.client?.iconActiveClass || 'activeSearchIcon';
-      const iconNormalClass =
-        content.client?.iconNormalClass || 'normalSearchIcon';
       if (!pathName) return;
-      menuItems.push({
-        icon,
-        label: content.client?.label,
-        onClick: () => history.push(`${pathName}`),
-        iconActiveClass,
-        iconNormalClass,
-      });
+      const result: NavMenuItem = {
+        icon: icons.navOverview,
+        label: content.client?.label || 'PLGUIN',
+      };
+      result.onClick = () => history.push(`${pathName}`);
+      const iconName: string = content.client?.iconName;
+      if (iconName) {
+        // TODO: support custom icon
+        result.icon = icons[iconName];
+      }
+      content.client?.iconActiveClass &&
+        (result.iconActiveClass = content.client?.iconActiveClass);
+      content.client?.iconNormalClass &&
+        (result.iconNormalClass = content.client?.iconNormalClass);
+      menuItems.push(result);
     });
   }
   importAll(require.context('../../plugins', true, /config\.json$/));

+ 2 - 1
client/src/plugins/system/config.json

@@ -4,6 +4,7 @@
   "client": {
     "path": "system",
     "entry": "SystemView.tsx",
-    "label": "System View"
+    "label": "System View",
+    "iconName": "navSystem"
   }
 }