Skip to content

Commit

Permalink
⚡️ 优化,存在 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Apr 4, 2024
1 parent 6bf24bd commit ca46b88
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/components/overlay/to-achiInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<slot name="right"></slot>
</div>
</TOverlay>
<ToPostSearch gid="2" v-model="showSearch" :keyword="search" />
<ToPostSearch gid="2" v-model="showSearch" v-model:keyword="search" />
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from "vue";
Expand Down Expand Up @@ -103,7 +103,7 @@ function onCancel() {
visible.value = false;
}
// 查找
// todo 存在 bug,点击成就标题时可能会没有效果
async function searchDirect(word: string): Promise<void> {
await TGLogger.Info(`[ToAchiInfo][${props.data?.id}][Search] 查询 ${word}`);
search.value = word;
Expand Down
50 changes: 43 additions & 7 deletions src/components/post/to-postSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="tops-top">查找:{{ search }}</div>
<div class="tops-act">
<span>分区:{{ getGidLabel() }}</span>
<v-btn size="small" class="tops-btn" @click="searchPosts()" rounded>
<v-btn :loading="load" size="small" class="tops-btn" @click="searchPosts()" rounded>
加载更多({{ results.length }})
</v-btn>
</div>
Expand All @@ -20,15 +20,17 @@
import { computed, onMounted, ref, watch } from "vue";
import Mys from "../../plugins/Mys";
import showSnackbar from "../func/snackbar";
import TOverlay from "../main/t-overlay.vue";
import TPostCard from "../main/t-postcard.vue";
// data
const search = ref("");
const game = ref("2");
const lastId = ref("");
const game = ref("2");
const isLast = ref(false);
const results = ref<TGApp.Plugins.Mys.Post.FullData[]>([]);
const load = ref(false);
interface ToPostSearchProps {
modelValue: boolean;
Expand All @@ -38,7 +40,6 @@ interface ToPostSearchProps {
interface ToPostSearchEmits {
(e: "update:modelValue", value: boolean): void;
(e: "cancel"): void;
}
Expand Down Expand Up @@ -85,18 +86,52 @@ watch(
watch(
() => props.keyword,
async (value) => {
search.value = value;
results.value = [];
lastId.value = "";
isLast.value = false;
if (search.value === "" && value !== "") {
search.value = value;
await searchPosts();
} else if (search.value !== value && value !== "") {
search.value = value;
results.value = [];
lastId.value = "";
isLast.value = false;
}
},
);
watch(
() => props.gid,
async (value) => {
if (game.value !== value) {
game.value = value;
results.value = [];
lastId.value = "";
isLast.value = false;
}
},
);
async function searchPosts() {
if (load.value) return;
load.value = true;
if (!props.gid || !props.keyword) {
showSnackbar({
text: "参数错误",
});
load.value = false;
return;
}
if (isLast.value) {
showSnackbar({
text: "没有更多了",
});
load.value = false;
return;
}
if (search.value === "") {
showSnackbar({
text: "请输入搜索关键词",
});
load.value = false;
return;
}
const res = await Mys.Posts.search(game.value, search.value, lastId.value);
Expand All @@ -107,6 +142,7 @@ async function searchPosts() {
}
lastId.value = res.last_id;
isLast.value = res.is_last;
load.value = false;
}
function getGidLabel(): string {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/common/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,14 @@ async function confirmDelCache(): Promise<void> {
for (const dir of CacheDir) {
await fs.removeDir(dir, { recursive: true });
}
await TGLogger.Info("[Config][confirmDelCache] 缓存清除完成");
loading.value = false;
showSnackbar({
text: "缓存已清除!即将退出应用!",
});
await TGLogger.Info("[Config][confirmDelCache] 缓存清除完成");
setTimeout(async () => {
await TauriProcess.exit();
}, 3000);
}, 1000);
}
// 恢复默认设置
Expand Down

0 comments on commit ca46b88

Please sign in to comment.