Skip to content

Commit

Permalink
fix(web): view the inline image
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Mar 3, 2024
1 parent b5fd038 commit 2e29fd7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/core/src/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './post'
export * from './public'
9 changes: 9 additions & 0 deletions packages/core/src/stores/public.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineStore } from 'pinia'

export const usePublicStore = defineStore('public', () => {
const globalImg = ref('')

return {
globalImg,
}
})
12 changes: 7 additions & 5 deletions packages/ui/src/ImgViewer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
const viewImg = ref('')
import { storeToRefs } from 'pinia'
const { globalImg } = storeToRefs(usePublicStore())
async function onClose() {
const btn = await waitForElement('.n-image-preview-toolbar')
Expand All @@ -8,12 +10,12 @@ async function onClose() {
const arr = [btn, mask]
arr.forEach(e => e?.addEventListener('click', () => {
viewImg.value = imgViewSrc
globalImg.value = imgViewSrc
}, { once: true }))
}
watch(viewImg, async () => {
if (viewImg.value === imgViewSrc)
watch(globalImg, async () => {
if (globalImg.value === imgViewSrc)
return
const img = await waitForElement<HTMLImageElement>('#img-viewer img')
Expand All @@ -30,7 +32,7 @@ watch(viewImg, async () => {
<main-image
class="h-0 w-0"
:lazy="false"
:src="viewImg"
:src="globalImg"
/>
</div>
</template>
5 changes: 3 additions & 2 deletions packages/ui/src/post/Text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const props = defineProps<{
text: string
}>()
const publicStore = usePublicStore()
const parsedText = parseProtocol(props.text)
.replace(/\/\/weibo.cn\/sinaurl\?u=(.+)/, (_, href) => decodeURIComponent(href)) // 去掉微博的链接跳转
const postStore = usePostStore()
const textRef = ref<HTMLParagraphElement | null>(null)
onMounted(() => {
Expand All @@ -18,7 +19,7 @@ onMounted(() => {
return
const src = target.dataset.src
postStore.viewImg = src
publicStore.globalImg = src
})
})
</script>
Expand Down

0 comments on commit 2e29fd7

Please sign in to comment.