diff --git a/src/components/userAchi/tua-achi-overlay.vue b/src/components/userAchi/tua-achi-overlay.vue index f1bb50f4..764a1124 100644 --- a/src/components/userAchi/tua-achi-overlay.vue +++ b/src/components/userAchi/tua-achi-overlay.vue @@ -72,8 +72,8 @@ interface ToAchiInfoEmits { const props = defineProps(); const emits = defineEmits(); -const showSearch = ref(false); -const search = ref(""); +const showSearch = ref(false); +const search = ref(); const visible = computed({ get: () => props.modelValue, diff --git a/src/components/viewPost/vp-overlay-search.vue b/src/components/viewPost/vp-overlay-search.vue index 72d58243..d10059ec 100644 --- a/src/components/viewPost/vp-overlay-search.vue +++ b/src/components/viewPost/vp-overlay-search.vue @@ -25,17 +25,17 @@ import TPostCard from "../app/t-postcard.vue"; import showSnackbar from "../func/snackbar.js"; // data -const search = ref(""); -const lastId = ref(""); -const game = ref("2"); -const isLast = ref(false); +const search = ref(); +const lastId = ref(""); +const game = ref("2"); +const isLast = ref(false); const results = ref([]); -const load = ref(false); +const load = ref(false); interface ToPostSearchProps { modelValue: boolean; gid: string; - keyword: string; + keyword?: string; } interface ToPostSearchEmits { @@ -69,40 +69,44 @@ function onCancel() { } onMounted(async () => { - search.value = props.keyword; game.value = props.gid; + if (props.keyword && props.keyword !== "") search.value = props.keyword; + if (props.modelValue) await searchPosts(); }); watch( () => props.modelValue, - async (value) => { - if (value && results.value.length === 0) { + async () => { + if (props.modelValue && results.value.length === 0) { await searchPosts(); - } else { - visible.value = value; + return; } + visible.value = props.modelValue; }, ); watch( () => props.keyword, - async (value) => { - if (search.value === "" && value !== "") { - search.value = value; - } else if (search.value !== value && value !== "") { - search.value = value; + async () => { + if (search.value === "" && props.keyword !== "") { + search.value = props.keyword; + return; + } + if (search.value !== props.keyword && props.keyword !== "") { + search.value = props.keyword; results.value = []; lastId.value = ""; isLast.value = false; + if (props.modelValue) await searchPosts(); } }, ); watch( () => props.gid, - async (value) => { - if (game.value !== value) { - game.value = value; + async () => { + if (game.value !== props.gid) { + game.value = props.gid; results.value = []; lastId.value = ""; isLast.value = false; @@ -111,7 +115,7 @@ watch( ); async function searchPosts() { - if (load.value) return; + if (load.value || !search.value) return; load.value = true; if (!props.gid || !props.keyword) { showSnackbar.warn("参数错误"); diff --git a/src/pages/common/PostNews.vue b/src/pages/common/PostNews.vue index a0c813f0..44b4863f 100644 --- a/src/pages/common/PostNews.vue +++ b/src/pages/common/PostNews.vue @@ -197,6 +197,7 @@ async function searchPost(): Promise { showSearch.value = true; } else { await createPost(search.value); + showSearch.value = false; } }