2023-08-25 09:02:12 +00:00
|
|
|
|
# Entity 数据列表操作菜单扩展点
|
|
|
|
|
|
|
|
|
|
## 原由
|
|
|
|
|
|
|
|
|
|
目前 Halo 2 的 Console 中,展示数据列表是统一使用 Entity 组件,Entity 组件中提供了用于放置操作按钮的插槽,此扩展点用于支持通过插件扩展部分数据列表的操作菜单项。
|
|
|
|
|
|
|
|
|
|
## 定义方式
|
|
|
|
|
|
|
|
|
|
目前支持扩展的数据列表:
|
|
|
|
|
|
2023-08-31 10:36:12 +00:00
|
|
|
|
- 文章:`"post:list-item:operation:create"?: (post: Ref<ListedPost>) => | OperationItem<ListedPost>[] | Promise<OperationItem<ListedPost>[]>`
|
feat: make comment and reply list item operations extendable (#6438)
#### What type of PR is this?
/area console
/kind feature
/milestone 2.18.x
#### What this PR does / why we need it:
评论和回复管理列表项的操作按钮支持被插件扩展。


#### Which issue(s) this PR fixes:
Fixes #6392
#### Special notes for your reviewer:
需要评论和回复的关于列表的已有功能是否正常。
如果需要测试扩展点是否有效,可以使用此插件测试:[plugin-starter-1.0.0-SNAPSHOT.jar.zip](https://github.com/user-attachments/files/16482348/plugin-starter-1.0.0-SNAPSHOT.jar.zip)
```
export default definePlugin({
components: {},
routes: [],
extensionPoints: {
"comment:list-item:operation:create": (comment: Ref<ListedComment>) => {
return [
{
priority: 21,
component: markRaw(VDropdownItem),
label: "测试评论菜单",
visible: true,
permissions: [],
action: () => {
console.log(comment)
},
},
];
},
"reply:list-item:operation:create": (reply: Ref<ListedReply>) => {
return [
{
priority: 11,
component: markRaw(VDropdownItem),
label: "测试回复菜单",
visible: true,
permissions: [],
action: () => {
console.log(reply)
},
},
];
},
},
});
```
#### Does this PR introduce a user-facing change?
```release-note
Console 评论和回复管理列表项的操作按钮支持被插件扩展。
```
2024-08-05 06:56:25 +00:00
|
|
|
|
- 评论:`"comment:list-item:operation:create"?: (comment: Ref<ListedComment>) => | OperationItem<ListedComment>[] | Promise<OperationItem<ListedComment>[]>`
|
|
|
|
|
- 回复:`"reply:list-item:operation:create"?: (reply: Ref<ListedReply>) => | OperationItem<ListedReply>[] | Promise<OperationItem<ListedReply>[]>`
|
2023-08-31 10:36:12 +00:00
|
|
|
|
- 插件:`"plugin:list-item:operation:create"?: (plugin: Ref<Plugin>) => | OperationItem<Plugin>[] | Promise<OperationItem<Plugin>[]>`
|
|
|
|
|
- 备份:`"backup:list-item:operation:create"?: (backup: Ref<Backup>) => | OperationItem<Backup>[] | Promise<OperationItem<Backup>[]>`
|
|
|
|
|
- 主题:`"theme:list-item:operation:create"?: (theme: Ref<Theme>) => | OperationItem<Theme>[] | Promise<OperationItem<Theme>[]>`
|
feat: make attachment list item operations extendable (#4689)
#### What type of PR is this?
/area console
/kind feature
/milestone 2.10.x
#### What this PR does / why we need it:
附件管理列表项的操作按钮支持被插件扩展。
<img width="1669" alt="image" src="https://github.com/halo-dev/halo/assets/21301288/be938c07-2976-4e22-9bf3-cdfaf53896e5">
#### Which issue(s) this PR fixes:
Fixes https://github.com/halo-dev/halo/issues/4667
#### Special notes for your reviewer:
需要测试附件的关于列表的已有功能是否正常。
如果需要测试扩展点是否有效,可以使用此插件测试:[plugin-s3-1.5.0-SNAPSHOT.jar.zip](https://github.com/halo-dev/halo/files/12839986/plugin-s3-1.5.0-SNAPSHOT.jar.zip)
```diff
export default definePlugin({
components: {},
routes: [],
extensionPoints: {
"plugin:self:tabs:create": (): PluginTab[] => {
return [
{
id: "s3-link",
label: "关联S3文件",
component: markRaw(HomeView),
permissions: [],
},
];
},
+ "attachment:list-item:operation:create": (attachment: Ref<Attachment>) => {
+ return [
+ {
+ priority: 21,
+ component: markRaw(VDropdownDivider),
+ },
+ {
+ priority: 22,
+ component: markRaw(VDropdownItem),
+ props: {
+ type: "danger",
+ },
+ label: "解除 S3 关联",
+ permissions: ["system:attachments:manage"],
+ action: () => {
+ console.log(attachment);
+ },
+ },
+ ];
+ },
},
});
```
#### Does this PR introduce a user-facing change?
```release-note
Console 附件管理列表项的操作按钮支持被插件扩展。
```
2023-10-08 09:58:37 +00:00
|
|
|
|
- 附件:`"attachment:list-item:operation:create"?: (attachment: Ref<Attachment>) => | OperationItem<Attachment>[] | Promise<OperationItem<Attachment>[]>`
|
2023-08-25 09:02:12 +00:00
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
|
|
|
|
|
> 此示例是在文章列表中添加一个`导出为 Markdown 文档`的操作菜单项。
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import type { ListedPost } from "@halo-dev/api-client";
|
|
|
|
|
import { VDropdownItem } from "@halo-dev/components";
|
|
|
|
|
import { definePlugin } from "@halo-dev/console-shared";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import { markRaw } from "vue";
|
|
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
|
extensionPoints: {
|
|
|
|
|
"post:list-item:operation:create": () => {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
priority: 21,
|
|
|
|
|
component: markRaw(VDropdownItem),
|
|
|
|
|
label: "导出为 Markdown 文档",
|
|
|
|
|
permissions: [],
|
|
|
|
|
action: async (post: ListedPost) => {
|
|
|
|
|
const { data } = await axios.get(
|
|
|
|
|
`/apis/api.console.halo.run/v1alpha1/posts/${post.post.metadata.name}/head-content`
|
|
|
|
|
);
|
|
|
|
|
const blob = new Blob([data.raw], {
|
|
|
|
|
type: "text/plain;charset=utf-8",
|
|
|
|
|
});
|
|
|
|
|
const url = window.URL.createObjectURL(blob);
|
|
|
|
|
const link = document.createElement("a");
|
|
|
|
|
link.href = url;
|
|
|
|
|
link.download = `${post.post.spec.title}.md`;
|
|
|
|
|
link.click();
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-31 10:36:12 +00:00
|
|
|
|
`OperationItem` 类型:
|
2023-08-25 09:02:12 +00:00
|
|
|
|
|
|
|
|
|
```ts
|
2023-08-31 10:36:12 +00:00
|
|
|
|
export interface OperationItem<T> {
|
2023-08-25 09:02:12 +00:00
|
|
|
|
priority: number; // 优先级,越小越靠前
|
|
|
|
|
component: Raw<Component>; // 菜单项组件,可以使用 `@halo-dev/components` 中提供的 `VDropdownItem`,也可以自定义
|
|
|
|
|
props?: Record<string, unknown>; // 组件的 props
|
|
|
|
|
action?: (item?: T) => void; // 点击事件
|
|
|
|
|
label?: string; // 菜单项名称
|
2023-08-31 10:36:12 +00:00
|
|
|
|
hidden?: boolean; // 是否隐藏
|
2023-08-25 09:02:12 +00:00
|
|
|
|
permissions?: string[]; // 权限
|
2023-08-31 10:36:12 +00:00
|
|
|
|
children?: OperationItem<T>[]; // 子菜单
|
2023-08-25 09:02:12 +00:00
|
|
|
|
}
|
|
|
|
|
```
|