🎨 调整帖子查找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 emits = defineEmits<ToAchiInfoEmits>();
const showSearch = ref(false);
const search = ref("");
const showSearch = ref<boolean>(false);
const search = ref<string>();
const visible = computed({
get: () => props.modelValue,

View File

@@ -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<string>();
const lastId = ref<string>("");
const game = ref<string>("2");
const isLast = ref<boolean>(false);
const results = ref<TGApp.Plugins.Mys.Post.FullData[]>([]);
const load = ref(false);
const load = ref<boolean>(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("参数错误");

View File

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