Skip to content

Commit

Permalink
♻️ 重构收藏数据库,更加beauty
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Mar 19, 2024
1 parent 66c6d3a commit 5d59245
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 186 deletions.
47 changes: 25 additions & 22 deletions src/components/app/t-setCollect.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<!-- todo 编辑收藏合集的 overlay -->
<div class="collect-box" data-html2canvas-ignore>
<div class="collect-btn" @click="switchCollect()" :title="isCollected ? '取消收藏' : '收藏'">
<v-icon :color="isCollected ? 'yellow' : 'white'">
Expand All @@ -8,14 +9,17 @@
</div>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import DataBase from "tauri-plugin-sql-api";
import { onBeforeMount, ref } from "vue";
import TGSqlite from "../../plugins/Sqlite";
import TSUserCollection from "../../plugins/Sqlite/modules/userCollect";
import showConfirm from "../func/confirm";
import showSnackbar from "../func/snackbar";
const isCollected = ref(false);
const collect = ref<Array<string>>([]);
const collect = ref<Array<TGApp.Sqlite.UserCollection.UFMap>>([]);
const db = ref<DataBase | undefined>(undefined);
interface TSetCollectProps {
modelValue: number;
Expand All @@ -24,35 +28,34 @@ interface TSetCollectProps {
const props = defineProps<TSetCollectProps>();
onMounted(async () => await getCollect());
async function getCollect(): Promise<void> {
const res = await TGSqlite.checkPostCollect(props.modelValue.toString());
if (res !== false) {
isCollected.value = true;
try {
collect.value = JSON.parse(res);
console.warn(collect.value);
} catch (e) {
showSnackbar({
text: `收藏数据解析失败: ${res}`,
color: "error",
});
}
onBeforeMount(async () => {
db.value = await TGSqlite.getDB();
const check = await TSUserCollection.getCollectPost(db.value, props.modelValue.toString());
if (typeof check === "boolean") {
isCollected.value = check;
return;
}
}
isCollected.value = true;
collect.value = check;
});
async function switchCollect(): Promise<void> {
if (db.value === undefined) {
showSnackbar({
text: "未获取到数据库",
color: "error",
});
return;
}
if (isCollected.value === false) {
collect.value = ["default"];
if (props.data === undefined) {
showSnackbar({
text: "获取帖子数据失败",
text: "未获取到帖子信息",
color: "error",
});
return;
}
await TGSqlite.collectPost(props.data, collect.value);
await TSUserCollection.addCollect(db.value, props.modelValue.toString(), props.data);
isCollected.value = true;
showSnackbar({
text: "收藏成功",
Expand All @@ -69,7 +72,7 @@ async function switchCollect(): Promise<void> {
return;
}
}
await TGSqlite.cancelCollect(props.modelValue.toString());
await TSUserCollection.deletePostCollect(db.value, props.modelValue.toString(), true);
isCollected.value = false;
showSnackbar({
text: "取消收藏成功",
Expand Down
6 changes: 3 additions & 3 deletions src/components/home/t-pool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ function checkCover(data: TGApp.Plugins.Mys.Gacha.Data[]): boolean {
const cover = homeStore.poolCover;
if (cover === undefined) return false;
let checkList = data.length;
Object.entries(cover).forEach(([key, value]) => {
const pool = data.find((item) => item.id.toString() === key);
Object.entries(cover).forEach(([key, value]: [string, unknown]) => {
const pool = data.find((item: TGApp.Plugins.Mys.Gacha.Data) => item.id.toString() === key);

Check notice on line 175 in src/components/home/t-pool.vue

View workflow job for this annotation

GitHub Actions / Qodana for JS

Comparison of expressions having incompatible types

Condition is always false since types 'string' and 'undefined' have no overlap
if (pool && value !== "/source/UI/empty.webp") {
checkList--;
}
Expand Down Expand Up @@ -345,11 +345,11 @@ onUnmounted(() => {
.pool-character {
display: flex;
overflow: hidden auto;
width: auto;
max-width: 280px;
height: 60px;
margin: 10px;
overflow: hidden auto;
}
.pool-character::-webkit-scrollbar-thumb {
Expand Down
2 changes: 1 addition & 1 deletion src/components/main/t-postcard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</v-card>
</template>
<script lang="ts" setup>
import { computed, nextTick, onBeforeMount, onMounted, ref, toRaw, watch } from "vue";
import { onBeforeMount, ref } from "vue";
import { createPost } from "../../utils/TGWindow";
import TpAvatar from "../post/tp-avatar.vue";
Expand Down
Loading

0 comments on commit 5d59245

Please sign in to comment.