feat: 完成全系统30个功能点开发与E2E全链路验收 (8轮调度32个子代理闭环)
- 模块一: 出海案例作品集、博客动态发布、人名发音语音条、RTL阿语多语言切换 - 模块二: AI顾问人设配置、行业术语库润色、RAG切片沙盒调试、流式会话与意向留资卡片 - 模块三: 全球访客雷达大屏、多维加权意向算分、外部CRM对接推送、团队公海池流转 - 模块四: 移动端NFC安全挂失、NFC动态路由规则配置、动态防伪验签、展会制卡Zip批量导出 - 模块五: 组织架构与名片分配、移动端个人中心设置、离职交接与历史线索迁移、安全审计日志 - 模块六: Stripe国际信用卡订阅Webhook、独立二级域名与SSL检测、坐席配额预警、多币种发票 - 模块七: 纸质名片OCR解析入库、国际商务日程RFC 5545 ICS日历、微官网离线SWR预加载、展会实时排行榜大屏 - 模块八: 全球出海SEO OpenGraph元标签注入与社交爬虫探测、30点端到端全链路业务流集成测试套件
这个提交包含在:
472
mpuniapp/pages/portal/ai-chat.uvue
普通文件
472
mpuniapp/pages/portal/ai-chat.uvue
普通文件
@@ -0,0 +1,472 @@
|
||||
<template>
|
||||
<view class="ai-page" :style="pageTheme">
|
||||
<view class="ai-sheet">
|
||||
<view class="ai-handle"></view>
|
||||
<text class="ai-title">{{ pageTitle }}</text>
|
||||
<text v-if="state.cardId === ''" class="ai-missing">{{ t('missingCard') }}</text>
|
||||
|
||||
<list-view class="ai-list">
|
||||
<list-item v-if="state.messages.length === 0" class="ai-empty-item">
|
||||
<view class="ai-empty">
|
||||
<text class="ai-empty-text">{{ t('empty') }}</text>
|
||||
</view>
|
||||
</list-item>
|
||||
<list-item
|
||||
v-for="(item, index) in state.messages"
|
||||
:key="index"
|
||||
class="ai-row-item"
|
||||
>
|
||||
<view v-if="item.type === 'lead_card' && item.cardPayload != null" class="ai-lead-card">
|
||||
<text class="ai-lead-card-title">{{ item.cardPayload.title }}</text>
|
||||
<text class="ai-lead-card-desc">{{ item.cardPayload.description }}</text>
|
||||
|
||||
<view v-if="!item.cardPayload.submitted" class="ai-lead-card-form">
|
||||
<view class="ai-lead-field">
|
||||
<text class="ai-lead-label">{{ t('nameLabel') }}</text>
|
||||
<input
|
||||
class="ai-lead-input"
|
||||
v-model="item.cardPayload.name"
|
||||
:placeholder="t('namePlaceholder')"
|
||||
:disabled="item.cardPayload.submitting"
|
||||
/>
|
||||
</view>
|
||||
<view class="ai-lead-field">
|
||||
<text class="ai-lead-label">{{ t('contactLabel') }}</text>
|
||||
<input
|
||||
class="ai-lead-input"
|
||||
v-model="item.cardPayload.contact"
|
||||
:placeholder="t('contactPlaceholder')"
|
||||
:disabled="item.cardPayload.submitting"
|
||||
/>
|
||||
</view>
|
||||
<text v-if="item.cardPayload.errorMessage" class="ai-lead-error">{{ item.cardPayload.errorMessage }}</text>
|
||||
<button
|
||||
class="ai-lead-submit-btn"
|
||||
:class="{ 'ai-lead-submit-btn-disabled': !canSubmitCard(item.cardPayload) || item.cardPayload.submitting }"
|
||||
:disabled="!canSubmitCard(item.cardPayload) || item.cardPayload.submitting"
|
||||
@click="handleSubmitCard(item.cardPayload)"
|
||||
>
|
||||
<text class="ai-lead-submit-btn-text">{{ cardBtnText(item.cardPayload) }}</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view v-else class="ai-lead-success">
|
||||
<text class="ai-lead-success-text">{{ t('submittedSuccess') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-else
|
||||
class="ai-bubble"
|
||||
:class="item.role === 'assistant' ? 'ai-bubble-assistant ai-glow' : 'ai-bubble-user'"
|
||||
>
|
||||
<text class="ai-bubble-text">{{ item.content }}</text>
|
||||
</view>
|
||||
</list-item>
|
||||
<list-item v-if="state.showLeadHint" class="ai-hint-item">
|
||||
<view class="ai-hint">
|
||||
<text class="ai-hint-text">{{ state.leadHint }}</text>
|
||||
</view>
|
||||
</list-item>
|
||||
</list-view>
|
||||
|
||||
<view class="ai-composer">
|
||||
<text class="ai-input-label">{{ t('inputLabel') }}</text>
|
||||
<input
|
||||
class="ai-input"
|
||||
v-model="state.draft"
|
||||
:placeholder="t('placeholder')"
|
||||
:disabled="state.cardId === '' || state.sending"
|
||||
confirm-type="send"
|
||||
@confirm="handleSend"
|
||||
/>
|
||||
<button
|
||||
class="primary-cta-btn"
|
||||
:class="{ 'primary-cta-btn-disabled': !canSend }"
|
||||
:disabled="!canSend"
|
||||
@click="handleSend"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ ctaLabel }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../common/tokens.uts';
|
||||
import {
|
||||
applyAiChatOptions,
|
||||
createAiChatState,
|
||||
resolveAiChatText,
|
||||
sendStreamChat,
|
||||
submitLeadCard,
|
||||
AiChatCopyKey,
|
||||
AiChatPageOptions,
|
||||
ChatLeadPayload,
|
||||
} from './useAiChat.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-ai': utsLightColors.ai,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-radius-modal': utsRadius.modal,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
const state = reactive(createAiChatState());
|
||||
const pageTitle = ref(getOmniText(getCurrentLocale(), 'card.ai_chat'));
|
||||
|
||||
const canSend = computed((): boolean => {
|
||||
if (state.cardId === '' || state.sending) {
|
||||
return false;
|
||||
}
|
||||
return state.draft.trim() !== '';
|
||||
});
|
||||
|
||||
const ctaLabel = computed((): string => {
|
||||
if (state.sending) {
|
||||
return resolveAiChatText('sending');
|
||||
}
|
||||
return resolveAiChatText('send');
|
||||
});
|
||||
|
||||
function t(key: AiChatCopyKey): string {
|
||||
return resolveAiChatText(key);
|
||||
}
|
||||
|
||||
function canSubmitCard(payload: ChatLeadPayload | null): boolean {
|
||||
if (payload == null) {
|
||||
return false;
|
||||
}
|
||||
return payload.name.trim() !== '' && payload.contact.trim() !== '';
|
||||
}
|
||||
|
||||
function cardBtnText(payload: ChatLeadPayload | null): string {
|
||||
if (payload != null && payload.submitting === true) {
|
||||
return resolveAiChatText('submitting');
|
||||
}
|
||||
return resolveAiChatText('submitLead');
|
||||
}
|
||||
|
||||
async function handleSubmitCard(payload: ChatLeadPayload | null): Promise<void> {
|
||||
if (payload == null) {
|
||||
return;
|
||||
}
|
||||
await submitLeadCard(state.cardId, payload);
|
||||
}
|
||||
|
||||
async function handleSend(): Promise<void> {
|
||||
await sendStreamChat(state);
|
||||
}
|
||||
|
||||
onLoad((options: AiChatPageOptions) => {
|
||||
applyAiChatOptions(state, options);
|
||||
pageTitle.value = getOmniText(getCurrentLocale(), 'card.ai_chat');
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ai-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: flex-end;
|
||||
height: 100%;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.ai-sheet {
|
||||
flex: 1;
|
||||
margin-block-start: var(--oc-space-24, 24px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-modal, 20px) var(--oc-radius-modal, 20px) 0 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-handle {
|
||||
width: 40px;
|
||||
height: 4px;
|
||||
margin-block-start: var(--oc-space-12, 12px);
|
||||
margin-inline: auto;
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
background-color: var(--oc-ai, #7C5CFF);
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.ai-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.25;
|
||||
padding-inline: var(--oc-space-16, 16px);
|
||||
margin-block-start: var(--oc-space-16, 16px);
|
||||
margin-block-end: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ai-missing {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
padding-inline: var(--oc-space-16, 16px);
|
||||
margin-block-end: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ai-list {
|
||||
flex: 1;
|
||||
padding-inline: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.ai-empty-item {
|
||||
padding-block: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.ai-empty {
|
||||
min-height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.ai-empty-text {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.ai-row-item {
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.ai-bubble {
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-12, 12px) var(--oc-space-16, 16px);
|
||||
min-height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
max-width: 88%;
|
||||
}
|
||||
|
||||
.ai-bubble-user {
|
||||
margin-inline-start: auto;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
}
|
||||
|
||||
.ai-bubble-assistant {
|
||||
margin-inline-end: auto;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-inline-start: 3px solid var(--oc-ai, #7C5CFF);
|
||||
}
|
||||
|
||||
.ai-glow {
|
||||
animation: oc-ai-glow 150ms cubic-bezier(0.2, 0.8, 0.2, 1);
|
||||
}
|
||||
|
||||
.ai-bubble-text {
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.ai-bubble-user .ai-bubble-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
}
|
||||
|
||||
.ai-lead-card {
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-16, 16px);
|
||||
margin-block: var(--oc-space-8, 8px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-lead-card-title {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.25;
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ai-lead-card-desc {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.ai-lead-card-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-lead-field {
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-lead-label {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text-2, #667085);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.ai-lead-input {
|
||||
height: 44px;
|
||||
min-height: 44px;
|
||||
padding-inline: 12px;
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.ai-lead-error {
|
||||
font-size: 12px;
|
||||
color: #F04438;
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ai-lead-submit-btn {
|
||||
height: 44px;
|
||||
min-height: 44px;
|
||||
background-color: var(--oc-primary-soft, #EAF1FF);
|
||||
border: 1px solid var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ai-lead-submit-btn-disabled {
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border-color: var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.ai-lead-submit-btn-text {
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ai-lead-submit-btn-disabled .ai-lead-submit-btn-text {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
.ai-lead-success {
|
||||
padding-block: var(--oc-space-12, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.ai-lead-success-text {
|
||||
font-size: 14px;
|
||||
color: #12B76A;
|
||||
line-height: 1.6;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.ai-hint-item {
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.ai-hint {
|
||||
min-height: 44px;
|
||||
padding: var(--oc-space-12, 12px) var(--oc-space-16, 16px);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
background-color: var(--oc-primary-soft, #EAF1FF);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.ai-hint-text {
|
||||
font-size: 14px;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.ai-composer {
|
||||
padding: var(--oc-space-12, 12px) var(--oc-space-16, 16px) var(--oc-space-24, 24px);
|
||||
border-top: 1px solid var(--oc-border, #E3E7ED);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ai-input-label {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text, #101828);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ai-input {
|
||||
height: 44px;
|
||||
min-height: 44px;
|
||||
padding-inline: 12px;
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
min-height: 44px;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled {
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled .primary-cta-btn-text {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
@keyframes oc-ai-glow {
|
||||
0% {
|
||||
box-shadow: 0 0 0 0 rgba(124, 92, 255, 0.2);
|
||||
}
|
||||
100% {
|
||||
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ai-glow {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<view class="article-page" :style="pageTheme">
|
||||
<view v-if="state.loading" class="article-skeleton">
|
||||
<view class="skeleton-cover"></view>
|
||||
<view class="skeleton-line skeleton-title"></view>
|
||||
<view class="skeleton-line"></view>
|
||||
<view class="skeleton-line skeleton-short"></view>
|
||||
</view>
|
||||
|
||||
<view v-else-if="state.empty" class="article-empty">
|
||||
<text class="article-empty-text">{{ emptyMessage }}</text>
|
||||
<button class="primary-cta-btn" @click="handleBack">
|
||||
<text class="primary-cta-btn-text">{{ backLabel }}</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<scroll-view v-else class="article-scroll" :scroll-y="true">
|
||||
<view class="article-content">
|
||||
<image
|
||||
v-if="state.mediaUrl !== ''"
|
||||
class="article-cover"
|
||||
:src="state.mediaUrl"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<text class="article-kicker">{{ articleKicker }}</text>
|
||||
<text class="article-title">{{ state.title }}</text>
|
||||
<rich-text
|
||||
v-if="state.isHtmlContent"
|
||||
class="article-rich"
|
||||
:nodes="state.content"
|
||||
></rich-text>
|
||||
<text v-else class="article-body">{{ state.content }}</text>
|
||||
<view class="article-bottom-spacer"></view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view v-if="!state.loading && !state.empty" class="article-cta-bar">
|
||||
<button class="primary-cta-btn" @click="handleCopy">
|
||||
<text class="primary-cta-btn-text">{{ shareCtaLabel }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../common/tokens.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
|
||||
import {
|
||||
createArticleDetailState,
|
||||
applyArticleDetailOptions,
|
||||
loadArticleDetail,
|
||||
copyArticleShareLink,
|
||||
goBackFromArticle,
|
||||
getArticleShareFields,
|
||||
getArticleBackLabel,
|
||||
getArticleEmptyMessage,
|
||||
getCurrentPageUrl,
|
||||
ArticleDetailPageOptions,
|
||||
} from './useArticleDetail.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
const state = reactive(createArticleDetailState());
|
||||
const shareCtaLabel = ref(getArticleShareFields(state, '').ctaLabel);
|
||||
const backLabel = ref(getArticleBackLabel());
|
||||
const emptyMessage = ref(getArticleEmptyMessage());
|
||||
const articleKicker = ref(getOmniText(getCurrentLocale(), 'portal.article'));
|
||||
|
||||
async function handleCopy(): Promise<void> {
|
||||
copyArticleShareLink(state, getCurrentPageUrl(state));
|
||||
}
|
||||
|
||||
function handleBack(): void {
|
||||
goBackFromArticle(state);
|
||||
}
|
||||
|
||||
onLoad((options: ArticleDetailPageOptions) => {
|
||||
const ready = applyArticleDetailOptions(state, options);
|
||||
if (ready) {
|
||||
loadArticleDetail(state);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.article-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.article-skeleton {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.skeleton-cover {
|
||||
height: 200px;
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.skeleton-line {
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.skeleton-title {
|
||||
height: 24px;
|
||||
width: 72%;
|
||||
}
|
||||
|
||||
.skeleton-short {
|
||||
width: 48%;
|
||||
}
|
||||
|
||||
.article-empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
padding: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.article-empty-text {
|
||||
font-size: 16px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.article-scroll {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.article-cover {
|
||||
width: 100%;
|
||||
height: 200px;
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.article-kicker {
|
||||
font-size: 12px;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.25;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.article-rich {
|
||||
font-size: 16px;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.article-body {
|
||||
font-size: 16px;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.article-bottom-spacer {
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.article-cta-bar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 12px var(--oc-space-16, 16px) var(--oc-space-24, 24px) var(--oc-space-16, 16px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border-top: 1px solid var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,304 @@
|
||||
<template>
|
||||
<view class="case-page" :style="pageTheme">
|
||||
<view v-if="state.loading" class="case-skeleton">
|
||||
<view class="skeleton-line line-title"></view>
|
||||
<view class="skeleton-media"></view>
|
||||
<view class="skeleton-line"></view>
|
||||
<view class="skeleton-line line-short"></view>
|
||||
</view>
|
||||
|
||||
<view v-else-if="state.empty" class="case-empty">
|
||||
<text class="case-empty-text">{{ copy.empty }}</text>
|
||||
<button class="primary-cta-btn" @click="handleBack">
|
||||
<text class="primary-cta-btn-text">{{ copy.back }}</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<scroll-view v-else class="case-scroll" :scroll-y="true">
|
||||
<view class="case-content">
|
||||
<text class="case-title">{{ state.title }}</text>
|
||||
|
||||
<swiper
|
||||
v-if="state.images.length > 1"
|
||||
class="case-swiper"
|
||||
:indicator-dots="true"
|
||||
:autoplay="false"
|
||||
circular
|
||||
>
|
||||
<swiper-item v-for="img in state.images" :key="img">
|
||||
<image class="case-media" :src="img" mode="aspectFill" />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<image
|
||||
v-else-if="state.images.length === 1"
|
||||
class="case-media case-media-single"
|
||||
:src="state.images[0]"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
|
||||
<text v-if="state.content !== ''" class="case-body">{{ state.content }}</text>
|
||||
|
||||
<view v-if="state.kpis.length > 0" class="kpi-row">
|
||||
<view v-for="kpi in state.kpis" :key="kpi.label" class="kpi-card">
|
||||
<text class="kpi-value">{{ kpi.value }}</text>
|
||||
<text class="kpi-label">{{ kpi.label }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="state.pdfUrl !== ''" class="ext-link-row">
|
||||
<text class="ext-link-label">{{ copy.pdf }}</text>
|
||||
<text class="ext-link-url">{{ state.pdfUrl }}</text>
|
||||
</view>
|
||||
<view v-if="state.youtubeUrl !== ''" class="ext-link-row">
|
||||
<text class="ext-link-label">{{ copy.youtube }}</text>
|
||||
<text class="ext-link-url">{{ state.youtubeUrl }}</text>
|
||||
</view>
|
||||
|
||||
<view class="case-bottom-spacer"></view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view v-if="!state.loading && !state.empty" class="case-cta-bar">
|
||||
<button class="primary-cta-btn" @click="handleConsult">
|
||||
<text class="primary-cta-btn-text">{{ copy.cta }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../common/tokens.uts';
|
||||
import {
|
||||
CASE_DETAIL_COPY,
|
||||
createCaseDetailState,
|
||||
applyCaseDetailOptions,
|
||||
loadCaseDetail,
|
||||
openCaseExchange,
|
||||
goCaseBack,
|
||||
CaseDetailPageOptions,
|
||||
} from './useCaseDetail.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
const copy = CASE_DETAIL_COPY;
|
||||
const state = reactive(createCaseDetailState());
|
||||
|
||||
function handleConsult(): void {
|
||||
openCaseExchange(state.cardId);
|
||||
}
|
||||
|
||||
function handleBack(): void {
|
||||
goCaseBack();
|
||||
}
|
||||
|
||||
onLoad((options: CaseDetailPageOptions) => {
|
||||
applyCaseDetailOptions(state, options);
|
||||
loadCaseDetail(state);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.case-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.case-scroll {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.case-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.case-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.25;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.case-swiper {
|
||||
height: 220px;
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
overflow: hidden;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.case-media {
|
||||
width: 100%;
|
||||
height: 220px;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.case-media-single {
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.case-body {
|
||||
font-size: 16px;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.kpi-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.kpi-card {
|
||||
flex: 1;
|
||||
min-width: 96px;
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-16, 16px);
|
||||
margin-inline-end: var(--oc-space-8, 8px);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.kpi-value {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
line-height: 1.25;
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.kpi-label {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.ext-link-row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-16, 16px);
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.ext-link-label {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.ext-link-url {
|
||||
font-size: 14px;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.case-bottom-spacer {
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.case-skeleton {
|
||||
padding: var(--oc-space-24, 24px) var(--oc-space-16, 16px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.skeleton-line {
|
||||
height: 16px;
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.line-title {
|
||||
width: 60%;
|
||||
height: 24px;
|
||||
}
|
||||
|
||||
.line-short {
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.skeleton-media {
|
||||
height: 180px;
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
margin: var(--oc-space-16, 16px) 0;
|
||||
}
|
||||
|
||||
.case-empty {
|
||||
margin: 40px var(--oc-space-16, 16px);
|
||||
padding: var(--oc-space-24, 24px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.case-empty-text {
|
||||
font-size: 16px;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.case-cta-bar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 12px var(--oc-space-16, 16px) var(--oc-space-24, 24px) var(--oc-space-16, 16px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border-top: 1px solid var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.case-empty .primary-cta-btn {
|
||||
max-width: 240px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,12 @@
|
||||
<template>
|
||||
<view class="portal-page">
|
||||
<view class="portal-page" :class="pageRtlClass">
|
||||
<view class="locale-bar">
|
||||
<view class="locale-selector-container">
|
||||
<i18n-selector :model-value="currentLang" @change="switchLang" />
|
||||
</view>
|
||||
<text class="locale-chip locale-exchange" @click="openExchange">{{ textOf('card.exchange') }}</text>
|
||||
</view>
|
||||
|
||||
<scroll-view class="portal-scroll" :scroll-y="true">
|
||||
<!-- 骨架加载态 -->
|
||||
<view v-if="state.loading" class="portal-skeleton">
|
||||
@@ -11,10 +18,10 @@
|
||||
|
||||
<!-- 异常提示态 -->
|
||||
<view v-else-if="state.errorMessage" class="portal-error-card">
|
||||
<text class="error-title">微官网暂不可用</text>
|
||||
<text class="error-title">{{ textOf('portal.unavailable') }}</text>
|
||||
<text class="error-desc">{{ state.errorMessage }}</text>
|
||||
<button class="retry-btn" @click="reloadPortal">
|
||||
<text class="retry-btn-text">重新加载</text>
|
||||
<text class="retry-btn-text">{{ textOf('portal.retry') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
@@ -41,15 +48,11 @@
|
||||
<!-- 姓名与发音试听 -->
|
||||
<view class="hero-name-row">
|
||||
<text class="hero-name">{{ state.card!.name }}</text>
|
||||
<view
|
||||
v-if="state.card!.audioPronunciationUrl"
|
||||
class="pronounce-pill"
|
||||
:class="{ 'pronounce-pill-active': state.isPlayingAudio }"
|
||||
@click="handleAudioToggle"
|
||||
>
|
||||
<text class="pronounce-icon">{{ state.isPlayingAudio ? '■' : '▶' }}</text>
|
||||
<text class="pronounce-label">{{ state.isPlayingAudio ? '播放中' : '发音' }}</text>
|
||||
</view>
|
||||
<audio-pronounce
|
||||
v-if="cardAudioUrl !== ''"
|
||||
:audio-url="cardAudioUrl"
|
||||
:label="textOf('portal.pronounce')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 头衔与所属公司 -->
|
||||
@@ -69,28 +72,49 @@
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">WA</text>
|
||||
</view>
|
||||
<text class="action-item-label">WhatsApp</text>
|
||||
<text class="action-item-label">{{ textOf('portal.whatsapp') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('linkedin')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">IN</text>
|
||||
</view>
|
||||
<text class="action-item-label">LinkedIn</text>
|
||||
<text class="action-item-label">{{ textOf('portal.linkedin') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('email')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">@</text>
|
||||
</view>
|
||||
<text class="action-item-label">邮件</text>
|
||||
<text class="action-item-label">{{ textOf('portal.email') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('phone')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">TEL</text>
|
||||
</view>
|
||||
<text class="action-item-label">电话呼出</text>
|
||||
<text class="action-item-label">{{ textOf('portal.phone') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('telegram')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">TG</text>
|
||||
</view>
|
||||
<text class="action-item-label">{{ textOf('portal.telegram') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('twitter')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">X</text>
|
||||
</view>
|
||||
<text class="action-item-label">{{ textOf('portal.twitter') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-item" @click="handleAction('wechat')">
|
||||
<view class="action-icon-box">
|
||||
<text class="action-icon-text">WX</text>
|
||||
</view>
|
||||
<text class="action-item-label">{{ textOf('portal.wechat') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -127,10 +151,16 @@
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<text
|
||||
v-if="state.card != null"
|
||||
class="ai-entry"
|
||||
@click="openAiChat"
|
||||
>{{ textOf('card.ai_chat') }}</text>
|
||||
|
||||
<!-- 4. 单屏唯一定位主 CTA (保存到通讯录) -->
|
||||
<view v-if="state.card != null" class="portal-cta-bar">
|
||||
<button class="primary-cta-btn" @click="handleSaveContact">
|
||||
<text class="primary-cta-btn-text">保存到手机通讯录</text>
|
||||
<text class="primary-cta-btn-text">{{ textOf('card.save_contact') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -148,14 +178,65 @@ import {
|
||||
triggerQuickAction,
|
||||
getBentoColSpanClass,
|
||||
filterVisibleBentoBlocks,
|
||||
persistPortalLocale,
|
||||
readStoredPortalLocale,
|
||||
readCardSuggestedLocale,
|
||||
resolvePortalLocale,
|
||||
PortalQuickAction,
|
||||
} from './usePortal.uts';
|
||||
import { saveToContacts } from '../../common/vcard-export.uts';
|
||||
import {
|
||||
OmniLocale,
|
||||
OmniMessageKey,
|
||||
detectLocale,
|
||||
getOmniText,
|
||||
isRtl,
|
||||
setCurrentLocale,
|
||||
} from '../../common/locale.uts';
|
||||
import I18nSelector from '../../components/i18n-selector/i18n-selector.uvue';
|
||||
import AudioPronounce from '../../components/audio-pronounce/audio-pronounce.uvue';
|
||||
import { releaseAudioPlayer } from './useAudioPlayer.uts';
|
||||
|
||||
const defaultAvatar = 'https://cdn.omnicard.ai/assets/default-avatar.png';
|
||||
|
||||
// 页面响应式状态
|
||||
const state = reactive(createPortalState());
|
||||
const currentCardId = ref('');
|
||||
const currentLang = ref<OmniLocale>(detectLocale());
|
||||
|
||||
const cardAudioUrl = computed((): string => {
|
||||
if (state.card == null) {
|
||||
return '';
|
||||
}
|
||||
const primaryUrl = state.card!.audioPronounceUrl;
|
||||
if (primaryUrl != null && primaryUrl.trim() !== '') {
|
||||
return primaryUrl.trim();
|
||||
}
|
||||
const fallbackUrl = state.card!.audioPronunciationUrl;
|
||||
if (fallbackUrl != null && fallbackUrl.trim() !== '') {
|
||||
return fallbackUrl.trim();
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
const pageRtlClass = computed((): string => {
|
||||
return isRtl(currentLang.value) ? 'portal-rtl' : '';
|
||||
});
|
||||
|
||||
function textOf(key: OmniMessageKey): string {
|
||||
return getOmniText(currentLang.value, key);
|
||||
}
|
||||
|
||||
function applyResolvedLocale(next: OmniLocale): void {
|
||||
setCurrentLocale(next);
|
||||
currentLang.value = next;
|
||||
}
|
||||
|
||||
function switchLang(next: OmniLocale): void {
|
||||
applyResolvedLocale(next);
|
||||
persistPortalLocale(next);
|
||||
}
|
||||
// 7 大语种动态切换支持: switchLang('zh-CN'); switchLang('en-US'); switchLang('ar-SA'); switchLang('es-ES'); switchLang('de-DE'); switchLang('fr-FR'); switchLang('ja-JP');
|
||||
|
||||
// 计算过滤后的 Bento 块
|
||||
const visibleBlocks = computed((): BentoBlockPublic[] => {
|
||||
@@ -172,11 +253,11 @@ function getColClass(colSpan: number): string {
|
||||
|
||||
// 块类型显示标签
|
||||
function getBlockTypeLabel(type: string): string {
|
||||
if (type === 'case') return '精选案例';
|
||||
if (type === 'article') return '深度洞见';
|
||||
if (type === 'social') return '社媒矩阵';
|
||||
if (type === 'video') return '展会视频';
|
||||
return '微官网内容';
|
||||
if (type === 'case') return textOf('portal.case');
|
||||
if (type === 'article') return textOf('portal.article');
|
||||
if (type === 'social') return textOf('portal.social');
|
||||
if (type === 'video') return textOf('portal.video');
|
||||
return textOf('portal.block');
|
||||
}
|
||||
|
||||
// 播放发音
|
||||
@@ -187,13 +268,16 @@ function handleAudioToggle(): void {
|
||||
}
|
||||
|
||||
// 快捷动作
|
||||
function handleAction(type: 'whatsapp' | 'linkedin' | 'email' | 'phone'): void {
|
||||
function handleAction(type: PortalQuickAction): void {
|
||||
if (!state.card) return;
|
||||
let targetVal = '';
|
||||
if (type === 'whatsapp') targetVal = state.card!.whatsapp || '';
|
||||
if (type === 'linkedin') targetVal = state.card!.linkedin || '';
|
||||
if (type === 'email') targetVal = state.card!.email || '';
|
||||
if (type === 'phone') targetVal = state.card!.phone || '';
|
||||
if (type === 'telegram') targetVal = state.card!.telegram || '';
|
||||
if (type === 'twitter') targetVal = state.card!.twitter || '';
|
||||
if (type === 'wechat') targetVal = state.card!.wechat || '';
|
||||
triggerQuickAction(type, targetVal);
|
||||
}
|
||||
|
||||
@@ -206,14 +290,45 @@ function handleCompanyClick(): void {
|
||||
});
|
||||
}
|
||||
|
||||
function openExchange(): void {
|
||||
if (!state.card) return;
|
||||
const cardId = state.card!.id != null ? String(state.card!.id) : currentCardId.value;
|
||||
const slug = state.card!.slug != null ? String(state.card!.slug) : '';
|
||||
uni.navigateTo({
|
||||
url: `/pages/portal/exchange?cardId=${cardId}&slug=${slug}`,
|
||||
});
|
||||
}
|
||||
|
||||
function openAiChat(): void {
|
||||
if (!state.card) return;
|
||||
const cardId = state.card!.id != null ? String(state.card!.id) : currentCardId.value;
|
||||
uni.navigateTo({
|
||||
url: `/pages/portal/ai-chat?cardId=${cardId}&lang=${currentLang.value}`,
|
||||
});
|
||||
}
|
||||
|
||||
// Bento 卡片点击
|
||||
function handleBlockClick(block: BentoBlockPublic): void {
|
||||
const blockId = block.id != null ? String(block.id) : '';
|
||||
const cardQuery = currentCardId.value;
|
||||
if (block.type === 'case') {
|
||||
uni.navigateTo({
|
||||
url: `/pages/portal/case-detail?cardId=${cardQuery}&blockId=${blockId}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (block.type === 'article') {
|
||||
uni.navigateTo({
|
||||
url: `/pages/portal/article-detail?cardId=${cardQuery}&blockId=${blockId}`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (block.linkUrl && block.linkUrl!.trim() !== '') {
|
||||
uni.setClipboardData({
|
||||
data: block.linkUrl!,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '已复制链接',
|
||||
title: textOf('portal.copied_link'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
@@ -242,12 +357,19 @@ function reloadPortal(): void {
|
||||
onLoad((options: any) => {
|
||||
const queryId = (options && (options.id || options.slug)) ? String(options.id || options.slug) : 'default';
|
||||
const querySource = (options && options.source) ? String(options.source) : 'link';
|
||||
const queryLang = (options && options.lang) ? String(options.lang) : '';
|
||||
currentCardId.value = queryId;
|
||||
loadCardPortal(state, queryId, querySource);
|
||||
const stored = readStoredPortalLocale();
|
||||
applyResolvedLocale(resolvePortalLocale(queryLang, stored, '', detectLocale()));
|
||||
loadCardPortal(state, queryId, querySource).then((cardData) => {
|
||||
const suggested = readCardSuggestedLocale(cardData);
|
||||
applyResolvedLocale(resolvePortalLocale(queryLang, stored, suggested, detectLocale()));
|
||||
});
|
||||
});
|
||||
|
||||
onUnload(() => {
|
||||
reportPortalStay(state, 100);
|
||||
releaseAudioPlayer();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -258,6 +380,67 @@ onUnload(() => {
|
||||
height: 100%;
|
||||
background-color: #F7F8FA;
|
||||
}
|
||||
.portal-rtl {
|
||||
direction: rtl;
|
||||
text-align: right;
|
||||
}
|
||||
.locale-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 16px 0 16px;
|
||||
}
|
||||
.locale-selector-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.locale-chip {
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
color: #0B5CFF;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.locale-chip-active {
|
||||
color: #0B5CFF;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* RTL 镜像适配 */
|
||||
.portal-rtl .hero-card {
|
||||
text-align: right;
|
||||
}
|
||||
.portal-rtl .hero-name-row {
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.portal-rtl .hero-name {
|
||||
margin-right: 0;
|
||||
margin-left: 12px;
|
||||
}
|
||||
.portal-rtl .hero-company-row {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
.portal-rtl .hero-company-name {
|
||||
margin-right: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.portal-rtl .hero-company-arrow {
|
||||
display: inline-block;
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
.portal-rtl .pronounce-icon {
|
||||
margin-right: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
.portal-rtl .ai-entry {
|
||||
right: auto;
|
||||
left: 16px;
|
||||
}
|
||||
|
||||
.portal-scroll {
|
||||
flex: 1;
|
||||
@@ -460,11 +643,13 @@ onUnload(() => {
|
||||
.quick-action-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.action-item {
|
||||
flex: 1;
|
||||
flex: 1 1 20%;
|
||||
min-width: 64px;
|
||||
min-height: 52px;
|
||||
background-color: #FFFFFF;
|
||||
border: 1px solid #E3E7ED;
|
||||
@@ -548,6 +733,17 @@ onUnload(() => {
|
||||
.portal-bottom-spacer {
|
||||
height: 80px;
|
||||
}
|
||||
.ai-entry {
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 96px;
|
||||
min-height: 44px;
|
||||
min-width: 44px;
|
||||
padding: 8px 12px;
|
||||
color: #7C5CFF;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
.portal-cta-bar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
|
||||
558
mpuniapp/pages/portal/useAiChat.uts
普通文件
558
mpuniapp/pages/portal/useAiChat.uts
普通文件
@@ -0,0 +1,558 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 门户 AI 顾问对话业务驱动层
|
||||
* 调用已有 askAiChat,空文本不发,cardId 必填
|
||||
*/
|
||||
|
||||
import {
|
||||
AiChatMessage,
|
||||
AiChatReply,
|
||||
AiChatRequest,
|
||||
ChatMessage,
|
||||
ChatMessageType,
|
||||
ChatLeadPayload,
|
||||
SubmitLeadParams,
|
||||
} from '../../common/types.uts';
|
||||
import { askAiChat, submitLead } from '../../common/api.uts';
|
||||
import {
|
||||
OmniLocale,
|
||||
getCurrentLocale,
|
||||
getOmniText,
|
||||
resolveDeviceLocale,
|
||||
setCurrentLocale,
|
||||
} from '../../common/locale.uts';
|
||||
|
||||
export {
|
||||
ChatMessage,
|
||||
ChatMessageType,
|
||||
ChatLeadPayload,
|
||||
AiChatMessage,
|
||||
AiChatReply,
|
||||
AiChatRequest,
|
||||
};
|
||||
|
||||
export type AiChatCopyKey =
|
||||
| 'title'
|
||||
| 'send'
|
||||
| 'sending'
|
||||
| 'placeholder'
|
||||
| 'empty'
|
||||
| 'leadHint'
|
||||
| 'missingCard'
|
||||
| 'inputLabel'
|
||||
| 'nameLabel'
|
||||
| 'namePlaceholder'
|
||||
| 'contactLabel'
|
||||
| 'contactPlaceholder'
|
||||
| 'submitLead'
|
||||
| 'submitting'
|
||||
| 'submittedSuccess'
|
||||
| 'leadCardTitle'
|
||||
| 'leadCardDesc'
|
||||
| 'submitFailed'
|
||||
| 'error';
|
||||
|
||||
export type SendChatInput = {
|
||||
cardId: string | number;
|
||||
locale?: string;
|
||||
messages: ChatMessage[];
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type AskAiChatFn = (req: AiChatRequest) => Promise<AiChatReply>;
|
||||
|
||||
export type SendChatApi = {
|
||||
askAiChat: AskAiChatFn;
|
||||
};
|
||||
|
||||
export type SendChatResult = {
|
||||
sent: boolean;
|
||||
reply: AiChatReply | null;
|
||||
messages: ChatMessage[];
|
||||
shouldCollectLead: boolean;
|
||||
leadHint: string;
|
||||
};
|
||||
|
||||
export type AiChatState = {
|
||||
cardId: string;
|
||||
locale: OmniLocale;
|
||||
draft: string;
|
||||
sending: boolean;
|
||||
messages: ChatMessage[];
|
||||
showLeadHint: boolean;
|
||||
leadHint: string;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type AiChatPageOptions = {
|
||||
cardId?: string;
|
||||
id?: string;
|
||||
lang?: string;
|
||||
locale?: string;
|
||||
};
|
||||
|
||||
function isZhLocale(): boolean {
|
||||
return getCurrentLocale() === 'zh-CN';
|
||||
}
|
||||
|
||||
function cloneMessages(messages: ChatMessage[]): ChatMessage[] {
|
||||
const next: ChatMessage[] = [];
|
||||
if (messages == null) {
|
||||
return next;
|
||||
}
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
const item = messages[i];
|
||||
const cloned: ChatMessage = {
|
||||
role: item.role,
|
||||
content: item.content,
|
||||
type: item.type != null ? item.type : 'text',
|
||||
};
|
||||
if (item.cardPayload != null) {
|
||||
cloned.cardPayload = {
|
||||
title: item.cardPayload.title,
|
||||
description: item.cardPayload.description,
|
||||
name: item.cardPayload.name,
|
||||
contact: item.cardPayload.contact,
|
||||
submitted: item.cardPayload.submitted,
|
||||
submitting: item.cardPayload.submitting,
|
||||
successMessage: item.cardPayload.successMessage,
|
||||
errorMessage: item.cardPayload.errorMessage,
|
||||
};
|
||||
}
|
||||
next.push(cloned);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
function resolveCardId(cardId: string | number): string {
|
||||
if (cardId == null) {
|
||||
return '';
|
||||
}
|
||||
return String(cardId).trim();
|
||||
}
|
||||
|
||||
function requestCardId(cardId: string | number): string | number {
|
||||
if (typeof cardId === 'number') {
|
||||
return cardId;
|
||||
}
|
||||
return resolveCardId(cardId);
|
||||
}
|
||||
|
||||
function emptySendResult(messages: ChatMessage[]): SendChatResult {
|
||||
return {
|
||||
sent: false,
|
||||
reply: null,
|
||||
messages,
|
||||
shouldCollectLead: false,
|
||||
leadHint: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面文案:标题走 card.ai_chat,其余本地词典
|
||||
*/
|
||||
export function resolveAiChatText(key: AiChatCopyKey): string {
|
||||
const locale = getCurrentLocale();
|
||||
if (key === 'title') {
|
||||
return getOmniText(locale, 'card.ai_chat');
|
||||
}
|
||||
if (key === 'error') {
|
||||
return getOmniText(locale, 'common.error');
|
||||
}
|
||||
|
||||
const zh = isZhLocale();
|
||||
if (key === 'send') {
|
||||
return zh ? '发送' : 'Send';
|
||||
}
|
||||
if (key === 'sending') {
|
||||
return zh ? '发送中' : 'Sending';
|
||||
}
|
||||
if (key === 'placeholder') {
|
||||
return zh ? '输入你想了解的内容' : 'Ask about this card';
|
||||
}
|
||||
if (key === 'empty') {
|
||||
return zh ? '向顾问提问,了解业务与服务。' : 'Ask the advisor about this business.';
|
||||
}
|
||||
if (key === 'leadHint') {
|
||||
return zh
|
||||
? '留下姓名和联系方式,方便继续沟通。'
|
||||
: 'Leave your name and contact so we can continue.';
|
||||
}
|
||||
if (key === 'missingCard') {
|
||||
return zh ? '缺少名片标识,暂时无法对话。' : 'A card ID is required to start this chat.';
|
||||
}
|
||||
if (key === 'inputLabel') {
|
||||
return zh ? '消息' : 'Message';
|
||||
}
|
||||
if (key === 'nameLabel') {
|
||||
return zh ? '您的称呼' : 'Your Name';
|
||||
}
|
||||
if (key === 'namePlaceholder') {
|
||||
return zh ? '例如:张经理 / Alex' : 'e.g. Alex Smith';
|
||||
}
|
||||
if (key === 'contactLabel') {
|
||||
return zh ? '联系方式' : 'Contact (WhatsApp / Email)';
|
||||
}
|
||||
if (key === 'contactPlaceholder') {
|
||||
return zh ? 'WhatsApp 或 电子邮箱' : 'WhatsApp or Email';
|
||||
}
|
||||
if (key === 'submitLead') {
|
||||
return zh ? '获取专属方案' : 'Get Custom Proposal';
|
||||
}
|
||||
if (key === 'submitting') {
|
||||
return zh ? '提交中' : 'Submitting';
|
||||
}
|
||||
if (key === 'submittedSuccess') {
|
||||
return zh
|
||||
? '已收到您的信息,顾问将尽快与您联系。'
|
||||
: 'Information received. Our advisor will reach out shortly.';
|
||||
}
|
||||
if (key === 'leadCardTitle') {
|
||||
return zh ? '获取专属方案与报价' : 'Get Custom Proposal & Pricing';
|
||||
}
|
||||
if (key === 'leadCardDesc') {
|
||||
return zh
|
||||
? '留下您的称呼与联系方式(WhatsApp 或邮箱),商务团队将快速与您对接。'
|
||||
: 'Leave your contact info and our team will get in touch.';
|
||||
}
|
||||
if (key === 'submitFailed') {
|
||||
return zh ? '提交失败,请重试' : 'Submission failed, please retry';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export function createAiChatState(): AiChatState {
|
||||
return {
|
||||
cardId: '',
|
||||
locale: getCurrentLocale(),
|
||||
draft: '',
|
||||
sending: false,
|
||||
messages: [],
|
||||
showLeadHint: false,
|
||||
leadHint: '',
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从页面 query 写入 cardId / lang
|
||||
*/
|
||||
export function applyAiChatOptions(
|
||||
state: AiChatState,
|
||||
options: AiChatPageOptions | null
|
||||
): boolean {
|
||||
const cardIdRaw = options != null ? options.cardId || options.id || '' : '';
|
||||
const langRaw = options != null ? options.lang || options.locale || '' : '';
|
||||
state.cardId = String(cardIdRaw).trim();
|
||||
|
||||
if (langRaw.trim() !== '') {
|
||||
const locale = resolveDeviceLocale(langRaw);
|
||||
setCurrentLocale(locale);
|
||||
state.locale = locale;
|
||||
} else {
|
||||
state.locale = getCurrentLocale();
|
||||
}
|
||||
|
||||
return state.cardId !== '';
|
||||
}
|
||||
|
||||
export function buildUserMessage(text: string): ChatMessage {
|
||||
const content = text != null ? text.trim() : '';
|
||||
return {
|
||||
role: 'user',
|
||||
content,
|
||||
type: 'text',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加一轮 user + assistant,返回新数组
|
||||
*/
|
||||
export function appendTurn(
|
||||
messages: ChatMessage[],
|
||||
userText: string,
|
||||
reply: AiChatReply
|
||||
): ChatMessage[] {
|
||||
const next = cloneMessages(messages);
|
||||
next.push(buildUserMessage(userText));
|
||||
const replyText = reply != null && reply.reply != null ? reply.reply : '';
|
||||
next.push({
|
||||
role: 'assistant',
|
||||
content: replyText,
|
||||
type: 'text',
|
||||
});
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送顾问对话。空文本不发,cardId 必填。可注入 askAiChat
|
||||
*/
|
||||
export async function sendChat(
|
||||
input: SendChatInput,
|
||||
api?: SendChatApi
|
||||
): Promise<SendChatResult> {
|
||||
const text = input != null && input.text != null ? input.text.trim() : '';
|
||||
const cardId = input != null ? resolveCardId(input.cardId) : '';
|
||||
const existing = input != null && input.messages != null ? input.messages : [];
|
||||
|
||||
if (text === '' || cardId === '') {
|
||||
return emptySendResult(existing);
|
||||
}
|
||||
|
||||
const outgoing = cloneMessages(existing);
|
||||
outgoing.push(buildUserMessage(text));
|
||||
|
||||
const req: AiChatRequest = {
|
||||
cardId: requestCardId(input.cardId),
|
||||
messages: outgoing,
|
||||
};
|
||||
const locale = input.locale != null ? input.locale.trim() : '';
|
||||
if (locale !== '') {
|
||||
req.locale = locale;
|
||||
}
|
||||
|
||||
const ask = api != null ? api.askAiChat : askAiChat;
|
||||
const reply = await ask(req);
|
||||
const shouldCollectLead = reply != null && reply.shouldCollectLead === true;
|
||||
|
||||
return {
|
||||
sent: true,
|
||||
reply,
|
||||
messages: appendTurn(existing, text, reply),
|
||||
shouldCollectLead,
|
||||
leadHint: shouldCollectLead ? resolveAiChatText('leadHint') : '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面发送:写入会话并给出留资引导标记
|
||||
*/
|
||||
export async function sendDraft(
|
||||
state: AiChatState,
|
||||
api?: SendChatApi
|
||||
): Promise<SendChatResult> {
|
||||
if (state.sending) {
|
||||
return emptySendResult(state.messages);
|
||||
}
|
||||
|
||||
state.sending = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
const result = await sendChat(
|
||||
{
|
||||
cardId: state.cardId,
|
||||
locale: state.locale,
|
||||
messages: state.messages,
|
||||
text: state.draft,
|
||||
},
|
||||
api
|
||||
);
|
||||
if (result.sent) {
|
||||
state.draft = '';
|
||||
state.messages = result.messages;
|
||||
state.showLeadHint = result.shouldCollectLead;
|
||||
state.leadHint = result.leadHint;
|
||||
}
|
||||
state.sending = false;
|
||||
return result;
|
||||
} catch (_e) {
|
||||
state.sending = false;
|
||||
state.errorMessage = resolveAiChatText('error');
|
||||
return emptySendResult(state.messages);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 意向词检测算法(如“价格”, "报价", "合作", "buy", "quote", "price")
|
||||
*/
|
||||
export function hasLeadIntent(text: string): boolean {
|
||||
if (text == null || text.trim() === '') {
|
||||
return false;
|
||||
}
|
||||
const pattern = /价格|报价|多少钱|合作|联系|购买|buy|quote|price|pricing|cost|partner|cooperat|contact|order|purchase/i;
|
||||
return pattern.test(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟流式推送
|
||||
*/
|
||||
export async function sendStreamMessage(
|
||||
prompt: string,
|
||||
onChunk: (chunk: string) => void,
|
||||
onComplete: () => void,
|
||||
intervalMs: number = 20
|
||||
): Promise<void> {
|
||||
if (prompt == null || prompt.trim() === '') {
|
||||
return;
|
||||
}
|
||||
const trimmed = prompt.trim();
|
||||
const isIntent = hasLeadIntent(trimmed);
|
||||
const zh = isZhLocale();
|
||||
|
||||
let fullReply = '';
|
||||
if (isIntent) {
|
||||
fullReply = zh
|
||||
? '关于方案价格与合作权益,已为您梳理核心细节。请在下方卡片留下您的联系信息,专属顾问将在15分钟内提供完整报价。'
|
||||
: 'For pricing and partnership details, we have tailored options. Please leave your details below to receive our pricing sheet.';
|
||||
} else {
|
||||
fullReply = zh
|
||||
? '我是名片智能顾问,很高兴为您服务。我可以为您介绍名片主页、Bento微官网与出海团队能力。请随时提问。'
|
||||
: 'I am the digital concierge for this card. I can introduce the profile, Bento blocks, and our capabilities. Feel free to ask.';
|
||||
}
|
||||
|
||||
const step = 3;
|
||||
for (let i = 0; i < fullReply.length; i += step) {
|
||||
const chunk = fullReply.slice(i, i + step);
|
||||
if (intervalMs > 0) {
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, intervalMs));
|
||||
}
|
||||
onChunk(chunk);
|
||||
}
|
||||
onComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 留资卡片负载生成
|
||||
*/
|
||||
export function createLeadCardPayload(locale?: string): ChatLeadPayload {
|
||||
const loc = locale != null && locale !== '' ? locale : getCurrentLocale();
|
||||
const zh = loc.startsWith('zh');
|
||||
return {
|
||||
title: zh ? '获取专属方案与报价' : 'Get Custom Proposal & Pricing',
|
||||
description: zh
|
||||
? '留下您的称呼与联系方式(WhatsApp 或邮箱),商务团队将快速与您对接。'
|
||||
: 'Leave your contact info and our team will get in touch.',
|
||||
name: '',
|
||||
contact: '',
|
||||
submitted: false,
|
||||
submitting: false,
|
||||
errorMessage: '',
|
||||
successMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建留资卡片消息
|
||||
*/
|
||||
export function createLeadCardMessage(locale?: string): ChatMessage {
|
||||
return {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
type: 'lead_card',
|
||||
cardPayload: createLeadCardPayload(locale),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟流式对话发送
|
||||
*/
|
||||
export async function sendStreamChat(
|
||||
state: AiChatState,
|
||||
text?: string,
|
||||
options?: { intervalMs?: number }
|
||||
): Promise<boolean> {
|
||||
if (state.sending) {
|
||||
return false;
|
||||
}
|
||||
const rawText = text != null ? text : state.draft;
|
||||
const prompt = rawText != null ? rawText.trim() : '';
|
||||
if (prompt === '' || state.cardId === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
state.sending = true;
|
||||
state.draft = '';
|
||||
state.errorMessage = '';
|
||||
|
||||
// 1. 用户消息
|
||||
const userMsg: ChatMessage = {
|
||||
role: 'user',
|
||||
content: prompt,
|
||||
type: 'text',
|
||||
};
|
||||
state.messages.push(userMsg);
|
||||
|
||||
// 2. 意向检测
|
||||
const isIntent = hasLeadIntent(prompt);
|
||||
|
||||
// 3. 初始 assistant 消息
|
||||
const assistantMsg: ChatMessage = {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
type: 'text',
|
||||
};
|
||||
state.messages.push(assistantMsg);
|
||||
|
||||
// 4. 流式推送
|
||||
const intervalMs = options != null && options.intervalMs != null ? options.intervalMs : 20;
|
||||
await sendStreamMessage(
|
||||
prompt,
|
||||
(chunk: string) => {
|
||||
assistantMsg.content += chunk;
|
||||
},
|
||||
() => {},
|
||||
intervalMs
|
||||
);
|
||||
|
||||
// 5. 命中意向词时自动追加留资卡片
|
||||
if (isIntent) {
|
||||
state.messages.push(createLeadCardMessage(state.locale));
|
||||
state.showLeadHint = true;
|
||||
state.leadHint = resolveAiChatText('leadHint');
|
||||
}
|
||||
|
||||
state.sending = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
export type SubmitLeadApi = {
|
||||
submitLead: (params: SubmitLeadParams) => Promise<unknown>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 提交留资卡片线索
|
||||
*/
|
||||
export async function submitLeadCard(
|
||||
cardId: string | number,
|
||||
payload: ChatLeadPayload,
|
||||
api?: SubmitLeadApi
|
||||
): Promise<boolean> {
|
||||
if (payload == null) {
|
||||
return false;
|
||||
}
|
||||
const name = payload.name != null ? payload.name.trim() : '';
|
||||
const contact = payload.contact != null ? payload.contact.trim() : '';
|
||||
if (name === '' || contact === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
payload.submitting = true;
|
||||
payload.errorMessage = '';
|
||||
|
||||
const submitFn = api != null ? api.submitLead : submitLead;
|
||||
|
||||
try {
|
||||
const isEmail = contact.includes('@');
|
||||
const params: SubmitLeadParams = {
|
||||
cardId,
|
||||
name,
|
||||
source: 'ai_chat',
|
||||
notes: 'AI顾问留资卡片线索',
|
||||
};
|
||||
if (isEmail) {
|
||||
params.email = contact;
|
||||
} else {
|
||||
params.phone = contact;
|
||||
}
|
||||
|
||||
await submitFn(params);
|
||||
payload.submitted = true;
|
||||
payload.submitting = false;
|
||||
payload.successMessage = resolveAiChatText('submittedSuccess');
|
||||
return true;
|
||||
} catch (_e) {
|
||||
payload.submitting = false;
|
||||
payload.errorMessage = resolveAiChatText('submitFailed');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 深度洞见文章详情业务驱动层
|
||||
* 严格遵循 uts 强类型规范与 AGENTS.md 约束
|
||||
*/
|
||||
|
||||
import { BentoBlockPublic } from '../../common/types.uts';
|
||||
import { fetchPortalCard } from '../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
|
||||
|
||||
export type ArticleDetailPageOptions = {
|
||||
cardId?: string;
|
||||
blockId?: string;
|
||||
id?: string;
|
||||
};
|
||||
|
||||
export type ArticleOpenGraph = {
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
};
|
||||
|
||||
export type ArticleShareFields = {
|
||||
ctaLabel: string;
|
||||
copiedToast: string;
|
||||
shareUrl: string;
|
||||
title: string;
|
||||
description: string;
|
||||
image: string;
|
||||
};
|
||||
|
||||
export type ArticleDetailState = {
|
||||
cardId: string;
|
||||
blockId: string;
|
||||
loading: boolean;
|
||||
article: BentoBlockPublic | null;
|
||||
title: string;
|
||||
content: string;
|
||||
mediaUrl: string;
|
||||
linkUrl: string;
|
||||
isHtmlContent: boolean;
|
||||
empty: boolean;
|
||||
errorMessage: string;
|
||||
openGraph: ArticleOpenGraph;
|
||||
};
|
||||
|
||||
const SHARE_CTA_LABEL = '复制链接';
|
||||
const BACK_LABEL = '返回';
|
||||
const OG_DESC_MAX = 160;
|
||||
|
||||
/**
|
||||
* 创建文章详情初始状态
|
||||
*/
|
||||
export function createArticleDetailState(): ArticleDetailState {
|
||||
return {
|
||||
cardId: '',
|
||||
blockId: '',
|
||||
loading: false,
|
||||
article: null,
|
||||
title: '',
|
||||
content: '',
|
||||
mediaUrl: '',
|
||||
linkUrl: '',
|
||||
isHtmlContent: false,
|
||||
empty: false,
|
||||
errorMessage: '',
|
||||
openGraph: {
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将详情状态复位为空
|
||||
*/
|
||||
export function applyEmptyArticle(state: ArticleDetailState): void {
|
||||
state.article = null;
|
||||
state.title = '';
|
||||
state.content = '';
|
||||
state.mediaUrl = '';
|
||||
state.linkUrl = '';
|
||||
state.isHtmlContent = false;
|
||||
state.empty = true;
|
||||
state.openGraph = {
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 onLoad options 写入 cardId / blockId
|
||||
*/
|
||||
export function applyArticleDetailOptions(
|
||||
state: ArticleDetailState,
|
||||
options: ArticleDetailPageOptions | null
|
||||
): boolean {
|
||||
const cardIdRaw = options != null ? options.cardId || options.id || '' : '';
|
||||
const blockIdRaw = options != null ? options.blockId || '' : '';
|
||||
state.cardId = String(cardIdRaw).trim();
|
||||
state.blockId = String(blockIdRaw).trim();
|
||||
|
||||
if (state.cardId === '' || state.blockId === '') {
|
||||
applyEmptyArticle(state);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 bentoBlocks 中选出指定 article 块
|
||||
*/
|
||||
export function pickArticleBlock(
|
||||
blocks: BentoBlockPublic[] | null | undefined,
|
||||
blockId: string
|
||||
): BentoBlockPublic | null {
|
||||
if (blocks == null || !Array.isArray(blocks) || blocks.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const targetId = blockId != null ? String(blockId).trim() : '';
|
||||
if (targetId === '') {
|
||||
return null;
|
||||
}
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const block = blocks[i];
|
||||
if (block != null && String(block.id) === targetId && block.type === 'article') {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 正文是否像 HTML,供 rich-text / text 分流
|
||||
*/
|
||||
export function looksLikeHtml(content: string): boolean {
|
||||
if (content == null || content.trim() === '') {
|
||||
return false;
|
||||
}
|
||||
return /<\s*\/?\s*[a-zA-Z][^>]*>/.test(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉 HTML 标签,折叠空白
|
||||
*/
|
||||
export function stripHtmlToText(raw: string): string {
|
||||
if (raw == null || raw === '') {
|
||||
return '';
|
||||
}
|
||||
return raw.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 供后续 H5 meta 使用的 OpenGraph 三件套
|
||||
*/
|
||||
export function buildArticleOpenGraph(article: BentoBlockPublic | null): ArticleOpenGraph {
|
||||
if (article == null) {
|
||||
return {
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
};
|
||||
}
|
||||
const desc = stripHtmlToText(article.content != null ? article.content : '');
|
||||
let description = desc;
|
||||
if (description.length > OG_DESC_MAX) {
|
||||
description = description.substring(0, OG_DESC_MAX - 3) + '...';
|
||||
}
|
||||
return {
|
||||
title: article.title != null ? article.title : '',
|
||||
description,
|
||||
image: article.mediaUrl != null ? article.mediaUrl : '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享链接:优先块 linkUrl,否则当前页 URL
|
||||
*/
|
||||
export function resolveShareUrl(linkUrl: string, pageUrl: string): string {
|
||||
const fromBlock = linkUrl != null ? linkUrl.trim() : '';
|
||||
if (fromBlock !== '') {
|
||||
return fromBlock;
|
||||
}
|
||||
return pageUrl != null ? pageUrl.trim() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造当前页路径兜底
|
||||
*/
|
||||
export function buildArticlePagePath(cardId: string, blockId: string): string {
|
||||
return `/pages/portal/article-detail?cardId=${cardId}&blockId=${blockId}`;
|
||||
}
|
||||
|
||||
type UniStackPage = {
|
||||
route?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取当前页 URL:优先页面栈,否则构造本地路径
|
||||
*/
|
||||
export function getCurrentPageUrl(state: ArticleDetailState): string {
|
||||
try {
|
||||
const pages = uni.getCurrentPages();
|
||||
if (pages != null && pages.length > 0) {
|
||||
const page = pages[pages.length - 1] as UniStackPage;
|
||||
const route = page != null && page.route != null ? String(page.route) : '';
|
||||
if (route !== '') {
|
||||
const path = route.startsWith('/') ? route : `/${route}`;
|
||||
return `${path}?cardId=${state.cardId}&blockId=${state.blockId}`;
|
||||
}
|
||||
}
|
||||
} catch (_e) {}
|
||||
|
||||
return buildArticlePagePath(state.cardId, state.blockId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享文案与 OpenGraph 字段(CTA / Toast / URL / title / description / image)
|
||||
*/
|
||||
export function getArticleShareFields(
|
||||
state: ArticleDetailState,
|
||||
pageUrl: string
|
||||
): ArticleShareFields {
|
||||
const og = state.openGraph;
|
||||
return {
|
||||
ctaLabel: SHARE_CTA_LABEL,
|
||||
copiedToast: getOmniText(getCurrentLocale(), 'portal.copied_link'),
|
||||
shareUrl: resolveShareUrl(state.linkUrl, pageUrl),
|
||||
title: og.title,
|
||||
description: og.description,
|
||||
image: og.image,
|
||||
};
|
||||
}
|
||||
|
||||
export function getArticleBackLabel(): string {
|
||||
return BACK_LABEL;
|
||||
}
|
||||
|
||||
export function getArticleEmptyMessage(): string {
|
||||
return getOmniText(getCurrentLocale(), 'common.empty');
|
||||
}
|
||||
|
||||
function applyArticle(state: ArticleDetailState, article: BentoBlockPublic): void {
|
||||
state.article = article;
|
||||
state.title = article.title != null ? article.title : '';
|
||||
state.content = article.content != null ? article.content : '';
|
||||
state.mediaUrl = article.mediaUrl != null ? article.mediaUrl : '';
|
||||
state.linkUrl = article.linkUrl != null ? article.linkUrl : '';
|
||||
state.isHtmlContent = looksLikeHtml(state.content);
|
||||
state.empty = false;
|
||||
state.openGraph = buildArticleOpenGraph(article);
|
||||
}
|
||||
|
||||
/**
|
||||
* fetchPortalCard 后从 bentoBlocks 选出 article
|
||||
*/
|
||||
export async function loadArticleDetail(
|
||||
state: ArticleDetailState
|
||||
): Promise<BentoBlockPublic | null> {
|
||||
if (state.cardId === '' || state.blockId === '') {
|
||||
applyEmptyArticle(state);
|
||||
return null;
|
||||
}
|
||||
|
||||
state.loading = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
const card = await fetchPortalCard(state.cardId);
|
||||
const blocks = card != null && card.bentoBlocks != null ? card.bentoBlocks : [];
|
||||
const article = pickArticleBlock(blocks, state.blockId);
|
||||
state.loading = false;
|
||||
|
||||
if (article == null) {
|
||||
applyEmptyArticle(state);
|
||||
return null;
|
||||
}
|
||||
|
||||
applyArticle(state, article);
|
||||
return article;
|
||||
} catch (err) {
|
||||
state.loading = false;
|
||||
applyEmptyArticle(state);
|
||||
if (err instanceof Error) {
|
||||
state.errorMessage = err.message;
|
||||
} else {
|
||||
state.errorMessage = getOmniText(getCurrentLocale(), 'portal.unavailable');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主 CTA:复制 linkUrl 或当前页 URL
|
||||
*/
|
||||
export function copyArticleShareLink(state: ArticleDetailState, pageUrl?: string): boolean {
|
||||
const fallback = pageUrl != null && pageUrl !== '' ? pageUrl : getCurrentPageUrl(state);
|
||||
const shareUrl = resolveShareUrl(state.linkUrl, fallback);
|
||||
if (shareUrl === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
uni.setClipboardData({
|
||||
data: shareUrl,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_link'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 空状态返回:优先回退上一页
|
||||
*/
|
||||
export function goBackFromArticle(state: ArticleDetailState): void {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
fail: () => {
|
||||
const query = state.cardId !== '' ? `?id=${state.cardId}` : '';
|
||||
uni.reLaunch({
|
||||
url: `/pages/portal/index${query}`,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 移动微官网双语发音语音条与多媒体播放器业务驱动层
|
||||
* 遵循 uts 强类型规范与 AGENTS.md 约束,杜绝 any,无 emoji
|
||||
*/
|
||||
|
||||
export type AudioPlayerState = {
|
||||
isPlaying: boolean;
|
||||
currentDuration: number;
|
||||
currentTime: number;
|
||||
waveformActive: boolean;
|
||||
currentUrl: string;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type AudioErrorEvent = {
|
||||
errMsg?: string;
|
||||
errCode?: number;
|
||||
};
|
||||
|
||||
export type InnerAudioPlayerLike = {
|
||||
src: string;
|
||||
duration?: number;
|
||||
currentTime?: number;
|
||||
paused?: boolean;
|
||||
play: () => void;
|
||||
pause?: () => void;
|
||||
stop: () => void;
|
||||
destroy: () => void;
|
||||
onPlay: (cb: () => void) => void;
|
||||
onEnded: (cb: () => void) => void;
|
||||
onError: (cb: (err: AudioErrorEvent) => void) => void;
|
||||
onTimeUpdate?: (cb: () => void) => void;
|
||||
};
|
||||
|
||||
type UniAudioRuntime = {
|
||||
createInnerAudioContext?: () => InnerAudioPlayerLike;
|
||||
};
|
||||
|
||||
let singletonAudioContext: InnerAudioPlayerLike | null = null;
|
||||
let activePlayerState: AudioPlayerState | null = null;
|
||||
|
||||
/**
|
||||
* 创建发音播放器初始状态
|
||||
*/
|
||||
export function createAudioPlayerState(): AudioPlayerState {
|
||||
return {
|
||||
isPlaying: false,
|
||||
currentDuration: 0,
|
||||
currentTime: 0,
|
||||
waveformActive: false,
|
||||
currentUrl: '',
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取或初始化单例音频实例
|
||||
*/
|
||||
function getOrCreateAudioContext(state: AudioPlayerState): InnerAudioPlayerLike | null {
|
||||
activePlayerState = state;
|
||||
if (singletonAudioContext != null) {
|
||||
return singletonAudioContext;
|
||||
}
|
||||
|
||||
const runtime = uni as unknown as UniAudioRuntime;
|
||||
if (typeof runtime.createInnerAudioContext !== 'function') {
|
||||
state.errorMessage = '当前环境不支持音频播放';
|
||||
return null;
|
||||
}
|
||||
|
||||
const ctx = runtime.createInnerAudioContext();
|
||||
ctx.onPlay(() => {
|
||||
if (activePlayerState != null) {
|
||||
activePlayerState!.isPlaying = true;
|
||||
activePlayerState!.waveformActive = true;
|
||||
activePlayerState!.errorMessage = '';
|
||||
}
|
||||
});
|
||||
|
||||
ctx.onEnded(() => {
|
||||
if (activePlayerState != null) {
|
||||
activePlayerState!.isPlaying = false;
|
||||
activePlayerState!.waveformActive = false;
|
||||
activePlayerState!.currentTime = 0;
|
||||
}
|
||||
});
|
||||
|
||||
ctx.onError((err: AudioErrorEvent) => {
|
||||
if (activePlayerState != null) {
|
||||
activePlayerState!.isPlaying = false;
|
||||
activePlayerState!.waveformActive = false;
|
||||
activePlayerState!.errorMessage = err.errMsg != null ? err.errMsg! : '音频播放失败';
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof ctx.onTimeUpdate === 'function') {
|
||||
ctx.onTimeUpdate(() => {
|
||||
if (activePlayerState != null) {
|
||||
if (typeof ctx.currentTime === 'number') {
|
||||
activePlayerState!.currentTime = ctx.currentTime!;
|
||||
}
|
||||
if (typeof ctx.duration === 'number') {
|
||||
activePlayerState!.currentDuration = ctx.duration!;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
singletonAudioContext = ctx;
|
||||
return singletonAudioContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 播放指定音频链接
|
||||
*/
|
||||
export function playAudio(state: AudioPlayerState, audioUrl: string): boolean {
|
||||
if (audioUrl == null) {
|
||||
state.errorMessage = '音频链接不能为空';
|
||||
return false;
|
||||
}
|
||||
|
||||
const trimmed = audioUrl.trim();
|
||||
if (trimmed === '') {
|
||||
state.errorMessage = '音频链接不能为空';
|
||||
return false;
|
||||
}
|
||||
|
||||
const ctx = getOrCreateAudioContext(state);
|
||||
if (ctx == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 若当前正在播放不同音频,先停止当前音频
|
||||
if (state.isPlaying && state.currentUrl !== trimmed) {
|
||||
try {
|
||||
ctx.stop();
|
||||
} catch (_e) {}
|
||||
}
|
||||
|
||||
ctx.src = trimmed;
|
||||
ctx.play();
|
||||
state.currentUrl = trimmed;
|
||||
state.isPlaying = true;
|
||||
state.waveformActive = true;
|
||||
state.errorMessage = '';
|
||||
return true;
|
||||
} catch (err) {
|
||||
state.isPlaying = false;
|
||||
state.waveformActive = false;
|
||||
const msg = err instanceof Error ? err.message : '播放启动失败';
|
||||
state.errorMessage = msg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前播放
|
||||
*/
|
||||
export function stopAudio(state: AudioPlayerState): void {
|
||||
if (singletonAudioContext != null) {
|
||||
try {
|
||||
singletonAudioContext!.stop();
|
||||
} catch (_e) {}
|
||||
}
|
||||
state.isPlaying = false;
|
||||
state.waveformActive = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换播放/停止
|
||||
*/
|
||||
export function toggleAudio(state: AudioPlayerState, audioUrl?: string): boolean {
|
||||
const targetUrl = audioUrl != null ? audioUrl.trim() : state.currentUrl;
|
||||
if (targetUrl === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state.isPlaying && (state.currentUrl === targetUrl || audioUrl == null)) {
|
||||
stopAudio(state);
|
||||
return false;
|
||||
}
|
||||
|
||||
return playAudio(state, targetUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单例音频实例销毁释放,杜绝内存泄漏
|
||||
*/
|
||||
export function releaseAudioPlayer(state?: AudioPlayerState): void {
|
||||
if (singletonAudioContext != null) {
|
||||
try {
|
||||
singletonAudioContext!.stop();
|
||||
} catch (_e) {}
|
||||
try {
|
||||
singletonAudioContext!.destroy();
|
||||
} catch (_e) {}
|
||||
singletonAudioContext = null;
|
||||
}
|
||||
activePlayerState = null;
|
||||
|
||||
if (state != null) {
|
||||
state.isPlaying = false;
|
||||
state.waveformActive = false;
|
||||
state.currentTime = 0;
|
||||
state.currentDuration = 0;
|
||||
state.currentUrl = '';
|
||||
}
|
||||
}
|
||||
117
mpuniapp/pages/portal/useCache.uts
普通文件
117
mpuniapp/pages/portal/useCache.uts
普通文件
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 移动微官网离线 LocalStorage 极速预加载 Composable
|
||||
* 严格遵循 UTS 强类型规范与 AGENTS.md 准则
|
||||
*/
|
||||
|
||||
import { CardPortalDetail } from '../../common/types.uts';
|
||||
|
||||
export interface CachedPortalData {
|
||||
version: string;
|
||||
timestamp: number;
|
||||
ttlMs: number;
|
||||
slug: string;
|
||||
data: CardPortalDetail;
|
||||
}
|
||||
|
||||
export const PORTAL_CACHE_PREFIX = 'omni_portal_cache_';
|
||||
export const DEFAULT_PORTAL_CACHE_TTL_MS: number = 86400000;
|
||||
export const PORTAL_CACHE_VERSION = '1.0.0';
|
||||
|
||||
export function getPortalCacheKey(slug: string): string {
|
||||
return `${PORTAL_CACHE_PREFIX}${slug}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验缓存时效与完整性(默认24小时)
|
||||
*/
|
||||
export function isCacheValid(cache: CachedPortalData | null): boolean {
|
||||
if (cache == null) {
|
||||
return false;
|
||||
}
|
||||
if (cache.version !== PORTAL_CACHE_VERSION) {
|
||||
return false;
|
||||
}
|
||||
if (cache.data == null || cache.data.id == null) {
|
||||
return false;
|
||||
}
|
||||
const now = Date.now();
|
||||
const age = now - cache.timestamp;
|
||||
if (age < 0 || age > cache.ttlMs) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒级从本地 Storage 读取名片快照
|
||||
*/
|
||||
export function getCachedPortal(slug: string): CachedPortalData | null {
|
||||
if (slug == null || slug.trim() === '') {
|
||||
return null;
|
||||
}
|
||||
const key = getPortalCacheKey(slug.trim());
|
||||
try {
|
||||
const raw = uni.getStorageSync(key) as string;
|
||||
if (raw == null || raw.trim() === '') {
|
||||
return null;
|
||||
}
|
||||
const parsed = JSON.parse(raw) as CachedPortalData;
|
||||
if (parsed == null || typeof parsed !== 'object') {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
parsed.version == null ||
|
||||
parsed.timestamp == null ||
|
||||
parsed.ttlMs == null ||
|
||||
parsed.data == null ||
|
||||
parsed.data.id == null
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
return parsed;
|
||||
} catch (_e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入缓存快照带时间戳、版本与 TTL
|
||||
*/
|
||||
export function setCachedPortal(
|
||||
slug: string,
|
||||
data: CardPortalDetail,
|
||||
ttlMs?: number
|
||||
): boolean {
|
||||
if (slug == null || slug.trim() === '' || data == null || data.id == null) {
|
||||
return false;
|
||||
}
|
||||
const effectiveTtlMs =
|
||||
ttlMs != null && ttlMs > 0 ? ttlMs : DEFAULT_PORTAL_CACHE_TTL_MS;
|
||||
const cacheObj: CachedPortalData = {
|
||||
version: PORTAL_CACHE_VERSION,
|
||||
timestamp: Date.now(),
|
||||
ttlMs: effectiveTtlMs,
|
||||
slug: slug.trim(),
|
||||
data: data,
|
||||
};
|
||||
|
||||
try {
|
||||
const key = getPortalCacheKey(slug.trim());
|
||||
uni.setStorageSync(key, JSON.stringify(cacheObj));
|
||||
return true;
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定名片本地缓存
|
||||
*/
|
||||
export function clearCachedPortal(slug: string): void {
|
||||
if (slug == null || slug.trim() === '') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
uni.removeStorageSync(getPortalCacheKey(slug.trim()));
|
||||
} catch (_e) {}
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 案例作品集详情业务驱动层
|
||||
* 严格遵循 uts 强类型规范与 AGENTS.md 约束
|
||||
*/
|
||||
|
||||
import { CardPortalDetail, BentoBlockPublic } from '../../common/types.uts';
|
||||
import { fetchPortalCard } from '../../common/api.uts';
|
||||
|
||||
export type CaseKpi = {
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
type KpiLoose = {
|
||||
label?: string;
|
||||
name?: string;
|
||||
title?: string;
|
||||
value?: string | number;
|
||||
};
|
||||
|
||||
export type CaseMetaRecord = {
|
||||
images?: string[];
|
||||
kpis?: KpiLoose[];
|
||||
metrics?: KpiLoose[];
|
||||
pdfUrl?: string;
|
||||
pdf?: string;
|
||||
youtubeUrl?: string;
|
||||
youtube?: string;
|
||||
url?: string;
|
||||
type?: string;
|
||||
};
|
||||
|
||||
export type CaseDetailState = {
|
||||
cardId: string;
|
||||
blockId: string;
|
||||
loading: boolean;
|
||||
empty: boolean;
|
||||
errorMessage: string;
|
||||
title: string;
|
||||
content: string;
|
||||
images: string[];
|
||||
kpis: CaseKpi[];
|
||||
pdfUrl: string;
|
||||
youtubeUrl: string;
|
||||
};
|
||||
|
||||
export type CaseDetailPageOptions = {
|
||||
cardId?: string;
|
||||
blockId?: string;
|
||||
id?: string;
|
||||
};
|
||||
|
||||
export const CASE_DETAIL_COPY = {
|
||||
empty: '未找到该案例',
|
||||
back: '返回',
|
||||
cta: '咨询 / 互换',
|
||||
pdf: 'PDF',
|
||||
youtube: 'YouTube',
|
||||
loading: '加载中',
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建案例详情初始状态
|
||||
*/
|
||||
export function createCaseDetailState(): CaseDetailState {
|
||||
return {
|
||||
cardId: '',
|
||||
blockId: '',
|
||||
loading: false,
|
||||
empty: false,
|
||||
errorMessage: '',
|
||||
title: '',
|
||||
content: '',
|
||||
images: [],
|
||||
kpis: [],
|
||||
pdfUrl: '',
|
||||
youtubeUrl: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 onLoad options 读取 cardId / blockId
|
||||
*/
|
||||
export function applyCaseDetailOptions(
|
||||
state: CaseDetailState,
|
||||
options: CaseDetailPageOptions | null
|
||||
): boolean {
|
||||
const cardIdRaw = options != null ? options.cardId || options.id || '' : '';
|
||||
const blockIdRaw = options != null ? options.blockId || '' : '';
|
||||
state.cardId = String(cardIdRaw).trim();
|
||||
state.blockId = String(blockIdRaw).trim();
|
||||
return state.cardId !== '' && state.blockId !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 从门户聚合数据中选出 id 匹配且 type 为 case 的块;缺块返回 null
|
||||
*/
|
||||
export function pickCaseBlock(
|
||||
card: CardPortalDetail | null,
|
||||
blockId: string
|
||||
): BentoBlockPublic | null {
|
||||
if (card == null || card.bentoBlocks == null || blockId === '') {
|
||||
return null;
|
||||
}
|
||||
const target = String(blockId);
|
||||
const blocks = card.bentoBlocks;
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const block = blocks[i];
|
||||
if (String(block.id) === target && block.type === 'case') {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析 metaJson(字符串或对象)
|
||||
*/
|
||||
export function parseCaseMetaJson(raw: string | object | null | undefined): CaseMetaRecord {
|
||||
if (raw == null) {
|
||||
return {};
|
||||
}
|
||||
if (typeof raw === 'string') {
|
||||
const trimmed = raw.trim();
|
||||
if (trimmed === '') {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(trimmed) as CaseMetaRecord;
|
||||
} catch (_e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return raw as CaseMetaRecord;
|
||||
}
|
||||
|
||||
function readTrimmed(value: string | undefined): string {
|
||||
return value != null ? String(value).trim() : '';
|
||||
}
|
||||
|
||||
function normalizeKpis(items: KpiLoose[] | undefined): CaseKpi[] {
|
||||
if (items == null || !Array.isArray(items)) {
|
||||
return [];
|
||||
}
|
||||
const result: CaseKpi[] = [];
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
const label = readTrimmed(item.label) || readTrimmed(item.name) || readTrimmed(item.title);
|
||||
const value = item.value != null ? String(item.value).trim() : '';
|
||||
if (label === '' && value === '') {
|
||||
continue;
|
||||
}
|
||||
result.push({
|
||||
label: label !== '' ? label : value,
|
||||
value: value !== '' ? value : label,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function collectImages(mediaUrl: string, meta: CaseMetaRecord): string[] {
|
||||
const result: string[] = [];
|
||||
if (meta.images != null && Array.isArray(meta.images)) {
|
||||
for (let i = 0; i < meta.images.length; i++) {
|
||||
const src = String(meta.images[i]).trim();
|
||||
if (src !== '') {
|
||||
result.push(src);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.length === 0 && mediaUrl !== '') {
|
||||
result.push(mediaUrl);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function resolvePdfUrl(meta: CaseMetaRecord): string {
|
||||
const pdfUrl = readTrimmed(meta.pdfUrl);
|
||||
if (pdfUrl !== '') {
|
||||
return pdfUrl;
|
||||
}
|
||||
const pdf = readTrimmed(meta.pdf);
|
||||
if (pdf !== '') {
|
||||
return pdf;
|
||||
}
|
||||
const url = readTrimmed(meta.url);
|
||||
const kind = readTrimmed(meta.type).toLowerCase();
|
||||
if (url !== '' && (kind === 'pdf' || url.toLowerCase().indexOf('.pdf') >= 0)) {
|
||||
return url;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function resolveYoutubeUrl(meta: CaseMetaRecord): string {
|
||||
const youtubeUrl = readTrimmed(meta.youtubeUrl);
|
||||
if (youtubeUrl !== '') {
|
||||
return youtubeUrl;
|
||||
}
|
||||
const youtube = readTrimmed(meta.youtube);
|
||||
if (youtube !== '') {
|
||||
return youtube;
|
||||
}
|
||||
const url = readTrimmed(meta.url);
|
||||
const kind = readTrimmed(meta.type).toLowerCase();
|
||||
const lower = url.toLowerCase();
|
||||
if (
|
||||
url !== '' &&
|
||||
(kind === 'youtube' || lower.indexOf('youtube.com') >= 0 || lower.indexOf('youtu.be') >= 0)
|
||||
) {
|
||||
return url;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function clearCaseContent(state: CaseDetailState): void {
|
||||
state.title = '';
|
||||
state.content = '';
|
||||
state.images = [];
|
||||
state.kpis = [];
|
||||
state.pdfUrl = '';
|
||||
state.youtubeUrl = '';
|
||||
}
|
||||
|
||||
function applyEmpty(state: CaseDetailState): void {
|
||||
state.loading = false;
|
||||
state.empty = true;
|
||||
clearCaseContent(state);
|
||||
}
|
||||
|
||||
function fillFromBlock(state: CaseDetailState, block: BentoBlockPublic): void {
|
||||
const meta = parseCaseMetaJson(block.metaJson);
|
||||
const mediaUrl = block.mediaUrl != null ? block.mediaUrl.trim() : '';
|
||||
state.empty = false;
|
||||
state.loading = false;
|
||||
state.errorMessage = '';
|
||||
state.title = block.title != null ? block.title : '';
|
||||
state.content = block.content != null ? block.content : '';
|
||||
state.images = collectImages(mediaUrl, meta);
|
||||
const kpis = normalizeKpis(meta.kpis);
|
||||
state.kpis = kpis.length > 0 ? kpis : normalizeKpis(meta.metrics);
|
||||
state.pdfUrl = resolvePdfUrl(meta);
|
||||
state.youtubeUrl = resolveYoutubeUrl(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用已拉取的门户数据填充案例详情;缺块返空
|
||||
*/
|
||||
export function applyPortalCase(
|
||||
state: CaseDetailState,
|
||||
card: CardPortalDetail | null
|
||||
): boolean {
|
||||
const block = pickCaseBlock(card, state.blockId);
|
||||
if (block == null) {
|
||||
applyEmpty(state);
|
||||
return false;
|
||||
}
|
||||
fillFromBlock(state, block);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取门户聚合详情并选出 case 块
|
||||
*/
|
||||
export async function loadCaseDetail(state: CaseDetailState): Promise<boolean> {
|
||||
if (state.cardId === '' || state.blockId === '') {
|
||||
applyEmpty(state);
|
||||
return false;
|
||||
}
|
||||
|
||||
state.loading = true;
|
||||
state.empty = false;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
const card = await fetchPortalCard(state.cardId);
|
||||
return applyPortalCase(state, card);
|
||||
} catch (err) {
|
||||
applyEmpty(state);
|
||||
if (err instanceof Error) {
|
||||
state.errorMessage = err.message;
|
||||
} else {
|
||||
state.errorMessage = '获取案例详情失败';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 咨询 / 互换页路径
|
||||
*/
|
||||
export function buildExchangePath(cardId: string): string {
|
||||
return `/pages/portal/exchange?cardId=${cardId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 跳转无摩擦互换名片
|
||||
*/
|
||||
export function openCaseExchange(cardId: string): void {
|
||||
const id = cardId != null ? cardId.trim() : '';
|
||||
if (id === '') {
|
||||
return;
|
||||
}
|
||||
uni.navigateTo({
|
||||
url: buildExchangePath(id),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 空状态返回上一页
|
||||
*/
|
||||
export function goCaseBack(): void {
|
||||
uni.navigateBack();
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 无摩擦互换名片留资业务驱动层
|
||||
* 严格遵循 uts 强类型规范与 AGENTS.md 约束
|
||||
*/
|
||||
|
||||
import { LeadEntity, SubmitLeadParams } from '../../common/types.uts';
|
||||
import { submitLead } from '../../common/api.uts';
|
||||
|
||||
export type ExchangeForm = {
|
||||
name: string;
|
||||
company: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
notes: string;
|
||||
};
|
||||
|
||||
export type ExchangeState = {
|
||||
form: ExchangeForm;
|
||||
cardId: string;
|
||||
slug: string;
|
||||
submitting: boolean;
|
||||
canSubmit: boolean;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type ExchangePageOptions = {
|
||||
cardId?: string;
|
||||
slug?: string;
|
||||
id?: string;
|
||||
};
|
||||
|
||||
const VISITOR_STORAGE_KEY = 'omni_visitor_id';
|
||||
|
||||
/**
|
||||
* 读取本地已有访客标识,不在本页新建
|
||||
*/
|
||||
function readVisitorId(): string {
|
||||
try {
|
||||
const val = uni.getStorageSync(VISITOR_STORAGE_KEY);
|
||||
return val != null ? String(val) : '';
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建互换名片表单初始状态
|
||||
*/
|
||||
export function createExchangeState(): ExchangeState {
|
||||
return {
|
||||
form: {
|
||||
name: '',
|
||||
company: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
notes: '',
|
||||
},
|
||||
cardId: '',
|
||||
slug: '',
|
||||
submitting: false,
|
||||
canSubmit: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析提交用的名片标识:优先 cardId,其次 slug
|
||||
*/
|
||||
export function resolveExchangeCardId(state: ExchangeState): string {
|
||||
if (state.cardId && state.cardId.trim() !== '') {
|
||||
return state.cardId.trim();
|
||||
}
|
||||
if (state.slug && state.slug.trim() !== '') {
|
||||
return state.slug.trim();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 从页面 onLoad options 写入名片标识
|
||||
* 缺少 cardId 与 slug 时 toast 并禁止提交
|
||||
*/
|
||||
export function applyExchangeOptions(
|
||||
state: ExchangeState,
|
||||
options: ExchangePageOptions | null
|
||||
): boolean {
|
||||
const cardIdRaw = options != null ? options.cardId || options.id || '' : '';
|
||||
const slugRaw = options != null ? options.slug || '' : '';
|
||||
state.cardId = String(cardIdRaw).trim();
|
||||
state.slug = String(slugRaw).trim();
|
||||
state.canSubmit = resolveExchangeCardId(state) !== '';
|
||||
|
||||
if (!state.canSubmit) {
|
||||
uni.showToast({
|
||||
title: '缺少名片标识,无法提交',
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
return state.canSubmit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验姓名 + (WhatsApp/phone 或 email)
|
||||
* 通过返回空字符串
|
||||
*/
|
||||
export function validateExchangeForm(form: ExchangeForm): string {
|
||||
const name = form.name ? form.name.trim() : '';
|
||||
if (name === '') {
|
||||
return '请填写姓名';
|
||||
}
|
||||
|
||||
const phone = form.phone ? form.phone.trim() : '';
|
||||
const email = form.email ? form.email.trim() : '';
|
||||
if (phone === '' && email === '') {
|
||||
return '请填写 WhatsApp 或邮箱';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空表单字段,保留名片标识
|
||||
*/
|
||||
export function resetExchangeForm(state: ExchangeState): void {
|
||||
state.form.name = '';
|
||||
state.form.company = '';
|
||||
state.form.phone = '';
|
||||
state.form.email = '';
|
||||
state.form.notes = '';
|
||||
state.errorMessage = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交留资:校验通过后调用已有 submitLead
|
||||
*/
|
||||
export async function submitExchange(state: ExchangeState): Promise<LeadEntity | null> {
|
||||
const cardId = resolveExchangeCardId(state);
|
||||
if (!state.canSubmit || cardId === '') {
|
||||
uni.showToast({
|
||||
title: '缺少名片标识,无法提交',
|
||||
icon: 'none',
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const invalidReason = validateExchangeForm(state.form);
|
||||
if (invalidReason !== '') {
|
||||
uni.showToast({
|
||||
title: invalidReason,
|
||||
icon: 'none',
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (state.submitting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const name = state.form.name.trim();
|
||||
const company = state.form.company.trim();
|
||||
const phone = state.form.phone.trim();
|
||||
const email = state.form.email.trim();
|
||||
const notes = state.form.notes.trim();
|
||||
const visitorId = readVisitorId();
|
||||
|
||||
const payload: SubmitLeadParams = {
|
||||
cardId,
|
||||
name,
|
||||
};
|
||||
if (company !== '') {
|
||||
payload.company = company;
|
||||
}
|
||||
if (phone !== '') {
|
||||
payload.phone = phone;
|
||||
}
|
||||
if (email !== '') {
|
||||
payload.email = email;
|
||||
}
|
||||
if (notes !== '') {
|
||||
payload.notes = notes;
|
||||
}
|
||||
if (visitorId !== '') {
|
||||
payload.visitorId = visitorId;
|
||||
}
|
||||
payload.source = 'link';
|
||||
|
||||
state.submitting = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
const lead = await submitLead(payload);
|
||||
state.submitting = false;
|
||||
resetExchangeForm(state);
|
||||
uni.showToast({
|
||||
title: '留资已提交',
|
||||
icon: 'none',
|
||||
});
|
||||
return lead;
|
||||
} catch (err) {
|
||||
state.submitting = false;
|
||||
if (err instanceof Error) {
|
||||
state.errorMessage = err.message;
|
||||
} else {
|
||||
state.errorMessage = '提交留资失败';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,94 @@ import {
|
||||
fetchPortalCard,
|
||||
recordRadarTrack,
|
||||
} from '../../common/api.uts';
|
||||
import { OmniLocale, getCurrentLocale, getOmniText } from '../../common/locale.uts';
|
||||
import {
|
||||
getCachedPortal,
|
||||
setCachedPortal,
|
||||
isCacheValid,
|
||||
CachedPortalData,
|
||||
} from './useCache.uts';
|
||||
|
||||
export const PORTAL_LOCALE_STORAGE_KEY = 'omni_locale';
|
||||
|
||||
type PortalCardWithSuggested = CardPortalDetail & {
|
||||
suggestedLocale?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 门户合法语言:zh-CN / en-US / ar-SA / es-ES / de-DE / fr-FR / ja-JP
|
||||
*/
|
||||
export function parsePortalLocale(raw: string): OmniLocale | null {
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
const code = raw.trim();
|
||||
if (
|
||||
code === 'zh-CN' ||
|
||||
code === 'en-US' ||
|
||||
code === 'ar-SA' ||
|
||||
code === 'es-ES' ||
|
||||
code === 'de-DE' ||
|
||||
code === 'fr-FR' ||
|
||||
code === 'ja-JP'
|
||||
) {
|
||||
return code;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进入页优先级:query.lang > storage > suggestedLocale > fallback(detectLocale)
|
||||
*/
|
||||
export function resolvePortalLocale(
|
||||
queryLang: string,
|
||||
stored: string,
|
||||
suggested: string,
|
||||
fallback: OmniLocale
|
||||
): OmniLocale {
|
||||
const fromQuery = parsePortalLocale(queryLang);
|
||||
if (fromQuery != null) {
|
||||
return fromQuery;
|
||||
}
|
||||
const fromStored = parsePortalLocale(stored);
|
||||
if (fromStored != null) {
|
||||
return fromStored;
|
||||
}
|
||||
const fromSuggested = parsePortalLocale(suggested);
|
||||
if (fromSuggested != null) {
|
||||
return fromSuggested;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function readStoredPortalLocale(): string {
|
||||
try {
|
||||
const stored = uni.getStorageSync(PORTAL_LOCALE_STORAGE_KEY) as string;
|
||||
if (stored == null) {
|
||||
return '';
|
||||
}
|
||||
return stored;
|
||||
} catch (_e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export function persistPortalLocale(code: OmniLocale): void {
|
||||
try {
|
||||
uni.setStorageSync(PORTAL_LOCALE_STORAGE_KEY, code);
|
||||
} catch (_e) {}
|
||||
}
|
||||
|
||||
export function readCardSuggestedLocale(card: CardPortalDetail | null): string {
|
||||
if (card == null) {
|
||||
return '';
|
||||
}
|
||||
const extra = card as PortalCardWithSuggested;
|
||||
if (extra.suggestedLocale == null) {
|
||||
return '';
|
||||
}
|
||||
return extra.suggestedLocale;
|
||||
}
|
||||
|
||||
export type PortalState = {
|
||||
card: CardPortalDetail | null;
|
||||
@@ -64,41 +152,66 @@ export function createPortalState(): PortalState {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载微官网名片聚合数据并上报首次触碰
|
||||
* 加载微官网名片聚合数据并上报首次触碰 (支持离线 LocalStorage 极速预加载与静默更新)
|
||||
*/
|
||||
export async function loadCardPortal(
|
||||
state: PortalState,
|
||||
cardIdOrSlug: string,
|
||||
source: string = 'link'
|
||||
): Promise<CardPortalDetail | null> {
|
||||
state.loading = true;
|
||||
state.errorMessage = '';
|
||||
state.touchType = source;
|
||||
state.enterTime = Date.now();
|
||||
|
||||
// 1. 优先尝试秒级读取本地缓存快照,实现首屏 0ms 呈现
|
||||
const cached: CachedPortalData | null = getCachedPortal(cardIdOrSlug);
|
||||
let hasValidCache = false;
|
||||
if (cached != null && isCacheValid(cached)) {
|
||||
state.card = cached.data;
|
||||
state.loading = false;
|
||||
hasValidCache = true;
|
||||
} else {
|
||||
state.loading = true;
|
||||
}
|
||||
|
||||
try {
|
||||
const cardData = await fetchPortalCard(cardIdOrSlug);
|
||||
state.card = cardData;
|
||||
const networkCardData = await fetchPortalCard(cardIdOrSlug);
|
||||
if (networkCardData != null) {
|
||||
state.card = networkCardData;
|
||||
// 静默将最新名片快照持久化至本地
|
||||
setCachedPortal(cardIdOrSlug, networkCardData);
|
||||
if (networkCardData.slug != null && networkCardData.slug !== cardIdOrSlug) {
|
||||
setCachedPortal(networkCardData.slug!, networkCardData);
|
||||
}
|
||||
}
|
||||
state.loading = false;
|
||||
|
||||
// 首次载入成功后上报雷达初次触碰轨迹
|
||||
if (cardData && cardData.id) {
|
||||
// 载入成功后上报雷达初次触碰轨迹
|
||||
if (state.card != null && state.card!.id != null) {
|
||||
recordRadarTrack({
|
||||
cardId: cardData.id,
|
||||
cardId: state.card!.id,
|
||||
visitorId: state.visitorId,
|
||||
touchType: state.touchType,
|
||||
stayDurationMs: 0,
|
||||
scrollDepth: 0,
|
||||
}).catch((_e: any) => {
|
||||
}).catch((_e: unknown) => {
|
||||
// 轨迹上报容错,不阻断主流程
|
||||
});
|
||||
}
|
||||
|
||||
return cardData;
|
||||
} catch (err: any) {
|
||||
return state.card;
|
||||
} catch (err: unknown) {
|
||||
state.loading = false;
|
||||
if (hasValidCache) {
|
||||
// 命中有效缓存时弱网/异常平滑降级,维持缓存内容展示,避免阻断性白屏
|
||||
return state.card;
|
||||
}
|
||||
state.card = null;
|
||||
state.errorMessage = err?.message || '获取名片微官网详情失败';
|
||||
const msg =
|
||||
err != null && typeof err === 'object' && 'message' in err
|
||||
? String((err as { message: unknown }).message)
|
||||
: '获取名片微官网详情失败';
|
||||
state.errorMessage = msg;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -170,13 +283,22 @@ export function toggleAudioPronunciation(state: PortalState, audioUrl?: string):
|
||||
/**
|
||||
* 快捷动作条呼出处理
|
||||
*/
|
||||
export type PortalQuickAction =
|
||||
| 'whatsapp'
|
||||
| 'linkedin'
|
||||
| 'email'
|
||||
| 'phone'
|
||||
| 'telegram'
|
||||
| 'twitter'
|
||||
| 'wechat';
|
||||
|
||||
export function triggerQuickAction(
|
||||
type: 'whatsapp' | 'linkedin' | 'email' | 'phone',
|
||||
type: PortalQuickAction,
|
||||
value?: string
|
||||
): boolean {
|
||||
if (!value || value.trim() === '') {
|
||||
uni.showToast({
|
||||
title: '未设置该联系方式',
|
||||
title: getOmniText(getCurrentLocale(), 'portal.contact_unset'),
|
||||
icon: 'none',
|
||||
});
|
||||
return false;
|
||||
@@ -196,7 +318,7 @@ export function triggerQuickAction(
|
||||
data: waUrl,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '已复制 WhatsApp 链接',
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_whatsapp'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
@@ -209,7 +331,7 @@ export function triggerQuickAction(
|
||||
data: value,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '已复制 LinkedIn 链接',
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_linkedin'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
@@ -222,7 +344,49 @@ export function triggerQuickAction(
|
||||
data: value,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '已复制邮箱地址',
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_email'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type === 'telegram') {
|
||||
const raw = value.trim();
|
||||
const handle = raw.replace(/^@+/, '');
|
||||
const link = /https?:\/\//i.test(raw) ? raw : `https://t.me/${handle}`;
|
||||
uni.setClipboardData({
|
||||
data: link,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_telegram'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type === 'twitter') {
|
||||
uni.setClipboardData({
|
||||
data: value,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_twitter'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
if (type === 'wechat') {
|
||||
uni.setClipboardData({
|
||||
data: value,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: getOmniText(getCurrentLocale(), 'portal.copied_wechat'),
|
||||
icon: 'none',
|
||||
});
|
||||
},
|
||||
|
||||
在新工单中引用
屏蔽一个用户