🎨 调整帖子查找overlay逻辑

This commit is contained in:
目棃
2024-11-24 11:26:26 +08:00
parent d56ed5f64a
commit f47c1619e8
3 changed files with 27 additions and 22 deletions

View File

@@ -72,8 +72,8 @@ interface ToAchiInfoEmits {
const props = defineProps<ToAchiInfoProps>(); const props = defineProps<ToAchiInfoProps>();
const emits = defineEmits<ToAchiInfoEmits>(); const emits = defineEmits<ToAchiInfoEmits>();
const showSearch = ref(false); const showSearch = ref<boolean>(false);
const search = ref(""); const search = ref<string>();
const visible = computed({ const visible = computed({
get: () => props.modelValue, get: () => props.modelValue,

View File

@@ -25,17 +25,17 @@ import TPostCard from "../app/t-postcard.vue";
import showSnackbar from "../func/snackbar.js"; import showSnackbar from "../func/snackbar.js";
// data // data
const search = ref(""); const search = ref<string>();
const lastId = ref(""); const lastId = ref<string>("");
const game = ref("2"); const game = ref<string>("2");
const isLast = ref(false); const isLast = ref<boolean>(false);
const results = ref<TGApp.Plugins.Mys.Post.FullData[]>([]); const results = ref<TGApp.Plugins.Mys.Post.FullData[]>([]);
const load = ref(false); const load = ref<boolean>(false);
interface ToPostSearchProps { interface ToPostSearchProps {
modelValue: boolean; modelValue: boolean;
gid: string; gid: string;
keyword: string; keyword?: string;
} }
interface ToPostSearchEmits { interface ToPostSearchEmits {
@@ -69,40 +69,44 @@ function onCancel() {
} }
onMounted(async () => { onMounted(async () => {
search.value = props.keyword;
game.value = props.gid; game.value = props.gid;
if (props.keyword && props.keyword !== "") search.value = props.keyword;
if (props.modelValue) await searchPosts();
}); });
watch( watch(
() => props.modelValue, () => props.modelValue,
async (value) => { async () => {
if (value && results.value.length === 0) { if (props.modelValue && results.value.length === 0) {
await searchPosts(); await searchPosts();
} else { return;
visible.value = value;
} }
visible.value = props.modelValue;
}, },
); );
watch( watch(
() => props.keyword, () => props.keyword,
async (value) => { async () => {
if (search.value === "" && value !== "") { if (search.value === "" && props.keyword !== "") {
search.value = value; search.value = props.keyword;
} else if (search.value !== value && value !== "") { return;
search.value = value; }
if (search.value !== props.keyword && props.keyword !== "") {
search.value = props.keyword;
results.value = []; results.value = [];
lastId.value = ""; lastId.value = "";
isLast.value = false; isLast.value = false;
if (props.modelValue) await searchPosts();
} }
}, },
); );
watch( watch(
() => props.gid, () => props.gid,
async (value) => { async () => {
if (game.value !== value) { if (game.value !== props.gid) {
game.value = value; game.value = props.gid;
results.value = []; results.value = [];
lastId.value = ""; lastId.value = "";
isLast.value = false; isLast.value = false;
@@ -111,7 +115,7 @@ watch(
); );
async function searchPosts() { async function searchPosts() {
if (load.value) return; if (load.value || !search.value) return;
load.value = true; load.value = true;
if (!props.gid || !props.keyword) { if (!props.gid || !props.keyword) {
showSnackbar.warn("参数错误"); showSnackbar.warn("参数错误");

View File

@@ -197,6 +197,7 @@ async function searchPost(): Promise<void> {
showSearch.value = true; showSearch.value = true;
} else { } else {
await createPost(search.value); await createPost(search.value);
showSearch.value = false;
} }
} }
</script> </script>