子窗口操作同步主窗口,帖子排序

This commit is contained in:
目棃
2024-03-23 14:31:29 +08:00
parent 55671ab22d
commit 9e030c976b
2 changed files with 47 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
<ToPostCollect v-model="showEdit" :post="props.data" @submit="refresh()" />
</template>
<script lang="ts" setup>
import { event } from "@tauri-apps/api";
import { onBeforeMount, ref, watch } from "vue";
import TSUserCollection from "../../plugins/Sqlite/modules/userCollect";
@@ -34,6 +35,7 @@ const props = defineProps<TbCollectProps>();
onBeforeMount(async () => await refresh());
async function refresh(): Promise<void> {
await event.emit("refreshCollect");
const check = await TSUserCollection.getPostCollect(props.modelValue.toString());
if (typeof check === "boolean") {
isCollected.value = check;
@@ -57,6 +59,7 @@ watch(
if (val === undefined) return;
if (isCollected.value === false) return;
const res = await TSUserCollection.updatePostInfo(props.modelValue.toString(), val);
await event.emit("refreshCollect");
if (!res) {
showSnackbar({
text: "更新帖子信息失败,数据库中不存在帖子信息!",
@@ -82,6 +85,7 @@ async function switchCollect(): Promise<void> {
return;
}
await TSUserCollection.addCollect(props.modelValue.toString(), props.data);
await event.emit("refreshCollect");
isCollected.value = true;
showSnackbar({
text: "收藏成功",
@@ -99,6 +103,7 @@ async function switchCollect(): Promise<void> {
}
}
await TSUserCollection.deletePostCollect(props.modelValue.toString(), true);
await event.emit("refreshCollect");
isCollected.value = false;
showSnackbar({
text: "取消收藏成功",