39 lines
1.2 KiB
Vue
39 lines
1.2 KiB
Vue
<template>
|
|
<NuxtLink v-if="data && data[0] && status !== 'pending'" :to="{ path: `/explorer/${project}${data[0].path}`, hash: hash }" :class="class">
|
|
<PreviewContent :project="project" :path="data[0].path" :anchor="hash">
|
|
<slot v-bind="$attrs"></slot>
|
|
</PreviewContent>
|
|
</NuxtLink>
|
|
<NuxtLink v-else-if="href" :to="{ path: href }" :class="class">
|
|
<slot v-bind="$attrs"></slot>
|
|
</NuxtLink>
|
|
<slot :class="class" v-else v-bind="$attrs"></slot>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { parseURL } from 'ufo';
|
|
|
|
const props = defineProps({
|
|
href: {
|
|
type: String,
|
|
required: false,
|
|
},
|
|
class: {
|
|
type: String,
|
|
required: false,
|
|
}
|
|
});
|
|
|
|
const route = useRoute();
|
|
const { hash, pathname } = parseURL(props.href);
|
|
const project = computed(() => parseInt(Array.isArray(route.params.projectId) ? '0' : route.params.projectId));
|
|
const { data, status } = await useFetch(`/api/project/${project.value}/file`, {
|
|
method: 'GET',
|
|
query: {
|
|
search: `%${pathname}`
|
|
},
|
|
transform: (data) => data?.map(e => ({ path: e.path })),
|
|
key: `file:${project.value}:%${pathname}`,
|
|
dedupe: 'defer'
|
|
});
|
|
</script> |