feat: migrate app routes and business modules
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
<template>
|
||||
<view class="message-detail-page">
|
||||
<ModulePageBackground module="notification" />
|
||||
<view class="page-header"
|
||||
><PageHeader
|
||||
title="消息详情"
|
||||
:action="notificationDetail.readStatus === '0' ? (markReadSubmitting ? '正在设置' : '设为已读') : ''"
|
||||
custom-back
|
||||
@action="requestMarkRead"
|
||||
@back="backToMessages"
|
||||
/></view>
|
||||
<view class="page-content">
|
||||
<view v-if="notificationDetailState === 'loading'" class="state-card"
|
||||
><AppLoading text="正在读取消息详情"
|
||||
/></view>
|
||||
<view v-else-if="notificationDetailState === 'error'" class="state-card">
|
||||
<text>暂时无法读取消息详情</text>
|
||||
<text>{{ notificationDetailError || "请稍后重试。" }}</text>
|
||||
<AppButton
|
||||
block
|
||||
type="secondary"
|
||||
label="重新加载"
|
||||
@click="loadDetail"
|
||||
/>
|
||||
<AppButton block label="返回消息中心" @click="backToMessages" />
|
||||
</view>
|
||||
<view v-else-if="notificationDetailState === 'invalid'" class="state-card">
|
||||
<text>消息不存在或链接已失效</text>
|
||||
<text>请返回消息中心查看最新通知。</text>
|
||||
<AppButton block label="返回消息中心" @click="backToMessages" />
|
||||
</view>
|
||||
<view v-else class="detail-card">
|
||||
<text class="detail-title">{{ notificationDetail.noticeTitle || "通知消息" }}</text>
|
||||
<text v-if="notificationDetail.publishTime" class="detail-time">{{
|
||||
notificationDetail.publishTime
|
||||
}}</text>
|
||||
<view class="detail-content"
|
||||
><text>{{ notificationDetail.noticeContent || "暂无通知正文" }}</text></view
|
||||
>
|
||||
<view
|
||||
v-if="
|
||||
notificationDetail.noticeTypeLabel ||
|
||||
notificationDetail.genealogyName ||
|
||||
notificationDetail.senderNickName ||
|
||||
notificationDetail.bizSummary
|
||||
"
|
||||
class="detail-meta"
|
||||
>
|
||||
<view v-if="notificationDetail.noticeTypeLabel" class="detail-meta__row"
|
||||
><text>通知类型</text><text>{{ notificationDetail.noticeTypeLabel }}</text></view
|
||||
>
|
||||
<view v-if="notificationDetail.genealogyName" class="detail-meta__row"
|
||||
><text>所属家谱</text><text>{{ notificationDetail.genealogyName }}</text></view
|
||||
>
|
||||
<view v-if="notificationDetail.senderNickName" class="detail-meta__row"
|
||||
><text>发送人</text><text>{{ notificationDetail.senderNickName }}</text></view
|
||||
>
|
||||
<view v-if="notificationDetail.bizSummary" class="detail-meta__row"
|
||||
><text>关联事项</text><text>{{ notificationDetail.bizSummary }}</text></view
|
||||
>
|
||||
</view>
|
||||
<AppButton v-if="noticeTarget" block :label="noticeTarget.label" @click="openRelatedBusiness" />
|
||||
<text v-if="markReadError" class="detail-operation-error">{{ markReadError }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<AppDialog
|
||||
:visible="markReadVisible"
|
||||
eyebrow="消息状态"
|
||||
title="把这条消息设为已读?"
|
||||
message="这条消息将不再显示为未读。"
|
||||
:confirm-text="markReadSubmitting ? '正在设置' : '确认设为已读'"
|
||||
cancel-text="取消"
|
||||
show-cancel
|
||||
:close-on-mask="false"
|
||||
@confirm="confirmMarkRead"
|
||||
@cancel="markReadVisible = false"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from "vue";
|
||||
import { onLoad, onUnload } from "@dcloudio/uni-app";
|
||||
import AppButton from "@/components/AppButton.vue";
|
||||
import AppDialog from "@/components/AppDialog.vue";
|
||||
import AppLoading from "@/components/AppLoading.vue";
|
||||
import ModulePageBackground from "@/components/ModulePageBackground.vue";
|
||||
import PageHeader from "@/components/PageHeader.vue";
|
||||
import {
|
||||
createRequestController,
|
||||
isRequestCancelled
|
||||
} from "@/services/api/request-controller.js";
|
||||
import { notificationApi } from "@/services/api/notification-service.js";
|
||||
import { getRequestErrorMessage } from "@/services/api/request-error-message.js";
|
||||
import { openNoticeTarget, returnTo } from "@/utils/navigation/gateway.js";
|
||||
|
||||
const notificationId = ref("");
|
||||
const notificationDetail = ref({});
|
||||
const notificationDetailState = ref("loading");
|
||||
const notificationDetailError = ref("");
|
||||
const notificationDetailController = createRequestController();
|
||||
const markReadController = createRequestController();
|
||||
const markReadVisible = ref(false);
|
||||
const markReadSubmitting = ref(false);
|
||||
const markReadError = ref("");
|
||||
let isPageActive = true;
|
||||
const noticeTarget = computed(() => {
|
||||
const genealogyId = notificationDetail.value?.genealogyId;
|
||||
const bizId = notificationDetail.value?.bizId;
|
||||
if (notificationDetail.value?.noticeType === "join_apply" && genealogyId) {
|
||||
return { type: "GENEALOGY_REVIEW", params: { genealogyId }, label: "去处理加入申请" };
|
||||
}
|
||||
if (notificationDetail.value?.noticeType === "family_feed" && genealogyId && bizId) {
|
||||
return { type: "FAMILY_FEED", params: { genealogyId, feedId: bizId }, label: "查看相关动态" };
|
||||
}
|
||||
if (notificationDetail.value?.noticeType === "memo_reminder" && genealogyId && bizId) {
|
||||
return { type: "MEMO_REMINDER", params: { genealogyId, memoId: bizId }, label: "查看相关备忘" };
|
||||
}
|
||||
if (notificationDetail.value?.noticeType === "CEREMONY_INVITE") {
|
||||
return { type: "CEREMONY_INVITE", params: {}, label: "查看活动邀请" };
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const loadDetail = async () => {
|
||||
if (!/^[1-9]\d*$/.test(notificationId.value)) {
|
||||
notificationDetailState.value = "invalid";
|
||||
return;
|
||||
}
|
||||
notificationDetailController.abort();
|
||||
notificationDetailState.value = "loading";
|
||||
notificationDetailError.value = "";
|
||||
try {
|
||||
const loadedNotification = await notificationApi.getNotificationDetail(notificationId.value, {
|
||||
requestController: notificationDetailController,
|
||||
});
|
||||
if (!isPageActive) return;
|
||||
notificationDetail.value = loadedNotification;
|
||||
notificationDetailState.value = "ready";
|
||||
} catch (error) {
|
||||
if (!isPageActive || isRequestCancelled(error)) return;
|
||||
notificationDetailError.value = getRequestErrorMessage(error, "请稍后重试。");
|
||||
notificationDetailState.value = "error";
|
||||
}
|
||||
};
|
||||
|
||||
const backToMessages = () => returnTo("N01");
|
||||
const openRelatedBusiness = () => noticeTarget.value
|
||||
? openNoticeTarget(noticeTarget.value.type, noticeTarget.value.params, "N02")
|
||||
: Promise.resolve(false);
|
||||
const requestMarkRead = () => {
|
||||
if (notificationDetailState.value !== "ready" || notificationDetail.value?.readStatus !== "0" || markReadSubmitting.value)
|
||||
return;
|
||||
markReadError.value = "";
|
||||
markReadVisible.value = true;
|
||||
};
|
||||
const confirmMarkRead = async () => {
|
||||
if (markReadSubmitting.value || notificationDetail.value?.readStatus !== "0") return;
|
||||
markReadSubmitting.value = true;
|
||||
markReadError.value = "";
|
||||
try {
|
||||
await notificationApi.markNotificationRead(notificationId.value, {
|
||||
requestController: markReadController,
|
||||
});
|
||||
if (!isPageActive) return;
|
||||
markReadVisible.value = false;
|
||||
await loadDetail();
|
||||
} catch (error) {
|
||||
if (!isPageActive || isRequestCancelled(error)) return;
|
||||
markReadError.value = getRequestErrorMessage(error, "标记已读失败,请稍后重试。");
|
||||
} finally {
|
||||
if (isPageActive) markReadSubmitting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onLoad((options) => {
|
||||
notificationId.value = String(options?.id || "");
|
||||
if (!/^[1-9]\d*$/.test(notificationId.value)) {
|
||||
notificationDetailState.value = "invalid";
|
||||
return;
|
||||
}
|
||||
loadDetail();
|
||||
});
|
||||
onUnload(() => {
|
||||
isPageActive = false;
|
||||
notificationDetailController.abort();
|
||||
markReadController.abort();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@import "../../styles/adaptive-frame-profiles.scss";
|
||||
.message-detail-page {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
flex-direction: column;
|
||||
background: $paper;
|
||||
}
|
||||
.page-header,
|
||||
.page-content {
|
||||
z-index: 1;
|
||||
}
|
||||
.page-content {
|
||||
flex: 1;
|
||||
padding: 18rpx 24rpx 72rpx;
|
||||
}
|
||||
.state-card,
|
||||
.detail-card {
|
||||
box-sizing: border-box;
|
||||
@include adaptive-notification-content;
|
||||
}
|
||||
.state-card {
|
||||
min-height: 340rpx;
|
||||
padding: 78rpx 52rpx 50rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.state-card text {
|
||||
display: block;
|
||||
}
|
||||
.state-card text:first-child,
|
||||
.detail-title {
|
||||
color: $ink;
|
||||
font-family: STKaiti, KaiTi, serif;
|
||||
font-size: clamp(19px, 35rpx, 24px);
|
||||
font-weight: 700;
|
||||
}
|
||||
.state-card text:nth-child(2) {
|
||||
margin-top: 18rpx;
|
||||
color: $ink-muted;
|
||||
font-size: clamp(15px, 24rpx, 18px);
|
||||
line-height: 1.65;
|
||||
}
|
||||
.state-card .app-button {
|
||||
margin-top: 28rpx;
|
||||
}
|
||||
.detail-card {
|
||||
padding: 44rpx 38rpx;
|
||||
}
|
||||
.detail-title,
|
||||
.detail-time {
|
||||
display: block;
|
||||
}
|
||||
.detail-time {
|
||||
margin-top: 16rpx;
|
||||
color: $ink-muted;
|
||||
font-size: clamp(15px, 24rpx, 18px);
|
||||
}
|
||||
.detail-content {
|
||||
margin-top: 36rpx;
|
||||
color: $ink;
|
||||
font-size: clamp(16px, 29rpx, 20px);
|
||||
line-height: 1.8;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.detail-meta {
|
||||
margin-top: 42rpx;
|
||||
padding-top: 24rpx;
|
||||
border-top: 1rpx solid rgba(91, 70, 42, 0.16);
|
||||
}
|
||||
.detail-meta__row {
|
||||
display: flex;
|
||||
gap: 22rpx;
|
||||
padding: 10rpx 0;
|
||||
color: $ink-muted;
|
||||
font-size: clamp(15px, 24rpx, 18px);
|
||||
line-height: 1.5;
|
||||
}
|
||||
.detail-meta__row text:first-child {
|
||||
flex: 0 0 116rpx;
|
||||
}
|
||||
.detail-meta__row text:last-child {
|
||||
flex: 1;
|
||||
color: $ink;
|
||||
}
|
||||
.detail-operation-error {
|
||||
display: block;
|
||||
margin-top: 22rpx;
|
||||
color: $brand-red;
|
||||
font-size: clamp(14px, 22rpx, 17px);
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user