mirror of
https://github.com/halo-dev/halo.git
synced 2025-12-20 16:44:38 +08:00
#### What type of PR is this? /area ui /kind api-change /milestone 2.22.x #### What this PR does / why we need it: See #7925 #### Which issue(s) this PR fixes: Fixes #7925 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note 将 `@halo-dev/console-shared` 重命名为 `@halo-dev/ui-shared` ```
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { usePluginModuleStore } from "@/stores/plugin";
|
|
import type { OperationItem } from "@halo-dev/ui-shared";
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
import { computed, toValue, type ComputedRef, type Ref } from "vue";
|
|
|
|
export function useOperationItemExtensionPoint<T>(
|
|
extensionPointName: string,
|
|
entity: Ref<T>,
|
|
presets: ComputedRef<OperationItem<T>[]>
|
|
) {
|
|
const { pluginModules } = usePluginModuleStore();
|
|
|
|
return useQuery({
|
|
queryKey: computed(() => [
|
|
"core:extension-points:operation-items",
|
|
extensionPointName,
|
|
toValue(entity),
|
|
]),
|
|
queryFn: async () => {
|
|
const itemsFromPlugins: OperationItem<T>[] = [];
|
|
for (const pluginModule of pluginModules) {
|
|
const { extensionPoints } = pluginModule;
|
|
if (!extensionPoints?.[extensionPointName]) {
|
|
continue;
|
|
}
|
|
|
|
const items = extensionPoints[extensionPointName](
|
|
entity
|
|
) as OperationItem<T>[];
|
|
|
|
itemsFromPlugins.push(...items);
|
|
}
|
|
|
|
return [...presets.value, ...itemsFromPlugins].sort(
|
|
(a, b) => a.priority - b.priority
|
|
);
|
|
},
|
|
enabled: computed(() => !!presets.value && !!entity.value),
|
|
});
|
|
}
|