feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -96,7 +96,7 @@
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.title"
|
||||
placeholder="例如:2026 全球智能硬件合规白皮书"
|
||||
:placeholder="t('phTitle')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.summary"
|
||||
placeholder="若不填写将自动从正文中提取摘要..."
|
||||
:placeholder="t('phSummary')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="editForm.content"
|
||||
placeholder="输入正文内容,支持段落与 Markdown..."
|
||||
:placeholder="t('phContent')"
|
||||
maxlength="2000"
|
||||
></textarea>
|
||||
</view>
|
||||
@@ -136,7 +136,7 @@
|
||||
<view class="form-field-switch">
|
||||
<view class="switch-info">
|
||||
<text class="switch-title">{{ t('fieldPublish') }}</text>
|
||||
<text class="switch-desc">{{ publishDescText }}</text>
|
||||
<text class="switch-desc">{{ t('publishDesc') }}</text>
|
||||
</view>
|
||||
<switch
|
||||
:checked="editForm.isPublished"
|
||||
@@ -157,7 +157,7 @@
|
||||
:disabled="state.saving"
|
||||
@click="handleSave"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ state.saving ? savingText : t('saveBtn') }}</text>
|
||||
<text class="primary-cta-btn-text">{{ state.saving ? t('saving') : t('saveBtn') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -201,16 +201,6 @@ const pageRtlClass = computed<string>(() => {
|
||||
return isRtl(getCurrentLocale()) ? 'page-rtl' : '';
|
||||
});
|
||||
|
||||
const publishDescText = computed<string>(() => {
|
||||
return getCurrentLocale() === 'zh-CN'
|
||||
? '开启后,全球访客可在您的名片微官网中直接浏览'
|
||||
: 'When enabled, visitors can view this insight on your micro-site';
|
||||
});
|
||||
|
||||
const savingText = computed<string>(() => {
|
||||
return getCurrentLocale() === 'zh-CN' ? '保存中...' : 'Saving...';
|
||||
});
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-gradient': utsLightColors.primaryGradient,
|
||||
@@ -281,7 +271,7 @@ async function handleToggleStatus(item: CardArticle): Promise<void> {
|
||||
const ok = await toggleArticlePublish(state, item);
|
||||
if (ok) {
|
||||
uni.showToast({
|
||||
title: getCurrentLocale() === 'zh-CN' ? '状态已切换' : 'Status Updated',
|
||||
title: t('statusUpdatedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
@@ -291,7 +281,7 @@ async function handleSave(): Promise<void> {
|
||||
const success = await saveArticle(state, editForm);
|
||||
if (success) {
|
||||
uni.showToast({
|
||||
title: getCurrentLocale() === 'zh-CN' ? '动态已保存' : 'Article Saved',
|
||||
title: t('savedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
} else if (state.errorMessage !== '') {
|
||||
@@ -302,20 +292,19 @@ async function handleSave(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(item: CardArticle): void {
|
||||
async function handleDelete(item: CardArticle): Promise<void> {
|
||||
if (item.id == null) return;
|
||||
const zh = getCurrentLocale() === 'zh-CN';
|
||||
uni.showModal({
|
||||
title: zh ? '确认删除' : 'Confirm Delete',
|
||||
content: zh ? '确定要删除该文章动态吗?' : 'Are you sure you want to delete this article?',
|
||||
confirmText: zh ? '删除' : 'Delete',
|
||||
cancelText: zh ? '取消' : 'Cancel',
|
||||
title: t('deleteConfirmTitle'),
|
||||
content: t('deleteConfirmContent'),
|
||||
confirmText: t('deleteConfirmOk'),
|
||||
cancelText: t('cancelBtn'),
|
||||
success: async (res: any) => {
|
||||
if (res.confirm) {
|
||||
const ok = await deleteArticle(state, item.id!);
|
||||
if (ok) {
|
||||
uni.showToast({
|
||||
title: zh ? '已删除' : 'Deleted',
|
||||
title: t('deletedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
:src="item.coverImage!"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="case-item-cover-placeholder">
|
||||
<text class="placeholder-text">{{ placeholderCoverText }}</text>
|
||||
<view v-else class="case-item-cover-placeholder">
|
||||
<text class="placeholder-text">{{ t('coverPlaceholder') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="case-item-body">
|
||||
@@ -49,7 +49,7 @@
|
||||
</view>
|
||||
|
||||
<view v-if="item.client != null && item.client !== ''" class="case-item-meta">
|
||||
<text class="case-meta-label">{{ clientPrefixText }}</text>
|
||||
<text class="case-meta-label">{{ t('clientPrefix') }}</text>
|
||||
<text class="case-meta-value">{{ item.client }}</text>
|
||||
</view>
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.title"
|
||||
placeholder="例如:全球智能硬件数字化交付方案"
|
||||
:placeholder="t('phTitle')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.client"
|
||||
placeholder="例如:阿联酋国际商业联合会"
|
||||
:placeholder="t('phClient')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -120,29 +120,18 @@
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.duration"
|
||||
placeholder="例如:2025.06 - 2025.12"
|
||||
:placeholder="t('phDuration')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 量化成效标签快捷选择 -->
|
||||
<!-- 成效标签(用户自填,禁止预填假 KPI) -->
|
||||
<view class="form-field">
|
||||
<text class="form-label">{{ t('fieldMetrics') }}</text>
|
||||
<view class="metrics-pill-group">
|
||||
<view
|
||||
v-for="metric in PRESET_CASE_METRICS"
|
||||
:key="metric"
|
||||
class="preset-metric-pill"
|
||||
:class="{ 'preset-metric-pill-active': editForm.metrics === metric }"
|
||||
@click="handleSelectMetric(metric)"
|
||||
>
|
||||
<text class="preset-metric-text">{{ metric }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<input
|
||||
class="form-input"
|
||||
type="text"
|
||||
v-model="editForm.metrics"
|
||||
placeholder="或自定义输入成效,如:触达 10,000+ 买家"
|
||||
:placeholder="t('phMetrics')"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -162,7 +151,7 @@
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="editForm.description"
|
||||
placeholder="简述方案背景、关键成效或客户反馈..."
|
||||
:placeholder="t('phDesc')"
|
||||
maxlength="500"
|
||||
></textarea>
|
||||
</view>
|
||||
@@ -179,7 +168,7 @@
|
||||
:disabled="state.saving"
|
||||
@click="handleSave"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ state.saving ? savingText : t('saveBtn') }}</text>
|
||||
<text class="primary-cta-btn-text">{{ state.saving ? t('saving') : t('saveBtn') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -194,7 +183,6 @@ import {
|
||||
loadCases,
|
||||
saveCase,
|
||||
deleteCase,
|
||||
PRESET_CASE_METRICS,
|
||||
resolveCasesText,
|
||||
CasesCopyKey,
|
||||
} from './useCardCases.uts';
|
||||
@@ -224,18 +212,6 @@ const pageRtlClass = computed<string>(() => {
|
||||
return isRtl(getCurrentLocale()) ? 'page-rtl' : '';
|
||||
});
|
||||
|
||||
const clientPrefixText = computed<string>(() => {
|
||||
return getCurrentLocale() === 'zh-CN' ? '合作客户: ' : 'Client: ';
|
||||
});
|
||||
|
||||
const placeholderCoverText = computed<string>(() => {
|
||||
return getCurrentLocale() === 'zh-CN' ? '产品展示' : 'Showcase';
|
||||
});
|
||||
|
||||
const savingText = computed<string>(() => {
|
||||
return getCurrentLocale() === 'zh-CN' ? '保存中...' : 'Saving...';
|
||||
});
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-gradient': utsLightColors.primaryGradient,
|
||||
@@ -291,10 +267,6 @@ function handleCloseDrawer(): void {
|
||||
state.drawerVisible = false;
|
||||
}
|
||||
|
||||
function handleSelectMetric(val: string): void {
|
||||
editForm.metrics = val;
|
||||
}
|
||||
|
||||
function handleImagesChange(imgs: string[]): void {
|
||||
uploadedImages.value = imgs;
|
||||
if (imgs.length > 0) {
|
||||
@@ -308,7 +280,7 @@ async function handleSave(): Promise<void> {
|
||||
const success = await saveCase(state, editForm);
|
||||
if (success) {
|
||||
uni.showToast({
|
||||
title: getCurrentLocale() === 'zh-CN' ? '案例已保存' : 'Case Saved',
|
||||
title: t('savedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
} else if (state.errorMessage !== '') {
|
||||
@@ -319,20 +291,19 @@ async function handleSave(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(item: CardCase): void {
|
||||
async function handleDelete(item: CardCase): Promise<void> {
|
||||
if (item.id == null) return;
|
||||
const zh = getCurrentLocale() === 'zh-CN';
|
||||
uni.showModal({
|
||||
title: zh ? '确认删除' : 'Confirm Delete',
|
||||
content: zh ? '确定要删除该案例吗?此操作无法撤销。' : 'Are you sure you want to delete this case?',
|
||||
confirmText: zh ? '删除' : 'Delete',
|
||||
cancelText: zh ? '取消' : 'Cancel',
|
||||
title: t('deleteConfirmTitle'),
|
||||
content: t('deleteConfirmContent'),
|
||||
confirmText: t('deleteConfirmOk'),
|
||||
cancelText: t('cancelBtn'),
|
||||
success: async (res: any) => {
|
||||
if (res.confirm) {
|
||||
const ok = await deleteCase(state, item.id!);
|
||||
if (ok) {
|
||||
uni.showToast({
|
||||
title: zh ? '已删除' : 'Deleted',
|
||||
title: t('deletedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
@@ -711,32 +682,6 @@ onLoad((options: any) => {
|
||||
height: 90px;
|
||||
}
|
||||
|
||||
.metrics-pill-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.preset-metric-pill {
|
||||
background-color: var(--oc-bg);
|
||||
border: 1px solid var(--oc-border);
|
||||
padding: 6px 12px;
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.preset-metric-pill-active {
|
||||
background-color: var(--oc-primary-soft);
|
||||
border-color: var(--oc-primary);
|
||||
}
|
||||
|
||||
.preset-metric-text {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--oc-text);
|
||||
}
|
||||
|
||||
.drawer-action-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@@ -55,13 +55,32 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="modules-stack">
|
||||
<!-- Module 1: Basic Profile -->
|
||||
<view class="module-card">
|
||||
<view class="module-card" :style="moduleCardStyle('basic')">
|
||||
<view class="module-card-header">
|
||||
<view class="module-title-wrap">
|
||||
<view class="module-indicator"></view>
|
||||
<text class="module-title">{{ t('basicSection') }}</text>
|
||||
</view>
|
||||
<view class="module-order-actions">
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('basic', -1)"
|
||||
:aria-label="t('moveUp')"
|
||||
@click="handleMoveModule('basic', -1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveUp') }}</text>
|
||||
</button>
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('basic', 1)"
|
||||
:aria-label="t('moveDown')"
|
||||
@click="handleMoveModule('basic', 1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveDown') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Avatar Uploader Stage -->
|
||||
@@ -127,27 +146,71 @@
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field field-last">
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('company') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
:class="{ 'field-input-locked': companyLocked }"
|
||||
type="text"
|
||||
v-model="state.company"
|
||||
:placeholder="t('company')"
|
||||
:disabled="state.saving || companyLocked"
|
||||
/>
|
||||
<text v-if="companyLocked" class="field-lock-hint">{{ t('lockedHint') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('slogan') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
:class="{ 'field-input-locked': sloganLocked }"
|
||||
type="text"
|
||||
v-model="state.slogan"
|
||||
:placeholder="t('slogan')"
|
||||
:disabled="state.saving || sloganLocked"
|
||||
/>
|
||||
<text v-if="sloganLocked" class="field-lock-hint">{{ t('lockedHint') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="field field-last">
|
||||
<text class="field-label">{{ t('timezone') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="text"
|
||||
v-model="state.timezone"
|
||||
:placeholder="t('timezone')"
|
||||
:disabled="state.saving"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Module 2: Social Matrix -->
|
||||
<view class="module-card">
|
||||
<view class="module-card" :style="moduleCardStyle('social')">
|
||||
<view class="module-card-header">
|
||||
<view class="module-title-wrap">
|
||||
<view class="module-indicator"></view>
|
||||
<text class="module-title">{{ t('socialSection') }}</text>
|
||||
</view>
|
||||
<text class="module-subtitle">{{ t('socialSectionDesc') }}</text>
|
||||
<view class="module-order-actions">
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('social', -1)"
|
||||
:aria-label="t('moveUp')"
|
||||
@click="handleMoveModule('social', -1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveUp') }}</text>
|
||||
</button>
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('social', 1)"
|
||||
:aria-label="t('moveDown')"
|
||||
@click="handleMoveModule('social', 1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveDown') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<text class="module-subtitle module-subtitle-block">{{ t('socialSectionDesc') }}</text>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('phone') }}</text>
|
||||
@@ -195,16 +258,34 @@
|
||||
</view>
|
||||
|
||||
<!-- Module 3: Privacy & Visibility -->
|
||||
<view class="module-card">
|
||||
<view class="module-card" :style="moduleCardStyle('privacy')">
|
||||
<view class="module-card-header">
|
||||
<view class="module-title-wrap">
|
||||
<view class="module-indicator"></view>
|
||||
<text class="module-title">{{ t('privacySection') }}</text>
|
||||
</view>
|
||||
<view class="gdpr-pill">
|
||||
<text class="gdpr-pill-text">{{ t('gdprBadge') }}</text>
|
||||
<view class="module-order-actions">
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('privacy', -1)"
|
||||
:aria-label="t('moveUp')"
|
||||
@click="handleMoveModule('privacy', -1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveUp') }}</text>
|
||||
</button>
|
||||
<button
|
||||
class="module-order-btn"
|
||||
:disabled="state.saving || !canMoveModule('privacy', 1)"
|
||||
:aria-label="t('moveDown')"
|
||||
@click="handleMoveModule('privacy', 1)"
|
||||
>
|
||||
<text class="module-order-btn-text">{{ t('moveDown') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<view class="gdpr-pill gdpr-pill-inline">
|
||||
<text class="gdpr-pill-text">{{ t('gdprBadge') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- Visibility Options -->
|
||||
<view class="privacy-options-group">
|
||||
@@ -274,6 +355,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Error Alert Banner -->
|
||||
<view v-if="state.errorMessage !== ''" class="card-error">
|
||||
@@ -314,6 +396,8 @@ import {
|
||||
updateOwnerCard,
|
||||
fetchOwnerCardInfo,
|
||||
buildUpdatePayload,
|
||||
isFieldLocked,
|
||||
moveModuleInOrder,
|
||||
CardEditCopyKey,
|
||||
CardEditPageOptions,
|
||||
} from './useCardEdit.uts';
|
||||
@@ -337,7 +421,8 @@ type CardEditExtendedKey =
|
||||
| 'duration24h'
|
||||
| 'duration7d'
|
||||
| 'duration30d'
|
||||
| 'temporaryNote';
|
||||
| 'temporaryNote'
|
||||
| 'lockedHint';
|
||||
|
||||
const EXTENDED_COPY: Record<OmniLocale, Record<string, string>> = {
|
||||
'zh-CN': {
|
||||
@@ -525,10 +610,55 @@ const avatarActionText = computed((): string => {
|
||||
return state.avatarUrl !== '' ? resolveCardEditText('avatarChange') : resolveCardEditText('avatarUpload');
|
||||
});
|
||||
|
||||
const companyLocked = computed((): boolean => {
|
||||
return isFieldLocked(state.lockedFields, 'company');
|
||||
});
|
||||
|
||||
const sloganLocked = computed((): boolean => {
|
||||
return isFieldLocked(state.lockedFields, 'slogan');
|
||||
});
|
||||
|
||||
const deleteAriaLabel = computed((): string => {
|
||||
return getOmniText(getCurrentLocale(), 'common.delete');
|
||||
});
|
||||
|
||||
function moduleIndexOf(key: string): number {
|
||||
const order = state.moduleOrder;
|
||||
for (let i = 0; i < order.length; i++) {
|
||||
if (order[i] === key) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
function moduleCardStyle(key: string): Record<string, string> {
|
||||
const index = moduleIndexOf(key);
|
||||
return {
|
||||
order: String(index >= 0 ? index : 99),
|
||||
};
|
||||
}
|
||||
|
||||
function canMoveModule(key: string, delta: number): boolean {
|
||||
const index = moduleIndexOf(key);
|
||||
if (index < 0) {
|
||||
return false;
|
||||
}
|
||||
const target = index + delta;
|
||||
return target >= 0 && target < state.moduleOrder.length;
|
||||
}
|
||||
|
||||
function handleMoveModule(key: string, delta: number): void {
|
||||
if (state.saving) {
|
||||
return;
|
||||
}
|
||||
const index = moduleIndexOf(key);
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
state.moduleOrder = moveModuleInOrder(state.moduleOrder, index, delta);
|
||||
}
|
||||
|
||||
function t(key: CardEditExtendedKey): string {
|
||||
const locale = getCurrentLocale();
|
||||
const dict = EXTENDED_COPY[locale];
|
||||
@@ -611,6 +741,7 @@ function handleBack(): void {
|
||||
|
||||
async function handleSave(): Promise<void> {
|
||||
const ok = await submitCardEdit(state);
|
||||
// 仅接口 code === 1000(submitCardEdit 已校验)时提示保存成功
|
||||
if (ok) {
|
||||
try {
|
||||
if (typeof uni !== 'undefined' && uni.setStorageSync != null && state.cardId != null) {
|
||||
@@ -799,6 +930,11 @@ onLoad((options: CardEditPageOptions) => {
|
||||
margin-block-end: 16px;
|
||||
}
|
||||
|
||||
.modules-stack {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.module-card-header {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -811,6 +947,43 @@ onLoad((options: CardEditPageOptions) => {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.module-order-actions {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-inline-start: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.module-order-btn {
|
||||
height: 32px;
|
||||
min-height: 32px;
|
||||
min-width: 44px;
|
||||
padding-inline: 8px;
|
||||
background-color: var(--oc-primary-soft, #EBF5FF);
|
||||
border-width: 0;
|
||||
border-radius: 9999px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.module-order-btn:active {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.module-order-btn[disabled] {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.module-order-btn-text {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
}
|
||||
|
||||
.module-indicator {
|
||||
@@ -833,12 +1006,23 @@ onLoad((options: CardEditPageOptions) => {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
.module-subtitle-block {
|
||||
margin-block-end: 12px;
|
||||
margin-block-start: -8px;
|
||||
}
|
||||
|
||||
.gdpr-pill {
|
||||
padding: 2px 8px;
|
||||
background-color: rgba(18, 183, 106, 0.1);
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
.gdpr-pill-inline {
|
||||
align-self: flex-start;
|
||||
margin-block-end: 12px;
|
||||
margin-block-start: -8px;
|
||||
}
|
||||
|
||||
.gdpr-pill-text {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
@@ -969,6 +1153,18 @@ onLoad((options: CardEditPageOptions) => {
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.field-input-locked {
|
||||
opacity: 0.72;
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
.field-lock-hint {
|
||||
margin-block-start: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.privacy-options-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
文件差异内容过多而无法显示
加载差异
@@ -164,6 +164,7 @@ import {
|
||||
createQrcodeState,
|
||||
loadPosterIntoState,
|
||||
resolveQrcodeText,
|
||||
savePosterToAlbum,
|
||||
QrcodeCopyKey,
|
||||
QrcodeQuery,
|
||||
} from './useCardQrcode.uts';
|
||||
@@ -446,7 +447,10 @@ function handlePrimaryCta(): void {
|
||||
if (!canCopy.value) {
|
||||
return;
|
||||
}
|
||||
copyPosterUrl(state.url);
|
||||
void (async () => {
|
||||
await savePosterToAlbum(state.svg);
|
||||
copyPosterUrl(state.url);
|
||||
})();
|
||||
}
|
||||
|
||||
onLoad((options: QrcodeQuery) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
updateCardArticle,
|
||||
deleteCardArticle,
|
||||
} from '../../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
import { getCurrentLocale } from '../../../common/locale.uts';
|
||||
|
||||
export type ArticlesApi = {
|
||||
fetchPage: (query: OwnerPageQuery) => Promise<OwnerPageData<CardArticle>>;
|
||||
@@ -68,11 +68,11 @@ export function extractArticleSummary(content?: string, maxLen: number = 120): s
|
||||
export function validateArticleForm(form: Partial<CardArticle>): string | null {
|
||||
const title = form.title != null ? form.title.trim() : '';
|
||||
if (title === '') {
|
||||
return '请输入文章或动态标题';
|
||||
return resolveArticlesText('errTitleRequired');
|
||||
}
|
||||
const content = form.content != null ? form.content.trim() : '';
|
||||
if (content === '') {
|
||||
return '请输入文章正文内容';
|
||||
return resolveArticlesText('errContentRequired');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ export async function loadArticles(
|
||||
state.list = items;
|
||||
state.empty = items.length === 0;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '加载文章列表失败';
|
||||
state.errorMessage = err.message || resolveArticlesText('errLoadFailed');
|
||||
} finally {
|
||||
state.loading = false;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ export async function saveArticle(
|
||||
await loadArticles(state, api);
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '保存文章失败';
|
||||
state.errorMessage = err.message || resolveArticlesText('errSaveFailed');
|
||||
return false;
|
||||
} finally {
|
||||
state.saving = false;
|
||||
@@ -167,7 +167,7 @@ export async function toggleArticlePublish(
|
||||
article.isPublished = targetStatus;
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '切换发布状态失败';
|
||||
state.errorMessage = err.message || resolveArticlesText('errToggleFailed');
|
||||
return false;
|
||||
} finally {
|
||||
state.saving = false;
|
||||
@@ -189,7 +189,7 @@ export async function deleteArticle(
|
||||
}
|
||||
return false;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '删除文章失败';
|
||||
state.errorMessage = err.message || resolveArticlesText('errDeleteFailed');
|
||||
return false;
|
||||
} finally {
|
||||
state.saving = false;
|
||||
@@ -211,8 +211,25 @@ export type ArticlesCopyKey =
|
||||
| 'fieldCover'
|
||||
| 'fieldContent'
|
||||
| 'fieldPublish'
|
||||
| 'publishDesc'
|
||||
| 'phTitle'
|
||||
| 'phSummary'
|
||||
| 'phContent'
|
||||
| 'saveBtn'
|
||||
| 'cancelBtn';
|
||||
| 'cancelBtn'
|
||||
| 'saving'
|
||||
| 'savedToast'
|
||||
| 'statusUpdatedToast'
|
||||
| 'deletedToast'
|
||||
| 'deleteConfirmTitle'
|
||||
| 'deleteConfirmContent'
|
||||
| 'deleteConfirmOk'
|
||||
| 'errTitleRequired'
|
||||
| 'errContentRequired'
|
||||
| 'errLoadFailed'
|
||||
| 'errSaveFailed'
|
||||
| 'errDeleteFailed'
|
||||
| 'errToggleFailed';
|
||||
|
||||
export function resolveArticlesText(key: ArticlesCopyKey): string {
|
||||
const locale = getCurrentLocale();
|
||||
@@ -247,10 +264,46 @@ export function resolveArticlesText(key: ArticlesCopyKey): string {
|
||||
return zh ? '文章正文 (支持富文本与 Markdown)' : 'Content';
|
||||
case 'fieldPublish':
|
||||
return zh ? '公开发布至微官网' : 'Publish to Micro-site';
|
||||
case 'publishDesc':
|
||||
return zh
|
||||
? '开启后,全球访客可在您的名片微官网中直接浏览'
|
||||
: 'When enabled, visitors can view this insight on your micro-site';
|
||||
case 'phTitle':
|
||||
return zh ? '输入文章或动态标题' : 'Enter article or insight title';
|
||||
case 'phSummary':
|
||||
return zh ? '选填,不填将从正文自动提取' : 'Optional; auto-extracted from content if empty';
|
||||
case 'phContent':
|
||||
return zh ? '输入正文,支持段落与 Markdown' : 'Write content; paragraphs and Markdown supported';
|
||||
case 'saveBtn':
|
||||
return zh ? '确认发布' : 'Publish';
|
||||
case 'cancelBtn':
|
||||
return zh ? '取消' : 'Cancel';
|
||||
case 'saving':
|
||||
return zh ? '保存中...' : 'Saving...';
|
||||
case 'savedToast':
|
||||
return zh ? '动态已保存' : 'Article Saved';
|
||||
case 'statusUpdatedToast':
|
||||
return zh ? '状态已切换' : 'Status Updated';
|
||||
case 'deletedToast':
|
||||
return zh ? '已删除' : 'Deleted';
|
||||
case 'deleteConfirmTitle':
|
||||
return zh ? '确认删除' : 'Confirm Delete';
|
||||
case 'deleteConfirmContent':
|
||||
return zh ? '确定要删除该文章动态吗?' : 'Are you sure you want to delete this article?';
|
||||
case 'deleteConfirmOk':
|
||||
return zh ? '删除' : 'Delete';
|
||||
case 'errTitleRequired':
|
||||
return zh ? '请输入文章或动态标题' : 'Please enter a title';
|
||||
case 'errContentRequired':
|
||||
return zh ? '请输入文章正文内容' : 'Please enter article content';
|
||||
case 'errLoadFailed':
|
||||
return zh ? '加载文章列表失败' : 'Failed to load articles';
|
||||
case 'errSaveFailed':
|
||||
return zh ? '保存文章失败' : 'Failed to save article';
|
||||
case 'errDeleteFailed':
|
||||
return zh ? '删除文章失败' : 'Failed to delete article';
|
||||
case 'errToggleFailed':
|
||||
return zh ? '切换发布状态失败' : 'Failed to update publish status';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -10,15 +10,7 @@ import {
|
||||
updateCardCase,
|
||||
deleteCardCase,
|
||||
} from '../../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
|
||||
export const PRESET_CASE_METRICS: string[] = [
|
||||
'+320% ROI',
|
||||
'+150% 留资率',
|
||||
'45k+ 国际线索',
|
||||
'2M+ 全球曝光',
|
||||
'Top 1 细分类目',
|
||||
];
|
||||
import { getCurrentLocale } from '../../../common/locale.uts';
|
||||
|
||||
export type CasesApi = {
|
||||
fetchPage: (query: OwnerPageQuery) => Promise<OwnerPageData<CardCase>>;
|
||||
@@ -61,10 +53,10 @@ export function createCasesState(cardId: string | number): CasesState {
|
||||
export function validateCaseForm(form: Partial<CardCase>): string | null {
|
||||
const title = form.title != null ? form.title.trim() : '';
|
||||
if (title === '') {
|
||||
return '请输入案例或产品标题';
|
||||
return resolveCasesText('errTitleRequired');
|
||||
}
|
||||
if (title.length > 150) {
|
||||
return '标题长度不能超过 150 个字符';
|
||||
return resolveCasesText('errTitleTooLong');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -85,7 +77,7 @@ export async function loadCases(
|
||||
state.list = items;
|
||||
state.empty = items.length === 0;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '加载案例列表失败';
|
||||
state.errorMessage = err.message || resolveCasesText('errLoadFailed');
|
||||
} finally {
|
||||
state.loading = false;
|
||||
}
|
||||
@@ -125,7 +117,7 @@ export async function saveCase(
|
||||
await loadCases(state, api);
|
||||
return true;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '保存案例失败';
|
||||
state.errorMessage = err.message || resolveCasesText('errSaveFailed');
|
||||
return false;
|
||||
} finally {
|
||||
state.saving = false;
|
||||
@@ -147,7 +139,7 @@ export async function deleteCase(
|
||||
}
|
||||
return false;
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err.message || '删除案例失败';
|
||||
state.errorMessage = err.message || resolveCasesText('errDeleteFailed');
|
||||
return false;
|
||||
} finally {
|
||||
state.saving = false;
|
||||
@@ -169,7 +161,25 @@ export type CasesCopyKey =
|
||||
| 'fieldDesc'
|
||||
| 'fieldCover'
|
||||
| 'saveBtn'
|
||||
| 'cancelBtn';
|
||||
| 'cancelBtn'
|
||||
| 'phTitle'
|
||||
| 'phClient'
|
||||
| 'phDuration'
|
||||
| 'phMetrics'
|
||||
| 'phDesc'
|
||||
| 'clientPrefix'
|
||||
| 'coverPlaceholder'
|
||||
| 'saving'
|
||||
| 'savedToast'
|
||||
| 'deletedToast'
|
||||
| 'deleteConfirmTitle'
|
||||
| 'deleteConfirmContent'
|
||||
| 'deleteConfirmOk'
|
||||
| 'errTitleRequired'
|
||||
| 'errTitleTooLong'
|
||||
| 'errLoadFailed'
|
||||
| 'errSaveFailed'
|
||||
| 'errDeleteFailed';
|
||||
|
||||
export function resolveCasesText(key: CasesCopyKey): string {
|
||||
const locale = getCurrentLocale();
|
||||
@@ -207,6 +217,42 @@ export function resolveCasesText(key: CasesCopyKey): string {
|
||||
return zh ? '保存案例' : 'Save Case';
|
||||
case 'cancelBtn':
|
||||
return zh ? '取消' : 'Cancel';
|
||||
case 'phTitle':
|
||||
return zh ? '输入案例或产品名称' : 'Enter case or product title';
|
||||
case 'phClient':
|
||||
return zh ? '选填合作客商或品牌' : 'Optional client or brand';
|
||||
case 'phDuration':
|
||||
return zh ? '例如项目起止时间' : 'e.g. project timeline';
|
||||
case 'phMetrics':
|
||||
return zh ? '选填成效标签' : 'Optional metrics tag';
|
||||
case 'phDesc':
|
||||
return zh ? '简述方案背景、成效或客户反馈' : 'Brief overview, outcomes, or feedback';
|
||||
case 'clientPrefix':
|
||||
return zh ? '合作客户: ' : 'Client: ';
|
||||
case 'coverPlaceholder':
|
||||
return zh ? '产品展示' : 'Showcase';
|
||||
case 'saving':
|
||||
return zh ? '保存中...' : 'Saving...';
|
||||
case 'savedToast':
|
||||
return zh ? '案例已保存' : 'Case Saved';
|
||||
case 'deletedToast':
|
||||
return zh ? '已删除' : 'Deleted';
|
||||
case 'deleteConfirmTitle':
|
||||
return zh ? '确认删除' : 'Confirm Delete';
|
||||
case 'deleteConfirmContent':
|
||||
return zh ? '确定要删除该案例吗?此操作无法撤销。' : 'Are you sure you want to delete this case?';
|
||||
case 'deleteConfirmOk':
|
||||
return zh ? '删除' : 'Delete';
|
||||
case 'errTitleRequired':
|
||||
return zh ? '请输入案例或产品标题' : 'Please enter a title';
|
||||
case 'errTitleTooLong':
|
||||
return zh ? '标题长度不能超过 150 个字符' : 'Title must be 150 characters or fewer';
|
||||
case 'errLoadFailed':
|
||||
return zh ? '加载案例列表失败' : 'Failed to load cases';
|
||||
case 'errSaveFailed':
|
||||
return zh ? '保存案例失败' : 'Failed to save case';
|
||||
case 'errDeleteFailed':
|
||||
return zh ? '删除案例失败' : 'Failed to delete case';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ export type CardEditCopyKey =
|
||||
| 'name'
|
||||
| 'jobTitle'
|
||||
| 'company'
|
||||
| 'slogan'
|
||||
| 'phone'
|
||||
| 'email'
|
||||
| 'whatsapp'
|
||||
| 'linkedin'
|
||||
| 'timezone'
|
||||
| 'save'
|
||||
| 'loading'
|
||||
| 'success'
|
||||
@@ -27,7 +29,50 @@ export type CardEditCopyKey =
|
||||
| 'back'
|
||||
| 'avatarUpload'
|
||||
| 'avatarChange'
|
||||
| 'avatarPlaceholder';
|
||||
| 'avatarPlaceholder'
|
||||
| 'lockedHint'
|
||||
| 'moduleOrderSection'
|
||||
| 'moveUp'
|
||||
| 'moveDown';
|
||||
|
||||
/** 极速编辑页可重排模块(无服务端排序字段,仅客户端顺序) */
|
||||
export type CardEditModuleKey = 'basic' | 'social' | 'privacy';
|
||||
|
||||
export const DEFAULT_MODULE_ORDER: CardEditModuleKey[] = [
|
||||
'basic',
|
||||
'social',
|
||||
'privacy',
|
||||
];
|
||||
|
||||
const MODULE_ORDER_STORAGE_PREFIX = 'omni_card_module_order_';
|
||||
|
||||
/** 品牌套件可锁定字段(接口 lockedFields / whitelist 原样或别名) */
|
||||
export type BrandLockFieldKey =
|
||||
| 'company'
|
||||
| 'companyName'
|
||||
| 'logo'
|
||||
| 'logoUrl'
|
||||
| 'primaryColor'
|
||||
| 'avatarUrl'
|
||||
| 'name'
|
||||
| 'title'
|
||||
| 'slogan'
|
||||
| 'phone'
|
||||
| 'email'
|
||||
| 'whatsapp'
|
||||
| 'linkedin'
|
||||
| 'telegram'
|
||||
| 'twitter'
|
||||
| 'wechat';
|
||||
|
||||
export type BrandKitLockSource = {
|
||||
logoUrl?: string;
|
||||
primaryColor?: string;
|
||||
lockedFields?: string[] | null;
|
||||
whitelist?: string[] | null;
|
||||
editableFields?: string[] | null;
|
||||
fieldWhitelist?: string[] | null;
|
||||
};
|
||||
|
||||
export type CardEditForm = {
|
||||
id?: string | number | null;
|
||||
@@ -43,6 +88,8 @@ export type CardEditForm = {
|
||||
telegram?: string;
|
||||
twitter?: string;
|
||||
wechat?: string;
|
||||
timezone?: string;
|
||||
lockedFields?: string[] | null;
|
||||
};
|
||||
|
||||
export type CardUpdatePayload = {
|
||||
@@ -59,6 +106,7 @@ export type CardUpdatePayload = {
|
||||
telegram?: string;
|
||||
twitter?: string;
|
||||
wechat?: string;
|
||||
timezone?: string;
|
||||
};
|
||||
|
||||
export type LoadCardApi = {
|
||||
@@ -79,6 +127,7 @@ export type SaveCardApi = {
|
||||
|
||||
export type SaveCardResult = {
|
||||
ok: boolean;
|
||||
code?: number;
|
||||
card: CardProfile | null;
|
||||
errorMessage: string;
|
||||
};
|
||||
@@ -93,11 +142,15 @@ export type CardEditState = {
|
||||
name: string;
|
||||
title: string;
|
||||
company: string;
|
||||
slogan: string;
|
||||
avatarUrl: string;
|
||||
phone: string;
|
||||
email: string;
|
||||
whatsapp: string;
|
||||
linkedin: string;
|
||||
timezone: string;
|
||||
moduleOrder: string[];
|
||||
lockedFields: string[];
|
||||
loading: boolean;
|
||||
saving: boolean;
|
||||
empty: boolean;
|
||||
@@ -149,12 +202,18 @@ export function resolveCardEditText(key: CardEditCopyKey): string {
|
||||
if (key === 'company') {
|
||||
return zh ? '公司' : 'Company';
|
||||
}
|
||||
if (key === 'slogan') {
|
||||
return zh ? '口号' : 'Slogan';
|
||||
}
|
||||
if (key === 'phone') {
|
||||
return zh ? '电话' : 'Phone';
|
||||
}
|
||||
if (key === 'email') {
|
||||
return zh ? '邮箱' : 'Email';
|
||||
}
|
||||
if (key === 'timezone') {
|
||||
return zh ? '时区' : 'Timezone';
|
||||
}
|
||||
if (key === 'missingId') {
|
||||
return zh ? '缺少名片编号' : 'Card ID is missing';
|
||||
}
|
||||
@@ -170,9 +229,121 @@ export function resolveCardEditText(key: CardEditCopyKey): string {
|
||||
if (key === 'avatarPlaceholder') {
|
||||
return zh ? '上传头像' : 'Upload avatar';
|
||||
}
|
||||
if (key === 'lockedHint') {
|
||||
return zh ? '品牌规范已锁定,不可修改' : 'Locked by brand kit';
|
||||
}
|
||||
if (key === 'moduleOrderSection') {
|
||||
return zh ? '模块顺序' : 'Module order';
|
||||
}
|
||||
if (key === 'moveUp') {
|
||||
return zh ? '上移' : 'Move up';
|
||||
}
|
||||
if (key === 'moveDown') {
|
||||
return zh ? '下移' : 'Move down';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function isKnownModuleKey(value: string): boolean {
|
||||
return (
|
||||
value === 'basic' || value === 'social' || value === 'privacy'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归一化模块顺序:去重、仅保留已知键,缺项按默认补齐
|
||||
*/
|
||||
export function normalizeModuleOrder(raw: unknown): string[] {
|
||||
const seen: Record<string, boolean> = {};
|
||||
const out: string[] = [];
|
||||
if (Array.isArray(raw)) {
|
||||
for (let i = 0; i < raw.length; i++) {
|
||||
const item = raw[i];
|
||||
if (typeof item !== 'string') {
|
||||
continue;
|
||||
}
|
||||
const key = item.trim();
|
||||
if (!isKnownModuleKey(key) || seen[key] === true) {
|
||||
continue;
|
||||
}
|
||||
seen[key] = true;
|
||||
out.push(key);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < DEFAULT_MODULE_ORDER.length; i++) {
|
||||
const key = DEFAULT_MODULE_ORDER[i];
|
||||
if (seen[key] !== true) {
|
||||
out.push(key);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上下移动模块。越界时原样返回。
|
||||
*/
|
||||
export function moveModuleInOrder(
|
||||
order: string[],
|
||||
index: number,
|
||||
delta: number
|
||||
): string[] {
|
||||
const normalized = normalizeModuleOrder(order);
|
||||
const target = index + delta;
|
||||
if (index < 0 || index >= normalized.length) {
|
||||
return normalized;
|
||||
}
|
||||
if (target < 0 || target >= normalized.length) {
|
||||
return normalized;
|
||||
}
|
||||
const next: string[] = [];
|
||||
for (let i = 0; i < normalized.length; i++) {
|
||||
next.push(normalized[i]);
|
||||
}
|
||||
const tmp = next[index];
|
||||
next[index] = next[target];
|
||||
next[target] = tmp;
|
||||
return next;
|
||||
}
|
||||
|
||||
export function moduleOrderStorageKey(cardId: string | number): string {
|
||||
return MODULE_ORDER_STORAGE_PREFIX + String(cardId);
|
||||
}
|
||||
|
||||
export function readStoredModuleOrder(
|
||||
cardId: string | number | null | undefined
|
||||
): string[] {
|
||||
if (cardId == null) {
|
||||
return normalizeModuleOrder(null);
|
||||
}
|
||||
try {
|
||||
if (typeof uni === 'undefined' || uni.getStorageSync == null) {
|
||||
return normalizeModuleOrder(null);
|
||||
}
|
||||
const cached = uni.getStorageSync(moduleOrderStorageKey(cardId));
|
||||
return normalizeModuleOrder(cached);
|
||||
} catch (_e) {
|
||||
return normalizeModuleOrder(null);
|
||||
}
|
||||
}
|
||||
|
||||
export function writeStoredModuleOrder(
|
||||
cardId: string | number | null | undefined,
|
||||
order: string[]
|
||||
): void {
|
||||
if (cardId == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (typeof uni === 'undefined' || uni.setStorageSync == null) {
|
||||
return;
|
||||
}
|
||||
uni.setStorageSync(
|
||||
moduleOrderStorageKey(cardId),
|
||||
normalizeModuleOrder(order)
|
||||
);
|
||||
} catch (_e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析为正整数。非正整数返回 null
|
||||
*/
|
||||
@@ -212,6 +383,153 @@ function pickFilled(value: string | null | undefined): string | null {
|
||||
return text;
|
||||
}
|
||||
|
||||
/** 品牌管控字段:whitelist 模式下未列入则锁定 */
|
||||
const BRAND_CONTROL_FIELDS: string[] = ['company', 'logoUrl', 'primaryColor'];
|
||||
|
||||
function normalizeLockToken(raw: string): string {
|
||||
return String(raw).trim();
|
||||
}
|
||||
|
||||
function fieldAliasGroup(field: string): string[] {
|
||||
const key = normalizeLockToken(field);
|
||||
if (key === 'company' || key === 'companyName') {
|
||||
return ['company', 'companyName'];
|
||||
}
|
||||
if (key === 'logo' || key === 'logoUrl') {
|
||||
return ['logo', 'logoUrl'];
|
||||
}
|
||||
return [key];
|
||||
}
|
||||
|
||||
function listIncludesField(
|
||||
list: string[] | null | undefined,
|
||||
field: string
|
||||
): boolean {
|
||||
if (list == null || list.length === 0) {
|
||||
return false;
|
||||
}
|
||||
const aliases = fieldAliasGroup(field);
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
const item = normalizeLockToken(list[i]);
|
||||
if (item === '') {
|
||||
continue;
|
||||
}
|
||||
for (let j = 0; j < aliases.length; j++) {
|
||||
if (item === aliases[j]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function readStringArray(value: unknown): string[] | null {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
const out: string[] = [];
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const item = value[i];
|
||||
if (typeof item === 'string') {
|
||||
const text = item.trim();
|
||||
if (text !== '') {
|
||||
out.push(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function readWhitelist(kit: BrandKitLockSource | null | undefined): string[] | null {
|
||||
if (kit == null) {
|
||||
return null;
|
||||
}
|
||||
const fromWhitelist = readStringArray(kit.whitelist);
|
||||
if (fromWhitelist != null) {
|
||||
return fromWhitelist;
|
||||
}
|
||||
const fromEditable = readStringArray(kit.editableFields);
|
||||
if (fromEditable != null) {
|
||||
return fromEditable;
|
||||
}
|
||||
return readStringArray(kit.fieldWhitelist);
|
||||
}
|
||||
|
||||
function deriveLocksFromWhitelist(whitelist: string[]): string[] {
|
||||
const locked: string[] = [];
|
||||
for (let i = 0; i < BRAND_CONTROL_FIELDS.length; i++) {
|
||||
const field = BRAND_CONTROL_FIELDS[i];
|
||||
if (!listIncludesField(whitelist, field)) {
|
||||
locked.push(field);
|
||||
}
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从名片或品牌套件提取锁定字段。
|
||||
* 优先 lockedFields;否则用 whitelist/editableFields 反推品牌管控字段。
|
||||
* 无锁定数据返回 [],不因仅有 brandKit 资产而锁全部。
|
||||
*/
|
||||
export function extractLockedFields(
|
||||
source:
|
||||
| (CardProfile & {
|
||||
lockedFields?: string[] | null;
|
||||
brandKit?: BrandKitLockSource | null;
|
||||
})
|
||||
| BrandKitLockSource
|
||||
| null
|
||||
| undefined
|
||||
): string[] {
|
||||
if (source == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const asRecord = source as {
|
||||
lockedFields?: string[] | null;
|
||||
brandKit?: BrandKitLockSource | null;
|
||||
whitelist?: string[] | null;
|
||||
editableFields?: string[] | null;
|
||||
fieldWhitelist?: string[] | null;
|
||||
};
|
||||
|
||||
const topLocked = readStringArray(asRecord.lockedFields);
|
||||
if (topLocked != null) {
|
||||
return topLocked;
|
||||
}
|
||||
|
||||
const kit =
|
||||
asRecord.brandKit != null
|
||||
? asRecord.brandKit
|
||||
: (source as BrandKitLockSource);
|
||||
|
||||
if (kit != null) {
|
||||
const kitLocked = readStringArray(kit.lockedFields);
|
||||
if (kitLocked != null) {
|
||||
return kitLocked;
|
||||
}
|
||||
const whitelist = readWhitelist(kit);
|
||||
if (whitelist != null && whitelist.length > 0) {
|
||||
return deriveLocksFromWhitelist(whitelist);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断表单字段是否被品牌套件锁定(含 company/companyName、logo/logoUrl 别名)
|
||||
*/
|
||||
export function isFieldLocked(
|
||||
lockedFields: string[] | null | undefined,
|
||||
field: string
|
||||
): boolean {
|
||||
return listIncludesField(lockedFields, field);
|
||||
}
|
||||
|
||||
function assignFilled(
|
||||
payload: CardUpdatePayload,
|
||||
key:
|
||||
@@ -226,9 +544,14 @@ function assignFilled(
|
||||
| 'linkedin'
|
||||
| 'telegram'
|
||||
| 'twitter'
|
||||
| 'wechat',
|
||||
value: string | null | undefined
|
||||
| 'wechat'
|
||||
| 'timezone',
|
||||
value: string | null | undefined,
|
||||
lockedFields?: string[] | null
|
||||
): void {
|
||||
if (isFieldLocked(lockedFields, key)) {
|
||||
return;
|
||||
}
|
||||
const filled = pickFilled(value);
|
||||
if (filled != null) {
|
||||
payload[key] = filled;
|
||||
@@ -236,26 +559,37 @@ function assignFilled(
|
||||
}
|
||||
|
||||
/**
|
||||
* 只带已填字段与解析后的 id。缺 id 返回 null
|
||||
* 只带已填字段与解析后的 id。缺 id 返回 null。
|
||||
* 锁定字段(含 companyName→company 别名)不进入 payload。
|
||||
*/
|
||||
export function buildUpdatePayload(form: CardEditForm): CardUpdatePayload | null {
|
||||
export function buildUpdatePayload(
|
||||
form: CardEditForm,
|
||||
lockedFields?: string[] | null
|
||||
): CardUpdatePayload | null {
|
||||
const id = parseCardId(form.id);
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
const locks =
|
||||
lockedFields != null
|
||||
? lockedFields
|
||||
: form.lockedFields != null
|
||||
? form.lockedFields
|
||||
: [];
|
||||
const payload: CardUpdatePayload = { id };
|
||||
assignFilled(payload, 'name', form.name);
|
||||
assignFilled(payload, 'title', form.title);
|
||||
assignFilled(payload, 'company', form.company);
|
||||
assignFilled(payload, 'slogan', form.slogan);
|
||||
assignFilled(payload, 'avatarUrl', form.avatarUrl);
|
||||
assignFilled(payload, 'phone', form.phone);
|
||||
assignFilled(payload, 'email', form.email);
|
||||
assignFilled(payload, 'whatsapp', form.whatsapp);
|
||||
assignFilled(payload, 'linkedin', form.linkedin);
|
||||
assignFilled(payload, 'telegram', form.telegram);
|
||||
assignFilled(payload, 'twitter', form.twitter);
|
||||
assignFilled(payload, 'wechat', form.wechat);
|
||||
assignFilled(payload, 'name', form.name, locks);
|
||||
assignFilled(payload, 'title', form.title, locks);
|
||||
assignFilled(payload, 'company', form.company, locks);
|
||||
assignFilled(payload, 'slogan', form.slogan, locks);
|
||||
assignFilled(payload, 'avatarUrl', form.avatarUrl, locks);
|
||||
assignFilled(payload, 'phone', form.phone, locks);
|
||||
assignFilled(payload, 'email', form.email, locks);
|
||||
assignFilled(payload, 'whatsapp', form.whatsapp, locks);
|
||||
assignFilled(payload, 'linkedin', form.linkedin, locks);
|
||||
assignFilled(payload, 'telegram', form.telegram, locks);
|
||||
assignFilled(payload, 'twitter', form.twitter, locks);
|
||||
assignFilled(payload, 'wechat', form.wechat, locks);
|
||||
assignFilled(payload, 'timezone', form.timezone, locks);
|
||||
return payload;
|
||||
}
|
||||
|
||||
@@ -310,16 +644,19 @@ export async function loadCard(
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存名片。可注入 updateOwnerCard。缺 id 不请求
|
||||
* 保存名片。可注入 updateOwnerCard。缺 id 不请求。
|
||||
* lockedFields 可显式传入,否则用 form.lockedFields。
|
||||
*/
|
||||
export async function saveCard(
|
||||
form: CardEditForm,
|
||||
api?: SaveCardApi
|
||||
api?: SaveCardApi,
|
||||
lockedFields?: string[] | null
|
||||
): Promise<SaveCardResult> {
|
||||
const payload = buildUpdatePayload(form);
|
||||
const payload = buildUpdatePayload(form, lockedFields);
|
||||
if (payload == null) {
|
||||
return {
|
||||
ok: false,
|
||||
code: undefined,
|
||||
card: null,
|
||||
errorMessage: '',
|
||||
};
|
||||
@@ -334,12 +671,15 @@ export async function saveCard(
|
||||
const card = await update(asUpdatePayload(payload));
|
||||
return {
|
||||
ok: true,
|
||||
// Cool-Admin:仅 code === 1000 视为更新成功(http 层已解包)
|
||||
code: 1000,
|
||||
card,
|
||||
errorMessage: '',
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
ok: false,
|
||||
code: undefined,
|
||||
card: null,
|
||||
errorMessage: readErrorMessage(err),
|
||||
};
|
||||
@@ -353,11 +693,15 @@ export function createCardEditState(): CardEditState {
|
||||
name: '',
|
||||
title: '',
|
||||
company: '',
|
||||
slogan: '',
|
||||
avatarUrl: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
whatsapp: '',
|
||||
linkedin: '',
|
||||
timezone: '',
|
||||
moduleOrder: normalizeModuleOrder(null),
|
||||
lockedFields: [],
|
||||
loading: false,
|
||||
saving: false,
|
||||
empty: false,
|
||||
@@ -382,6 +726,9 @@ export function applyCardEditOptions(
|
||||
state.cardId = parsed;
|
||||
state.missingId = parsed == null;
|
||||
state.empty = parsed == null;
|
||||
if (parsed != null) {
|
||||
state.moduleOrder = readStoredModuleOrder(parsed);
|
||||
}
|
||||
return parsed != null;
|
||||
}
|
||||
|
||||
@@ -402,11 +749,19 @@ function applyCardToState(state: CardEditState, card: CardProfile): void {
|
||||
state.name = card.name != null ? String(card.name) : '';
|
||||
state.title = readOptionalText(card.title);
|
||||
state.company = readOptionalText(card.company);
|
||||
state.slogan = readOptionalText(card.slogan);
|
||||
state.avatarUrl = readOptionalText(card.avatarUrl);
|
||||
state.phone = readOptionalText(card.phone);
|
||||
state.email = readOptionalText(card.email);
|
||||
state.whatsapp = readOptionalText(card.whatsapp);
|
||||
state.linkedin = readOptionalText(card.linkedin);
|
||||
state.timezone = readOptionalText(card.timezone);
|
||||
state.lockedFields = extractLockedFields(
|
||||
card as CardProfile & {
|
||||
lockedFields?: string[] | null;
|
||||
brandKit?: BrandKitLockSource | null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function applyLoadResult(
|
||||
@@ -419,6 +774,7 @@ export function applyLoadResult(
|
||||
state.missingId = false;
|
||||
} else {
|
||||
state.empty = true;
|
||||
state.lockedFields = [];
|
||||
}
|
||||
state.errorMessage = result.errorMessage;
|
||||
}
|
||||
@@ -429,11 +785,14 @@ export function formFromState(state: CardEditState): CardEditForm {
|
||||
name: state.name,
|
||||
title: state.title,
|
||||
company: state.company,
|
||||
slogan: state.slogan,
|
||||
avatarUrl: state.avatarUrl,
|
||||
phone: state.phone,
|
||||
email: state.email,
|
||||
whatsapp: state.whatsapp,
|
||||
linkedin: state.linkedin,
|
||||
timezone: state.timezone,
|
||||
lockedFields: state.lockedFields,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,9 +834,15 @@ export async function submitCardEdit(
|
||||
}
|
||||
state.saving = true;
|
||||
state.errorMessage = '';
|
||||
const result = await saveCard(formFromState(state), api);
|
||||
if (result.ok && result.card != null) {
|
||||
const result = await saveCard(
|
||||
formFromState(state),
|
||||
api,
|
||||
state.lockedFields
|
||||
);
|
||||
// 仅接口 code === 1000 视为保存成功
|
||||
if (result.ok && result.code === 1000 && result.card != null) {
|
||||
applyCardToState(state, result.card);
|
||||
writeStoredModuleOrder(state.cardId, state.moduleOrder);
|
||||
state.saving = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
CardProfile,
|
||||
CardStatus,
|
||||
OwnerPageData,
|
||||
OwnerPagePagination,
|
||||
OwnerPageQuery,
|
||||
} from '../../../common/types.uts';
|
||||
import { fetchOwnerCardPage } from '../../../common/api.uts';
|
||||
@@ -36,7 +37,17 @@ export type CardHomeCopyKey =
|
||||
| 'statusDraft'
|
||||
| 'statusPublished'
|
||||
| 'statusArchived'
|
||||
| 'quotaExceeded';
|
||||
| 'quotaExceeded'
|
||||
| 'scanGuide'
|
||||
| 'linkLabel'
|
||||
| 'copy'
|
||||
| 'emptyDesc'
|
||||
| 'cases'
|
||||
| 'articles'
|
||||
| 'linkEmpty'
|
||||
| 'switchTitle'
|
||||
| 'quotaBadge'
|
||||
| 'emptyHeading';
|
||||
|
||||
export type LoadCardsQuery = {
|
||||
page: number;
|
||||
@@ -52,11 +63,7 @@ export type LoadCardsApi = {
|
||||
|
||||
export type LoadCardsResult = {
|
||||
list: CardHomeItem[];
|
||||
pagination: {
|
||||
page: number;
|
||||
size: number;
|
||||
total: number;
|
||||
};
|
||||
pagination: OwnerPagePagination;
|
||||
empty: boolean;
|
||||
errorMessage: string;
|
||||
};
|
||||
@@ -105,7 +112,7 @@ export function resolveCardHomeText(key: CardHomeCopyKey): string {
|
||||
|
||||
const zh = isZhLocale();
|
||||
if (key === 'poster') {
|
||||
return zh ? '分享海报' : 'Share poster';
|
||||
return zh ? '出示名片' : 'Show card';
|
||||
}
|
||||
if (key === 'title') {
|
||||
return zh ? '我的名片' : 'My cards';
|
||||
@@ -131,6 +138,36 @@ export function resolveCardHomeText(key: CardHomeCopyKey): string {
|
||||
if (key === 'quotaExceeded') {
|
||||
return zh ? '名片配额已满,升级后可继续创建' : 'Card quota is full. Upgrade to create more.';
|
||||
}
|
||||
if (key === 'scanGuide') {
|
||||
return zh ? '扫码即可保存这张名片' : 'Scan to save this card';
|
||||
}
|
||||
if (key === 'linkLabel') {
|
||||
return zh ? '名片链接' : 'Card link';
|
||||
}
|
||||
if (key === 'copy') {
|
||||
return zh ? '复制' : 'Copy';
|
||||
}
|
||||
if (key === 'emptyDesc') {
|
||||
return zh ? '创建第一张名片后,就可以在这里出示' : 'Create a card, then show it here';
|
||||
}
|
||||
if (key === 'cases') {
|
||||
return zh ? '相册' : 'Gallery';
|
||||
}
|
||||
if (key === 'articles') {
|
||||
return zh ? '动态' : 'Posts';
|
||||
}
|
||||
if (key === 'linkEmpty') {
|
||||
return zh ? '暂无链接' : 'No link yet';
|
||||
}
|
||||
if (key === 'switchTitle') {
|
||||
return zh ? '选择名片' : 'Choose a card';
|
||||
}
|
||||
if (key === 'quotaBadge') {
|
||||
return zh ? '配额已满' : 'Quota full';
|
||||
}
|
||||
if (key === 'emptyHeading') {
|
||||
return zh ? '还没有名片' : 'No cards yet';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主参展分享码海报业务驱动层
|
||||
* 解析 slug / id,拉取公开短链二维码,复制链接
|
||||
* 解析 slug / id,拉取公开短链二维码,复制链接,保存海报到相册
|
||||
*/
|
||||
|
||||
import { fetchCardQrcodeSvg } from '../../../common/api.uts';
|
||||
@@ -47,7 +47,10 @@ export type QrcodeCopyKey =
|
||||
| 'empty'
|
||||
| 'error'
|
||||
| 'loading'
|
||||
| 'title';
|
||||
| 'title'
|
||||
| 'saveSuccess'
|
||||
| 'saveFailed'
|
||||
| 'saveUnavailable';
|
||||
|
||||
const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
'zh-CN': {
|
||||
@@ -58,6 +61,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: '暂无数据',
|
||||
error: '出错了',
|
||||
loading: '加载中...',
|
||||
saveSuccess: '已保存到相册',
|
||||
saveFailed: '保存失败',
|
||||
saveUnavailable: '暂无可保存的图片',
|
||||
},
|
||||
'en-US': {
|
||||
title: 'Share Card',
|
||||
@@ -67,6 +73,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'Nothing here yet',
|
||||
error: 'Something went wrong',
|
||||
loading: 'Loading...',
|
||||
saveSuccess: 'Saved to Photos',
|
||||
saveFailed: 'Could not save',
|
||||
saveUnavailable: 'No image to save',
|
||||
},
|
||||
'ar-SA': {
|
||||
title: 'مشاركة البطاقة',
|
||||
@@ -76,6 +85,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'لا توجد بيانات بعد',
|
||||
error: 'حدث خطأ',
|
||||
loading: 'جار التحميل...',
|
||||
saveSuccess: 'تم الحفظ في الصور',
|
||||
saveFailed: 'تعذر الحفظ',
|
||||
saveUnavailable: 'لا توجد صورة للحفظ',
|
||||
},
|
||||
'es-ES': {
|
||||
title: 'Compartir tarjeta',
|
||||
@@ -85,6 +97,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'Aun no hay datos',
|
||||
error: 'Algo salio mal',
|
||||
loading: 'Cargando...',
|
||||
saveSuccess: 'Guardado en Fotos',
|
||||
saveFailed: 'No se pudo guardar',
|
||||
saveUnavailable: 'No hay imagen para guardar',
|
||||
},
|
||||
'de-DE': {
|
||||
title: 'Karte teilen',
|
||||
@@ -94,6 +109,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'Noch keine Daten',
|
||||
error: 'Etwas ist schiefgelaufen',
|
||||
loading: 'Wird geladen...',
|
||||
saveSuccess: 'In Fotos gespeichert',
|
||||
saveFailed: 'Speichern fehlgeschlagen',
|
||||
saveUnavailable: 'Kein Bild zum Speichern',
|
||||
},
|
||||
'fr-FR': {
|
||||
title: 'Partager la carte',
|
||||
@@ -103,6 +121,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'Aucune donnee',
|
||||
error: 'Une erreur est survenue',
|
||||
loading: 'Chargement...',
|
||||
saveSuccess: 'Enregistre dans Photos',
|
||||
saveFailed: 'Echec de l enregistrement',
|
||||
saveUnavailable: 'Aucune image a enregistrer',
|
||||
},
|
||||
'ja-JP': {
|
||||
title: '名刺をシェア',
|
||||
@@ -112,6 +133,9 @@ const QRCODE_COPY: Record<OmniLocale, Record<QrcodeCopyKey, string>> = {
|
||||
empty: 'データがありません',
|
||||
error: 'エラーが発生しました',
|
||||
loading: '読み込み中...',
|
||||
saveSuccess: '写真に保存しました',
|
||||
saveFailed: '保存に失敗しました',
|
||||
saveUnavailable: '保存できる画像がありません',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -264,3 +288,106 @@ export function copyPosterUrl(url: string | null | undefined): boolean {
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅本地路径 / 网络图 / data:image 可入库;纯 SVG 标记不可直接进相册
|
||||
*/
|
||||
export function isSaveablePosterImage(source: string | null | undefined): boolean {
|
||||
const text = trimText(source);
|
||||
if (text === '') {
|
||||
return false;
|
||||
}
|
||||
const lower = text.toLowerCase();
|
||||
if (lower.indexOf('<svg') >= 0 || lower.indexOf('<?xml') === 0) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
lower.indexOf('http://') === 0 ||
|
||||
lower.indexOf('https://') === 0 ||
|
||||
lower.indexOf('data:image') === 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function toastSaveFailed(unavailable: boolean): void {
|
||||
if (unavailable) {
|
||||
uni.showToast({
|
||||
title: resolveQrcodeText('saveUnavailable'),
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: resolveQrcodeText('saveFailed'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
function invokeSaveImageToPhotosAlbum(filePath: string): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: filePath,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: resolveQrcodeText('saveSuccess'),
|
||||
icon: 'none',
|
||||
});
|
||||
resolve(true);
|
||||
},
|
||||
fail: (_err: unknown) => {
|
||||
toastSaveFailed(false);
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function downloadRemoteImage(url: string): Promise<string> {
|
||||
return new Promise<string>(resolve => {
|
||||
uni.downloadFile({
|
||||
url: url,
|
||||
success: (res: { statusCode?: number; tempFilePath?: string }) => {
|
||||
const path =
|
||||
res != null && res.tempFilePath != null
|
||||
? String(res.tempFilePath).trim()
|
||||
: '';
|
||||
const code = res != null && res.statusCode != null ? res.statusCode : 0;
|
||||
if (code === 200 && path !== '') {
|
||||
resolve(path);
|
||||
return;
|
||||
}
|
||||
resolve('');
|
||||
},
|
||||
fail: (_err: unknown) => {
|
||||
resolve('');
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存海报到相册:必须等 uni.saveImageToPhotosAlbum 成功才 toast 已保存
|
||||
*/
|
||||
export async function savePosterToAlbum(
|
||||
imageSource: string | null | undefined
|
||||
): Promise<boolean> {
|
||||
const source = trimText(imageSource);
|
||||
if (source === '' || !isSaveablePosterImage(source)) {
|
||||
toastSaveFailed(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
let filePath = source;
|
||||
const lower = source.toLowerCase();
|
||||
if (lower.indexOf('http://') === 0 || lower.indexOf('https://') === 0) {
|
||||
filePath = await downloadRemoteImage(source);
|
||||
if (filePath === '') {
|
||||
toastSaveFailed(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return invokeSaveImageToPhotosAlbum(filePath);
|
||||
}
|
||||
|
||||
@@ -269,6 +269,7 @@ import { getCurrentLocale, getOmniText, isRtl } from '../../common/locale.uts';
|
||||
import { utsLightColors, utsRadius, utsSpacing, utsTypography } from '../../common/tokens.uts';
|
||||
import {
|
||||
applyLeadDetailOptions,
|
||||
callLeadPhone,
|
||||
createLeadDetailState,
|
||||
formatTrackDepth,
|
||||
formatTrackPlace,
|
||||
@@ -276,6 +277,7 @@ import {
|
||||
formatWhatsAppUrl,
|
||||
generateAiIcebreaker,
|
||||
goBackFromLeadDetail,
|
||||
openLeadWhatsApp,
|
||||
parseNoteAttachments,
|
||||
refreshLeadDetail,
|
||||
resolveLeadDetailText,
|
||||
@@ -285,6 +287,7 @@ import {
|
||||
updateLeadStage,
|
||||
LeadDetailCopyKey,
|
||||
LeadDetailPageOptions,
|
||||
ParsedNoteResult,
|
||||
} from './useLeadDetail.uts';
|
||||
import { parseLeadStatus } from './useLeads.uts';
|
||||
import { RadarTrack } from '../../common/types.uts';
|
||||
@@ -449,12 +452,7 @@ function handleBack(): void {
|
||||
}
|
||||
|
||||
function handleCallPhone(): void {
|
||||
if (phoneText.value === '') {
|
||||
return;
|
||||
}
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: phoneText.value,
|
||||
});
|
||||
callLeadPhone(state.phone);
|
||||
}
|
||||
|
||||
function handleCopyEmail(): void {
|
||||
@@ -468,20 +466,7 @@ function handleCopyEmail(): void {
|
||||
}
|
||||
|
||||
function handleWhatsApp(): void {
|
||||
const waUrl = formatWhatsAppUrl(state.phone);
|
||||
if (waUrl === '') {
|
||||
return;
|
||||
}
|
||||
// #ifdef H5
|
||||
if (typeof window !== 'undefined') {
|
||||
window.open(waUrl, '_blank');
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
uni.setClipboardData({
|
||||
data: waUrl,
|
||||
showToast: true,
|
||||
});
|
||||
openLeadWhatsApp(state.phone);
|
||||
}
|
||||
|
||||
async function handleSaveContact(): Promise<void> {
|
||||
@@ -525,7 +510,24 @@ function handleCopyScript(): void {
|
||||
}
|
||||
|
||||
async function handleSave(): Promise<void> {
|
||||
await submitLeadNote(state);
|
||||
const next = state.nextNote.trim();
|
||||
const hasAttachments =
|
||||
state.attachments != null && state.attachments.length > 0;
|
||||
if (next === '' && !hasAttachments) {
|
||||
uni.showToast({
|
||||
title: resolveLeadDetailText('notesRequiredToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 仅接口 code === 1000(submitLeadNote 已校验)时提示备忘已保存并清空输入
|
||||
const ok = await submitLeadNote(state);
|
||||
if (ok) {
|
||||
uni.showToast({
|
||||
title: resolveLeadDetailText('noteSavedToast'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const parsedNotes = computed((): ParsedNoteResult => {
|
||||
|
||||
@@ -236,7 +236,7 @@ const hotUnreadText = computed((): string => {
|
||||
});
|
||||
|
||||
const statsLabel = computed((): string => {
|
||||
return getCurrentLocale() === 'zh-CN' ? '统计' : 'Stats';
|
||||
return resolveLeadsText('stats');
|
||||
});
|
||||
|
||||
const leadsCountSummary = computed((): string => {
|
||||
@@ -315,8 +315,9 @@ function handleCopyEmail(email: string | undefined): void {
|
||||
});
|
||||
}
|
||||
|
||||
function selectStatus(status: string): void {
|
||||
async function selectStatus(status: string): Promise<void> {
|
||||
applyLeadStatusFilter(state, status);
|
||||
await refreshLeads(state);
|
||||
}
|
||||
|
||||
function handleOpenLead(item: LeadEntity): void {
|
||||
|
||||
@@ -240,7 +240,7 @@ import {
|
||||
ModePageOptions,
|
||||
} from './useMode.uts';
|
||||
|
||||
type ModePageCopyKey = ModeCopyKey | 'offlineHint';
|
||||
type ModePageCopyKey = ModeCopyKey | 'offlineHint' | 'offlineUnavailable';
|
||||
|
||||
type ModeSubCopyKey =
|
||||
| 'specsTitle'
|
||||
@@ -279,7 +279,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: '生效中',
|
||||
pendingApplyPill: '待应用',
|
||||
securityProtocolTitle: 'RFC 6350 离线保底协议与安全锁',
|
||||
securityProtocolDesc: '弱网无网时芯片直接写入离线 vCard;挂失后云端立即锁定拒绝访问',
|
||||
securityProtocolDesc: '离线 vCard 烧录待设备能力就绪后开放;挂失后云端立即锁定拒绝访问',
|
||||
},
|
||||
'en-US': {
|
||||
specsTitle: 'Hardware & Card Binding',
|
||||
@@ -298,7 +298,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: 'Active',
|
||||
pendingApplyPill: 'Pending',
|
||||
securityProtocolTitle: 'RFC 6350 Offline Protocol & Security Lock',
|
||||
securityProtocolDesc: 'Offline vCard written in weak network; remote lock immediately on suspension',
|
||||
securityProtocolDesc: 'Offline vCard burn opens when device write is ready; remote lock on suspension',
|
||||
},
|
||||
'ar-SA': {
|
||||
specsTitle: 'الشريحة وربط البطاقة',
|
||||
@@ -317,7 +317,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: 'مفعّل',
|
||||
pendingApplyPill: 'قيد التطبيق',
|
||||
securityProtocolTitle: 'بروتوكول RFC 6350 دون اتصال وقفل الأمان',
|
||||
securityProtocolDesc: 'كتابة vCard دون اتصال في الشبكة الضعيفة وقفل فوري عند الإيقاف',
|
||||
securityProtocolDesc: 'كتابة vCard دون اتصال تُتاح عند جاهزية الجهاز؛ قفل فوري عند الإيقاف',
|
||||
},
|
||||
'es-ES': {
|
||||
specsTitle: 'Hardware y Vinculación',
|
||||
@@ -336,7 +336,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: 'Activo',
|
||||
pendingApplyPill: 'Pendiente',
|
||||
securityProtocolTitle: 'Protocolo RFC 6350 fuera de línea y bloqueo',
|
||||
securityProtocolDesc: 'Escritura vCard local en red débil; bloqueo inmediato al suspender',
|
||||
securityProtocolDesc: 'La escritura vCard offline se abrirá cuando el dispositivo lo permita; bloqueo al suspender',
|
||||
},
|
||||
'de-DE': {
|
||||
specsTitle: 'Hardware & Bindung',
|
||||
@@ -355,7 +355,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: 'Aktiv',
|
||||
pendingApplyPill: 'Ausstehend',
|
||||
securityProtocolTitle: 'RFC 6350 Offline-Protokoll & Sicherheitssperre',
|
||||
securityProtocolDesc: 'Offline-vCard bei schwachem Netz; sofortige Sperre bei Verlust',
|
||||
securityProtocolDesc: 'Offline-vCard-Schreiben erst bei Gerätefähigkeit; sofortige Sperre bei Verlust',
|
||||
},
|
||||
'fr-FR': {
|
||||
specsTitle: 'Puce et Liaison',
|
||||
@@ -374,7 +374,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: 'Actif',
|
||||
pendingApplyPill: 'En attente',
|
||||
securityProtocolTitle: 'Protocole hors ligne RFC 6350 et verrou de sécurité',
|
||||
securityProtocolDesc: 'Écriture vCard locale en réseau faible ; verrouillage immédiat si perdue',
|
||||
securityProtocolDesc: 'Écriture vCard hors ligne dès que l’appareil le permet ; verrouillage si perdue',
|
||||
},
|
||||
'ja-JP': {
|
||||
specsTitle: 'ハードウェアと連携',
|
||||
@@ -393,7 +393,7 @@ const MODE_SUB_COPY: Record<OmniLocale, Record<ModeSubCopyKey, string>> = {
|
||||
activeScenePill: '適用中',
|
||||
pendingApplyPill: '変更待機',
|
||||
securityProtocolTitle: 'RFC 6350 オフライン規格&セキュリティロック',
|
||||
securityProtocolDesc: '回線微弱時はオフラインvCardを書き込み、利用停止時は即時遮断',
|
||||
securityProtocolDesc: 'オフラインvCard書き込みは端末対応後に開放、利用停止時は即時遮断',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -472,31 +472,12 @@ const selectedModeSub = computed((): string => {
|
||||
});
|
||||
|
||||
function resolveOfflineHint(): string {
|
||||
const locale: OmniLocale = getCurrentLocale();
|
||||
if (locale === 'zh-CN') {
|
||||
return '离线 vCard 由系统在弱网时写入';
|
||||
}
|
||||
if (locale === 'ar-SA') {
|
||||
return 'يكتب النظام بطاقة vCard دون اتصال عند ضعف الشبكة';
|
||||
}
|
||||
if (locale === 'es-ES') {
|
||||
return 'Si la red es débil, el sistema escribe el vCard sin conexión';
|
||||
}
|
||||
if (locale === 'de-DE') {
|
||||
return 'Bei schwachem Netz schreibt das System eine Offline-vCard';
|
||||
}
|
||||
if (locale === 'fr-FR') {
|
||||
return 'En cas de réseau faible, le système écrit une vCard hors ligne';
|
||||
}
|
||||
if (locale === 'ja-JP') {
|
||||
return '回線が弱いときは、システムがオフライン vCard を書き込みます';
|
||||
}
|
||||
return 'The system writes an offline vCard when the connection is weak';
|
||||
return resolveModeText('offlineUnavailable');
|
||||
}
|
||||
|
||||
function t(key: ModePageCopyKey): string {
|
||||
if (key === 'offlineHint') {
|
||||
return resolveOfflineHint();
|
||||
if (key === 'offlineHint' || key === 'offlineUnavailable') {
|
||||
return resolveModeText('offlineUnavailable');
|
||||
}
|
||||
return resolveModeText(key);
|
||||
}
|
||||
|
||||
@@ -84,19 +84,19 @@
|
||||
<view class="meta-grid">
|
||||
<view class="meta-cell">
|
||||
<text class="meta-label">{{ t('uidLabel') }}</text>
|
||||
<text class="meta-value">{{ state.record.uid }}</text>
|
||||
<text class="meta-value">{{ state.record!.uid }}</text>
|
||||
</view>
|
||||
<view class="meta-cell">
|
||||
<text class="meta-label">{{ t('cardIdLabel') }}</text>
|
||||
<text class="meta-value">#{{ state.record.cardId || state.cardIdRaw || '-' }}</text>
|
||||
<text class="meta-value">#{{ state.record!.cardId || state.cardIdRaw || '-' }}</text>
|
||||
</view>
|
||||
<view class="meta-cell">
|
||||
<text class="meta-label">{{ extraText('hardwareSpecs') }}</text>
|
||||
<text class="meta-value">{{ state.record.batchNo || 'NTAG215-STD' }}</text>
|
||||
<text class="meta-value">{{ state.record!.batchNo || 'NTAG215-STD' }}</text>
|
||||
</view>
|
||||
<view class="meta-cell">
|
||||
<text class="meta-label">Scene Mode</text>
|
||||
<text class="meta-value uppercase-txt">{{ state.record.sceneMode || 'business' }}</text>
|
||||
<text class="meta-value uppercase-txt">{{ state.record!.sceneMode || 'business' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -190,11 +190,13 @@ import { getCurrentLocale, getOmniText, isRtl } from '../../../common/locale.uts
|
||||
import { utsLightColors, utsRadius, utsSpacing, utsTypography } from '../../../common/tokens.uts';
|
||||
import {
|
||||
applyScanOptions,
|
||||
buildNdefUri,
|
||||
createScanState,
|
||||
resolveScanText,
|
||||
resolveStatusLine,
|
||||
startScan,
|
||||
submitScan,
|
||||
writeNdefToTag,
|
||||
ScanCopyKey,
|
||||
ScanPageOptions,
|
||||
} from './useScan.uts';
|
||||
@@ -353,7 +355,9 @@ function extraText(key: ExtraCopyKey): string {
|
||||
return isZh ? '物理实体卡绑定成功' : 'NFC Card Successfully Bound';
|
||||
}
|
||||
if (key === 'boundSuccessDesc') {
|
||||
return isZh ? '名片直链已烧录至云端路由,碰一碰即可瞬间交换名片。' : 'Portal URL is routed. Tap to share instantly.';
|
||||
return isZh
|
||||
? '云端路由已绑定。芯片内容需等系统写入 API 成功后才会确认。'
|
||||
: 'Cloud routing is bound. Chip content is confirmed only after a successful system write.';
|
||||
}
|
||||
if (key === 'actionDone') {
|
||||
return isZh ? '完成' : 'Done';
|
||||
@@ -395,7 +399,22 @@ function handleActivate(): void {
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
submitScan(state);
|
||||
void runActivateAndWrite();
|
||||
}
|
||||
|
||||
async function runActivateAndWrite(): Promise<void> {
|
||||
const record = await submitScan(state);
|
||||
if (record == null) {
|
||||
return;
|
||||
}
|
||||
const cardId =
|
||||
record.cardId != null
|
||||
? record.cardId
|
||||
: state.deviceCardId != null
|
||||
? state.deviceCardId
|
||||
: state.cardIdRaw;
|
||||
const uri = buildNdefUri(cardId);
|
||||
await writeNdefToTag(uri);
|
||||
}
|
||||
|
||||
onLoad((options: ScanPageOptions) => {
|
||||
@@ -1025,7 +1044,7 @@ onLoad((options: ScanPageOptions) => {
|
||||
}
|
||||
|
||||
.primary-cta-btn:active {
|
||||
opacity: 0.88;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled {
|
||||
@@ -1043,19 +1062,16 @@ onLoad((options: ScanPageOptions) => {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
/* 脉冲微动画:400ms 单次,不循环 */
|
||||
/* 脉冲微动画:400ms 单次,不循环(仅 opacity,无 scale) */
|
||||
@keyframes scan-pulse {
|
||||
0% {
|
||||
opacity: 0.4;
|
||||
transform: scale(0.92);
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
100% {
|
||||
opacity: 0.4;
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1065,6 +1081,10 @@ onLoad((options: ScanPageOptions) => {
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.scan-ring {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@@ -1062,7 +1062,7 @@ async function handleExecuteSecurity(): Promise<void> {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-inline-end: 12px;
|
||||
background-color: #FFFFFF;
|
||||
background-color: var(--oc-surface, #FFFFFF);
|
||||
}
|
||||
|
||||
.radio-checked {
|
||||
@@ -1264,8 +1264,7 @@ async function handleExecuteSecurity(): Promise<void> {
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: var(--window-bottom, 0px);
|
||||
background-color: rgba(255, 255, 255, 0.94);
|
||||
backdrop-filter: blur(12px);
|
||||
background-color: var(--oc-surface, #FFFFFF);
|
||||
border-top-width: 1px;
|
||||
border-top-color: var(--oc-border, #EBF1F7);
|
||||
padding: 12px var(--oc-space-16, 16px) calc(16px + env(safe-area-inset-bottom, 0px));
|
||||
|
||||
@@ -37,7 +37,8 @@ export type ModeCopyKey =
|
||||
| 'missingDevice'
|
||||
| 'applySuccess'
|
||||
| 'applyError'
|
||||
| 'loading';
|
||||
| 'loading'
|
||||
| 'offlineUnavailable';
|
||||
|
||||
export type ModePageOptions = {
|
||||
uid?: string;
|
||||
@@ -81,6 +82,17 @@ export type ApplySceneResult = {
|
||||
device: NFCRecord | null;
|
||||
};
|
||||
|
||||
export type OfflineWriteParams = {
|
||||
uid?: string;
|
||||
cardId?: string | number;
|
||||
vcard?: string;
|
||||
};
|
||||
|
||||
export type OfflineWriteResult = {
|
||||
ok: boolean;
|
||||
error: string;
|
||||
};
|
||||
|
||||
const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
'zh-CN': {
|
||||
title: '场景模式',
|
||||
@@ -103,6 +115,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: '操作成功',
|
||||
applyError: '操作失败',
|
||||
loading: '加载中...',
|
||||
offlineUnavailable: '此设备暂不能写入离线名片',
|
||||
},
|
||||
'en-US': {
|
||||
title: 'Scene mode',
|
||||
@@ -125,6 +138,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: 'Done',
|
||||
applyError: 'Something went wrong',
|
||||
loading: 'Loading...',
|
||||
offlineUnavailable: 'This device cannot write offline cards yet',
|
||||
},
|
||||
'ar-SA': {
|
||||
title: 'وضع المشهد',
|
||||
@@ -147,6 +161,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: 'تم',
|
||||
applyError: 'تعذّر الإكمال',
|
||||
loading: 'جارٍ التحميل...',
|
||||
offlineUnavailable: 'لا يمكن لهذا الجهاز كتابة البطاقة دون اتصال حالياً',
|
||||
},
|
||||
'es-ES': {
|
||||
title: 'Modo de escena',
|
||||
@@ -169,6 +184,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: 'Listo',
|
||||
applyError: 'No se pudo completar',
|
||||
loading: 'Cargando...',
|
||||
offlineUnavailable: 'Este dispositivo aún no puede escribir tarjetas sin conexión',
|
||||
},
|
||||
'de-DE': {
|
||||
title: 'Szenenmodus',
|
||||
@@ -191,6 +207,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: 'Erledigt',
|
||||
applyError: 'Vorgang fehlgeschlagen',
|
||||
loading: 'Wird geladen...',
|
||||
offlineUnavailable: 'Dieses Gerät kann Offline-Visitenkarten noch nicht schreiben',
|
||||
},
|
||||
'fr-FR': {
|
||||
title: 'Mode scène',
|
||||
@@ -213,6 +230,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: 'Terminé',
|
||||
applyError: 'Échec de l’opération',
|
||||
loading: 'Chargement...',
|
||||
offlineUnavailable: 'Cet appareil ne peut pas encore écrire de cartes hors ligne',
|
||||
},
|
||||
'ja-JP': {
|
||||
title: 'シーンモード',
|
||||
@@ -235,6 +253,7 @@ const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
applySuccess: '完了しました',
|
||||
applyError: '操作に失敗しました',
|
||||
loading: '読み込み中...',
|
||||
offlineUnavailable: 'この端末ではオフライン名刺を書き込めません',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -395,6 +414,33 @@ export async function applyScene(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前无真实 NDEF 写芯片能力;禁止伪造可写
|
||||
*/
|
||||
export function canWriteOfflineVCard(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 离线 vCard 烧录:无真实写芯片实现时一律失败,不 toast 成功/已烧录
|
||||
*/
|
||||
export async function writeOfflineVCard(
|
||||
_payload?: OfflineWriteParams
|
||||
): Promise<OfflineWriteResult> {
|
||||
const error = resolveModeText('offlineUnavailable');
|
||||
if (!canWriteOfflineVCard()) {
|
||||
return {
|
||||
ok: false,
|
||||
error,
|
||||
};
|
||||
}
|
||||
// 真实写芯片接入前不可达;显式失败兜底,杜绝假成功
|
||||
return {
|
||||
ok: false,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
export function createModeState(): NfcModeState {
|
||||
return {
|
||||
uid: '',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主 NFC 贴卡激活业务驱动层
|
||||
* H5 无天线走手动 UID;APP startScan 为占位,调不到原生 NFC 时回退手动输入
|
||||
* H5 无天线走手动 UID;APP 经 uni.getNFCAdapter 尝试读芯片 UID,失败回退手动输入
|
||||
*/
|
||||
|
||||
import { NFCRecord } from '../../../common/types.uts';
|
||||
@@ -21,7 +21,11 @@ export type ScanCopyKey =
|
||||
| 'nfcUnavailable'
|
||||
| 'success'
|
||||
| 'error'
|
||||
| 'retry';
|
||||
| 'retry'
|
||||
| 'writeSuccess'
|
||||
| 'writeFailed'
|
||||
| 'writeUnavailable'
|
||||
| 'writeCancelled';
|
||||
|
||||
export type ScanState = {
|
||||
uid: string;
|
||||
@@ -104,6 +108,18 @@ export function resolveScanText(key: ScanCopyKey): string {
|
||||
if (key === 'retry') {
|
||||
return zh ? '重试' : 'Try again';
|
||||
}
|
||||
if (key === 'writeSuccess') {
|
||||
return zh ? '已写入' : 'Written to tag';
|
||||
}
|
||||
if (key === 'writeFailed') {
|
||||
return zh ? '写入失败' : 'Could not write';
|
||||
}
|
||||
if (key === 'writeUnavailable') {
|
||||
return zh ? '暂无可写内容' : 'Nothing to write';
|
||||
}
|
||||
if (key === 'writeCancelled') {
|
||||
return zh ? '已取消写入' : 'Write cancelled';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -214,12 +230,130 @@ export function applyScanOptions(state: ScanState, options: ScanPageOptions | nu
|
||||
}
|
||||
|
||||
/**
|
||||
* APP 原生贴卡占位。调不到天线时回退手动输入,禁止伪造成功
|
||||
* NFC 标签 id(ArrayBuffer)转大写 Hex UID;空则返回空串
|
||||
*/
|
||||
function nfcIdToHex(id: ArrayBuffer | null | undefined): string {
|
||||
if (id == null) {
|
||||
return '';
|
||||
}
|
||||
const bytes = new Uint8Array(id);
|
||||
let hex = '';
|
||||
let i = 0;
|
||||
const len = bytes.length;
|
||||
while (i < len) {
|
||||
let part = bytes[i].toString(16);
|
||||
if (part.length < 2) {
|
||||
part = '0' + part;
|
||||
}
|
||||
hex += part;
|
||||
i++;
|
||||
}
|
||||
return hex.toUpperCase();
|
||||
}
|
||||
|
||||
type NfcFail = {
|
||||
errMsg?: string;
|
||||
};
|
||||
|
||||
type NfcIdResult = {
|
||||
id?: ArrayBuffer | null;
|
||||
};
|
||||
|
||||
type NfcCallbackOptions = {
|
||||
success?: () => void;
|
||||
fail?: (err: NfcFail) => void;
|
||||
};
|
||||
|
||||
type NdefWriteOptions = {
|
||||
uris?: string[];
|
||||
success?: () => void;
|
||||
fail?: (err: NfcFail) => void;
|
||||
};
|
||||
|
||||
type NdefWriter = {
|
||||
writeNdefMessage: (options: NdefWriteOptions) => void;
|
||||
connect?: (options: NfcCallbackOptions) => void;
|
||||
};
|
||||
|
||||
type NfcAdapter = {
|
||||
getNdef: () => NdefWriter | null;
|
||||
startDiscovery: (options: NfcCallbackOptions) => void;
|
||||
onDiscovered: (callback: (res: NfcIdResult) => void) => void;
|
||||
};
|
||||
|
||||
type UniWithNfc = {
|
||||
getNFCAdapter?: () => NfcAdapter | null;
|
||||
};
|
||||
|
||||
function readNfcAdapter(): NfcAdapter | null {
|
||||
const runtime = uni as UniWithNfc;
|
||||
if (runtime.getNFCAdapter == null) {
|
||||
return null;
|
||||
}
|
||||
return runtime.getNFCAdapter();
|
||||
}
|
||||
|
||||
/**
|
||||
* APP:调用官方风格 uni.getNFCAdapter + startDiscovery / onDiscovered 尝试读 UID。
|
||||
* 同步路径仅在已读到合法 UID 时返回非空;读不到、API 不存在或抛错返回空串,禁止伪造。
|
||||
*/
|
||||
function tryReadUidFromAntenna(state: ScanState): string {
|
||||
// #ifdef APP
|
||||
try {
|
||||
const adapter = readNfcAdapter();
|
||||
if (adapter == null) {
|
||||
return '';
|
||||
}
|
||||
let syncUid = '';
|
||||
adapter.startDiscovery({
|
||||
success: () => {
|
||||
adapter.onDiscovered((res: NfcIdResult) => {
|
||||
const uid = parseUid(nfcIdToHex(res.id));
|
||||
if (uid === '') {
|
||||
return;
|
||||
}
|
||||
// 异步贴卡成功:写入真实 UID,不伪造
|
||||
state.uid = uid;
|
||||
state.empty = false;
|
||||
state.scanning = false;
|
||||
state.manualInput = false;
|
||||
state.errorMessage = '';
|
||||
syncUid = uid;
|
||||
});
|
||||
},
|
||||
fail: (_err: { errMsg?: string }) => {
|
||||
// 由 startScan 统一走手动输入回退
|
||||
},
|
||||
});
|
||||
return parseUid(syncUid);
|
||||
} catch (_err) {
|
||||
return '';
|
||||
}
|
||||
// #endif
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* APP 尝试官方 NFC Adapter 读 UID;仅合法 UID 才成功。否则回退手动输入,禁止伪造成功
|
||||
*/
|
||||
export function startScan(state: ScanState): boolean {
|
||||
// #ifdef APP
|
||||
// Native NFC antenna is not wired in this skeleton.
|
||||
try {
|
||||
const uid = tryReadUidFromAntenna(state);
|
||||
if (parseUid(uid) !== '') {
|
||||
state.uid = parseUid(uid);
|
||||
state.scanning = false;
|
||||
state.manualInput = false;
|
||||
state.empty = false;
|
||||
state.errorMessage = '';
|
||||
state.record = null;
|
||||
return true;
|
||||
}
|
||||
} catch (_err) {
|
||||
// 落入下方失败回退
|
||||
}
|
||||
// #endif
|
||||
|
||||
state.scanning = false;
|
||||
state.manualInput = true;
|
||||
state.record = null;
|
||||
@@ -285,3 +419,123 @@ export async function submitScan(state: ScanState): Promise<NFCRecord | null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可写 NDEF URI:有合法 cardId 才生成;否则空串表示无可写内容
|
||||
*/
|
||||
export function buildNdefUri(cardId: string | number | null | undefined): string {
|
||||
const id = parseCardId(cardId);
|
||||
if (id == null) {
|
||||
return '';
|
||||
}
|
||||
return `https://omnicard.ai/c/${id}`;
|
||||
}
|
||||
|
||||
function toastWriteUnavailable(): void {
|
||||
if (typeof uni === 'undefined' || typeof uni.showToast !== 'function') {
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: resolveScanText('writeUnavailable'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
function toastWriteFailed(): void {
|
||||
if (typeof uni === 'undefined' || typeof uni.showToast !== 'function') {
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: resolveScanText('writeFailed'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
function toastWriteCancelled(): void {
|
||||
if (typeof uni === 'undefined' || typeof uni.showToast !== 'function') {
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: resolveScanText('writeCancelled'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
function isWriteCancelledError(err: { errMsg?: string } | null | undefined): boolean {
|
||||
if (err == null || err.errMsg == null) {
|
||||
return false;
|
||||
}
|
||||
const msg = String(err.errMsg).toLowerCase();
|
||||
return msg.indexOf('cancel') >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 贴卡写入 NDEF:仅系统写入接口的 success 回调才 toast 已写入。
|
||||
* 天线未写 / 取消 / 失败 / 无可写内容均不得报写入成功。
|
||||
*/
|
||||
export function writeNdefToTag(uri: string | null | undefined): Promise<boolean> {
|
||||
const payload = uri == null ? '' : String(uri).trim();
|
||||
if (payload === '') {
|
||||
toastWriteUnavailable();
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
return new Promise<boolean>(resolve => {
|
||||
try {
|
||||
const adapter = readNfcAdapter();
|
||||
if (adapter == null) {
|
||||
toastWriteFailed();
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const ndef = adapter.getNdef();
|
||||
if (ndef == null) {
|
||||
toastWriteFailed();
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const runWrite = (): void => {
|
||||
ndef.writeNdefMessage({
|
||||
uris: [payload],
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: resolveScanText('writeSuccess'),
|
||||
icon: 'none',
|
||||
});
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err: { errMsg?: string }) => {
|
||||
if (isWriteCancelledError(err)) {
|
||||
toastWriteCancelled();
|
||||
} else {
|
||||
toastWriteFailed();
|
||||
}
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (typeof ndef.connect === 'function') {
|
||||
ndef.connect({
|
||||
success: () => {
|
||||
runWrite();
|
||||
},
|
||||
fail: (err: { errMsg?: string }) => {
|
||||
if (isWriteCancelledError(err)) {
|
||||
toastWriteCancelled();
|
||||
} else {
|
||||
toastWriteFailed();
|
||||
}
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
runWrite();
|
||||
} catch (_err) {
|
||||
toastWriteFailed();
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -282,8 +282,12 @@ export async function unfreezeDevice(
|
||||
/**
|
||||
* 国际化多语言文案字典解析
|
||||
*/
|
||||
export function resolveSecurityText(key: SecurityCopyKey): string {
|
||||
const isZh = getCurrentLocale() === 'zh-CN';
|
||||
export function resolveSecurityText(key: SecurityCopyKey, locale?: string): string {
|
||||
const lang =
|
||||
locale != null && String(locale).trim() !== ''
|
||||
? String(locale).trim()
|
||||
: getCurrentLocale();
|
||||
const isZh = lang === 'zh-CN';
|
||||
|
||||
switch (key) {
|
||||
case 'title':
|
||||
|
||||
文件差异内容过多而无法显示
加载差异
@@ -10,6 +10,12 @@ import {
|
||||
setAppLocale,
|
||||
getOmniText,
|
||||
} from '../../../common/locale.uts';
|
||||
import {
|
||||
CardProfile,
|
||||
OwnerPageData,
|
||||
OwnerPageQuery,
|
||||
} from '../../../common/types.uts';
|
||||
import { fetchOwnerCardPage } from '../../../common/api.uts';
|
||||
|
||||
export { PORTAL_LOCALE_STORAGE_KEY };
|
||||
|
||||
@@ -18,6 +24,8 @@ export type UserProfileAccount = {
|
||||
company: string;
|
||||
department: string;
|
||||
avatar: string;
|
||||
cardId: string;
|
||||
cardSlug: string;
|
||||
};
|
||||
|
||||
export type NotificationSettings = {
|
||||
@@ -74,13 +82,104 @@ function defaultStorage(): StorageApi {
|
||||
|
||||
export function getDefaultAccount(): UserProfileAccount {
|
||||
return {
|
||||
name: 'Alex Vance',
|
||||
company: 'Nexus Tech Global',
|
||||
department: 'Overseas Business Dept',
|
||||
avatar: 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?auto=format&fit=crop&w=256&q=80',
|
||||
name: '',
|
||||
company: '',
|
||||
department: '',
|
||||
avatar: '',
|
||||
cardId: '',
|
||||
cardSlug: '',
|
||||
};
|
||||
}
|
||||
|
||||
export type LoadProfileAccountApi = {
|
||||
fetchOwnerCardPage: (
|
||||
query: OwnerPageQuery
|
||||
) => Promise<OwnerPageData<CardProfile>>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 读取接口可选组织字段:仅 trim,缺失或空白一律空串
|
||||
*/
|
||||
export function readOptionalOrgText(value: string | null | undefined): string {
|
||||
if (value == null) {
|
||||
return '';
|
||||
}
|
||||
return String(value).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司/部门展示:有值原样返回,缺失或空串走 i18n 空态
|
||||
*/
|
||||
export function displayOrgField(value: string | null | undefined): string {
|
||||
const text = readOptionalOrgText(value);
|
||||
if (text === '') {
|
||||
return resolveProfileText('empty');
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口失败或无数据时清空公司与部门,禁止保留上次/示例值
|
||||
*/
|
||||
export function clearOrgFields(state: ProfileState): void {
|
||||
state.account.company = '';
|
||||
state.account.department = '';
|
||||
}
|
||||
|
||||
function readDepartmentFromCard(card: CardProfile): string {
|
||||
const extra = card as CardProfile & { department?: string | null };
|
||||
return readOptionalOrgText(extra.department);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从名片分页接口拉取当前用户公司/部门(仅使用接口返回字段)
|
||||
*/
|
||||
export async function loadOwnerProfileAccount(
|
||||
state: ProfileState,
|
||||
api?: LoadProfileAccountApi
|
||||
): Promise<boolean> {
|
||||
const fetchPage =
|
||||
api != null ? api.fetchOwnerCardPage : fetchOwnerCardPage;
|
||||
state.loading = true;
|
||||
try {
|
||||
const data = await fetchPage({ page: 1, size: 1 } as OwnerPageQuery);
|
||||
const list = data.list != null ? data.list : [];
|
||||
if (list.length === 0) {
|
||||
clearOrgFields(state);
|
||||
state.account.cardId = '';
|
||||
state.account.cardSlug = '';
|
||||
state.errorMessage = '';
|
||||
state.loading = false;
|
||||
return true;
|
||||
}
|
||||
const card = list[0];
|
||||
state.account.company = readOptionalOrgText(card.company);
|
||||
state.account.department = readDepartmentFromCard(card);
|
||||
state.account.cardId = card.id != null ? String(card.id) : '';
|
||||
const slugText = card.slug != null ? String(card.slug).trim() : '';
|
||||
state.account.cardSlug = slugText;
|
||||
if (card.name != null && String(card.name).trim() !== '') {
|
||||
state.account.name = String(card.name).trim();
|
||||
}
|
||||
if (card.avatarUrl != null && String(card.avatarUrl).trim() !== '') {
|
||||
state.account.avatar = String(card.avatarUrl).trim();
|
||||
}
|
||||
state.errorMessage = '';
|
||||
state.loading = false;
|
||||
return true;
|
||||
} catch (err: unknown) {
|
||||
clearOrgFields(state);
|
||||
state.account.cardId = '';
|
||||
state.account.cardSlug = '';
|
||||
const msg = err instanceof Error && err.message !== ''
|
||||
? err.message
|
||||
: resolveProfileText('error');
|
||||
state.errorMessage = msg;
|
||||
state.loading = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function getDefaultNotifications(): NotificationSettings {
|
||||
return {
|
||||
radarPush: true,
|
||||
@@ -90,9 +189,9 @@ export function getDefaultNotifications(): NotificationSettings {
|
||||
|
||||
export function getDefaultMetrics(): ProfileMetrics {
|
||||
return {
|
||||
cardsCount: 6,
|
||||
visitorsCount: 128,
|
||||
leadsCount: 24,
|
||||
cardsCount: 0,
|
||||
visitorsCount: 0,
|
||||
leadsCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,7 +226,7 @@ export function saveProfileMetrics(metrics: ProfileMetrics, storage?: StorageApi
|
||||
}
|
||||
|
||||
export function createProfileState(locale?: OmniLocale): ProfileState {
|
||||
const currentLocale = locale != null && locale !== '' ? locale : getCurrentLocale();
|
||||
const currentLocale = locale != null ? locale : getCurrentLocale();
|
||||
return {
|
||||
account: getDefaultAccount(),
|
||||
notifications: getDefaultNotifications(),
|
||||
@@ -166,25 +265,32 @@ export function loadProfileSettings(storage?: StorageApi): ProfileState {
|
||||
const parsedAccount = safeParseJson<Record<string, unknown>>(rawAccount);
|
||||
|
||||
if (parsedAccount != null && typeof parsedAccount === 'object') {
|
||||
const defaultAcc = getDefaultAccount();
|
||||
const safeName = typeof parsedAccount.name === 'string' && parsedAccount.name.trim() !== ''
|
||||
const safeName = typeof parsedAccount.name === 'string'
|
||||
? parsedAccount.name.trim()
|
||||
: defaultAcc.name;
|
||||
const safeCompany = typeof parsedAccount.company === 'string' && parsedAccount.company.trim() !== ''
|
||||
: '';
|
||||
const safeCompany = typeof parsedAccount.company === 'string'
|
||||
? parsedAccount.company.trim()
|
||||
: defaultAcc.company;
|
||||
const safeDept = typeof parsedAccount.department === 'string' && parsedAccount.department.trim() !== ''
|
||||
: '';
|
||||
const safeDept = typeof parsedAccount.department === 'string'
|
||||
? parsedAccount.department.trim()
|
||||
: defaultAcc.department;
|
||||
const safeAvatar = typeof parsedAccount.avatar === 'string' && parsedAccount.avatar.trim() !== ''
|
||||
: '';
|
||||
const safeAvatar = typeof parsedAccount.avatar === 'string'
|
||||
? parsedAccount.avatar.trim()
|
||||
: defaultAcc.avatar;
|
||||
: '';
|
||||
const safeCardId = typeof parsedAccount.cardId === 'string'
|
||||
? parsedAccount.cardId.trim()
|
||||
: '';
|
||||
const safeCardSlug = typeof parsedAccount.cardSlug === 'string'
|
||||
? parsedAccount.cardSlug.trim()
|
||||
: '';
|
||||
|
||||
state.account = {
|
||||
name: safeName,
|
||||
company: safeCompany,
|
||||
department: safeDept,
|
||||
avatar: safeAvatar,
|
||||
cardId: safeCardId,
|
||||
cardSlug: safeCardSlug,
|
||||
};
|
||||
}
|
||||
} catch (_e) {
|
||||
@@ -418,6 +524,9 @@ export function resolveProfileText(key: string): string {
|
||||
if (key === 'error') {
|
||||
return getOmniText(locale, 'common.error');
|
||||
}
|
||||
if (key === 'empty') {
|
||||
return getOmniText(locale, 'common.empty');
|
||||
}
|
||||
|
||||
const isZh = locale === 'zh-CN';
|
||||
|
||||
@@ -507,25 +616,25 @@ export function resolveProfileText(key: string): string {
|
||||
case 'confirmLogoutContent':
|
||||
return isZh ? '确定要退出当前账号吗?' : 'Are you sure you want to sign out?';
|
||||
case 'myCardsSub':
|
||||
return isZh ? '查看与出示专属数字名片' : 'View and present digital cards';
|
||||
return isZh ? '查看和切换名片' : 'View and switch cards';
|
||||
case 'cardEditSub':
|
||||
return isZh ? '修改履历、职业信息与社交矩阵' : 'Update profile and social links';
|
||||
return isZh ? '改姓名、职位和联系方式' : 'Name, role, and contact details';
|
||||
case 'productCasesSub':
|
||||
return isZh ? '展示产品与案例' : 'Portfolio and cases';
|
||||
return isZh ? '名片上展示的案例' : 'Cases shown on your card';
|
||||
case 'articleDynamicsSub':
|
||||
return isZh ? '发布业务动态与文章' : 'Publish dynamic posts';
|
||||
return isZh ? '名片上展示的文章' : 'Articles shown on your card';
|
||||
case 'sharePosterSub':
|
||||
return isZh ? '展会专属扫码展台与立牌' : 'Expo QR poster and stand';
|
||||
return isZh ? '全屏出示二维码' : 'Full-screen QR';
|
||||
case 'exchangeHallSub':
|
||||
return isZh ? '面对面扫码或碰卡互换' : 'Face-to-face card exchange';
|
||||
return isZh ? '当面交换名片' : 'Exchange in person';
|
||||
case 'nfcScanSub':
|
||||
return isZh ? '新实体卡贴碰写入绑定' : 'Tap and bind new NFC card';
|
||||
return isZh ? '把实体卡绑到名片' : 'Bind a physical card';
|
||||
case 'nfcModeSub':
|
||||
return isZh ? '展会与拜访场景切换' : 'Switch expo and meeting modes';
|
||||
return isZh ? '更换这张卡打开的页面' : 'Choose what the card opens';
|
||||
case 'nfcSecuritySub':
|
||||
return isZh ? '防盗刷保护与远程紧急冻结' : 'Remote freeze and theft protection';
|
||||
return isZh ? '卡片丢失时远程停用' : 'Freeze a lost card';
|
||||
case 'teamBriefingSub':
|
||||
return isZh ? '全员名片分发与获客大盘战报' : 'Team leads and distribution briefing';
|
||||
return isZh ? '团队今天的获客' : "Today's team results";
|
||||
case 'avatarActionSheetTitle':
|
||||
return isZh ? '头像管理' : 'Avatar Options';
|
||||
case 'avatarActionPreview':
|
||||
@@ -536,8 +645,12 @@ export function resolveProfileText(key: string): string {
|
||||
return isZh ? '移除当前头像' : 'Remove Avatar';
|
||||
case 'aboutApp':
|
||||
return isZh ? '关于 OmniCard' : 'About OmniCard';
|
||||
case 'aboutBody':
|
||||
return isZh ? '数字名片、微官网和访客雷达' : 'Digital cards, microsites, and visitor radar';
|
||||
case 'confirm':
|
||||
return isZh ? '知道了' : 'OK';
|
||||
case 'appVersion':
|
||||
return isZh ? '企业旗舰版 v1.2.0' : 'Enterprise v1.2.0';
|
||||
return 'OmniCard';
|
||||
case 'securitySafe':
|
||||
return isZh ? '保护中' : 'Protected';
|
||||
case 'livePulse':
|
||||
|
||||
文件差异内容过多而无法显示
加载差异
@@ -80,7 +80,7 @@
|
||||
<view class="metric-header-row">
|
||||
<text class="metric-label">{{ t('metricTotal') }}</text>
|
||||
<view class="metric-badge metric-badge-brand">
|
||||
<text class="metric-badge-text">TOTAL</text>
|
||||
<text class="metric-badge-text">{{ t('badgeTotal') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="metric-value text-brand">{{ state.summary.totalLeads }}</text>
|
||||
@@ -96,7 +96,7 @@
|
||||
<text class="metric-label text-hot">{{ t('metricHot') }}</text>
|
||||
<view class="metric-badge metric-badge-hot">
|
||||
<view class="hot-spark-dot"></view>
|
||||
<text class="metric-badge-text text-hot">HOT</text>
|
||||
<text class="metric-badge-text text-hot">{{ t('badgeHot') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="metric-value text-hot">{{ state.summary.hotLeads }}</text>
|
||||
@@ -111,7 +111,7 @@
|
||||
<view class="metric-header-row">
|
||||
<text class="metric-label">{{ t('metricWon') }}</text>
|
||||
<view class="metric-badge metric-badge-won">
|
||||
<text class="metric-badge-text text-won">WON</text>
|
||||
<text class="metric-badge-text text-won">{{ t('badgeWon') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="metric-value text-won">{{ state.summary.wonLeads }}</text>
|
||||
@@ -126,7 +126,7 @@
|
||||
<view class="metric-header-row">
|
||||
<text class="metric-label">{{ t('metricRate') }}</text>
|
||||
<view class="metric-badge metric-badge-rate">
|
||||
<text class="metric-badge-text text-brand">CVR</text>
|
||||
<text class="metric-badge-text text-brand">{{ t('badgeRate') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="metric-value text-brand">{{ state.summary.overallRate }}%</text>
|
||||
@@ -142,7 +142,7 @@
|
||||
<view class="card-header-bar">
|
||||
<view class="card-title-group">
|
||||
<text class="card-title">{{ t('funnelTitle') }}</text>
|
||||
<text class="card-title-badge">4 STAGES</text>
|
||||
<text class="card-title-badge">{{ t('funnelStages') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
<view class="channel-accent-dot" :class="'accent-dot-' + ch.source"></view>
|
||||
<text class="channel-name">{{ ch.label }}</text>
|
||||
</view>
|
||||
<text class="channel-cvr-pill">{{ ch.conversionRate }}% CVR</text>
|
||||
<text class="channel-cvr-pill">{{ ch.conversionRate }}% {{ t('badgeRate') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="channel-data-row">
|
||||
@@ -295,17 +295,18 @@ const pageRtlClass = computed((): string => {
|
||||
return isRtl(getCurrentLocale()) ? 'stats-rtl' : '';
|
||||
});
|
||||
|
||||
/** R31: bar flex from API counts only; zero when empty, never fallback filler */
|
||||
const healthHotFlex = computed((): number => {
|
||||
return state.summary.hotLeads > 0 ? state.summary.hotLeads : 1;
|
||||
return state.summary.hotLeads > 0 ? state.summary.hotLeads : 0;
|
||||
});
|
||||
|
||||
const healthWarmFlex = computed((): number => {
|
||||
const warm = state.summary.totalLeads - state.summary.hotLeads - state.summary.wonLeads;
|
||||
return warm > 0 ? warm : 1;
|
||||
return warm > 0 ? warm : 0;
|
||||
});
|
||||
|
||||
const healthCoolFlex = computed((): number => {
|
||||
return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
function t(key: string): string {
|
||||
|
||||
@@ -397,7 +397,7 @@ export async function refreshOverview(
|
||||
state.loading = false;
|
||||
if (result.errorMessage === '') {
|
||||
try {
|
||||
uni.vibrateShort();
|
||||
uni.vibrateShort({ type: 'light' });
|
||||
} catch (_e) {
|
||||
// 兼容不支持振动的端环境
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export type LeadDetailCopyKey =
|
||||
| 'notes'
|
||||
| 'notesPlaceholder'
|
||||
| 'save'
|
||||
| 'saving'
|
||||
| 'back'
|
||||
| 'empty'
|
||||
| 'missingId'
|
||||
@@ -52,7 +53,10 @@ export type LeadDetailCopyKey =
|
||||
| 'scriptCopiedToast'
|
||||
| 'savedContactToast'
|
||||
| 'leadTitle'
|
||||
| 'aiScriptTitle';
|
||||
| 'aiScriptTitle'
|
||||
| 'callFailed'
|
||||
| 'noteSavedToast'
|
||||
| 'notesRequiredToast';
|
||||
|
||||
export type LeadDetailPageOptions = {
|
||||
id?: string;
|
||||
@@ -91,6 +95,13 @@ export type SaveNoteApi = {
|
||||
) => Promise<LeadEntity>;
|
||||
};
|
||||
|
||||
export type SaveNoteResult = {
|
||||
ok: boolean;
|
||||
code?: number;
|
||||
lead: LeadEntity | null;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type LeadDetailState = {
|
||||
rawId: string;
|
||||
leadId: string | number | null;
|
||||
@@ -221,12 +232,18 @@ export function resolveLeadDetailText(key: LeadDetailCopyKey): string {
|
||||
if (key === 'aiScriptTitle') {
|
||||
return zh ? '建议跟进话术' : 'Follow-up Suggestion';
|
||||
}
|
||||
if (key === 'callFailed') {
|
||||
return zh ? '无法拨打电话' : 'Unable to place the call';
|
||||
}
|
||||
if (key === 'noteSavedToast') {
|
||||
return zh ? '备忘已保存' : 'Note saved';
|
||||
}
|
||||
if (key === 'notesRequiredToast') {
|
||||
return zh ? '请输入备忘或上传附件' : 'Please enter note or upload attachment';
|
||||
}
|
||||
if (key === 'saving') {
|
||||
return zh ? '保存中' : 'Saving';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -313,6 +330,80 @@ export function formatWhatsAppUrl(rawPhone: string | null | undefined): string {
|
||||
return `https://wa.me/${digits}`;
|
||||
}
|
||||
|
||||
function toastNone(title: string): void {
|
||||
uni.showToast({
|
||||
title,
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开外链:优先 window.open(H5),否则复制链接(对齐 useLogin openOrCopyAuthUrl)
|
||||
*/
|
||||
function openExternalUrl(url: string): boolean {
|
||||
const safeUrl = url != null ? url.trim() : '';
|
||||
if (safeUrl === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
let opened = false;
|
||||
try {
|
||||
if (typeof window !== 'undefined' && typeof window.open === 'function') {
|
||||
window.open(safeUrl, '_blank');
|
||||
opened = true;
|
||||
}
|
||||
} catch (_e) {}
|
||||
|
||||
if (opened) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
uni.setClipboardData({
|
||||
data: safeUrl,
|
||||
showToast: true,
|
||||
});
|
||||
return true;
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 有合法电话号时调 uni.makePhoneCall;无号码 toast comingSoon。
|
||||
* 不伪造成功:fail 回调提示 callFailed。
|
||||
*/
|
||||
export function callLeadPhone(phone: string | null | undefined): boolean {
|
||||
const trimmed = phone != null ? String(phone).trim() : '';
|
||||
const digits = trimmed.replace(/[^0-9]/g, '');
|
||||
if (trimmed === '' || digits === '') {
|
||||
toastNone(resolveLeadDetailText('comingSoon'));
|
||||
return false;
|
||||
}
|
||||
|
||||
uni.makePhoneCall({
|
||||
phoneNumber: trimmed,
|
||||
fail: () => {
|
||||
toastNone(resolveLeadDetailText('callFailed'));
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 有 WhatsApp/电话号码时打开 wa.me;无号码 toast comingSoon,不打开空链接。
|
||||
*/
|
||||
export function openLeadWhatsApp(
|
||||
phoneOrWhatsApp: string | null | undefined
|
||||
): boolean {
|
||||
const waUrl = formatWhatsAppUrl(phoneOrWhatsApp);
|
||||
if (waUrl === '') {
|
||||
toastNone(resolveLeadDetailText('comingSoon'));
|
||||
return false;
|
||||
}
|
||||
return openExternalUrl(waUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 跟进话术生成器 (基于客户姓名、公司、渠道与意向板块)
|
||||
*/
|
||||
@@ -417,11 +508,19 @@ export function parseNoteAttachments(
|
||||
return { cleanText, imageUrls };
|
||||
}
|
||||
|
||||
export type DeviceContactDraft = {
|
||||
id?: string | number;
|
||||
name: string;
|
||||
company?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存到手机系统通讯录 (深度复用通用 RFC 6350 / vCard 引擎)
|
||||
*/
|
||||
export async function saveContactToDevice(
|
||||
lead: LeadEntity | null
|
||||
lead: DeviceContactDraft | null
|
||||
): Promise<boolean> {
|
||||
if (lead == null) {
|
||||
return false;
|
||||
@@ -516,11 +615,12 @@ export async function loadDetail(
|
||||
|
||||
/**
|
||||
* 更新 notes(支持附件结构化嵌入):POST /admin/crm/lead/update { id, notes }
|
||||
* 仅 Cool-Admin code === 1000(http 层已解包成功)视为保存成功
|
||||
*/
|
||||
export async function saveNote(
|
||||
input: SaveNoteInput,
|
||||
api?: SaveNoteApi
|
||||
): Promise<LeadEntity> {
|
||||
): Promise<SaveNoteResult> {
|
||||
const notes = appendStructuredNote(
|
||||
input.notes,
|
||||
input.next,
|
||||
@@ -532,7 +632,22 @@ export async function saveNote(
|
||||
id: input.id,
|
||||
notes,
|
||||
};
|
||||
return post<LeadEntity>('/admin/crm/lead/update', payload);
|
||||
try {
|
||||
const lead = await post<LeadEntity>('/admin/crm/lead/update', payload);
|
||||
return {
|
||||
ok: true,
|
||||
code: 1000,
|
||||
lead,
|
||||
errorMessage: '',
|
||||
};
|
||||
} catch (err) {
|
||||
return {
|
||||
ok: false,
|
||||
code: undefined,
|
||||
lead: null,
|
||||
errorMessage: readErrorMessage(err),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function createLeadDetailState(): LeadDetailState {
|
||||
@@ -653,27 +768,27 @@ export async function submitLeadNote(
|
||||
}
|
||||
state.saving = true;
|
||||
state.errorMessage = '';
|
||||
try {
|
||||
const saved = await saveNote(
|
||||
{
|
||||
id: state.leadId,
|
||||
notes: state.existingNotes,
|
||||
next,
|
||||
status: state.lead != null ? state.lead.status : undefined,
|
||||
attachments: state.attachments,
|
||||
},
|
||||
api
|
||||
);
|
||||
applyLeadToState(state, saved);
|
||||
const result = await saveNote(
|
||||
{
|
||||
id: state.leadId,
|
||||
notes: state.existingNotes,
|
||||
next,
|
||||
status: state.lead != null ? state.lead.status : undefined,
|
||||
attachments: state.attachments,
|
||||
},
|
||||
api
|
||||
);
|
||||
// 仅接口 code === 1000 才清空输入并标成已保存
|
||||
if (result.ok && result.code === 1000 && result.lead != null) {
|
||||
applyLeadToState(state, result.lead);
|
||||
state.nextNote = '';
|
||||
state.attachments = [];
|
||||
state.saving = false;
|
||||
return true;
|
||||
} catch (err) {
|
||||
state.saving = false;
|
||||
state.errorMessage = readErrorMessage(err);
|
||||
return false;
|
||||
}
|
||||
state.saving = false;
|
||||
state.errorMessage = result.errorMessage;
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function updateLeadStage(
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
LeadEntity,
|
||||
LeadStatus,
|
||||
OwnerPageData,
|
||||
OwnerPagePagination,
|
||||
OwnerPageQuery,
|
||||
RadarTrack,
|
||||
} from '../../common/types.uts';
|
||||
@@ -45,6 +46,7 @@ export type LeadsCopyKey =
|
||||
| 'sourceQr'
|
||||
| 'sourceLink'
|
||||
| 'sourceAi'
|
||||
| 'stats'
|
||||
| 'statTotal'
|
||||
| 'statHot'
|
||||
| 'statNew'
|
||||
@@ -69,11 +71,7 @@ export type LoadLeadsApi = {
|
||||
|
||||
export type LoadLeadsResult = {
|
||||
list: LeadEntity[];
|
||||
pagination: {
|
||||
page: number;
|
||||
size: number;
|
||||
total: number;
|
||||
};
|
||||
pagination: OwnerPagePagination;
|
||||
empty: boolean;
|
||||
errorMessage: string;
|
||||
};
|
||||
@@ -211,6 +209,9 @@ export function resolveLeadsText(key: LeadsCopyKey): string {
|
||||
if (key === 'sourceAi') {
|
||||
return 'AI Chat';
|
||||
}
|
||||
if (key === 'stats') {
|
||||
return zh ? '统计' : 'Stats';
|
||||
}
|
||||
if (key === 'statTotal') {
|
||||
return zh ? '总潜客' : 'Total Leads';
|
||||
}
|
||||
|
||||
@@ -32,7 +32,22 @@ export type RadarCopyKey =
|
||||
| 'activeNow'
|
||||
| 'blocksViewed'
|
||||
| 'filterAll'
|
||||
| 'avgStay';
|
||||
| 'avgStay'
|
||||
| 'unknown'
|
||||
| 'localNetwork'
|
||||
| 'networkAddress'
|
||||
| 'onlineNow'
|
||||
| 'openedNfc'
|
||||
| 'openedQr'
|
||||
| 'openedLink'
|
||||
| 'blockHero'
|
||||
| 'blockCase'
|
||||
| 'blockArticle'
|
||||
| 'blockSocial'
|
||||
| 'blockVideo'
|
||||
| 'blockForm'
|
||||
| 'blockAppointment'
|
||||
| 'blockContact';
|
||||
|
||||
export type LoadTracksInput = {
|
||||
cardId?: string | number | null;
|
||||
@@ -56,6 +71,7 @@ export type LoadTracksResult = {
|
||||
export type RadarStats = {
|
||||
totalVisits: number;
|
||||
highIntentCount: number;
|
||||
onlineCount: number;
|
||||
intentRateText: string;
|
||||
avgStayText: string;
|
||||
topLocation: string;
|
||||
@@ -168,6 +184,51 @@ export function resolveRadarText(key: RadarCopyKey): string {
|
||||
if (key === 'avgStay') {
|
||||
return zh ? '平均停留' : 'Avg Stay';
|
||||
}
|
||||
if (key === 'unknown') {
|
||||
return zh ? '未知' : 'Unknown';
|
||||
}
|
||||
if (key === 'localNetwork') {
|
||||
return zh ? '本地网络' : 'Local network';
|
||||
}
|
||||
if (key === 'networkAddress') {
|
||||
return zh ? '网络地址' : 'Network';
|
||||
}
|
||||
if (key === 'onlineNow') {
|
||||
return zh ? '在线' : 'Online';
|
||||
}
|
||||
if (key === 'openedNfc') {
|
||||
return zh ? '通过 NFC 碰一碰打开名片' : 'Opened your card with an NFC tap';
|
||||
}
|
||||
if (key === 'openedQr') {
|
||||
return zh ? '扫描展台二维码进入名片' : 'Opened your card from the QR showcase';
|
||||
}
|
||||
if (key === 'openedLink') {
|
||||
return zh ? '通过链接打开了你的名片' : 'Opened your card from a direct link';
|
||||
}
|
||||
if (key === 'blockHero') {
|
||||
return zh ? '名片主页' : 'Profile';
|
||||
}
|
||||
if (key === 'blockCase') {
|
||||
return zh ? '案例' : 'Case';
|
||||
}
|
||||
if (key === 'blockArticle') {
|
||||
return zh ? '文章' : 'Article';
|
||||
}
|
||||
if (key === 'blockSocial') {
|
||||
return zh ? '社交' : 'Social';
|
||||
}
|
||||
if (key === 'blockVideo') {
|
||||
return zh ? '视频' : 'Video';
|
||||
}
|
||||
if (key === 'blockForm') {
|
||||
return zh ? '留资表单' : 'Lead form';
|
||||
}
|
||||
if (key === 'blockAppointment') {
|
||||
return zh ? '预约会面' : 'Meeting';
|
||||
}
|
||||
if (key === 'blockContact') {
|
||||
return zh ? '联系方式' : 'Contact';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -222,6 +283,14 @@ export function formatStay(ms: number | null | undefined): string {
|
||||
if (safe < 1000) {
|
||||
return `${safe}ms`;
|
||||
}
|
||||
if (safe >= 60000) {
|
||||
const minutes = Math.floor(safe / 60000);
|
||||
const seconds = Math.round((safe % 60000) / 1000);
|
||||
if (seconds <= 0) {
|
||||
return `${minutes}m`;
|
||||
}
|
||||
return `${minutes}m ${seconds}s`;
|
||||
}
|
||||
return `${(safe / 1000).toFixed(1)}s`;
|
||||
}
|
||||
|
||||
@@ -236,22 +305,65 @@ export function formatDepth(depth: number | null | undefined): string {
|
||||
return `${clamped}%`;
|
||||
}
|
||||
|
||||
function isBlankGeo(value: string): boolean {
|
||||
const text = value.trim().toLowerCase();
|
||||
return text === '' || text === 'unknown' || text === 'null' || text === 'undefined';
|
||||
}
|
||||
|
||||
function isLocalGeo(value: string): boolean {
|
||||
const text = value.trim().toLowerCase();
|
||||
return text === 'local' || text === 'localhost';
|
||||
}
|
||||
|
||||
/**
|
||||
* 国家 / 城市一行展示
|
||||
* 国家 / 城市一行展示。空值与 Unknown 走「未知」,内网 Local 走「本地网络」,不回退示例城市
|
||||
*/
|
||||
export function formatLocation(country?: string, city?: string): string {
|
||||
const countryText = country != null ? String(country).trim() : '';
|
||||
const cityText = city != null ? String(city).trim() : '';
|
||||
if (countryText !== '' && cityText !== '') {
|
||||
return `${countryText} / ${cityText}`;
|
||||
if (isLocalGeo(countryText) || isLocalGeo(cityText)) {
|
||||
return resolveRadarText('localNetwork');
|
||||
}
|
||||
if (countryText !== '') {
|
||||
return countryText;
|
||||
const displayCountry = !isBlankGeo(countryText) ? countryText : resolveRadarText('unknown');
|
||||
const displayCity = !isBlankGeo(cityText) ? cityText : '';
|
||||
if (displayCity !== '') {
|
||||
return `${displayCountry} / ${displayCity}`;
|
||||
}
|
||||
if (cityText !== '') {
|
||||
return cityText;
|
||||
return displayCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
* 公网 IP 才展示。回环、内网与空地址不当作地理位置
|
||||
*/
|
||||
export function formatPublicIp(ip?: string): string {
|
||||
const raw = ip != null ? String(ip).trim() : '';
|
||||
if (raw === '') {
|
||||
return '';
|
||||
}
|
||||
return '';
|
||||
const clean = raw.replace(/^::ffff:/i, '').toLowerCase();
|
||||
if (
|
||||
clean === '' ||
|
||||
clean === '::1' ||
|
||||
clean === 'localhost' ||
|
||||
clean === '0.0.0.0' ||
|
||||
clean === '127.0.0.1' ||
|
||||
clean.startsWith('127.') ||
|
||||
clean.startsWith('10.') ||
|
||||
clean.startsWith('192.168.') ||
|
||||
clean.startsWith('169.254.') ||
|
||||
/^172\.(1[6-9]|2\d|3[0-1])\./.test(clean)
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
return raw.replace(/^::ffff:/i, '');
|
||||
}
|
||||
|
||||
export function formatNetworkLine(ip?: string): string {
|
||||
const pub = formatPublicIp(ip);
|
||||
if (pub === '') {
|
||||
return '';
|
||||
}
|
||||
return `${resolveRadarText('networkAddress')} ${pub}`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,24 +416,348 @@ export function getIntentBadgeText(level: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* 访客活动主通知流文案(如 "Alex tapped your NFC card")
|
||||
* 访客显示名:有线索或内部用户姓名就用姓名,否则用访客编号,不编造身份
|
||||
*/
|
||||
export function formatVisitorHeadline(item: RadarTrack): string {
|
||||
export function formatVisitorName(item: RadarTrack): string {
|
||||
const named = item.visitorName != null ? String(item.visitorName).trim() : '';
|
||||
if (named !== '') {
|
||||
return named;
|
||||
}
|
||||
const zh = isZhLocale();
|
||||
const vid = item.visitorId != null && item.visitorId.trim() !== '' ? item.visitorId.trim() : '';
|
||||
let name = 'Visitor';
|
||||
if (vid !== '') {
|
||||
const shortId = vid.replace(/^vis_([a-z0-9]+_)?/i, '');
|
||||
name = shortId !== '' ? `Visitor #${shortId}` : 'Visitor';
|
||||
if (vid === '') {
|
||||
return zh ? '访客' : 'Visitor';
|
||||
}
|
||||
const shortId = vid.replace(/^vis_/i, '');
|
||||
const tail = shortId.length > 10 ? shortId.slice(-8) : shortId;
|
||||
return zh ? `访客 ${tail}` : `Visitor ${tail}`;
|
||||
}
|
||||
|
||||
export function visitorAvatarLetter(item: RadarTrack): string {
|
||||
const name = formatVisitorName(item).trim();
|
||||
if (name === '') {
|
||||
return 'V';
|
||||
}
|
||||
return name.slice(0, 1).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 触达动作,只描述真实渠道,不把浏览写成已留资
|
||||
*/
|
||||
export function formatVisitorAction(item: RadarTrack): string {
|
||||
if (item.touchType === 'nfc') {
|
||||
return zh ? `${name} 通过 NFC 碰一碰接入名片` : `${name} tapped your NFC card`;
|
||||
return resolveRadarText('openedNfc');
|
||||
}
|
||||
if (item.touchType === 'qr') {
|
||||
return zh ? `${name} 扫描了展台名片二维码` : `${name} scanned your QR showcase`;
|
||||
return resolveRadarText('openedQr');
|
||||
}
|
||||
return zh ? `${name} 浏览了你的数字微官网` : `${name} saved your contact card`;
|
||||
return resolveRadarText('openedLink');
|
||||
}
|
||||
|
||||
/**
|
||||
* 访客活动主通知流文案
|
||||
*/
|
||||
export function formatVisitorHeadline(item: RadarTrack): string {
|
||||
return `${formatVisitorName(item)} ${formatVisitorAction(item)}`;
|
||||
}
|
||||
|
||||
export function readTrackTime(item: { createdAt?: string | Date; createTime?: string | Date }): number {
|
||||
const raw = item.createdAt != null ? item.createdAt : item.createTime;
|
||||
return parseTimeValue(raw);
|
||||
}
|
||||
|
||||
function parseTimeValue(raw: string | Date | null | undefined): number {
|
||||
if (raw == null) {
|
||||
return 0;
|
||||
}
|
||||
if (raw instanceof Date) {
|
||||
const time = raw.getTime();
|
||||
return Number.isFinite(time) ? time : 0;
|
||||
}
|
||||
const text = String(raw).trim();
|
||||
if (text === '') {
|
||||
return 0;
|
||||
}
|
||||
const direct = Date.parse(text);
|
||||
if (!Number.isNaN(direct) && direct > 0) {
|
||||
return direct;
|
||||
}
|
||||
const normalized = Date.parse(text.replace(' ', 'T'));
|
||||
if (!Number.isNaN(normalized) && normalized > 0) {
|
||||
return normalized;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** 5 分钟内有足迹视为仍在浏览 */
|
||||
export const RADAR_ONLINE_WINDOW_MS = 5 * 60 * 1000;
|
||||
|
||||
export function isVisitorOnline(
|
||||
item: { createdAt?: string | Date; createTime?: string | Date },
|
||||
now = Date.now()
|
||||
): boolean {
|
||||
const time = readTrackTime(item);
|
||||
if (time <= 0) {
|
||||
return false;
|
||||
}
|
||||
const diff = now - time;
|
||||
return diff <= RADAR_ONLINE_WINDOW_MS && diff >= -60000;
|
||||
}
|
||||
|
||||
function padTime(value: number): string {
|
||||
const text = String(value);
|
||||
return text.length < 2 ? `0${text}` : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绝对时间,供名片主核对监控时刻
|
||||
*/
|
||||
export function formatClockTime(createdAt?: string | Date): string {
|
||||
const time = readTrackTime({ createdAt });
|
||||
if (time <= 0) {
|
||||
return '';
|
||||
}
|
||||
const date = new Date(time);
|
||||
return `${padTime(date.getMonth() + 1)}-${padTime(date.getDate())} ${padTime(date.getHours())}:${padTime(date.getMinutes())}`;
|
||||
}
|
||||
|
||||
export function formatMonitorTime(item: { createdAt?: string | Date; createTime?: string | Date }): string {
|
||||
const raw = item.createdAt != null ? item.createdAt : item.createTime;
|
||||
const clock = formatClockTime(raw);
|
||||
const relative = formatRelativeTime(raw);
|
||||
if (clock === '') {
|
||||
return relative;
|
||||
}
|
||||
return `${clock} · ${relative}`;
|
||||
}
|
||||
|
||||
function blockTypeLabel(key: string): string {
|
||||
const id = key.trim().toLowerCase();
|
||||
if (id === 'hero' || id === 'profile') {
|
||||
return resolveRadarText('blockHero');
|
||||
}
|
||||
if (id === 'case' || id === 'cases') {
|
||||
return resolveRadarText('blockCase');
|
||||
}
|
||||
if (id === 'article' || id === 'articles') {
|
||||
return resolveRadarText('blockArticle');
|
||||
}
|
||||
if (id === 'social') {
|
||||
return resolveRadarText('blockSocial');
|
||||
}
|
||||
if (id === 'video') {
|
||||
return resolveRadarText('blockVideo');
|
||||
}
|
||||
if (id === 'form') {
|
||||
return resolveRadarText('blockForm');
|
||||
}
|
||||
if (id === 'appointment') {
|
||||
return resolveRadarText('blockAppointment');
|
||||
}
|
||||
if (id === 'contact' || id === 'contact_btn') {
|
||||
return resolveRadarText('blockContact');
|
||||
}
|
||||
return key.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览内容:优先用模块标题,否则用类型名称,原始编号仅在没有标题时保留
|
||||
*/
|
||||
export function formatViewedLabels(item: RadarTrack): string[] {
|
||||
const labels: string[] = [];
|
||||
const seen: Record<string, boolean> = {};
|
||||
const contents = item.viewedContents;
|
||||
if (contents != null && Array.isArray(contents) && contents.length > 0) {
|
||||
for (let i = 0; i < contents.length; i++) {
|
||||
const row = contents[i];
|
||||
const title = row.title != null ? String(row.title).trim() : '';
|
||||
const key = row.key != null ? String(row.key).trim() : '';
|
||||
const label = title !== '' ? title : blockTypeLabel(key);
|
||||
if (label !== '' && seen[label] !== true) {
|
||||
seen[label] = true;
|
||||
labels.push(label);
|
||||
}
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
const blocks = item.viewedBlocks;
|
||||
if (blocks == null || !Array.isArray(blocks)) {
|
||||
return labels;
|
||||
}
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const label = blockTypeLabel(String(blocks[i]));
|
||||
if (label !== '' && seen[label] !== true) {
|
||||
seen[label] = true;
|
||||
labels.push(label);
|
||||
}
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
export function formatViewedLine(item: RadarTrack): string {
|
||||
const labels = formatViewedLabels(item);
|
||||
if (labels.length === 0) {
|
||||
return '';
|
||||
}
|
||||
return `${resolveRadarText('blocksViewed')} ${labels.join(' · ')}`;
|
||||
}
|
||||
|
||||
function sessionKey(item: RadarTrack): string {
|
||||
const visitorId = item.visitorId != null ? item.visitorId.trim() : '';
|
||||
const cardId = item.cardId != null ? String(item.cardId) : '';
|
||||
if (visitorId === '' || cardId === '') {
|
||||
return '';
|
||||
}
|
||||
return `${visitorId}_${cardId}`;
|
||||
}
|
||||
|
||||
function copyTrack(item: RadarTrack): RadarTrack {
|
||||
const blocks = item.viewedBlocks != null && Array.isArray(item.viewedBlocks) ? item.viewedBlocks.slice() : [];
|
||||
const contents =
|
||||
item.viewedContents != null && Array.isArray(item.viewedContents) ? item.viewedContents.slice() : undefined;
|
||||
return {
|
||||
id: item.id,
|
||||
tenantId: item.tenantId,
|
||||
cardId: item.cardId,
|
||||
visitorId: item.visitorId,
|
||||
ip: item.ip,
|
||||
country: item.country,
|
||||
city: item.city,
|
||||
touchType: item.touchType,
|
||||
stayDurationMs: item.stayDurationMs,
|
||||
scrollDepth: item.scrollDepth,
|
||||
viewedBlocks: blocks,
|
||||
viewedContents: contents,
|
||||
visitorName: item.visitorName,
|
||||
visitorCompany: item.visitorCompany,
|
||||
avatarUrl: item.avatarUrl,
|
||||
cardTitle: item.cardTitle,
|
||||
createdAt: item.createdAt != null ? item.createdAt : item.createTime,
|
||||
createTime: item.createTime != null ? item.createTime : item.createdAt,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 同一访客对同一名片的进入与离开合并成一条监控会话
|
||||
*/
|
||||
export function consolidateRadarTracks(tracks: RadarTrack[]): RadarTrack[] {
|
||||
const order: string[] = [];
|
||||
const map: Record<string, RadarTrack> = {};
|
||||
const singles: RadarTrack[] = [];
|
||||
|
||||
for (let i = 0; i < tracks.length; i++) {
|
||||
const item = tracks[i];
|
||||
const key = sessionKey(item);
|
||||
if (key === '') {
|
||||
singles.push(copyTrack(item));
|
||||
continue;
|
||||
}
|
||||
const prev = map[key];
|
||||
if (prev == null) {
|
||||
map[key] = copyTrack(item);
|
||||
order.push(key);
|
||||
continue;
|
||||
}
|
||||
prev.stayDurationMs = Math.max(prev.stayDurationMs || 0, item.stayDurationMs || 0);
|
||||
prev.scrollDepth = Math.max(prev.scrollDepth || 0, item.scrollDepth || 0);
|
||||
const prevBlocks = prev.viewedBlocks != null ? prev.viewedBlocks : [];
|
||||
const nextBlocks = item.viewedBlocks != null && Array.isArray(item.viewedBlocks) ? item.viewedBlocks : [];
|
||||
const merged: string[] = [];
|
||||
const seenBlock: Record<string, boolean> = {};
|
||||
for (let b = 0; b < prevBlocks.length; b++) {
|
||||
const text = String(prevBlocks[b]);
|
||||
if (seenBlock[text] !== true) {
|
||||
seenBlock[text] = true;
|
||||
merged.push(text);
|
||||
}
|
||||
}
|
||||
for (let b = 0; b < nextBlocks.length; b++) {
|
||||
const text = String(nextBlocks[b]);
|
||||
if (seenBlock[text] !== true) {
|
||||
seenBlock[text] = true;
|
||||
merged.push(text);
|
||||
}
|
||||
}
|
||||
prev.viewedBlocks = merged;
|
||||
const name = item.visitorName != null ? String(item.visitorName).trim() : '';
|
||||
if ((prev.visitorName == null || String(prev.visitorName).trim() === '') && name !== '') {
|
||||
prev.visitorName = name;
|
||||
}
|
||||
const company = item.visitorCompany != null ? String(item.visitorCompany).trim() : '';
|
||||
if ((prev.visitorCompany == null || String(prev.visitorCompany).trim() === '') && company !== '') {
|
||||
prev.visitorCompany = company;
|
||||
}
|
||||
const avatar = item.avatarUrl != null ? String(item.avatarUrl).trim() : '';
|
||||
if ((prev.avatarUrl == null || String(prev.avatarUrl).trim() === '') && avatar !== '') {
|
||||
prev.avatarUrl = avatar;
|
||||
}
|
||||
if (item.touchType === 'nfc') {
|
||||
prev.touchType = 'nfc';
|
||||
} else if (item.touchType === 'qr' && prev.touchType !== 'nfc') {
|
||||
prev.touchType = 'qr';
|
||||
}
|
||||
const prevContents = prev.viewedContents != null ? prev.viewedContents : [];
|
||||
const nextContents = item.viewedContents != null && Array.isArray(item.viewedContents) ? item.viewedContents : [];
|
||||
const contentMap: Record<string, string> = {};
|
||||
const contentOrder: string[] = [];
|
||||
for (let c = 0; c < prevContents.length; c++) {
|
||||
const row = prevContents[c];
|
||||
const contentKey = row.key != null ? String(row.key) : '';
|
||||
if (contentKey === '') {
|
||||
continue;
|
||||
}
|
||||
if (contentMap[contentKey] == null) {
|
||||
contentOrder.push(contentKey);
|
||||
}
|
||||
contentMap[contentKey] = row.title != null ? String(row.title) : '';
|
||||
}
|
||||
for (let c = 0; c < nextContents.length; c++) {
|
||||
const row = nextContents[c];
|
||||
const contentKey = row.key != null ? String(row.key) : '';
|
||||
if (contentKey === '') {
|
||||
continue;
|
||||
}
|
||||
const title = row.title != null ? String(row.title).trim() : '';
|
||||
if (contentMap[contentKey] == null) {
|
||||
contentOrder.push(contentKey);
|
||||
contentMap[contentKey] = title;
|
||||
} else if (contentMap[contentKey] === '' && title !== '') {
|
||||
contentMap[contentKey] = title;
|
||||
}
|
||||
}
|
||||
if (contentOrder.length > 0) {
|
||||
const nextViewed: RadarTrack['viewedContents'] = [];
|
||||
for (let c = 0; c < contentOrder.length; c++) {
|
||||
const contentKey = contentOrder[c];
|
||||
nextViewed.push({ key: contentKey, title: contentMap[contentKey] });
|
||||
}
|
||||
prev.viewedContents = nextViewed;
|
||||
}
|
||||
if (readTrackTime(item) >= readTrackTime(prev)) {
|
||||
prev.id = item.id;
|
||||
prev.createdAt = item.createdAt != null ? item.createdAt : item.createTime;
|
||||
prev.createTime = item.createTime != null ? item.createTime : item.createdAt;
|
||||
if (item.ip != null && String(item.ip).trim() !== '') {
|
||||
prev.ip = item.ip;
|
||||
}
|
||||
if (item.country != null && String(item.country).trim() !== '') {
|
||||
prev.country = item.country;
|
||||
}
|
||||
if (item.city != null && String(item.city).trim() !== '') {
|
||||
prev.city = item.city;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const merged: RadarTrack[] = [];
|
||||
for (let i = 0; i < order.length; i++) {
|
||||
merged.push(map[order[i]]);
|
||||
}
|
||||
for (let i = 0; i < singles.length; i++) {
|
||||
merged.push(singles[i]);
|
||||
}
|
||||
merged.sort((a, b) => readTrackTime(b) - readTrackTime(a));
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,20 +765,9 @@ export function formatVisitorHeadline(item: RadarTrack): string {
|
||||
*/
|
||||
export function formatRelativeTime(createdAt?: string | Date): string {
|
||||
const zh = isZhLocale();
|
||||
if (createdAt == null) {
|
||||
return zh ? '刚刚' : 'Just Now';
|
||||
}
|
||||
let time = 0;
|
||||
if (typeof createdAt === 'string') {
|
||||
const parsed = Date.parse(createdAt);
|
||||
if (!Number.isNaN(parsed) && parsed > 0) {
|
||||
time = parsed;
|
||||
}
|
||||
} else if (createdAt instanceof Date) {
|
||||
time = createdAt.getTime();
|
||||
}
|
||||
const time = parseTimeValue(createdAt);
|
||||
if (time <= 0) {
|
||||
return zh ? '刚刚' : 'Just Now';
|
||||
return zh ? '时间未知' : 'Time unknown';
|
||||
}
|
||||
const diffMs = Math.max(0, Date.now() - time);
|
||||
const diffMin = Math.floor(diffMs / 60000);
|
||||
@@ -391,8 +816,24 @@ export function computeRadarStats(tracks: RadarTrack[], total: number): RadarSta
|
||||
}
|
||||
}
|
||||
|
||||
const rate = tracks.length > 0 ? Math.round((highCount / tracks.length) * 100) : (count > 0 ? 32 : 0);
|
||||
const rate = tracks.length > 0 ? Math.round((highCount / tracks.length) * 100) : 0;
|
||||
const avgStay = tracks.length > 0 ? Math.round(totalStay / tracks.length) : 0;
|
||||
const seenOnline: Record<string, boolean> = {};
|
||||
let onlineCount = 0;
|
||||
for (let i = 0; i < tracks.length; i++) {
|
||||
const current = tracks[i];
|
||||
if (!isVisitorOnline(current)) {
|
||||
continue;
|
||||
}
|
||||
const visitorKey = current.visitorId != null && current.visitorId.trim() !== ''
|
||||
? current.visitorId.trim()
|
||||
: String(current.id);
|
||||
if (seenOnline[visitorKey] === true) {
|
||||
continue;
|
||||
}
|
||||
seenOnline[visitorKey] = true;
|
||||
onlineCount += 1;
|
||||
}
|
||||
|
||||
let topCountry = '';
|
||||
let maxC = 0;
|
||||
@@ -406,9 +847,10 @@ export function computeRadarStats(tracks: RadarTrack[], total: number): RadarSta
|
||||
return {
|
||||
totalVisits: count,
|
||||
highIntentCount: highCount,
|
||||
onlineCount,
|
||||
intentRateText: `${rate}%`,
|
||||
avgStayText: formatStay(avgStay),
|
||||
topLocation: topCountry !== '' ? topCountry : 'Global',
|
||||
topLocation: topCountry !== '' ? formatLocation(topCountry, '') : resolveRadarText('unknown'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -416,7 +858,7 @@ export function computeRadarStats(tracks: RadarTrack[], total: number): RadarSta
|
||||
* 计算走势高度 (7 个数据柱)
|
||||
*/
|
||||
export function computeTrendHeights(tracks: RadarTrack[]): number[] {
|
||||
const defaultHeights: number[] = [35, 60, 45, 80, 55, 90, 75];
|
||||
const defaultHeights: number[] = [0, 0, 0, 0, 0, 0, 0];
|
||||
if (tracks.length === 0) {
|
||||
return defaultHeights;
|
||||
}
|
||||
@@ -441,6 +883,54 @@ function readErrorMessage(err: unknown): string {
|
||||
return resolveRadarText('error');
|
||||
}
|
||||
|
||||
function readRowField(row: RadarTrack, camel: string, snake: string): unknown {
|
||||
const record = row as unknown as Record<string, unknown>;
|
||||
const primary = record[camel];
|
||||
if (primary != null && primary !== '') {
|
||||
return primary;
|
||||
}
|
||||
return record[snake];
|
||||
}
|
||||
|
||||
function normalizeTrack(row: RadarTrack): RadarTrack {
|
||||
const blocksRaw = readRowField(row, 'viewedBlocks', 'viewed_blocks');
|
||||
let viewedBlocks: string[] = [];
|
||||
if (Array.isArray(blocksRaw)) {
|
||||
viewedBlocks = blocksRaw.map((item) => String(item));
|
||||
} else if (typeof blocksRaw === 'string' && blocksRaw.trim() !== '') {
|
||||
viewedBlocks = [blocksRaw];
|
||||
}
|
||||
const createTime = readRowField(row, 'createTime', 'create_time');
|
||||
const createdAt = readRowField(row, 'createdAt', 'created_at');
|
||||
const time = createTime != null ? createTime : createdAt;
|
||||
const stayRaw = readRowField(row, 'stayDurationMs', 'stay_duration_ms');
|
||||
const depthRaw = readRowField(row, 'scrollDepth', 'scroll_depth');
|
||||
const stay = Number(stayRaw);
|
||||
const depth = Number(depthRaw);
|
||||
const touch = readRowField(row, 'touchType', 'touch_type');
|
||||
const touchType = touch === 'nfc' || touch === 'qr' || touch === 'link' ? touch : 'link';
|
||||
return {
|
||||
id: row.id,
|
||||
tenantId: readRowField(row, 'tenantId', 'tenant_id') as string | number | undefined,
|
||||
cardId: (readRowField(row, 'cardId', 'card_id') as string | number) || row.cardId,
|
||||
visitorId: String(readRowField(row, 'visitorId', 'visitor_id') || ''),
|
||||
ip: readRowField(row, 'ip', 'ip') as string | undefined,
|
||||
country: readRowField(row, 'country', 'country') as string | undefined,
|
||||
city: readRowField(row, 'city', 'city') as string | undefined,
|
||||
touchType,
|
||||
stayDurationMs: Number.isFinite(stay) ? stay : 0,
|
||||
scrollDepth: Number.isFinite(depth) ? depth : 0,
|
||||
viewedBlocks,
|
||||
viewedContents: row.viewedContents,
|
||||
visitorName: row.visitorName,
|
||||
visitorCompany: row.visitorCompany,
|
||||
avatarUrl: row.avatarUrl,
|
||||
cardTitle: row.cardTitle,
|
||||
createdAt: (createdAt != null ? createdAt : time) as string | Date | undefined,
|
||||
createTime: (createTime != null ? createTime : time) as string | Date | undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function parseTrackList(payload: OwnerPageData<RadarTrack> | null | undefined): RadarTrack[] {
|
||||
if (payload == null || payload.list == null) {
|
||||
return [];
|
||||
@@ -448,7 +938,11 @@ function parseTrackList(payload: OwnerPageData<RadarTrack> | null | undefined):
|
||||
if (!Array.isArray(payload.list)) {
|
||||
return [];
|
||||
}
|
||||
return payload.list;
|
||||
const list: RadarTrack[] = [];
|
||||
for (let i = 0; i < payload.list.length; i++) {
|
||||
list.push(normalizeTrack(payload.list[i]));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主独立数据统计与销售漏斗业务驱动层
|
||||
* 纯函数计算转化率、漏斗阶段折损、渠道成效矩阵与国际化
|
||||
* R31: 数字与柱状仅来自接口;失败/缺字段时归零且图表为空
|
||||
*/
|
||||
|
||||
import { LeadEntity, OwnerPageQuery } from '../../common/types.uts';
|
||||
import { LeadEntity, OwnerPageData, OwnerPageQuery } from '../../common/types.uts';
|
||||
import { fetchOwnerLeadPage } from '../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../common/locale.uts';
|
||||
|
||||
@@ -40,6 +41,12 @@ export type StatsState = {
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type LoadStatsApi = {
|
||||
fetchOwnerLeadPage?: (
|
||||
query: OwnerPageQuery
|
||||
) => Promise<OwnerPageData<LeadEntity> | Record<string, unknown> | null>;
|
||||
};
|
||||
|
||||
function isZhLocale(): boolean {
|
||||
return getCurrentLocale() === 'zh-CN';
|
||||
}
|
||||
@@ -166,40 +173,71 @@ export function resolveStatsText(key: string): string {
|
||||
if (key === 'stepDescWon') {
|
||||
return isZhLocale() ? '签约成交' : 'Closed';
|
||||
}
|
||||
if (key === 'badgeTotal') {
|
||||
return isZhLocale() ? '总量' : 'TOTAL';
|
||||
}
|
||||
if (key === 'badgeHot') {
|
||||
return isZhLocale() ? '高意向' : 'HOT';
|
||||
}
|
||||
if (key === 'badgeWon') {
|
||||
return isZhLocale() ? '成交' : 'WON';
|
||||
}
|
||||
if (key === 'badgeRate') {
|
||||
return isZhLocale() ? '转化' : 'CVR';
|
||||
}
|
||||
if (key === 'funnelStages') {
|
||||
return isZhLocale() ? '四阶' : '4 STAGES';
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
function emptySummary(): StatsSummary {
|
||||
return {
|
||||
totalLeads: 0,
|
||||
hotLeads: 0,
|
||||
wonLeads: 0,
|
||||
overallRate: 0,
|
||||
};
|
||||
}
|
||||
|
||||
export function createStatsState(): StatsState {
|
||||
return {
|
||||
period: 'all',
|
||||
summary: {
|
||||
totalLeads: 0,
|
||||
hotLeads: 0,
|
||||
wonLeads: 0,
|
||||
overallRate: 0,
|
||||
},
|
||||
funnel: [
|
||||
{ key: 'new', label: resolveStatsText('stepNew'), count: 0, rate: 0 },
|
||||
{ key: 'hot', label: resolveStatsText('stepHot'), count: 0, rate: 0 },
|
||||
{ key: 'contacted', label: resolveStatsText('stepContacted'), count: 0, rate: 0 },
|
||||
{ key: 'won', label: resolveStatsText('stepWon'), count: 0, rate: 0 },
|
||||
],
|
||||
channels: [
|
||||
{ source: 'nfc', label: resolveStatsText('sourceNfc'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
|
||||
{ source: 'qr', label: resolveStatsText('sourceQr'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
|
||||
{ source: 'link', label: resolveStatsText('sourceLink'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
|
||||
{ source: 'ai_chat', label: resolveStatsText('sourceAi'), leadsCount: 0, wonCount: 0, conversionRate: 0 },
|
||||
],
|
||||
summary: emptySummary(),
|
||||
funnel: [],
|
||||
channels: [],
|
||||
loading: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/** R31: 失败或缺字段时数字归零、图表清空 */
|
||||
export function resetStatsToEmpty(state: StatsState): void {
|
||||
state.summary = emptySummary();
|
||||
state.funnel = [];
|
||||
state.channels = [];
|
||||
}
|
||||
|
||||
function parseLeadList(res: OwnerPageData<LeadEntity> | Record<string, unknown> | null): LeadEntity[] {
|
||||
if (res == null) {
|
||||
return [];
|
||||
}
|
||||
const list = (res as OwnerPageData<LeadEntity>).list;
|
||||
if (list == null || !Array.isArray(list)) {
|
||||
return [];
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod): StatsState {
|
||||
const state = createStatsState();
|
||||
state.period = period;
|
||||
|
||||
if (leads == null || leads.length === 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
let totalCount = 0;
|
||||
let hotCount = 0;
|
||||
let newCount = 0;
|
||||
@@ -217,7 +255,8 @@ export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod):
|
||||
const item = leads[i];
|
||||
totalCount++;
|
||||
|
||||
if (item.status === 'hot' || item.intentScore >= 80) {
|
||||
const score = item.intentScore != null ? item.intentScore : 0;
|
||||
if (item.status === 'hot' || score >= 80) {
|
||||
hotCount++;
|
||||
}
|
||||
if (item.status === 'new') {
|
||||
@@ -242,55 +281,90 @@ export function computeStatsFromLeads(leads: LeadEntity[], period: StatsPeriod):
|
||||
state.summary.wonLeads = wonCount;
|
||||
state.summary.overallRate = calcConversionRate(totalCount, wonCount);
|
||||
|
||||
// 漏斗阶梯与转化率
|
||||
state.funnel[0].count = totalCount;
|
||||
state.funnel[0].rate = totalCount > 0 ? 100 : 0;
|
||||
state.funnel = [
|
||||
{
|
||||
key: 'new',
|
||||
label: resolveStatsText('stepNew'),
|
||||
count: totalCount,
|
||||
rate: totalCount > 0 ? 100 : 0,
|
||||
},
|
||||
{
|
||||
key: 'hot',
|
||||
label: resolveStatsText('stepHot'),
|
||||
count: hotCount,
|
||||
rate: calcFunnelStepRate(hotCount, totalCount),
|
||||
},
|
||||
{
|
||||
key: 'contacted',
|
||||
label: resolveStatsText('stepContacted'),
|
||||
count: contactedCount,
|
||||
rate: calcFunnelStepRate(contactedCount, totalCount),
|
||||
},
|
||||
{
|
||||
key: 'won',
|
||||
label: resolveStatsText('stepWon'),
|
||||
count: wonCount,
|
||||
rate: calcFunnelStepRate(wonCount, totalCount),
|
||||
},
|
||||
];
|
||||
|
||||
state.funnel[1].count = hotCount;
|
||||
state.funnel[1].rate = calcFunnelStepRate(hotCount, totalCount);
|
||||
|
||||
state.funnel[2].count = contactedCount;
|
||||
state.funnel[2].rate = calcFunnelStepRate(contactedCount, totalCount);
|
||||
|
||||
state.funnel[3].count = wonCount;
|
||||
state.funnel[3].rate = calcFunnelStepRate(wonCount, totalCount);
|
||||
|
||||
// 渠道成效
|
||||
state.channels[0].leadsCount = channelMap['nfc'].leads;
|
||||
state.channels[0].wonCount = channelMap['nfc'].won;
|
||||
state.channels[0].conversionRate = calcConversionRate(channelMap['nfc'].leads, channelMap['nfc'].won);
|
||||
|
||||
state.channels[1].leadsCount = channelMap['qr'].leads;
|
||||
state.channels[1].wonCount = channelMap['qr'].won;
|
||||
state.channels[1].conversionRate = calcConversionRate(channelMap['qr'].leads, channelMap['qr'].won);
|
||||
|
||||
state.channels[2].leadsCount = channelMap['link'].leads;
|
||||
state.channels[2].wonCount = channelMap['link'].won;
|
||||
state.channels[2].conversionRate = calcConversionRate(channelMap['link'].leads, channelMap['link'].won);
|
||||
|
||||
state.channels[3].leadsCount = channelMap['ai_chat'].leads;
|
||||
state.channels[3].wonCount = channelMap['ai_chat'].won;
|
||||
state.channels[3].conversionRate = calcConversionRate(channelMap['ai_chat'].leads, channelMap['ai_chat'].won);
|
||||
state.channels = [
|
||||
{
|
||||
source: 'nfc',
|
||||
label: resolveStatsText('sourceNfc'),
|
||||
leadsCount: channelMap['nfc'].leads,
|
||||
wonCount: channelMap['nfc'].won,
|
||||
conversionRate: calcConversionRate(channelMap['nfc'].leads, channelMap['nfc'].won),
|
||||
},
|
||||
{
|
||||
source: 'qr',
|
||||
label: resolveStatsText('sourceQr'),
|
||||
leadsCount: channelMap['qr'].leads,
|
||||
wonCount: channelMap['qr'].won,
|
||||
conversionRate: calcConversionRate(channelMap['qr'].leads, channelMap['qr'].won),
|
||||
},
|
||||
{
|
||||
source: 'link',
|
||||
label: resolveStatsText('sourceLink'),
|
||||
leadsCount: channelMap['link'].leads,
|
||||
wonCount: channelMap['link'].won,
|
||||
conversionRate: calcConversionRate(channelMap['link'].leads, channelMap['link'].won),
|
||||
},
|
||||
{
|
||||
source: 'ai_chat',
|
||||
label: resolveStatsText('sourceAi'),
|
||||
leadsCount: channelMap['ai_chat'].leads,
|
||||
wonCount: channelMap['ai_chat'].won,
|
||||
conversionRate: calcConversionRate(channelMap['ai_chat'].leads, channelMap['ai_chat'].won),
|
||||
},
|
||||
];
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export async function loadStatsData(state: StatsState): Promise<void> {
|
||||
export async function loadStatsData(state: StatsState, api?: LoadStatsApi): Promise<void> {
|
||||
state.loading = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
const fetchPage =
|
||||
api != null && api.fetchOwnerLeadPage != null
|
||||
? api.fetchOwnerLeadPage
|
||||
: fetchOwnerLeadPage;
|
||||
|
||||
try {
|
||||
const query: OwnerPageQuery = {
|
||||
page: 1,
|
||||
size: 100,
|
||||
};
|
||||
const res = await fetchOwnerLeadPage(query);
|
||||
const computed = computeStatsFromLeads(res.list, state.period);
|
||||
const res = await fetchPage(query);
|
||||
const list = parseLeadList(res);
|
||||
const computed = computeStatsFromLeads(list, state.period);
|
||||
state.summary = computed.summary;
|
||||
state.funnel = computed.funnel;
|
||||
state.channels = computed.channels;
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
resetStatsToEmpty(state);
|
||||
state.errorMessage = msg !== '' ? msg : resolveStatsText('error');
|
||||
} finally {
|
||||
state.loading = false;
|
||||
|
||||
文件差异内容过多而无法显示
加载差异
@@ -24,6 +24,7 @@ export interface WorkplaceState {
|
||||
activeCard: CardProfile | null;
|
||||
cardList: CardProfile[];
|
||||
activeQrSvg: string;
|
||||
activeShareUrl: string;
|
||||
kpis: WorkplaceKpi;
|
||||
hotRadarItem: WorkplaceRadarItem | null;
|
||||
recentLeads: LeadEntity[];
|
||||
@@ -37,6 +38,7 @@ export function createWorkplaceState(): WorkplaceState {
|
||||
activeCard: null,
|
||||
cardList: [],
|
||||
activeQrSvg: '',
|
||||
activeShareUrl: '',
|
||||
kpis: {
|
||||
tapCount: 0,
|
||||
viewCount: 0,
|
||||
@@ -58,36 +60,29 @@ export async function loadWorkplaceData(state: WorkplaceState): Promise<void> {
|
||||
|
||||
try {
|
||||
// 1. 并行获取工作台概览、名片列表、最新待跟进线索
|
||||
const overviewPromise = fetchWorkplaceOverview(5).catch((_err: any): WorkplaceOverviewResult => {
|
||||
return {
|
||||
kpis: {
|
||||
tapCount: 28,
|
||||
viewCount: 45,
|
||||
newLeadCount: 6,
|
||||
conversionRate: 42.8,
|
||||
tapDelta: 5,
|
||||
viewDelta: 12,
|
||||
newLeadDelta: 2,
|
||||
},
|
||||
radarFeed: [
|
||||
{
|
||||
id: 1,
|
||||
cardId: 1,
|
||||
cardTitle: 'APAC VP 商务名片',
|
||||
country: 'AE',
|
||||
city: 'Dubai',
|
||||
touchType: 'nfc',
|
||||
stayDurationMs: 220000,
|
||||
viewedBlocks: ['hero', 'cases', 'appointment'],
|
||||
intentScore: 92,
|
||||
createTime: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
const overviewPromise = fetchWorkplaceOverview(5).then((data: WorkplaceOverviewResult) => {
|
||||
state.radarOnline = true;
|
||||
return data;
|
||||
}).catch(() => {
|
||||
state.radarOnline = false;
|
||||
const emptyKpi: WorkplaceKpi = {
|
||||
tapCount: 0,
|
||||
viewCount: 0,
|
||||
newLeadCount: 0,
|
||||
conversionRate: 0,
|
||||
tapDelta: 0,
|
||||
viewDelta: 0,
|
||||
newLeadDelta: 0,
|
||||
};
|
||||
const emptyResult: WorkplaceOverviewResult = {
|
||||
kpis: emptyKpi,
|
||||
radarFeed: [],
|
||||
};
|
||||
return emptyResult;
|
||||
});
|
||||
|
||||
const cardsPromise = fetchOwnerCardPage({ page: 1, size: 10 }).catch((_err: any) => null);
|
||||
const leadsPromise = fetchOwnerLeadPage({ page: 1, size: 3 }).catch((_err: any) => null);
|
||||
const cardsPromise = fetchOwnerCardPage({ page: 1, size: 10 }).catch(() => null);
|
||||
const leadsPromise = fetchOwnerLeadPage({ page: 1, size: 3 }).catch(() => null);
|
||||
|
||||
const [overview, cardPage, leadPage] = await Promise.all([
|
||||
overviewPromise,
|
||||
@@ -99,70 +94,59 @@ export async function loadWorkplaceData(state: WorkplaceState): Promise<void> {
|
||||
if (overview != null && overview.kpis != null) {
|
||||
state.kpis = overview.kpis;
|
||||
}
|
||||
state.hotRadarItem = null;
|
||||
if (overview != null && overview.radarFeed != null && overview.radarFeed.length > 0) {
|
||||
state.hotRadarItem = overview.radarFeed[0];
|
||||
}
|
||||
|
||||
// 3. 赋值待跟进潜客
|
||||
if (leadPage != null && leadPage.list != null && leadPage.list.length > 0) {
|
||||
if (leadPage != null && leadPage.list != null) {
|
||||
state.recentLeads = leadPage.list;
|
||||
} else {
|
||||
state.recentLeads = [
|
||||
{
|
||||
id: 101,
|
||||
cardId: 1,
|
||||
name: 'Sarah Jenkins',
|
||||
company: 'Vertex Energy SG',
|
||||
phone: '+65 8123 4567',
|
||||
status: 'new',
|
||||
intentScore: 88,
|
||||
source: 'nfc',
|
||||
notes: '展会现场已碰卡,对新能源储能方案有深度合作意向',
|
||||
},
|
||||
{
|
||||
id: 102,
|
||||
cardId: 1,
|
||||
name: 'Ahmed Al-Mansoor',
|
||||
company: 'Oasis Green Holdings',
|
||||
email: 'ahmed@oasisgreen.ae',
|
||||
status: 'contacted',
|
||||
intentScore: 95,
|
||||
source: 'qr',
|
||||
notes: '已发送产品白皮书与报价单,等待确认试用样品',
|
||||
},
|
||||
];
|
||||
state.recentLeads = [];
|
||||
}
|
||||
|
||||
// 4. 处理名片与二维码展台
|
||||
if (cardPage != null && cardPage.list != null && cardPage.list.length > 0) {
|
||||
state.cardList = cardPage.list;
|
||||
const published = cardPage.list.find((c: CardProfile) => c.status === 'published');
|
||||
state.activeCard = published != null ? published : cardPage.list[0];
|
||||
} else {
|
||||
state.activeCard = {
|
||||
id: 1,
|
||||
name: 'Kenji Tanaka',
|
||||
title: 'APAC Logistics VP',
|
||||
company: 'TransPacific AutoLink',
|
||||
status: 'published',
|
||||
url: 'https://omnicard.cc/kenji-tanaka',
|
||||
};
|
||||
state.cardList = [state.activeCard!];
|
||||
state.activeCard = null;
|
||||
state.cardList = [];
|
||||
state.activeQrSvg = '';
|
||||
state.activeShareUrl = '';
|
||||
}
|
||||
|
||||
if (state.activeCard != null) {
|
||||
state.activeQrSvg = '';
|
||||
state.activeShareUrl = '';
|
||||
try {
|
||||
const slugOrId = state.activeCard!.slug || String(state.activeCard!.id);
|
||||
const qrRes = await fetchCardQrcodeSvg(slugOrId);
|
||||
if (qrRes != null && qrRes.svg != null) {
|
||||
if (qrRes != null && qrRes.svg != null && qrRes.svg !== '') {
|
||||
state.activeQrSvg = qrRes.svg;
|
||||
} else {
|
||||
state.activeQrSvg = '';
|
||||
}
|
||||
if (qrRes != null && qrRes.url != null && qrRes.url !== '') {
|
||||
state.activeShareUrl = qrRes.url;
|
||||
} else if (state.activeCard!.url != null && state.activeCard!.url !== '') {
|
||||
state.activeShareUrl = state.activeCard!.url!;
|
||||
}
|
||||
} catch (_e) {
|
||||
// 二维码后备
|
||||
state.activeQrSvg = '';
|
||||
state.activeShareUrl = '';
|
||||
}
|
||||
} else {
|
||||
state.activeQrSvg = '';
|
||||
state.activeShareUrl = '';
|
||||
}
|
||||
} catch (err: any) {
|
||||
state.errorMessage = err?.message != null ? String(err.message) : '加载工作台数据异常';
|
||||
if (state.activeCard == null && state.recentLeads.length === 0 && state.radarOnline === false) {
|
||||
state.errorMessage = resolveWorkplaceText('workplace.load_error');
|
||||
}
|
||||
} catch (_err) {
|
||||
state.errorMessage = resolveWorkplaceText('workplace.load_error');
|
||||
state.activeQrSvg = '';
|
||||
state.activeShareUrl = '';
|
||||
} finally {
|
||||
state.loading = false;
|
||||
}
|
||||
@@ -304,6 +288,38 @@ export function resolveWorkplaceText(key: string, locale?: string): string {
|
||||
zh: '出示名片码',
|
||||
en: 'Show Card QR',
|
||||
},
|
||||
'workplace.qr_empty': {
|
||||
zh: '暂无二维码',
|
||||
en: 'QR code unavailable',
|
||||
},
|
||||
'workplace.empty_card': {
|
||||
zh: '还没有名片',
|
||||
en: 'No card yet',
|
||||
},
|
||||
'workplace.empty_leads': {
|
||||
zh: '今天还没有要跟进的线索',
|
||||
en: 'No leads to follow up',
|
||||
},
|
||||
'workplace.empty_radar': {
|
||||
zh: '还没有新的访客',
|
||||
en: 'No new visitors',
|
||||
},
|
||||
'workplace.switch_card': {
|
||||
zh: '切换',
|
||||
en: 'Switch',
|
||||
},
|
||||
'workplace.published': {
|
||||
zh: '已发布',
|
||||
en: 'Published',
|
||||
},
|
||||
'workplace.load_error': {
|
||||
zh: '工作台暂时没加载出来',
|
||||
en: 'Workplace could not be loaded',
|
||||
},
|
||||
'workplace.score': {
|
||||
zh: '意向',
|
||||
en: 'Intent',
|
||||
},
|
||||
};
|
||||
|
||||
const item = dict[key];
|
||||
|
||||
在新工单中引用
屏蔽一个用户