feat: directus插件与组合式函数编写

- plugins:Directus插件
- composable:Directus图片/文件的相关组合式函数
This commit is contained in:
2025-10-15 16:47:33 +08:00
parent e158ec8cf5
commit de7c03a7a9
4 changed files with 67 additions and 2 deletions

View File

@ -0,0 +1,22 @@
export const useDirectusFiles = () => {
const config = useRuntimeConfig();
const baseUrl = config.public.directus.url;
const getFileUrl = (
id?: string | null,
options?: Record<string, string | number | boolean>
): string => {
if (!id) return '';
const query = options
? '?' +
new URLSearchParams(
Object.entries(options).map(([key, value]) => [key, String(value)])
).toString()
: '';
return `${baseUrl}/assets/${id}${query}`;
};
return {
getFileUrl,
};
};