Files
gao-customer-h5/src/pages/setting/Agreement.vue
T
2026-11-13 15:11:53 +08:00

134 lines
2.8 KiB
Vue

<template>
<div class="tui-page-layout tui-navbar agreement">
<t-navbar
fixed
:z-index="20"
:title="routeNavBarTitle"
left-arrow
@left-click="goBack"
/>
<main class="tui-page-content scroll column bg-white">
<template v-if="article">
<header class="header" v-entrance-transition>
<h3 v-text="article.title || '协议'" />
<markdown-view
v-if="article.description"
class="description"
:content="article.description"
/>
</header>
<article-view
:article="article"
empty-text="暂无协议正文"
:resolve-attachment-url="resolveAttachmentUrl"
v-entrance-transition
/>
</template>
<t-empty
v-else
:description="isLoading ? '正在加载协议' : '协议不存在'"
/>
</main>
</div>
</template>
<script setup lang="ts">
import { type Article, ArticleAPI, AttachmentAPI } from "timi-web-api";
import { ArticleView, usePane } from "timi-tdesign-mobile";
import { MarkdownView } from "timi-web";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
defineOptions({
name: "Agreement"
});
const route = useRoute();
const router = useRouter();
const pane = usePane();
const props = defineProps<{ articleId?: string }>();
function goBack(): void {
if (pane) {
pane.close();
return;
}
router.back();
}
const routeNavBarTitle = computed(() => {
switch (route.name) {
case "Agreement":
return "协议";
case "ServiceAgreement":
return "服务协议";
case "PrivacyAgreement":
return "隐私协议";
case "OpenSourceAgreement":
return "开源软件协议";
default:
return "协议";
}
});
const article = ref<Article>();
const isLoading = ref(false);
let loadToken = 0;
function resolveAttachmentUrl(attachmentId: string): string {
return AttachmentAPI.getReadURL(attachmentId);
}
async function loadArticle(): Promise<void> {
const requestToken = loadToken + 1;
loadToken = requestToken;
article.value = undefined;
const articleId = String(props.articleId || route.params.id || "").trim();
if (!articleId) {
return;
}
isLoading.value = true;
try {
const result = await ArticleAPI.detail(articleId);
if (requestToken !== loadToken) {
return;
}
article.value = result;
} catch (error) {
Message.error(getErrorMessage(error, "协议加载失败"));
} finally {
if (requestToken === loadToken) {
isLoading.value = false;
}
}
}
watch(() => props.articleId || route.params.id, async () => {
await loadArticle();
}, { immediate: true });
</script>
<style scoped lang="less">
.agreement {
.header {
padding: 0 1rem;
h3 {
color: #0f172a;
margin: 0;
text-align: center;
}
.description {
color: #52607a;
font-size: .875rem;
}
}
:deep(.content) {
border: none;
}
}
</style>