Skip to content

Commit

Permalink
fix: view inline image
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Feb 29, 2024
1 parent f7f771e commit 8503d3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/ui/src/ImgViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ async function onClose() {
}, { once: true }))
}
const src = computed(() => postStore.viewImg)
watch(() => postStore.viewImg, async () => {
if (postStore.viewImg === imgViewSrc)
return
const img = await waitForElement<HTMLImageElement>('#img-viewer img')
img?.click()
await onClose()
})
Expand All @@ -28,7 +31,8 @@ watch(() => postStore.viewImg, async () => {
>
<main-image
class="h-0 w-0"
:src="postStore.viewImg"
:lazy="false"
:src="src"
/>
</div>
</template>
3 changes: 2 additions & 1 deletion packages/ui/src/MainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ onMounted(() => {
</form>

<!-- TODO: 设成 settings 的弹窗,来手动设置图床链接 -->
<div>
<div class="center gap-2 text-3">
使用远程图片
<n-switch
v-model:value="useLocalImage"
size="small"
/>
</div>

Expand Down
10 changes: 8 additions & 2 deletions packages/ui/src/MainImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ watch(useCdn, () => {
imgRef.value.imageRef.parentElement.classList.remove('img-error')
})
onMounted(() => {
function setImgSrc() {
if (!imgRef.value)
return
const img = imgRef.value.imageRef as HTMLImageElement
const { disconnect } = lazyLoadImage([img])
disconnectFn.value = disconnect
Expand All @@ -40,7 +43,10 @@ onMounted(() => {
const config = window.config.data
const src = `file://${config.publicPath}${props.src.slice(1)}`
realSrc.value = src
})
}
watch(() => props.src, setImgSrc)
onMounted(setImgSrc)
onUnmounted(() => {
disconnectFn.value?.()
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/post/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defineProps<{

<template>
<div
class="flex flex-col gap-4 rounded px-2 py-8 sm:max-w-60rem"
class="flex flex-col gap-4 rounded px-2 py-8 md:w-60rem"
>
<post-item
v-for="item in posts"
Expand Down

0 comments on commit 8503d3c

Please sign in to comment.