mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
✨ 完成战绩分享
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
<div
|
<div
|
||||||
class="tur-hs-box"
|
class="tur-hs-box"
|
||||||
:style="{
|
:style="{
|
||||||
backgroundImage: 'url(' + data.bg + ')',
|
backgroundImage: 'url(' + getUrl.bg + ')',
|
||||||
backgroundSize: 'cover',
|
backgroundSize: 'cover',
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="tur-hs-title">
|
<div class="tur-hs-title">
|
||||||
<!-- canvas -->
|
<!-- canvas -->
|
||||||
<img :src="data.comfortIcon" alt="comfort">
|
<img :src="getUrl.icon" alt="comfort">
|
||||||
{{ data.comfortName }}
|
{{ data.comfortName }}
|
||||||
</div>
|
</div>
|
||||||
<div class="tur-hs-text-grid">
|
<div class="tur-hs-text-grid">
|
||||||
@@ -35,11 +35,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
// vue
|
||||||
|
import { onMounted, ref } from "vue";
|
||||||
|
// utils
|
||||||
|
import { saveImgLocal } from "../../utils/saveImg";
|
||||||
|
|
||||||
interface TurHomeSubProps {
|
interface TurHomeSubProps {
|
||||||
data: TGApp.Sqlite.Record.Home;
|
data: TGApp.Sqlite.Record.Home;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<TurHomeSubProps>();
|
const props = defineProps<TurHomeSubProps>();
|
||||||
|
const getUrl = ref({
|
||||||
|
icon: "",
|
||||||
|
bg: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
getUrl.value.icon = await saveImgLocal(props.data.comfortIcon);
|
||||||
|
getUrl.value.bg = await saveImgLocal(props.data.bg);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.tur-hs-box {
|
.tur-hs-box {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
<div
|
<div
|
||||||
class="tur-ws-box"
|
class="tur-ws-box"
|
||||||
:style="{
|
:style="{
|
||||||
backgroundImage: 'url(' + data.bg + ')',
|
backgroundImage: 'url(' + getUrl.bg + ')',
|
||||||
backgroundPositionX: 'right',
|
backgroundPositionX: 'right',
|
||||||
backgroundSize: 'auto 100%',
|
backgroundSize: 'auto 100%',
|
||||||
backgroundRepeat: 'no-repeat'
|
backgroundRepeat: 'no-repeat'
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<div class="tur-ws-icon">
|
<div class="tur-ws-icon">
|
||||||
<img :src="iconShow" alt="icon">
|
<img :src="getUrl.icon" alt="icon">
|
||||||
</div>
|
</div>
|
||||||
<div class="tur-ws-content">
|
<div class="tur-ws-content">
|
||||||
<div class="tur-ws-title">
|
<div class="tur-ws-title">
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<span>级</span>
|
<span>级</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="data.offerings.length>0" class="tur-ws-sub">
|
<div v-if="data.offerings.length>0" class="tur-ws-sub">
|
||||||
<img :src="data.offerings[0].icon" alt="offer">
|
<img :src="getUrl.offer" alt="offer">
|
||||||
<span>{{ data.offerings[0].name }}等级:</span>
|
<span>{{ data.offerings[0].name }}等级:</span>
|
||||||
<span>{{ data.offerings[0].level }}</span>
|
<span>{{ data.offerings[0].level }}</span>
|
||||||
<span>级</span>
|
<span>级</span>
|
||||||
@@ -39,6 +39,8 @@
|
|||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref } from "vue";
|
||||||
// tauri
|
// tauri
|
||||||
import { event } from "@tauri-apps/api";
|
import { event } from "@tauri-apps/api";
|
||||||
|
// utils
|
||||||
|
import { saveImgLocal } from "../../utils/saveImg";
|
||||||
|
|
||||||
interface TurWorldSubProps {
|
interface TurWorldSubProps {
|
||||||
theme: "default" | "dark",
|
theme: "default" | "dark",
|
||||||
@@ -46,20 +48,34 @@ interface TurWorldSubProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<TurWorldSubProps>();
|
const props = defineProps<TurWorldSubProps>();
|
||||||
const iconShow = ref("");
|
const getUrl = ref({
|
||||||
|
bg: "",
|
||||||
|
icon: "",
|
||||||
|
iconLight: "",
|
||||||
|
iconDark: "",
|
||||||
|
offer: "",
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
props.theme === "dark" ? iconShow.value = props.data.iconLight : iconShow.value = props.data.iconDark;
|
|
||||||
await listenOnTheme();
|
await listenOnTheme();
|
||||||
|
getUrl.value.bg = await saveImgLocal(props.data.bg);
|
||||||
|
getUrl.value.iconLight = await saveImgLocal(props.data.iconLight);
|
||||||
|
getUrl.value.iconDark = await saveImgLocal(props.data.iconDark);
|
||||||
|
if (props.data.offerings.length > 0) {
|
||||||
|
getUrl.value.offer = await saveImgLocal(props.data.offerings[0].icon);
|
||||||
|
}
|
||||||
|
props.theme === "dark"
|
||||||
|
? getUrl.value.icon = getUrl.value.iconLight
|
||||||
|
: getUrl.value.icon = getUrl.value.iconDark;
|
||||||
});
|
});
|
||||||
|
|
||||||
async function listenOnTheme () {
|
async function listenOnTheme () {
|
||||||
await event.listen("readTheme", (e) => {
|
await event.listen("readTheme", (e) => {
|
||||||
const theme = e.payload as string;
|
const theme = e.payload as string;
|
||||||
if (theme === "dark") {
|
if (theme === "dark") {
|
||||||
iconShow.value = props.data.iconLight;
|
getUrl.value.icon = getUrl.value.iconLight;
|
||||||
} else {
|
} else {
|
||||||
iconShow.value = props.data.iconDark;
|
getUrl.value.icon = getUrl.value.iconDark;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,12 @@
|
|||||||
</template>
|
</template>
|
||||||
更新数据
|
更新数据
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
<v-btn variant="outlined" class="ur-top-btn" @click="shareRecord()">
|
||||||
|
<template #prepend>
|
||||||
|
<v-icon>mdi-share</v-icon>
|
||||||
|
</template>
|
||||||
|
分享
|
||||||
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
<div class="ur-sub-title">
|
<div class="ur-sub-title">
|
||||||
<img src="/src/assets/icons/arrow-right.svg" alt="overview">
|
<img src="/src/assets/icons/arrow-right.svg" alt="overview">
|
||||||
@@ -48,6 +54,8 @@ import { useUserStore } from "../../store/modules/user";
|
|||||||
// utils
|
// utils
|
||||||
import TGRequest from "../../web/request/TGRequest";
|
import TGRequest from "../../web/request/TGRequest";
|
||||||
import TGSqlite from "../../plugins/Sqlite";
|
import TGSqlite from "../../plugins/Sqlite";
|
||||||
|
import html2canvas from "html2canvas";
|
||||||
|
import { saveCanvasImg } from "../../utils/saveImg";
|
||||||
|
|
||||||
// store
|
// store
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
@@ -98,6 +106,39 @@ function getTitle () {
|
|||||||
const role = JSON.parse(recordData.value.role) as TGApp.Sqlite.Record.Role;
|
const role = JSON.parse(recordData.value.role) as TGApp.Sqlite.Record.Role;
|
||||||
return `${role.nickname} Lv.${role.level}【${recordData.value.uid}】`;
|
return `${role.nickname} Lv.${role.level}【${recordData.value.uid}】`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function shareRecord () {
|
||||||
|
const recordBox = document.querySelector(".ur-box") as HTMLElement;
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
const width = recordBox.clientWidth + 50;
|
||||||
|
const height = recordBox.offsetHeight + 50;
|
||||||
|
canvas.width = width * 1.2;
|
||||||
|
canvas.height = height * 1.2;
|
||||||
|
canvas.style.width = `${width}px`;
|
||||||
|
canvas.style.height = `${height}px`;
|
||||||
|
canvas.getContext("2d")!.scale(1.2, 1.2);
|
||||||
|
const options = {
|
||||||
|
backgroundColor: getTheme() === "dark" ? "#2c2c2c" : "#ece5d8",
|
||||||
|
windowHeight: height,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
useCORS: true,
|
||||||
|
canvas,
|
||||||
|
x: -10,
|
||||||
|
y: -10,
|
||||||
|
};
|
||||||
|
const fileName = `战绩-${user.value.gameUid}-${Math.floor(Date.now() / 1000)}`;
|
||||||
|
const canvasData = await html2canvas(recordBox, options);
|
||||||
|
await saveCanvasImg(canvasData, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTheme () {
|
||||||
|
let theme = localStorage.getItem("theme");
|
||||||
|
if (theme) {
|
||||||
|
theme = JSON.parse(theme).theme;
|
||||||
|
}
|
||||||
|
return theme || "default";
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.ur-box {
|
.ur-box {
|
||||||
@@ -130,7 +171,7 @@ function getTitle () {
|
|||||||
background: var(--common-bg-2);
|
background: var(--common-bg-2);
|
||||||
color: var(--common-color-white);
|
color: var(--common-color-white);
|
||||||
text-shadow: 0 0 10px rgb(0 0 0 / 40%);
|
text-shadow: 0 0 10px rgb(0 0 0 / 40%);
|
||||||
margin-left: auto;
|
margin-left: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ur-sub-title {
|
.ur-sub-title {
|
||||||
|
|||||||
Reference in New Issue
Block a user