💄 背景色同步

This commit is contained in:
目棃
2025-04-01 14:29:31 +08:00
parent fce56dcf55
commit a1cd7ff840
3 changed files with 31 additions and 8 deletions

View File

@@ -13,7 +13,13 @@
<v-progress-circular :indeterminate="true" color="primary" size="small" /> <v-progress-circular :indeterminate="true" color="primary" size="small" />
<span>加载中...</span> <span>加载中...</span>
</div> </div>
<VpOverlayImage :image="image" v-model="showOverlay" v-model:link="localUrl" :ori="true" /> <VpOverlayImage
:image="image"
v-model="showOverlay"
v-model:link="localUrl"
:ori="true"
v-model:bgColor="bgColor"
/>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref } from "vue"; import { computed, onMounted, onUnmounted, ref } from "vue";
@@ -40,6 +46,7 @@ type TpEmoticonProps = { data: TpCustomEmoticon };
const props = defineProps<TpEmoticonProps>(); const props = defineProps<TpEmoticonProps>();
const localUrl = ref<string>(); const localUrl = ref<string>();
const showOverlay = ref<boolean>(false); const showOverlay = ref<boolean>(false);
const bgColor = ref<string>("transparent");
const image = computed<TpImage>(() => { const image = computed<TpImage>(() => {
return { return {
insert: { image: props.data.insert.custom_emoticon.url }, insert: { image: props.data.insert.custom_emoticon.url },
@@ -77,6 +84,7 @@ onUnmounted(() => {
max-width: 100%; max-width: 100%;
height: auto; height: auto;
border-radius: 4px; border-radius: 4px;
background: v-bind(bgColor);
} }
.tp-emo-info { .tp-emo-info {

View File

@@ -25,6 +25,7 @@
v-model="showOverlay" v-model="showOverlay"
v-model:link="localUrl" v-model:link="localUrl"
v-model:ori="showOri" v-model:ori="showOri"
v-model:bgColor="bgColor"
/> />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@@ -58,6 +59,7 @@ const showOri = ref<boolean>(
props.data.insert.image.endsWith(".gif") || imageQualityPercent.value === 100, props.data.insert.image.endsWith(".gif") || imageQualityPercent.value === 100,
); );
const localUrl = ref<string>(); const localUrl = ref<string>();
const bgColor = ref<string>("transparent");
const imgWidth = computed<string>(() => { const imgWidth = computed<string>(() => {
if (props.data.attributes === undefined) return "auto"; if (props.data.attributes === undefined) return "auto";
@@ -117,6 +119,7 @@ function getImageTitle(): string {
height: auto; height: auto;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
background: v-bind(bgColor);
} }
.tp-image-load { .tp-image-load {

View File

@@ -51,6 +51,7 @@ const props = defineProps<TpoImageProps>();
const visible = defineModel<boolean>(); const visible = defineModel<boolean>();
const localLink = defineModel<string>("link"); const localLink = defineModel<string>("link");
const showOri = defineModel<boolean>("ori"); const showOri = defineModel<boolean>("ori");
const bgColor = defineModel<string>("bgColor", { default: "transparent" });
const bgMode = ref<number>(0); // 0: transparent, 1: black, 2: white const bgMode = ref<number>(0); // 0: transparent, 1: black, 2: white
const isOriSize = ref<boolean>(false); const isOriSize = ref<boolean>(false);
const buffer = shallowRef<Uint8Array | null>(null); const buffer = shallowRef<Uint8Array | null>(null);
@@ -65,6 +66,13 @@ function setBlackBg(): void {
bgMode.value = (bgMode.value + 1) % 3; bgMode.value = (bgMode.value + 1) % 3;
const bgLabelList = ["透明", "黑色", "白色"]; const bgLabelList = ["透明", "黑色", "白色"];
showSnackbar.success(`背景已切换为${bgLabelList[bgMode.value]}`); showSnackbar.success(`背景已切换为${bgLabelList[bgMode.value]}`);
if (bgMode.value === 0) {
bgColor.value = "transparent";
} else if (bgMode.value === 1) {
bgColor.value = "black";
} else {
bgColor.value = "white";
}
} }
async function onCopy(): Promise<void> { async function onCopy(): Promise<void> {
@@ -122,9 +130,16 @@ async function onDownload(): Promise<void> {
justify-content: center; justify-content: center;
border: 1px solid var(--tgc-od-white); border: 1px solid var(--tgc-od-white);
border-radius: 4px; border-radius: 4px;
background: v-bind("bgMode === 1 ? 'black' : bgMode === 2 ? 'white' : 'transparent'");
cursor: zoom-in; cursor: zoom-in;
overflow-y: auto; overflow-y: auto;
img {
max-width: 100%;
max-height: 100%;
border-radius: 4px;
background: v-bind(bgColor);
object-fit: contain;
}
} }
.tpoi-top-ori { .tpoi-top-ori {
@@ -133,13 +148,10 @@ async function onDownload(): Promise<void> {
max-width: 100%; max-width: 100%;
max-height: 70%; max-height: 70%;
cursor: zoom-out; cursor: zoom-out;
}
.tpoi-top img { img {
max-width: 100%; background: v-bind(bgColor);
max-height: 100%; }
border-radius: 4px;
object-fit: contain;
} }
.tpoi-bottom { .tpoi-bottom {