|
|
@ -4,8 +4,6 @@ import { useAuthSession } from '../../../composables/useAuthSession' |
|
|
|
|
|
|
|
|
definePageMeta({ title: '编辑文章' }) |
|
|
definePageMeta({ title: '编辑文章' }) |
|
|
|
|
|
|
|
|
type PostRow = { id: number; title: string; slug: string; visibility: string } |
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute() |
|
|
const route = useRoute() |
|
|
const id = computed(() => route.params.id as string) |
|
|
const id = computed(() => route.params.id as string) |
|
|
const { user, refresh: refreshAuth } = useAuthSession() |
|
|
const { user, refresh: refreshAuth } = useAuthSession() |
|
|
@ -20,27 +18,6 @@ const state = reactive({ |
|
|
}) |
|
|
}) |
|
|
const loading = ref(true) |
|
|
const loading = ref(true) |
|
|
const saving = ref(false) |
|
|
const saving = ref(false) |
|
|
const postsNav = ref<PostRow[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const currentNumericId = computed(() => Number.parseInt(id.value, 10)) |
|
|
|
|
|
|
|
|
|
|
|
const newerPost = computed((): PostRow | null => { |
|
|
|
|
|
const list = postsNav.value |
|
|
|
|
|
const idx = list.findIndex((p) => p.id === currentNumericId.value) |
|
|
|
|
|
if (idx <= 0) { |
|
|
|
|
|
return null |
|
|
|
|
|
} |
|
|
|
|
|
return list[idx - 1] ?? null |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const olderPost = computed((): PostRow | null => { |
|
|
|
|
|
const list = postsNav.value |
|
|
|
|
|
const idx = list.findIndex((p) => p.id === currentNumericId.value) |
|
|
|
|
|
if (idx < 0 || idx >= list.length - 1) { |
|
|
|
|
|
return null |
|
|
|
|
|
} |
|
|
|
|
|
return list[idx + 1] ?? null |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const publicPostHref = computed(() => { |
|
|
const publicPostHref = computed(() => { |
|
|
const ps = user.value?.publicSlug |
|
|
const ps = user.value?.publicSlug |
|
|
@ -50,18 +27,6 @@ const publicPostHref = computed(() => { |
|
|
return `/@${ps}/posts/${encodeURIComponent(state.slug)}` |
|
|
return `/@${ps}/posts/${encodeURIComponent(state.slug)}` |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
/** 公开文跳站点详情,否则进编辑页 */ |
|
|
|
|
|
function navTargetHref(p: PostRow | null) { |
|
|
|
|
|
if (!p) { |
|
|
|
|
|
return '' |
|
|
|
|
|
} |
|
|
|
|
|
const ps = user.value?.publicSlug |
|
|
|
|
|
if (p.visibility === 'public' && ps) { |
|
|
|
|
|
return `/@${ps}/posts/${encodeURIComponent(p.slug)}` |
|
|
|
|
|
} |
|
|
|
|
|
return `/me/posts/${p.id}` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function load() { |
|
|
async function load() { |
|
|
loading.value = true |
|
|
loading.value = true |
|
|
try { |
|
|
try { |
|
|
@ -80,18 +45,8 @@ async function load() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function loadPostNav() { |
|
|
|
|
|
try { |
|
|
|
|
|
const res = await request<ApiResponse<{ posts: PostRow[] }>>('/api/me/posts') |
|
|
|
|
|
postsNav.value = unwrapApiBody(res).posts |
|
|
|
|
|
} catch { |
|
|
|
|
|
postsNav.value = [] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
void refreshAuth(true) |
|
|
void refreshAuth(true) |
|
|
void loadPostNav() |
|
|
|
|
|
void load() |
|
|
void load() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
@ -157,54 +112,6 @@ const shareUrl = computed(() => { |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<UCard v-if="!loading" :ui="{ body: 'p-3 sm:p-4' }"> |
|
|
|
|
|
<div class="flex flex-wrap items-center gap-2"> |
|
|
|
|
|
<UButton |
|
|
|
|
|
v-if="newerPost" |
|
|
|
|
|
:to="navTargetHref(newerPost)" |
|
|
|
|
|
variant="soft" |
|
|
|
|
|
color="neutral" |
|
|
|
|
|
size="sm" |
|
|
|
|
|
leading-icon="i-lucide-chevron-up" |
|
|
|
|
|
> |
|
|
|
|
|
较新 |
|
|
|
|
|
</UButton> |
|
|
|
|
|
<UButton |
|
|
|
|
|
v-else |
|
|
|
|
|
disabled |
|
|
|
|
|
variant="soft" |
|
|
|
|
|
color="neutral" |
|
|
|
|
|
size="sm" |
|
|
|
|
|
leading-icon="i-lucide-chevron-up" |
|
|
|
|
|
> |
|
|
|
|
|
较新 |
|
|
|
|
|
</UButton> |
|
|
|
|
|
<UButton |
|
|
|
|
|
v-if="olderPost" |
|
|
|
|
|
:to="navTargetHref(olderPost)" |
|
|
|
|
|
variant="soft" |
|
|
|
|
|
color="neutral" |
|
|
|
|
|
size="sm" |
|
|
|
|
|
leading-icon="i-lucide-chevron-down" |
|
|
|
|
|
> |
|
|
|
|
|
较旧 |
|
|
|
|
|
</UButton> |
|
|
|
|
|
<UButton |
|
|
|
|
|
v-else |
|
|
|
|
|
disabled |
|
|
|
|
|
variant="soft" |
|
|
|
|
|
color="neutral" |
|
|
|
|
|
size="sm" |
|
|
|
|
|
leading-icon="i-lucide-chevron-down" |
|
|
|
|
|
> |
|
|
|
|
|
较旧 |
|
|
|
|
|
</UButton> |
|
|
|
|
|
</div> |
|
|
|
|
|
<p v-if="newerPost || olderPost" class="text-xs text-muted mt-2"> |
|
|
|
|
|
顺序与列表一致(最新在上)。公开文章打开站点详情,其余进入对应编辑页。 |
|
|
|
|
|
</p> |
|
|
|
|
|
</UCard> |
|
|
|
|
|
|
|
|
|
|
|
<div v-if="loading" class="text-muted"> |
|
|
<div v-if="loading" class="text-muted"> |
|
|
加载中… |
|
|
加载中… |
|
|
</div> |
|
|
</div> |
|
|
|