Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

refactor: router and menu generation #651

Merged
merged 7 commits into from
Oct 19, 2022

Conversation

ruibaby
Copy link
Member

@ruibaby ruibaby commented Oct 18, 2022

What type of PR is this?

/kind api-change
/kind improvement
/milestone 2.0

What this PR does / why we need it:

Ref halo-dev/halo#2595

重构路由和侧边菜单生成的逻辑,注意,此 PR 对插件的 Console 入口文件中的路由和菜单定义包含破坏性更新。

  1. 移除 definePlugin 方法的 menus 字段,改为在 route 的 meta 中定义。
  2. RoutesMenu 组件从 @halo-dev/components 包中移出。
  3. BasicLayout 组件从 @halo-dev/console-shared 包中移出。

定义路由的方式:

import { definePlugin } from "@halo-dev/console-shared";
import BasicLayout from "@/layouts/BasicLayout.vue";
import AttachmentList from "./AttachmentList.vue";
import AttachmentSelectorModal from "./components/AttachmentSelectorModal.vue";
import { IconFolder } from "@halo-dev/components";
import { markRaw } from "vue";

export default definePlugin({
  name: "attachmentModule",
  components: [AttachmentSelectorModal],
  routes: [
    {
      path: "/attachments",
      component: BasicLayout,
      children: [
        {
          path: "",
          name: "Attachments",
          component: AttachmentList,
          meta: {
            title: "附件",
            permissions: ["system:attachments:view"],
            menu: {
              name: "附件",
              group: "内容",
              icon: markRaw(IconFolder),
              priority: 4,
              mobile: true,
            },
          },
        },
      ],
    },
  ],
});

menu 字段类型:

interface RouteMeta {
  title?: string;
  searchable?: boolean;
  permissions?: string[];
  menu?: {
    name: string;
    group?: string;
    icon?: Component;
    priority: number;
    mobile?: true;
  };
}

插件适配需要做的改动:

  1. 移除 definePlugin 中的 menus 字段。
  2. 在需要添加到菜单的 route 中提供 meta.menu 对象,可参考上方的 menu 字段类型。

详细文档可查阅:https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation

todolist:

  • 完善预设的菜单分组定义。
  • 绑定权限,根据权限决定是否需要将路由添加到菜单。
  • 优化菜单排序的定义方式。

Which issue(s) this PR fixes:

Fixes halo-dev/halo#2595

Special notes for your reviewer:

/cc @halo-dev/sig-halo-console

测试方式:

  1. 需要 pnpm build:packages
  2. 测试后台的菜单及路由是否有异常。
  3. 新建角色测试路由和菜单对权限的绑定。
  4. 按照 https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation 文档,创建插件,测试插件添加路由和菜单是否正常。

Does this PR introduce a user-facing change?

重构路由和侧边菜单生成的逻辑。

@f2c-ci-robot f2c-ci-robot bot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Oct 18, 2022
@f2c-ci-robot f2c-ci-robot bot added this to the 2.0 milestone Oct 18, 2022
@vercel
Copy link

vercel bot commented Oct 18, 2022

@ruibaby is attempting to deploy a commit to the halo-dev Team on Vercel.

A member of the Team first needs to authorize it.

@f2c-ci-robot f2c-ci-robot bot added the kind/improvement Categorizes issue or PR as related to a improvement. label Oct 18, 2022
@vercel
Copy link

vercel bot commented Oct 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
halo-admin-next ✅ Ready (Inspect) Visit Preview Oct 19, 2022 at 6:45AM (UTC)
halo-admin-ui ✅ Ready (Inspect) Visit Preview Oct 19, 2022 at 6:45AM (UTC)

@ruibaby
Copy link
Member Author

ruibaby commented Oct 19, 2022

/retitle refactor: router and menu generation

@f2c-ci-robot f2c-ci-robot bot changed the title WIP: refactor: router and menu generation refactor: router and menu generation Oct 19, 2022
@f2c-ci-robot f2c-ci-robot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 19, 2022
Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 19, 2022
Copy link
Member

@guqing guqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Oct 19, 2022
@f2c-ci-robot f2c-ci-robot bot merged commit 54755c5 into halo-dev:main Oct 19, 2022
@ruibaby ruibaby deleted the refactor/route-map-setting branch October 19, 2022 10:44
JohnNiang pushed a commit to JohnNiang/halo that referenced this pull request Mar 2, 2023
#### What type of PR is this?

/kind api-change
/kind improvement
/milestone 2.0

#### What this PR does / why we need it:

Ref halo-dev#2595

重构路由和侧边菜单生成的逻辑,**注意,此 PR 对插件的 Console 入口文件中的路由和菜单定义包含破坏性更新。**

1. 移除 `definePlugin` 方法的 `menus` 字段,改为在 route 的 meta 中定义。
2. 将 `RoutesMenu` 组件从 `@halo-dev/components` 包中移出。
3. 将 `BasicLayout` 组件从 `@halo-dev/console-shared` 包中移出。

定义路由的方式:

```ts
import { definePlugin } from "@halo-dev/console-shared";
import BasicLayout from "@/layouts/BasicLayout.vue";
import AttachmentList from "./AttachmentList.vue";
import AttachmentSelectorModal from "./components/AttachmentSelectorModal.vue";
import { IconFolder } from "@halo-dev/components";
import { markRaw } from "vue";

export default definePlugin({
  name: "attachmentModule",
  components: [AttachmentSelectorModal],
  routes: [
    {
      path: "/attachments",
      component: BasicLayout,
      children: [
        {
          path: "",
          name: "Attachments",
          component: AttachmentList,
          meta: {
            title: "附件",
            permissions: ["system:attachments:view"],
            menu: {
              name: "附件",
              group: "内容",
              icon: markRaw(IconFolder),
              priority: 4,
              mobile: true,
            },
          },
        },
      ],
    },
  ],
});
```

menu 字段类型:

```ts
interface RouteMeta {
  title?: string;
  searchable?: boolean;
  permissions?: string[];
  menu?: {
    name: string;
    group?: string;
    icon?: Component;
    priority: number;
    mobile?: true;
  };
}
```

插件适配需要做的改动:

1. 移除 `definePlugin` 中的 menus 字段。
2. 在需要添加到菜单的 route 中提供 `meta.menu` 对象,可参考上方的 menu 字段类型。

详细文档可查阅:https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation

todolist:

- [x] 完善预设的菜单分组定义。
- [x] 绑定权限,根据权限决定是否需要将路由添加到菜单。
- [x] 优化菜单排序的定义方式。

#### Which issue(s) this PR fixes:

Fixes halo-dev#2595

#### Special notes for your reviewer:

/cc @halo-dev/sig-halo-console 

测试方式:

1. 需要 `pnpm build:packages`
2. 测试后台的菜单及路由是否有异常。
3. 新建角色测试路由和菜单对权限的绑定。
4. 按照 https://github.com/ruibaby/halo-console/tree/refactor/route-map-setting/docs/routes-generation 文档,创建插件,测试插件添加路由和菜单是否正常。

#### Does this PR introduce a user-facing change?

```release-note
重构路由和侧边菜单生成的逻辑。
```
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/improvement Categorizes issue or PR as related to a improvement. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

重构 Console 的路由菜单生成规则
3 participants