💄 调整图片样式

This commit is contained in:
目棃
2024-08-18 12:00:14 +08:00
parent ff032c2178
commit e95f380ff7

View File

@@ -1,16 +1,18 @@
<template> <template>
<div class="tp-image-box" @click="showOverlay = true"> <div class="tp-image-box" @click="showOverlay = true">
<img <div :style="{ width: getWidth }">
:style="getImageStyle()" <img
:src="localUrl" :style="getImageStyle()"
:alt="props.data.insert.image" :src="localUrl"
:title="getImageTitle()" :alt="props.data.insert.image"
/> :title="getImageTitle()"
/>
</div>
</div> </div>
<TpoImage :image="props.data" v-model="showOverlay" /> <TpoImage :image="props.data" v-model="showOverlay" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { StyleValue, ref, onMounted, onUnmounted } from "vue"; import { StyleValue, ref, onMounted, onUnmounted, computed } from "vue";
import { saveImgLocal } from "../../utils/TGShare.js"; import { saveImgLocal } from "../../utils/TGShare.js";
import { bytesToSize } from "../../utils/toolFunc.js"; import { bytesToSize } from "../../utils/toolFunc.js";
@@ -45,6 +47,11 @@ onMounted(async () => {
localUrl.value = await saveImgLocal(link); localUrl.value = await saveImgLocal(link);
}); });
const getWidth = computed(() => {
if (props.data.attributes == undefined) return "auto";
return `${props.data.attributes.width}px`;
});
onUnmounted(() => { onUnmounted(() => {
if (localUrl.value) URL.revokeObjectURL(localUrl.value); if (localUrl.value) URL.revokeObjectURL(localUrl.value);
}); });
@@ -84,6 +91,9 @@ function getImageUrl(): string {
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
.tp-image-box { .tp-image-box {
display: flex;
align-items: center;
justify-content: center;
margin: 10px auto; margin: 10px auto;
} }