mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
♻️ 优化代码,减少 dom
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<TOverlay v-model="visible" hide :to-click="onCancel">
|
<TOverlay v-model="visible" hide :to-click="onCancel" blur-val="20px">
|
||||||
<div class="tuc-do-box">
|
<div class="tuc-do-box">
|
||||||
<div class="tuc-do-bg">
|
<div class="tuc-do-bg">
|
||||||
<img :src="props.dataVal.img" alt="role">
|
<img :src="props.dataVal.img" alt="role">
|
||||||
@@ -20,54 +20,15 @@
|
|||||||
<TucDetailItemBox v-model="weaponBox" />
|
<TucDetailItemBox v-model="weaponBox" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
v-for="(item, index) in data.reliquary"
|
||||||
class="tuc-dol-item"
|
class="tuc-dol-item"
|
||||||
:style="{
|
:style="{
|
||||||
cursor: data.reliquary[1] ? 'pointer' : 'default',
|
cursor: item ? 'pointer' : 'default',
|
||||||
border: selected.pos === 1 ? '2px solid var(--common-color-yellow)' : '',
|
border: selected.pos === index + 1 ? '2px solid var(--common-color-yellow)' : '',
|
||||||
}"
|
}"
|
||||||
@click="showDetail(data.reliquary[1],'圣遗物',1)"
|
@click="showDetail(item,'圣遗物',index + 1)"
|
||||||
>
|
>
|
||||||
<TucDetailRelic v-model="data.reliquary[1]" pos="1" />
|
<TucDetailRelic :model-value="item" :pos="index.toString()" />
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="tuc-dol-item"
|
|
||||||
:style="{
|
|
||||||
cursor: data.reliquary[2] ? 'pointer' : 'default',
|
|
||||||
border: selected.pos === 2 ? '2px solid var(--common-color-yellow)' : '',
|
|
||||||
}"
|
|
||||||
@click="showDetail(data.reliquary[2],'圣遗物',2)"
|
|
||||||
>
|
|
||||||
<TucDetailRelic v-model="data.reliquary[2]" pos="2" />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="tuc-dol-item"
|
|
||||||
:style="{
|
|
||||||
cursor: data.reliquary[3] ? 'pointer' : 'default',
|
|
||||||
border: selected.pos === 3 ? '2px solid var(--common-color-yellow)' : '',
|
|
||||||
}"
|
|
||||||
@click="showDetail(data.reliquary[3],'圣遗物',3)"
|
|
||||||
>
|
|
||||||
<TucDetailRelic v-model="data.reliquary[3]" pos="3" />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="tuc-dol-item"
|
|
||||||
:style="{
|
|
||||||
cursor: data.reliquary[4] ? 'pointer' : 'default',
|
|
||||||
border: selected.pos === 4 ? '2px solid var(--common-color-yellow)' : '',
|
|
||||||
}"
|
|
||||||
@click="showDetail(data.reliquary[4],'圣遗物',4)"
|
|
||||||
>
|
|
||||||
<TucDetailRelic v-model="data.reliquary[4]" pos="4" />
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="tuc-dol-item"
|
|
||||||
:style="{
|
|
||||||
cursor: data.reliquary[5] ? 'pointer' : 'default',
|
|
||||||
border: selected.pos === 5 ? '2px solid var(--common-color-yellow)' : '',
|
|
||||||
}"
|
|
||||||
@click="showDetail(data.reliquary[5],'圣遗物',5)"
|
|
||||||
>
|
|
||||||
<TucDetailRelic v-model="data.reliquary[5]" pos="5" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 右侧环状排列6个命座 -->
|
<!-- 右侧环状排列6个命座 -->
|
||||||
@@ -86,9 +47,18 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- 底部说明 -->
|
<!-- 底部说明 -->
|
||||||
<div class="tuc-do-bottom">
|
<div class="tuc-do-bottom">
|
||||||
<TucDetailDescWeapon v-if="selected.type === '武器'" v-model="selected.data" />
|
<TucDetailDescWeapon
|
||||||
<TucDetailDescConstellation v-else-if="selected.type === '命座'" v-model="selected.data" />
|
v-if="selected.type === '武器'"
|
||||||
<TucDetailDescRelic v-else-if="selected.type === '圣遗物'" v-model="selected.data" />
|
v-model="selected.data as TGApp.Sqlite.Character.RoleWeapon"
|
||||||
|
/>
|
||||||
|
<TucDetailDescConstellation
|
||||||
|
v-else-if="selected.type === '命座'"
|
||||||
|
v-model="selected.data as TGApp.Sqlite.Character.RoleConstellation"
|
||||||
|
/>
|
||||||
|
<TucDetailDescRelic
|
||||||
|
v-else-if="selected.type === '圣遗物'"
|
||||||
|
v-model="selected.data as TGApp.Sqlite.Character.RoleReliquary"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -96,7 +66,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// vue
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, onUpdated, ref } from "vue";
|
||||||
import TOverlay from "../main/t-overlay.vue";
|
import TOverlay from "../main/t-overlay.vue";
|
||||||
import TucDetailDescWeapon from "./tuc-detail-desc-weapon.vue";
|
import TucDetailDescWeapon from "./tuc-detail-desc-weapon.vue";
|
||||||
import TucDetailDescConstellation from "./tuc-detail-desc-constellation.vue";
|
import TucDetailDescConstellation from "./tuc-detail-desc-constellation.vue";
|
||||||
@@ -137,6 +107,7 @@ const data = ref({
|
|||||||
4: false as TGApp.Sqlite.Character.RoleReliquary | false,
|
4: false as TGApp.Sqlite.Character.RoleReliquary | false,
|
||||||
5: false as TGApp.Sqlite.Character.RoleReliquary | false,
|
5: false as TGApp.Sqlite.Character.RoleReliquary | false,
|
||||||
},
|
},
|
||||||
|
costume: [] as TGApp.Sqlite.Character.RoleCostume[],
|
||||||
});
|
});
|
||||||
const selected = ref({
|
const selected = ref({
|
||||||
data: {} as TGApp.Sqlite.Character.RoleConstellation
|
data: {} as TGApp.Sqlite.Character.RoleConstellation
|
||||||
@@ -146,7 +117,9 @@ const selected = ref({
|
|||||||
pos: 0, // 用于标记选中的是哪个位置
|
pos: 0, // 用于标记选中的是哪个位置
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
// 加载数据
|
||||||
|
function loadData () {
|
||||||
|
if (!props.modelValue) return;
|
||||||
data.value.weapon = JSON.parse(props.dataVal.weapon) as TGApp.Sqlite.Character.RoleWeapon;
|
data.value.weapon = JSON.parse(props.dataVal.weapon) as TGApp.Sqlite.Character.RoleWeapon;
|
||||||
data.value.constellation = JSON.parse(props.dataVal.constellation) as TGApp.Sqlite.Character.RoleConstellation[];
|
data.value.constellation = JSON.parse(props.dataVal.constellation) as TGApp.Sqlite.Character.RoleConstellation[];
|
||||||
if (props.dataVal.reliquary !== "") {
|
if (props.dataVal.reliquary !== "") {
|
||||||
@@ -155,11 +128,21 @@ onMounted(() => {
|
|||||||
data.value.reliquary[item.pos] = item;
|
data.value.reliquary[item.pos] = item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
data.value.costume = JSON.parse(props.dataVal.costume) as TGApp.Sqlite.Character.RoleCostume[];
|
||||||
selected.value = {
|
selected.value = {
|
||||||
data: data.value.weapon,
|
data: data.value.weapon,
|
||||||
type: "武器",
|
type: "武器",
|
||||||
pos: 0,
|
pos: 0,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadData();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听外部数据变化
|
||||||
|
onUpdated(() => {
|
||||||
|
loadData();
|
||||||
});
|
});
|
||||||
|
|
||||||
const weaponBox = computed(() => {
|
const weaponBox = computed(() => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tuc-rb-box" @click="showOverlay">
|
<div class="tuc-rb-box">
|
||||||
<div class="tuc-rb-top">
|
<div class="tuc-rb-top">
|
||||||
<TItemBox v-model="avatarBox" />
|
<TItemBox v-model="avatarBox" />
|
||||||
<TItemBox v-model="weaponBox" />
|
<TItemBox v-model="weaponBox" />
|
||||||
@@ -22,13 +22,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ToUcDetail v-model="visible" :data-val="props.modelValue" />
|
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// vue
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import TItemBox from "../main/t-itembox.vue";
|
import TItemBox from "../main/t-itembox.vue";
|
||||||
import ToUcDetail from "./tuc-detail-overlay.vue";
|
|
||||||
// utils
|
// utils
|
||||||
import TGSqlite from "../../plugins/Sqlite";
|
import TGSqlite from "../../plugins/Sqlite";
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@ interface TucRoleBoxProps {
|
|||||||
modelValue: TGApp.Sqlite.Character.UserRole;
|
modelValue: TGApp.Sqlite.Character.UserRole;
|
||||||
}
|
}
|
||||||
|
|
||||||
const visible = ref(false);
|
|
||||||
const props = defineProps<TucRoleBoxProps>();
|
const props = defineProps<TucRoleBoxProps>();
|
||||||
|
|
||||||
const avatarBox = computed(() => {
|
const avatarBox = computed(() => {
|
||||||
@@ -91,10 +88,6 @@ function getAvatarName () {
|
|||||||
: props.modelValue.name
|
: props.modelValue.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showOverlay () {
|
|
||||||
visible.value = true;
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.tuc-rb-box {
|
.tuc-rb-box {
|
||||||
|
|||||||
@@ -20,21 +20,23 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- grid 布局,参考 Snap.Hutao -->
|
<!-- grid 布局,参考 Snap.Hutao -->
|
||||||
<div class="uc-grid">
|
<div class="uc-grid">
|
||||||
<TucRoleBox v-for="role in roleList" :model-value="role" />
|
<TucRoleBox v-for="role in roleList" :model-value="role" @click="selectRole(role)" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<ToUcDetail v-model="visible" :data-val="dataVal" />
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// vue
|
// vue
|
||||||
import { computed, onMounted, onUpdated, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import ToLoading from "../../components/overlay/to-loading.vue";
|
import ToLoading from "../../components/overlay/to-loading.vue";
|
||||||
|
import TucRoleBox from "../../components/userCharacter/tuc-role-box.vue";
|
||||||
|
import ToUcDetail from "../../components/userCharacter/tuc-detail-overlay.vue";
|
||||||
// store
|
// store
|
||||||
import { useUserStore } from "../../store/modules/user";
|
import { useUserStore } from "../../store/modules/user";
|
||||||
// utils
|
// utils
|
||||||
import TGSqlite from "../../plugins/Sqlite";
|
import TGSqlite from "../../plugins/Sqlite";
|
||||||
import TGRequest from "../../web/request/TGRequest";
|
import TGRequest from "../../web/request/TGRequest";
|
||||||
import { generateShareImg } from "../../utils/TGShare";
|
import { generateShareImg } from "../../utils/TGShare";
|
||||||
import TucRoleBox from "../../components/userCharacter/tuc-role-box.vue";
|
|
||||||
|
|
||||||
// store
|
// store
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
@@ -49,6 +51,10 @@ const roleList = ref([] as TGApp.Sqlite.Character.UserRole[]);
|
|||||||
const roleCookie = computed(() => userStore.getCookieGroup4());
|
const roleCookie = computed(() => userStore.getCookieGroup4());
|
||||||
const user = computed(() => userStore.getCurAccount());
|
const user = computed(() => userStore.getCurAccount());
|
||||||
|
|
||||||
|
// overlay
|
||||||
|
const visible = ref(false);
|
||||||
|
const dataVal = ref({} as TGApp.Sqlite.Character.UserRole);
|
||||||
|
|
||||||
// grid
|
// grid
|
||||||
const gridGap = ref("10px");
|
const gridGap = ref("10px");
|
||||||
|
|
||||||
@@ -107,6 +113,11 @@ function getUpdateTime () {
|
|||||||
});
|
});
|
||||||
return new Date(lastUpdateTime).toLocaleString().replace(/\//g, "-");
|
return new Date(lastUpdateTime).toLocaleString().replace(/\//g, "-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectRole (role: TGApp.Sqlite.Character.UserRole) {
|
||||||
|
dataVal.value = role;
|
||||||
|
visible.value = true;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
.uc-box {
|
.uc-box {
|
||||||
|
|||||||
Reference in New Issue
Block a user