feat: 完成前端业务闭环与后端联调
This commit is contained in:
+22
-11
@@ -55,7 +55,7 @@
|
||||
class="people-primary-action"
|
||||
type="secondary"
|
||||
block
|
||||
:label="loadingMore ? '正在加载…' : '加载更多人物'"
|
||||
:label="loadingMore ? '正在加载…' : loadMoreError ? '加载失败,重新加载' : '加载更多人物'"
|
||||
@click="loadMore"
|
||||
/>
|
||||
</view>
|
||||
@@ -125,9 +125,10 @@ const keyword = ref("");
|
||||
const total = ref(0);
|
||||
const pageNum = ref(1);
|
||||
const loadingMore = ref(false);
|
||||
const loadMoreError = ref(false);
|
||||
const peopleListRequestController = createRequestController();
|
||||
let loadSequence = 0;
|
||||
const hasValidContext = computed(() => Boolean(genealogyId.value));
|
||||
const hasValidContext = computed(() => /^[1-9]\d*$/.test(genealogyId.value));
|
||||
const hasMore = computed(() => people.value.length < total.value);
|
||||
|
||||
const applySearch = () => {
|
||||
@@ -136,41 +137,48 @@ const applySearch = () => {
|
||||
return;
|
||||
}
|
||||
keyword.value = keywordInput.value.trim();
|
||||
pageNum.value = 1;
|
||||
loadMoreError.value = false;
|
||||
void loadPeople();
|
||||
};
|
||||
const clearSearch = () => {
|
||||
keywordInput.value = "";
|
||||
keyword.value = "";
|
||||
pageNum.value = 1;
|
||||
loadMoreError.value = false;
|
||||
void loadPeople();
|
||||
};
|
||||
const loadPeople = async ({ append = false } = {}) => {
|
||||
if (!hasValidContext.value) return;
|
||||
const activeLoad = ++loadSequence;
|
||||
if (append) loadingMore.value = true;
|
||||
const requestedPage = append ? pageNum.value + 1 : 1;
|
||||
if (append) {
|
||||
loadingMore.value = true;
|
||||
loadMoreError.value = false;
|
||||
}
|
||||
else peopleState.value = "loading";
|
||||
try {
|
||||
const personPage = await lineageApi.getPersonPage(
|
||||
genealogyId.value,
|
||||
{ pageNum: pageNum.value, pageSize: 10, keyword: keyword.value },
|
||||
{ pageNum: requestedPage, pageSize: 10, keyword: keyword.value },
|
||||
{ requestController: peopleListRequestController },
|
||||
);
|
||||
if (activeLoad !== loadSequence) return;
|
||||
people.value = append ? [...people.value, ...personPage.rows] : personPage.rows;
|
||||
pageNum.value = requestedPage;
|
||||
total.value = personPage.total;
|
||||
peopleState.value = people.value.length ? "ready" : "empty";
|
||||
} catch (error) {
|
||||
if (activeLoad !== loadSequence || isRequestCancelled(error)) return;
|
||||
if (!append) people.value = [];
|
||||
peopleState.value = "error";
|
||||
if (append) loadMoreError.value = true;
|
||||
else {
|
||||
people.value = [];
|
||||
peopleState.value = "error";
|
||||
}
|
||||
} finally {
|
||||
if (activeLoad === loadSequence) loadingMore.value = false;
|
||||
}
|
||||
};
|
||||
const loadMore = () => {
|
||||
if (loadingMore.value || !hasMore.value) return;
|
||||
pageNum.value += 1;
|
||||
void loadPeople({ append: true });
|
||||
};
|
||||
const openPerson = (person) =>
|
||||
@@ -188,7 +196,7 @@ const openPerson = (person) =>
|
||||
const handleStateAction = () => {
|
||||
if (peopleState.value === "invalid") return goBack();
|
||||
if (peopleState.value === "error") {
|
||||
pageNum.value = 1;
|
||||
loadMoreError.value = false;
|
||||
return loadPeople();
|
||||
}
|
||||
return goBack();
|
||||
@@ -224,7 +232,7 @@ onUnload(() => {
|
||||
}
|
||||
.people-content {
|
||||
flex: 1;
|
||||
padding: 22rpx 24rpx 100rpx;
|
||||
padding: 22rpx 24rpx calc(100rpx + env(safe-area-inset-bottom));
|
||||
}
|
||||
.people-search {
|
||||
@include adaptive-records-field;
|
||||
@@ -269,6 +277,7 @@ onUnload(() => {
|
||||
min-height: clamp(92px, 190rpx, 108px);
|
||||
align-items: center;
|
||||
margin-top: 12px;
|
||||
background-color: rgba($paper, 0.82);
|
||||
}
|
||||
.person-card:first-child {
|
||||
margin-top: 0;
|
||||
@@ -284,11 +293,13 @@ onUnload(() => {
|
||||
font-family: STKaiti, KaiTi, serif;
|
||||
font-size: clamp(17px, 31rpx, 22px);
|
||||
font-weight: 700;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.person-card__meta {
|
||||
margin-top: 7rpx;
|
||||
color: $ink-muted;
|
||||
font-size: clamp(14px, 23rpx, 17px);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.person-card__hint {
|
||||
margin-top: 8rpx;
|
||||
|
||||
Reference in New Issue
Block a user