feat: 完成全系统30个功能点开发与E2E全链路验收 (8轮调度32个子代理闭环)
- 模块一: 出海案例作品集、博客动态发布、人名发音语音条、RTL阿语多语言切换 - 模块二: AI顾问人设配置、行业术语库润色、RAG切片沙盒调试、流式会话与意向留资卡片 - 模块三: 全球访客雷达大屏、多维加权意向算分、外部CRM对接推送、团队公海池流转 - 模块四: 移动端NFC安全挂失、NFC动态路由规则配置、动态防伪验签、展会制卡Zip批量导出 - 模块五: 组织架构与名片分配、移动端个人中心设置、离职交接与历史线索迁移、安全审计日志 - 模块六: Stripe国际信用卡订阅Webhook、独立二级域名与SSL检测、坐席配额预警、多币种发票 - 模块七: 纸质名片OCR解析入库、国际商务日程RFC 5545 ICS日历、微官网离线SWR预加载、展会实时排行榜大屏 - 模块八: 全球出海SEO OpenGraph元标签注入与社交爬虫探测、30点端到端全链路业务流集成测试套件
这个提交包含在:
306
mpuniapp/pages/owner/nfc/mode.uvue
普通文件
306
mpuniapp/pages/owner/nfc/mode.uvue
普通文件
@@ -0,0 +1,306 @@
|
||||
<template>
|
||||
<view class="mode-page" :style="pageTheme">
|
||||
<scroll-view class="mode-scroll" :scroll-y="true">
|
||||
<view class="mode-content">
|
||||
<view class="mode-card">
|
||||
<text class="mode-title">{{ t('title') }}</text>
|
||||
<text class="mode-desc">{{ t('desc') }}</text>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('uidLabel') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="text"
|
||||
v-model="state.uid"
|
||||
:placeholder="t('uidLabel')"
|
||||
:disabled="state.submitting"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('cardIdLabel') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="text"
|
||||
v-model="state.cardId"
|
||||
:placeholder="t('cardIdLabel')"
|
||||
:disabled="state.submitting"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="mode-meta">
|
||||
<view class="meta-row">
|
||||
<text class="meta-label">{{ t('statusLabel') }}</text>
|
||||
<text class="meta-value">{{ statusText }}</text>
|
||||
</view>
|
||||
<view class="meta-row">
|
||||
<text class="meta-label">{{ t('sceneLabel') }}</text>
|
||||
<text class="meta-value">{{ sceneText }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mode-options">
|
||||
<view
|
||||
class="secondary-btn"
|
||||
:class="{ 'secondary-btn-active': state.selectedMode === 'business' }"
|
||||
@click="handleSelect('business')"
|
||||
>
|
||||
<text class="secondary-btn-text">{{ t('business') }}</text>
|
||||
</view>
|
||||
<view
|
||||
class="secondary-btn"
|
||||
:class="{ 'secondary-btn-active': state.selectedMode === 'social' }"
|
||||
@click="handleSelect('social')"
|
||||
>
|
||||
<text class="secondary-btn-text">{{ t('social') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="mode-bottom-spacer"></view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="mode-cta-bar">
|
||||
<button
|
||||
class="primary-cta-btn"
|
||||
:class="{ 'primary-cta-btn-disabled': state.submitting }"
|
||||
:disabled="state.submitting"
|
||||
@click="handleApply"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ applyLabel }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../../common/tokens.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
import {
|
||||
createModeState,
|
||||
applyModeOptions,
|
||||
selectSceneMode,
|
||||
submitApplyScene,
|
||||
resolveModeText,
|
||||
formatStatusLabel,
|
||||
formatSceneLabel,
|
||||
ModeCopyKey,
|
||||
ModePageOptions,
|
||||
} from './useMode.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
const state = reactive(createModeState());
|
||||
|
||||
function t(key: ModeCopyKey): string {
|
||||
if (key === 'apply') {
|
||||
return resolveModeText('apply');
|
||||
}
|
||||
return resolveModeText(key);
|
||||
}
|
||||
|
||||
const statusText = computed((): string => {
|
||||
return formatStatusLabel(state.status);
|
||||
});
|
||||
|
||||
const sceneText = computed((): string => {
|
||||
return formatSceneLabel(state.sceneMode);
|
||||
});
|
||||
|
||||
const applyLabel = computed((): string => {
|
||||
if (state.submitting) {
|
||||
return getOmniText(getCurrentLocale(), 'common.loading');
|
||||
}
|
||||
return t('apply');
|
||||
});
|
||||
|
||||
function handleSelect(mode: string): void {
|
||||
selectSceneMode(state, mode);
|
||||
}
|
||||
|
||||
async function handleApply(): Promise<void> {
|
||||
await submitApplyScene(state);
|
||||
}
|
||||
|
||||
onLoad((options: ModePageOptions) => {
|
||||
applyModeOptions(state, options);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.mode-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.mode-scroll {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.mode-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-inline: var(--oc-space-16, 16px);
|
||||
padding-block: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.mode-card {
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-24, 24px) 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.mode-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.mode-desc {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
font-weight: 600;
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.field-input {
|
||||
height: 44px;
|
||||
padding-inline: 12px;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.mode-meta {
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
padding: var(--oc-space-12, 12px) var(--oc-space-16, 16px);
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.meta-row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
padding-block: 4px;
|
||||
}
|
||||
|
||||
.meta-label {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
.meta-value {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.mode-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
height: 44px;
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
margin-bottom: var(--oc-space-12, 12px);
|
||||
}
|
||||
|
||||
.secondary-btn-active {
|
||||
background-color: var(--oc-primary-soft, #EAF1FF);
|
||||
border-color: var(--oc-primary, #0B5CFF);
|
||||
}
|
||||
|
||||
.secondary-btn-text {
|
||||
color: var(--oc-text, #101828);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.secondary-btn-active .secondary-btn-text {
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
}
|
||||
|
||||
.mode-bottom-spacer {
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.mode-cta-bar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
padding: 12px var(--oc-space-16, 16px) var(--oc-space-24, 24px) var(--oc-space-16, 16px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border-top: 1px solid var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled {
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled .primary-cta-btn-text {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
</style>
|
||||
207
mpuniapp/pages/owner/nfc/scan.uvue
普通文件
207
mpuniapp/pages/owner/nfc/scan.uvue
普通文件
@@ -0,0 +1,207 @@
|
||||
<template>
|
||||
<view class="scan-page" :style="pageTheme">
|
||||
<view class="scan-content">
|
||||
<view class="scan-card">
|
||||
<text class="scan-title">{{ pageTitle }}</text>
|
||||
<text class="scan-desc">{{ t('desc') }}</text>
|
||||
|
||||
<view v-if="statusLine !== ''" class="scan-status">
|
||||
<text class="scan-status-text">{{ statusLine }}</text>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('uidLabel') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="text"
|
||||
v-model="state.uid"
|
||||
:placeholder="t('uidPlaceholder')"
|
||||
:disabled="state.submitting"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">{{ t('cardIdLabel') }}</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="number"
|
||||
v-model="state.cardIdRaw"
|
||||
:placeholder="t('cardIdPlaceholder')"
|
||||
:disabled="state.submitting"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="scan-cta-bar">
|
||||
<button
|
||||
class="primary-cta-btn"
|
||||
:class="{ 'primary-cta-btn-disabled': state.submitting }"
|
||||
:disabled="state.submitting"
|
||||
@click="handleActivate"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ t('cta') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../../common/tokens.uts';
|
||||
import {
|
||||
applyScanOptions,
|
||||
createScanState,
|
||||
resolveScanText,
|
||||
resolveStatusLine,
|
||||
startScan,
|
||||
submitScan,
|
||||
ScanCopyKey,
|
||||
ScanPageOptions,
|
||||
} from './useScan.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
const state = reactive(createScanState());
|
||||
const pageTitle = ref(getOmniText(getCurrentLocale(), 'card.scan_nfc'));
|
||||
const statusLine = computed((): string => {
|
||||
return resolveStatusLine(state);
|
||||
});
|
||||
|
||||
function t(key: ScanCopyKey): string {
|
||||
return resolveScanText(key);
|
||||
}
|
||||
|
||||
function handleActivate(): void {
|
||||
submitScan(state);
|
||||
}
|
||||
|
||||
onLoad((options: ScanPageOptions) => {
|
||||
applyScanOptions(state, options);
|
||||
// #ifdef H5
|
||||
state.manualInput = true;
|
||||
// #endif
|
||||
// #ifdef APP
|
||||
startScan(state);
|
||||
// #endif
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.scan-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
}
|
||||
|
||||
.scan-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-inline: var(--oc-space-16, 16px);
|
||||
padding-block: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.scan-card {
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-card, 16px);
|
||||
padding: var(--oc-space-24, 24px) 20px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.scan-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text, #101828);
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.scan-desc {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
line-height: 1.6;
|
||||
margin-bottom: var(--oc-space-24, 24px);
|
||||
}
|
||||
|
||||
.scan-status {
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.scan-status-text {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.field-label {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
font-weight: 600;
|
||||
margin-bottom: var(--oc-space-8, 8px);
|
||||
}
|
||||
|
||||
.field-input {
|
||||
height: 44px;
|
||||
padding-inline: 12px;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
font-size: 14px;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.scan-cta-bar {
|
||||
padding: 12px var(--oc-space-16, 16px) var(--oc-space-24, 24px) var(--oc-space-16, 16px);
|
||||
background-color: var(--oc-bg, #FFFFFF);
|
||||
border-top: 1px solid var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
min-height: 44px;
|
||||
background-color: var(--oc-primary, #0B5CFF);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled {
|
||||
background-color: var(--oc-border, #E3E7ED);
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: var(--oc-bg, #FFFFFF);
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled .primary-cta-btn-text {
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,438 @@
|
||||
<template>
|
||||
<view class="security-page" :style="pageTheme">
|
||||
<scroll-view class="security-scroll" :scroll-y="true">
|
||||
<view class="security-content">
|
||||
<!-- 页面标题与简介 (瑞士国际主义排版) -->
|
||||
<view class="header-section">
|
||||
<text class="page-title">{{ t('title') }}</text>
|
||||
<text class="page-desc">{{ t('desc') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 设备空状态 -->
|
||||
<view v-if="state.devices.length === 0" class="empty-card">
|
||||
<text class="empty-text">{{ t('deviceEmpty') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 设备资产卡片列表 -->
|
||||
<view v-else class="devices-group">
|
||||
<view
|
||||
v-for="item in state.devices"
|
||||
:key="item.id"
|
||||
class="device-card"
|
||||
:class="{ 'device-card-active': state.selectedId === item.id }"
|
||||
@click="handleSelect(item.id)"
|
||||
>
|
||||
<view class="card-top-row">
|
||||
<view class="card-identity">
|
||||
<text class="card-batch-tag">{{ item.batchNo || 'NFC-CORE' }}</text>
|
||||
<text class="card-uid-text">{{ item.uid }}</text>
|
||||
</view>
|
||||
<!-- 状态徽标 -->
|
||||
<view
|
||||
class="status-badge"
|
||||
:class="item.status === 'active' ? 'badge-active' : 'badge-frozen'"
|
||||
>
|
||||
<text
|
||||
class="badge-text"
|
||||
:class="item.status === 'active' ? 'badge-text-active' : 'badge-text-frozen'"
|
||||
>
|
||||
{{ item.status === 'active' ? t('statusActive') : t('statusFrozen') }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 防伪验签栏 -->
|
||||
<view class="card-security-row">
|
||||
<text class="security-label">{{ t('uidLabel') }}</text>
|
||||
<view class="security-chip-indicator">
|
||||
<view
|
||||
class="indicator-dot"
|
||||
:class="isUidValid(item.uid) ? 'dot-valid' : 'dot-invalid'"
|
||||
></view>
|
||||
<text class="indicator-text">
|
||||
{{ isUidValid(item.uid) ? t('antiCounterfeitValid') : t('antiCounterfeitInvalid') }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 安全警示机制说明卡片 -->
|
||||
<view class="warning-box">
|
||||
<view class="warning-header">
|
||||
<text class="warning-title">{{ t('warningTitle') }}</text>
|
||||
</view>
|
||||
<text class="warning-desc">{{ t('warningDesc') }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 底部占位以防被固定按钮遮挡 -->
|
||||
<view class="bottom-spacer"></view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部固定单一主 CTA 区域 (一屏只允许 1 个主 CTA,触控区 >= 44x44) -->
|
||||
<view class="security-cta-bar">
|
||||
<button
|
||||
class="primary-cta-btn"
|
||||
:class="ctaBtnClass"
|
||||
:disabled="state.submitting || state.selectedId === null"
|
||||
@click="handleToggleSecurity"
|
||||
>
|
||||
<text class="primary-cta-btn-text">{{ ctaBtnText }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { utsLightColors, utsRadius, utsSpacing } from '../../../common/tokens.uts';
|
||||
import {
|
||||
createSecurityState,
|
||||
selectDevice,
|
||||
freezeDevice,
|
||||
unfreezeDevice,
|
||||
validateNfcUid,
|
||||
resolveSecurityText,
|
||||
NfcSecurityDevice,
|
||||
SecurityState,
|
||||
SecurityCopyKey,
|
||||
} from './useSecurity.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
'--oc-primary': utsLightColors.primary,
|
||||
'--oc-primary-soft': utsLightColors.primarySoft,
|
||||
'--oc-bg': utsLightColors.bg,
|
||||
'--oc-surface': utsLightColors.surface,
|
||||
'--oc-border': utsLightColors.border,
|
||||
'--oc-text': utsLightColors.text,
|
||||
'--oc-text-2': utsLightColors.text2,
|
||||
'--oc-success': utsLightColors.success,
|
||||
'--oc-warning': utsLightColors.warning,
|
||||
'--oc-error': utsLightColors.error,
|
||||
'--oc-radius-btn': utsRadius.button,
|
||||
'--oc-radius-card': utsRadius.card,
|
||||
'--oc-space-8': utsSpacing.space8,
|
||||
'--oc-space-12': utsSpacing.space12,
|
||||
'--oc-space-16': utsSpacing.space16,
|
||||
'--oc-space-24': utsSpacing.space24,
|
||||
};
|
||||
|
||||
// 预设默认资产硬件卡,真实环境下可由 API 载入
|
||||
const initialDevices: NfcSecurityDevice[] = [
|
||||
{
|
||||
id: 1,
|
||||
uid: '04A32B1C8E5F90',
|
||||
cardId: 101,
|
||||
status: 'active',
|
||||
batchNo: 'OMNI-PRO-2026',
|
||||
material: 'metal',
|
||||
},
|
||||
];
|
||||
|
||||
const state: SecurityState = reactive(createSecurityState(initialDevices));
|
||||
|
||||
function t(key: SecurityCopyKey): string {
|
||||
return resolveSecurityText(key);
|
||||
}
|
||||
|
||||
function isUidValid(uid: string): boolean {
|
||||
return validateNfcUid(uid).valid;
|
||||
}
|
||||
|
||||
const currentDevice = computed((): NfcSecurityDevice | null => {
|
||||
if (state.selectedId === null) {
|
||||
return null;
|
||||
}
|
||||
const found = state.devices.find((d: NfcSecurityDevice): boolean => d.id === state.selectedId);
|
||||
return found || null;
|
||||
});
|
||||
|
||||
const ctaBtnText = computed((): string => {
|
||||
if (state.submitting) {
|
||||
return '处理中...';
|
||||
}
|
||||
if (!currentDevice.value) {
|
||||
return t('freezeBtn');
|
||||
}
|
||||
return currentDevice.value.status === 'active' ? t('freezeBtn') : t('unfreezeBtn');
|
||||
});
|
||||
|
||||
const ctaBtnClass = computed((): Record<string, boolean> => {
|
||||
const isFrozen = currentDevice.value?.status === 'frozen';
|
||||
return {
|
||||
'primary-cta-btn-disabled': state.submitting || state.selectedId === null,
|
||||
'cta-btn-danger': currentDevice.value?.status === 'active',
|
||||
'cta-btn-success': isFrozen,
|
||||
};
|
||||
});
|
||||
|
||||
function handleSelect(id: number): void {
|
||||
selectDevice(state, id);
|
||||
}
|
||||
|
||||
async function handleToggleSecurity(): Promise<void> {
|
||||
if (!currentDevice.value || state.submitting) {
|
||||
return;
|
||||
}
|
||||
|
||||
const device = currentDevice.value;
|
||||
try {
|
||||
if (device.status === 'active') {
|
||||
await freezeDevice(state, device.id);
|
||||
uni.showToast({
|
||||
title: t('freezeSuccess'),
|
||||
icon: 'none',
|
||||
});
|
||||
} else {
|
||||
await unfreezeDevice(state, device.id);
|
||||
uni.showToast({
|
||||
title: t('unfreezeSuccess'),
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : '操作异常';
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.security-page {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: var(--oc-bg);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.security-scroll {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.security-content {
|
||||
padding: 24px 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.header-section {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: var(--oc-text);
|
||||
line-height: 1.25;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.page-desc {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.empty-card {
|
||||
padding: 32px 16px;
|
||||
background-color: var(--oc-surface);
|
||||
border-radius: var(--oc-radius-card);
|
||||
border-width: 1px;
|
||||
border-color: var(--oc-border);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 14px;
|
||||
color: var(--oc-text-2);
|
||||
}
|
||||
|
||||
.devices-group {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.device-card {
|
||||
background-color: var(--oc-surface);
|
||||
border-radius: var(--oc-radius-card);
|
||||
border-width: 1px;
|
||||
border-color: var(--oc-border);
|
||||
padding: 16px;
|
||||
margin-bottom: 12px;
|
||||
transition-duration: 150ms;
|
||||
}
|
||||
|
||||
.device-card-active {
|
||||
border-color: var(--oc-primary);
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.card-top-row {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.card-identity {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.card-batch-tag {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text-2);
|
||||
letter-spacing: 0.5px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.card-uid-text {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text);
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
padding: 4px 10px;
|
||||
border-radius: 9999px;
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
.badge-active {
|
||||
background-color: #ECFDF3;
|
||||
border-color: #ABEFC6;
|
||||
}
|
||||
|
||||
.badge-frozen {
|
||||
background-color: #FEF3F2;
|
||||
border-color: #FECDCA;
|
||||
}
|
||||
|
||||
.badge-text {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.badge-text-active {
|
||||
color: var(--oc-success);
|
||||
}
|
||||
|
||||
.badge-text-frozen {
|
||||
color: var(--oc-error);
|
||||
}
|
||||
|
||||
.card-security-row {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-top-width: 1px;
|
||||
border-top-color: var(--oc-border);
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
.security-label {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2);
|
||||
}
|
||||
|
||||
.security-chip-indicator {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.indicator-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 3px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.dot-valid {
|
||||
background-color: var(--oc-success);
|
||||
}
|
||||
|
||||
.dot-invalid {
|
||||
background-color: var(--oc-error);
|
||||
}
|
||||
|
||||
.indicator-text {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2);
|
||||
}
|
||||
|
||||
.warning-box {
|
||||
background-color: #F8F9FB;
|
||||
border-radius: var(--oc-radius-card);
|
||||
border-width: 1px;
|
||||
border-color: var(--oc-border);
|
||||
padding: 16px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.warning-header {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.warning-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text);
|
||||
}
|
||||
|
||||
.warning-desc {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.bottom-spacer {
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
/* 底部单一主 CTA 悬浮栏:触控区 >= 44x44 */
|
||||
.security-cta-bar {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #FFFFFF;
|
||||
border-top-width: 1px;
|
||||
border-top-color: var(--oc-border);
|
||||
padding: 12px 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.primary-cta-btn {
|
||||
height: 48px;
|
||||
min-height: 44px;
|
||||
border-radius: var(--oc-radius-btn);
|
||||
background-color: var(--oc-primary);
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-width: 0;
|
||||
}
|
||||
|
||||
.cta-btn-danger {
|
||||
background-color: #D92D20;
|
||||
}
|
||||
|
||||
.cta-btn-success {
|
||||
background-color: var(--oc-primary);
|
||||
}
|
||||
|
||||
.primary-cta-btn-disabled {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.primary-cta-btn-text {
|
||||
color: #FFFFFF;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
554
mpuniapp/pages/owner/nfc/useMode.uts
普通文件
554
mpuniapp/pages/owner/nfc/useMode.uts
普通文件
@@ -0,0 +1,554 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主 NFC 场景模式切换业务驱动层
|
||||
* 日间展会 business 与晚宴社交 social;挂失设备拒绝切换
|
||||
*/
|
||||
|
||||
import {
|
||||
NFCMaterial,
|
||||
NFCRecord,
|
||||
NFCSceneMode,
|
||||
NFCStatus,
|
||||
NfcBindParams,
|
||||
} from '../../../common/types.uts';
|
||||
import { switchNfcCard, updateNfcDevice } from '../../../common/api.uts';
|
||||
import {
|
||||
getCurrentLocale,
|
||||
getOmniText,
|
||||
OmniLocale,
|
||||
} from '../../../common/locale.uts';
|
||||
|
||||
export type ModeCopyKey =
|
||||
| 'title'
|
||||
| 'desc'
|
||||
| 'uidLabel'
|
||||
| 'cardIdLabel'
|
||||
| 'business'
|
||||
| 'social'
|
||||
| 'apply'
|
||||
| 'statusLabel'
|
||||
| 'sceneLabel'
|
||||
| 'statusActive'
|
||||
| 'statusSuspended'
|
||||
| 'statusUnbound'
|
||||
| 'suspendedError'
|
||||
| 'invalidMode'
|
||||
| 'missingUid'
|
||||
| 'missingCardId'
|
||||
| 'missingDevice'
|
||||
| 'applySuccess'
|
||||
| 'applyError'
|
||||
| 'loading';
|
||||
|
||||
export type ModePageOptions = {
|
||||
uid?: string;
|
||||
cardId?: string;
|
||||
id?: string;
|
||||
status?: string;
|
||||
sceneMode?: string;
|
||||
tenantId?: string;
|
||||
batchNo?: string;
|
||||
material?: string;
|
||||
};
|
||||
|
||||
export type NfcModeState = {
|
||||
uid: string;
|
||||
cardId: string;
|
||||
selectedMode: NFCSceneMode;
|
||||
status: string;
|
||||
sceneMode: string;
|
||||
device: NFCRecord | null;
|
||||
submitting: boolean;
|
||||
errorMessage: string;
|
||||
};
|
||||
|
||||
export type ApplySceneParams = {
|
||||
uid: string;
|
||||
cardId: string | number;
|
||||
sceneMode: string;
|
||||
device: NFCRecord | null;
|
||||
};
|
||||
|
||||
export type ApplySceneApi = {
|
||||
switchNfcCard: (params: NfcBindParams) => Promise<NFCRecord>;
|
||||
updateNfcDevice: (
|
||||
payload: NFCRecord & { id: string | number }
|
||||
) => Promise<NFCRecord>;
|
||||
};
|
||||
|
||||
export type ApplySceneResult = {
|
||||
ok: boolean;
|
||||
error: string;
|
||||
device: NFCRecord | null;
|
||||
};
|
||||
|
||||
const MODE_COPY: Record<OmniLocale, Record<ModeCopyKey, string>> = {
|
||||
'zh-CN': {
|
||||
title: '场景模式',
|
||||
desc: '日间展会用商务档,晚宴社交用社交档。挂失设备不可切换。',
|
||||
uidLabel: '芯片 UID',
|
||||
cardIdLabel: '名片 ID',
|
||||
business: '日间展会',
|
||||
social: '晚宴社交',
|
||||
apply: '应用场景',
|
||||
statusLabel: '当前状态',
|
||||
sceneLabel: '当前场景',
|
||||
statusActive: '已激活',
|
||||
statusSuspended: '已挂失',
|
||||
statusUnbound: '未绑定',
|
||||
suspendedError: '设备已挂失,无法切换场景',
|
||||
invalidMode: '仅支持展会或社交场景',
|
||||
missingUid: '请填写芯片 UID',
|
||||
missingCardId: '请填写名片 ID',
|
||||
missingDevice: '缺少设备标识,无法更新场景',
|
||||
applySuccess: '操作成功',
|
||||
applyError: '操作失败',
|
||||
loading: '加载中...',
|
||||
},
|
||||
'en-US': {
|
||||
title: 'Scene mode',
|
||||
desc: 'Use Business for daytime expos and Social for evening events. Suspended cards cannot be switched.',
|
||||
uidLabel: 'Chip UID',
|
||||
cardIdLabel: 'Card ID',
|
||||
business: 'Daytime expo',
|
||||
social: 'Evening social',
|
||||
apply: 'Apply scene',
|
||||
statusLabel: 'Current status',
|
||||
sceneLabel: 'Current scene',
|
||||
statusActive: 'Active',
|
||||
statusSuspended: 'Suspended',
|
||||
statusUnbound: 'Unbound',
|
||||
suspendedError: 'This card is suspended and cannot change scenes',
|
||||
invalidMode: 'Only business or social scenes are available',
|
||||
missingUid: 'Enter the chip UID',
|
||||
missingCardId: 'Enter the card ID',
|
||||
missingDevice: 'A device ID is required to update the scene',
|
||||
applySuccess: 'Done',
|
||||
applyError: 'Something went wrong',
|
||||
loading: 'Loading...',
|
||||
},
|
||||
'ar-SA': {
|
||||
title: 'وضع المشهد',
|
||||
desc: 'استخدم وضع الأعمال للمعارض النهارية ووضع التواصل للأمسيات. لا يمكن تبديل البطاقة الموقوفة.',
|
||||
uidLabel: 'معرّف الشريحة',
|
||||
cardIdLabel: 'معرّف البطاقة',
|
||||
business: 'معرض نهاري',
|
||||
social: 'أمسية اجتماعية',
|
||||
apply: 'تطبيق المشهد',
|
||||
statusLabel: 'الحالة الحالية',
|
||||
sceneLabel: 'المشهد الحالي',
|
||||
statusActive: 'نشط',
|
||||
statusSuspended: 'موقوف',
|
||||
statusUnbound: 'غير مرتبط',
|
||||
suspendedError: 'البطاقة موقوفة ولا يمكن تغيير المشهد',
|
||||
invalidMode: 'يتوفر وضع الأعمال أو التواصل فقط',
|
||||
missingUid: 'أدخل معرّف الشريحة',
|
||||
missingCardId: 'أدخل معرّف البطاقة',
|
||||
missingDevice: 'يلزم معرّف الجهاز لتحديث المشهد',
|
||||
applySuccess: 'تم',
|
||||
applyError: 'تعذّر الإكمال',
|
||||
loading: 'جارٍ التحميل...',
|
||||
},
|
||||
'es-ES': {
|
||||
title: 'Modo de escena',
|
||||
desc: 'Usa Negocios en ferias diurnas y Social en eventos nocturnos. Las tarjetas suspendidas no se pueden cambiar.',
|
||||
uidLabel: 'UID del chip',
|
||||
cardIdLabel: 'ID de tarjeta',
|
||||
business: 'Feria diurna',
|
||||
social: 'Evento social',
|
||||
apply: 'Aplicar escena',
|
||||
statusLabel: 'Estado actual',
|
||||
sceneLabel: 'Escena actual',
|
||||
statusActive: 'Activa',
|
||||
statusSuspended: 'Suspendida',
|
||||
statusUnbound: 'Sin vincular',
|
||||
suspendedError: 'La tarjeta está suspendida y no puede cambiar de escena',
|
||||
invalidMode: 'Solo están disponibles las escenas de negocios o social',
|
||||
missingUid: 'Introduce el UID del chip',
|
||||
missingCardId: 'Introduce el ID de la tarjeta',
|
||||
missingDevice: 'Se necesita el ID del dispositivo para actualizar la escena',
|
||||
applySuccess: 'Listo',
|
||||
applyError: 'No se pudo completar',
|
||||
loading: 'Cargando...',
|
||||
},
|
||||
'de-DE': {
|
||||
title: 'Szenenmodus',
|
||||
desc: 'Business für Tagesmessen, Social für Abendveranstaltungen. Gesperrte Karten lassen sich nicht wechseln.',
|
||||
uidLabel: 'Chip-UID',
|
||||
cardIdLabel: 'Karten-ID',
|
||||
business: 'Tagesmesse',
|
||||
social: 'Abendempfang',
|
||||
apply: 'Szene anwenden',
|
||||
statusLabel: 'Aktueller Status',
|
||||
sceneLabel: 'Aktuelle Szene',
|
||||
statusActive: 'Aktiv',
|
||||
statusSuspended: 'Gesperrt',
|
||||
statusUnbound: 'Nicht gebunden',
|
||||
suspendedError: 'Die Karte ist gesperrt und kann die Szene nicht wechseln',
|
||||
invalidMode: 'Nur Business- oder Social-Szenen sind verfügbar',
|
||||
missingUid: 'Chip-UID eingeben',
|
||||
missingCardId: 'Karten-ID eingeben',
|
||||
missingDevice: 'Zum Aktualisieren der Szene ist eine Geräte-ID erforderlich',
|
||||
applySuccess: 'Erledigt',
|
||||
applyError: 'Vorgang fehlgeschlagen',
|
||||
loading: 'Wird geladen...',
|
||||
},
|
||||
'fr-FR': {
|
||||
title: 'Mode scène',
|
||||
desc: 'Business pour les salons de jour, Social pour les soirées. Les cartes suspendues ne peuvent pas être changées.',
|
||||
uidLabel: 'UID de la puce',
|
||||
cardIdLabel: 'ID de carte',
|
||||
business: 'Salon de jour',
|
||||
social: 'Soirée',
|
||||
apply: 'Appliquer la scène',
|
||||
statusLabel: 'Statut actuel',
|
||||
sceneLabel: 'Scène actuelle',
|
||||
statusActive: 'Active',
|
||||
statusSuspended: 'Suspendue',
|
||||
statusUnbound: 'Non liée',
|
||||
suspendedError: 'Cette carte est suspendue et ne peut pas changer de scène',
|
||||
invalidMode: 'Seules les scènes business ou social sont disponibles',
|
||||
missingUid: 'Saisissez l’UID de la puce',
|
||||
missingCardId: 'Saisissez l’ID de la carte',
|
||||
missingDevice: 'Un identifiant d’appareil est requis pour mettre à jour la scène',
|
||||
applySuccess: 'Terminé',
|
||||
applyError: 'Échec de l’opération',
|
||||
loading: 'Chargement...',
|
||||
},
|
||||
'ja-JP': {
|
||||
title: 'シーンモード',
|
||||
desc: '日中の展示会はビジネス、夜の交流はソーシャル。利用停止中のカードは切り替えできません。',
|
||||
uidLabel: 'チップ UID',
|
||||
cardIdLabel: '名刺 ID',
|
||||
business: '日中展示会',
|
||||
social: '夜の交流',
|
||||
apply: 'シーンを適用',
|
||||
statusLabel: '現在の状態',
|
||||
sceneLabel: '現在のシーン',
|
||||
statusActive: '有効',
|
||||
statusSuspended: '利用停止',
|
||||
statusUnbound: '未連携',
|
||||
suspendedError: 'このカードは利用停止中のため、シーンを切り替えできません',
|
||||
invalidMode: 'ビジネスまたはソーシャルのみ選択できます',
|
||||
missingUid: 'チップ UID を入力してください',
|
||||
missingCardId: '名刺 ID を入力してください',
|
||||
missingDevice: 'シーンを更新するにはデバイス ID が必要です',
|
||||
applySuccess: '完了しました',
|
||||
applyError: '操作に失敗しました',
|
||||
loading: '読み込み中...',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 场景文案:能复用 locale.uts 的走词典,其余走本地七语表
|
||||
*/
|
||||
export function resolveModeText(key: ModeCopyKey): string {
|
||||
if (key === 'applySuccess') {
|
||||
return getOmniText(getCurrentLocale(), 'common.success');
|
||||
}
|
||||
if (key === 'applyError') {
|
||||
return getOmniText(getCurrentLocale(), 'common.error');
|
||||
}
|
||||
if (key === 'loading') {
|
||||
return getOmniText(getCurrentLocale(), 'common.loading');
|
||||
}
|
||||
const locale = getCurrentLocale();
|
||||
const bag = MODE_COPY[locale] != null ? MODE_COPY[locale] : MODE_COPY['en-US'];
|
||||
return bag[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 只放行 business | social
|
||||
*/
|
||||
export function parseSceneMode(raw: string | null | undefined): NFCSceneMode | null {
|
||||
if (raw === 'business' || raw === 'social') {
|
||||
return raw;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseStatus(raw: string | null | undefined): NFCStatus | null {
|
||||
if (raw === 'active' || raw === 'suspended' || raw === 'unbound') {
|
||||
return raw;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function parseMaterial(raw: string | null | undefined): NFCMaterial | null {
|
||||
if (raw === 'wood' || raw === 'metal' || raw === 'pvc') {
|
||||
return raw;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function trimText(value: string | number | null | undefined): string {
|
||||
if (value == null) {
|
||||
return '';
|
||||
}
|
||||
return String(value).trim();
|
||||
}
|
||||
|
||||
function toCardNumber(cardId: string | number): number {
|
||||
const n = typeof cardId === 'number' ? cardId : Number(String(cardId).trim());
|
||||
if (n !== n || n === 0) {
|
||||
return 0;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function sameCardId(
|
||||
left: string | number | null | undefined,
|
||||
right: string | number | null | undefined
|
||||
): boolean {
|
||||
const a = trimText(left);
|
||||
const b = trimText(right);
|
||||
if (a === '' || b === '') {
|
||||
return false;
|
||||
}
|
||||
return a === b;
|
||||
}
|
||||
|
||||
function hasDeviceId(device: NFCRecord | null): boolean {
|
||||
if (device == null) {
|
||||
return false;
|
||||
}
|
||||
return trimText(device.id) !== '';
|
||||
}
|
||||
|
||||
function fail(error: string, device: NFCRecord | null): ApplySceneResult {
|
||||
return {
|
||||
ok: false,
|
||||
error,
|
||||
device,
|
||||
};
|
||||
}
|
||||
|
||||
function resolveApi(api?: ApplySceneApi): ApplySceneApi {
|
||||
if (api != null) {
|
||||
return api;
|
||||
}
|
||||
return {
|
||||
switchNfcCard,
|
||||
updateNfcDevice,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换场景:挂失拒绝;换绑仅 active 且 cardId 不同;始终 update 写 sceneMode
|
||||
*/
|
||||
export async function applyScene(
|
||||
params: ApplySceneParams,
|
||||
api?: ApplySceneApi
|
||||
): Promise<ApplySceneResult> {
|
||||
const uid = trimText(params.uid);
|
||||
if (uid === '') {
|
||||
return fail(resolveModeText('missingUid'), params.device);
|
||||
}
|
||||
|
||||
const mode = parseSceneMode(params.sceneMode);
|
||||
if (mode == null) {
|
||||
return fail(resolveModeText('invalidMode'), params.device);
|
||||
}
|
||||
|
||||
const cardNumber = toCardNumber(params.cardId);
|
||||
if (cardNumber === 0) {
|
||||
return fail(resolveModeText('missingCardId'), params.device);
|
||||
}
|
||||
|
||||
const device = params.device;
|
||||
if (device != null && device.status === 'suspended') {
|
||||
return fail(resolveModeText('suspendedError'), device);
|
||||
}
|
||||
|
||||
if (!hasDeviceId(device)) {
|
||||
return fail(resolveModeText('missingDevice'), device);
|
||||
}
|
||||
|
||||
const readyDevice = device as NFCRecord;
|
||||
const client = resolveApi(api);
|
||||
let working = readyDevice;
|
||||
|
||||
const needSwitch =
|
||||
readyDevice.status === 'active' && !sameCardId(readyDevice.cardId, params.cardId);
|
||||
if (needSwitch) {
|
||||
working = await client.switchNfcCard({
|
||||
uid,
|
||||
cardId: cardNumber,
|
||||
});
|
||||
}
|
||||
|
||||
const payload: NFCRecord & { id: string | number } = {
|
||||
id: working.id,
|
||||
uid: working.uid,
|
||||
tenantId: working.tenantId,
|
||||
cardId: working.cardId,
|
||||
batchNo: working.batchNo,
|
||||
material: working.material,
|
||||
status: working.status,
|
||||
sceneMode: mode,
|
||||
lastScannedAt: working.lastScannedAt,
|
||||
};
|
||||
const updated = await client.updateNfcDevice(payload);
|
||||
return {
|
||||
ok: true,
|
||||
error: '',
|
||||
device: updated,
|
||||
};
|
||||
}
|
||||
|
||||
export function createModeState(): NfcModeState {
|
||||
return {
|
||||
uid: '',
|
||||
cardId: '',
|
||||
selectedMode: 'business',
|
||||
status: '',
|
||||
sceneMode: '',
|
||||
device: null,
|
||||
submitting: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
function buildDeviceFromOptions(
|
||||
state: NfcModeState,
|
||||
options: ModePageOptions
|
||||
): NFCRecord | null {
|
||||
const id = trimText(options.id);
|
||||
if (id === '') {
|
||||
return null;
|
||||
}
|
||||
const status = parseStatus(state.status);
|
||||
const sceneMode = parseSceneMode(state.sceneMode);
|
||||
const material = parseMaterial(options.material);
|
||||
return {
|
||||
id,
|
||||
uid: state.uid,
|
||||
tenantId: trimText(options.tenantId) !== '' ? trimText(options.tenantId) : 0,
|
||||
cardId: state.cardId === '' ? null : state.cardId,
|
||||
batchNo: trimText(options.batchNo),
|
||||
material: material != null ? material : 'pvc',
|
||||
status: status != null ? status : 'unbound',
|
||||
sceneMode: sceneMode != null ? sceneMode : 'business',
|
||||
lastScannedAt: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 从页面 query 写入 uid / cardId / 当前状态与场景
|
||||
*/
|
||||
export function applyModeOptions(
|
||||
state: NfcModeState,
|
||||
options: ModePageOptions | null
|
||||
): void {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
const uid = trimText(options.uid);
|
||||
if (uid !== '') {
|
||||
state.uid = uid;
|
||||
}
|
||||
const cardId = trimText(options.cardId);
|
||||
if (cardId !== '') {
|
||||
state.cardId = cardId;
|
||||
}
|
||||
const status = parseStatus(options.status);
|
||||
if (status != null) {
|
||||
state.status = status;
|
||||
}
|
||||
const sceneMode = parseSceneMode(options.sceneMode);
|
||||
if (sceneMode != null) {
|
||||
state.sceneMode = sceneMode;
|
||||
state.selectedMode = sceneMode;
|
||||
}
|
||||
state.device = buildDeviceFromOptions(state, options);
|
||||
}
|
||||
|
||||
export function selectSceneMode(state: NfcModeState, raw: string): boolean {
|
||||
const mode = parseSceneMode(raw);
|
||||
if (mode == null) {
|
||||
return false;
|
||||
}
|
||||
state.selectedMode = mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function formatStatusLabel(status: string): string {
|
||||
if (status === 'active') {
|
||||
return resolveModeText('statusActive');
|
||||
}
|
||||
if (status === 'suspended') {
|
||||
return resolveModeText('statusSuspended');
|
||||
}
|
||||
if (status === 'unbound') {
|
||||
return resolveModeText('statusUnbound');
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
export function formatSceneLabel(mode: string): string {
|
||||
if (mode === 'business') {
|
||||
return resolveModeText('business');
|
||||
}
|
||||
if (mode === 'social') {
|
||||
return resolveModeText('social');
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
function toastNone(title: string): void {
|
||||
uni.showToast({
|
||||
title,
|
||||
icon: 'none',
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面提交:调用 applyScene,成功后回写状态
|
||||
*/
|
||||
export async function submitApplyScene(
|
||||
state: NfcModeState,
|
||||
api?: ApplySceneApi
|
||||
): Promise<ApplySceneResult> {
|
||||
if (state.submitting) {
|
||||
return {
|
||||
ok: false,
|
||||
error: '',
|
||||
device: state.device,
|
||||
};
|
||||
}
|
||||
|
||||
if (state.device != null) {
|
||||
state.device.uid = state.uid;
|
||||
state.device.cardId = state.cardId === '' ? null : state.cardId;
|
||||
}
|
||||
|
||||
state.submitting = true;
|
||||
state.errorMessage = '';
|
||||
const result = await applyScene(
|
||||
{
|
||||
uid: state.uid,
|
||||
cardId: state.cardId,
|
||||
sceneMode: state.selectedMode,
|
||||
device: state.device,
|
||||
},
|
||||
api
|
||||
);
|
||||
state.submitting = false;
|
||||
|
||||
if (!result.ok) {
|
||||
state.errorMessage = result.error;
|
||||
toastNone(result.error);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result.device != null) {
|
||||
state.device = result.device;
|
||||
state.status = result.device.status;
|
||||
state.sceneMode = result.device.sceneMode;
|
||||
state.uid = result.device.uid;
|
||||
if (result.device.cardId != null && trimText(result.device.cardId) !== '') {
|
||||
state.cardId = String(result.device.cardId);
|
||||
}
|
||||
}
|
||||
toastNone(resolveModeText('applySuccess'));
|
||||
return result;
|
||||
}
|
||||
287
mpuniapp/pages/owner/nfc/useScan.uts
普通文件
287
mpuniapp/pages/owner/nfc/useScan.uts
普通文件
@@ -0,0 +1,287 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主 NFC 贴卡激活业务驱动层
|
||||
* H5 无天线走手动 UID;APP startScan 为占位,调不到原生 NFC 时回退手动输入
|
||||
*/
|
||||
|
||||
import { NFCRecord } from '../../../common/types.uts';
|
||||
import { bindNfcDevice, activateNfcDevice } from '../../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
|
||||
export type ScanCopyKey =
|
||||
| 'title'
|
||||
| 'desc'
|
||||
| 'uidLabel'
|
||||
| 'uidPlaceholder'
|
||||
| 'cardIdLabel'
|
||||
| 'cardIdPlaceholder'
|
||||
| 'cta'
|
||||
| 'empty'
|
||||
| 'uidRequired'
|
||||
| 'cardIdRequired'
|
||||
| 'nfcUnavailable'
|
||||
| 'success'
|
||||
| 'error'
|
||||
| 'retry';
|
||||
|
||||
export type ScanState = {
|
||||
uid: string;
|
||||
cardIdRaw: string;
|
||||
deviceCardId: number | null;
|
||||
submitting: boolean;
|
||||
scanning: boolean;
|
||||
manualInput: boolean;
|
||||
errorMessage: string;
|
||||
empty: boolean;
|
||||
record: NFCRecord | null;
|
||||
};
|
||||
|
||||
export type ScanPageOptions = {
|
||||
cardId?: string;
|
||||
uid?: string;
|
||||
id?: string;
|
||||
};
|
||||
|
||||
export type ActivateByTapInput = {
|
||||
uid: string;
|
||||
cardId?: string | number | null;
|
||||
deviceCardId?: string | number | null;
|
||||
};
|
||||
|
||||
function isZhLocale(): boolean {
|
||||
return getCurrentLocale() === 'zh-CN';
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面文案:能复用 locale.uts 的走词典,缺 key 时中英本地词典
|
||||
*/
|
||||
export function resolveScanText(key: ScanCopyKey): string {
|
||||
const locale = getCurrentLocale();
|
||||
if (key === 'title') {
|
||||
return getOmniText(locale, 'card.scan_nfc');
|
||||
}
|
||||
if (key === 'success') {
|
||||
return getOmniText(locale, 'common.success');
|
||||
}
|
||||
if (key === 'error') {
|
||||
return getOmniText(locale, 'common.error');
|
||||
}
|
||||
if (key === 'empty') {
|
||||
return getOmniText(locale, 'common.empty');
|
||||
}
|
||||
|
||||
const zh = isZhLocale();
|
||||
if (key === 'desc') {
|
||||
return zh
|
||||
? '贴近实体卡,或手动填写芯片 UID 完成绑定'
|
||||
: 'Hold the card to this phone, or enter the chip UID to bind it';
|
||||
}
|
||||
if (key === 'uidLabel') {
|
||||
return zh ? '芯片 UID' : 'Chip UID';
|
||||
}
|
||||
if (key === 'uidPlaceholder') {
|
||||
return zh ? '输入芯片 UID' : 'Enter chip UID';
|
||||
}
|
||||
if (key === 'cardIdLabel') {
|
||||
return zh ? '名片编号' : 'Card ID';
|
||||
}
|
||||
if (key === 'cardIdPlaceholder') {
|
||||
return zh ? '输入名片编号' : 'Enter card ID';
|
||||
}
|
||||
if (key === 'cta') {
|
||||
return zh ? '激活并绑定' : 'Activate and bind';
|
||||
}
|
||||
if (key === 'uidRequired') {
|
||||
return zh ? '请填写芯片 UID' : 'Enter the chip UID';
|
||||
}
|
||||
if (key === 'cardIdRequired') {
|
||||
return zh ? '请填写名片编号' : 'Enter a card ID';
|
||||
}
|
||||
if (key === 'nfcUnavailable') {
|
||||
return zh
|
||||
? '当前无法读取 NFC,请手动填写 UID'
|
||||
: 'NFC is unavailable. Enter the UID instead';
|
||||
}
|
||||
if (key === 'retry') {
|
||||
return zh ? '重试' : 'Try again';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 去空。空串视为非法 UID
|
||||
*/
|
||||
export function parseUid(raw: string | number | null | undefined): string {
|
||||
if (raw == null) {
|
||||
return '';
|
||||
}
|
||||
return String(raw).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析为正整数。非正整数返回 null
|
||||
*/
|
||||
export function parseCardId(raw: string | number | null | undefined): number | null {
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
if (typeof raw === 'number') {
|
||||
if (raw <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (Math.floor(raw) !== raw) {
|
||||
return null;
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
const text = String(raw).trim();
|
||||
if (text === '') {
|
||||
return null;
|
||||
}
|
||||
if (!/^[1-9]\d*$/.test(text)) {
|
||||
return null;
|
||||
}
|
||||
return Number(text);
|
||||
}
|
||||
|
||||
function readErrorMessage(err: unknown): string {
|
||||
if (err instanceof Error && err.message !== '') {
|
||||
return err.message;
|
||||
}
|
||||
return resolveScanText('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* 贴卡激活:有入参 cardId 则 bind;设备已有 cardId 且入参为空则 activate
|
||||
*/
|
||||
export async function activateByTap(
|
||||
input: ActivateByTapInput,
|
||||
existing?: { cardId?: string | number | null } | null
|
||||
): Promise<NFCRecord> {
|
||||
const uid = parseUid(input.uid);
|
||||
if (uid === '') {
|
||||
throw new Error(resolveScanText('uidRequired'));
|
||||
}
|
||||
|
||||
const incomingCardId = parseCardId(input.cardId);
|
||||
const fromInputDevice = parseCardId(input.deviceCardId);
|
||||
const fromExisting = existing != null ? parseCardId(existing.cardId) : null;
|
||||
const deviceCardId = fromInputDevice != null ? fromInputDevice : fromExisting;
|
||||
|
||||
try {
|
||||
if (incomingCardId == null && deviceCardId != null) {
|
||||
return await activateNfcDevice({ uid });
|
||||
}
|
||||
if (incomingCardId != null) {
|
||||
return await bindNfcDevice({ uid, cardId: incomingCardId });
|
||||
}
|
||||
throw new Error(resolveScanText('cardIdRequired'));
|
||||
} catch (err) {
|
||||
throw new Error(readErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
export function createScanState(): ScanState {
|
||||
return {
|
||||
uid: '',
|
||||
cardIdRaw: '',
|
||||
deviceCardId: null,
|
||||
submitting: false,
|
||||
scanning: false,
|
||||
manualInput: true,
|
||||
errorMessage: '',
|
||||
empty: true,
|
||||
record: null,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyScanOptions(state: ScanState, options: ScanPageOptions | null): void {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
if (options.uid != null) {
|
||||
state.uid = parseUid(options.uid);
|
||||
}
|
||||
const cardRaw =
|
||||
options.cardId != null && options.cardId !== ''
|
||||
? options.cardId
|
||||
: options.id != null
|
||||
? options.id
|
||||
: '';
|
||||
if (cardRaw !== '') {
|
||||
state.cardIdRaw = String(cardRaw).trim();
|
||||
}
|
||||
state.empty = parseUid(state.uid) === '';
|
||||
}
|
||||
|
||||
/**
|
||||
* APP 原生贴卡占位。调不到天线时回退手动输入,禁止伪造成功
|
||||
*/
|
||||
export function startScan(state: ScanState): boolean {
|
||||
// #ifdef APP
|
||||
// Native NFC antenna is not wired in this skeleton.
|
||||
// #endif
|
||||
state.scanning = false;
|
||||
state.manualInput = true;
|
||||
state.record = null;
|
||||
if (parseUid(state.uid) === '') {
|
||||
state.empty = true;
|
||||
state.errorMessage = resolveScanText('nfcUnavailable');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveStatusLine(state: ScanState): string {
|
||||
if (state.errorMessage !== '') {
|
||||
return state.errorMessage;
|
||||
}
|
||||
if (state.empty && parseUid(state.uid) === '') {
|
||||
return resolveScanText('empty');
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面主 CTA:校验后走 activateByTap,失败写入一句错误
|
||||
*/
|
||||
export async function submitScan(state: ScanState): Promise<NFCRecord | null> {
|
||||
if (state.submitting) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const uid = parseUid(state.uid);
|
||||
if (uid === '') {
|
||||
state.empty = true;
|
||||
state.errorMessage = resolveScanText('uidRequired');
|
||||
return null;
|
||||
}
|
||||
|
||||
state.uid = uid;
|
||||
state.empty = false;
|
||||
state.submitting = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
const record = await activateByTap(
|
||||
{
|
||||
uid,
|
||||
cardId: state.cardIdRaw,
|
||||
deviceCardId: state.deviceCardId,
|
||||
},
|
||||
{ cardId: state.deviceCardId }
|
||||
);
|
||||
state.submitting = false;
|
||||
state.record = record;
|
||||
if (record.cardId != null) {
|
||||
const bound = parseCardId(record.cardId);
|
||||
if (bound != null) {
|
||||
state.deviceCardId = bound;
|
||||
}
|
||||
}
|
||||
return record;
|
||||
} catch (err) {
|
||||
state.submitting = false;
|
||||
state.record = null;
|
||||
state.errorMessage = readErrorMessage(err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
/**
|
||||
* OmniCard AI (CRMmp) - 名片主移动端 NFC 安全与远程挂失业务驱动层
|
||||
* 管理 NFC 资产设备列表、在线/挂失冻结状态流转、防伪 UID 格式校验与安全哈希查验
|
||||
* 遵循 AGENTS.md 规范与 uts 强类型约束
|
||||
*/
|
||||
|
||||
import { NFCRecord } from '../../../common/types.uts';
|
||||
import { freezeNfcDevice, unfreezeNfcDevice } from '../../../common/api.uts';
|
||||
import { getCurrentLocale, getOmniText } from '../../../common/locale.uts';
|
||||
|
||||
export type SecurityDeviceStatus = 'active' | 'frozen';
|
||||
|
||||
export interface NfcSecurityDevice {
|
||||
id: number;
|
||||
uid: string;
|
||||
cardId?: number | null;
|
||||
status: SecurityDeviceStatus;
|
||||
securityHash?: string;
|
||||
batchNo?: string;
|
||||
material?: string;
|
||||
lastScannedAt?: string | null;
|
||||
}
|
||||
|
||||
export interface SecurityState {
|
||||
devices: NfcSecurityDevice[];
|
||||
selectedId: number | null;
|
||||
submitting: boolean;
|
||||
errorMessage: string;
|
||||
}
|
||||
|
||||
export interface SecurityApi {
|
||||
freeze: (params: { id: number; uid?: string }) => Promise<unknown>;
|
||||
unfreeze: (params: { id: number; uid?: string }) => Promise<unknown>;
|
||||
}
|
||||
|
||||
export type SecurityCopyKey =
|
||||
| 'title'
|
||||
| 'desc'
|
||||
| 'statusActive'
|
||||
| 'statusFrozen'
|
||||
| 'freezeBtn'
|
||||
| 'unfreezeBtn'
|
||||
| 'warningTitle'
|
||||
| 'warningDesc'
|
||||
| 'deviceEmpty'
|
||||
| 'uidLabel'
|
||||
| 'batchLabel'
|
||||
| 'antiCounterfeitValid'
|
||||
| 'antiCounterfeitInvalid'
|
||||
| 'errorNotFound'
|
||||
| 'errorAlreadyFrozen'
|
||||
| 'errorNotFrozen'
|
||||
| 'freezeSuccess'
|
||||
| 'unfreezeSuccess';
|
||||
|
||||
const DEFAULT_SALT = 'OMNICARD_SECURE_SALT_2026';
|
||||
|
||||
/**
|
||||
* 规范化 UID:去除冒号、空格、连字符并转大写
|
||||
*/
|
||||
export function normalizeUid(raw: string | null | undefined): string {
|
||||
if (raw == null) {
|
||||
return '';
|
||||
}
|
||||
return String(raw).replace(/[\s:-]/g, '').toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 防伪 UID 格式校验:
|
||||
* 严格校验十六进制字符,仅放行标准 4 字节(8 字符)或 7 字节(14 字符)NFC 芯片 UID
|
||||
*/
|
||||
export function validateNfcUid(raw: string | null | undefined): {
|
||||
valid: boolean;
|
||||
normalizedUid: string;
|
||||
error?: string;
|
||||
} {
|
||||
const normalized = normalizeUid(raw);
|
||||
if (!normalized) {
|
||||
return {
|
||||
valid: false,
|
||||
normalizedUid: '',
|
||||
error: 'UID 不能为空',
|
||||
};
|
||||
}
|
||||
|
||||
// 严格检查是否为纯十六进制字符
|
||||
if (!/^[0-9A-F]+$/.test(normalized)) {
|
||||
return {
|
||||
valid: false,
|
||||
normalizedUid: normalized,
|
||||
error: 'UID 必须为有效十六进制格式',
|
||||
};
|
||||
}
|
||||
|
||||
// 校验长度:标准 4 字节 (8 字符) 或 7 字节 (14 字符)
|
||||
if (normalized.length !== 8 && normalized.length !== 14) {
|
||||
return {
|
||||
valid: false,
|
||||
normalizedUid: normalized,
|
||||
error: 'UID 长度不符合标准 NFC 规范 (需为 8 或 14 字符)',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
normalizedUid: normalized,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算确定性防伪安全哈希码
|
||||
* 基于 UID 与安全盐生成 32 位 Hex 防伪数字签名
|
||||
*/
|
||||
export function computeSecurityHash(
|
||||
uid: string,
|
||||
salt: string = DEFAULT_SALT
|
||||
): string {
|
||||
const cleanUid = normalizeUid(uid);
|
||||
if (!cleanUid) {
|
||||
return '';
|
||||
}
|
||||
const text = cleanUid + ':' + (salt || DEFAULT_SALT);
|
||||
|
||||
let h1 = 0x811c9dc5;
|
||||
let h2 = 0x9e3779b9;
|
||||
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const code = text.charCodeAt(i);
|
||||
h1 = Math.imul(h1 ^ code, 0x01000193);
|
||||
h2 = Math.imul(h2 ^ code, 0x5bd1e995);
|
||||
h1 = (h1 << 13) | (h1 >>> 19);
|
||||
h2 = (h2 << 15) | (h2 >>> 17);
|
||||
}
|
||||
|
||||
const p1 = (h1 >>> 0).toString(16).padStart(8, '0');
|
||||
const p2 = (h2 >>> 0).toString(16).padStart(8, '0');
|
||||
const p3 = ((h1 ^ h2) >>> 0).toString(16).padStart(8, '0');
|
||||
const p4 = ((h1 + h2) >>> 0).toString(16).padStart(8, '0');
|
||||
|
||||
return (p1 + p2 + p3 + p4).toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查验防伪安全哈希是否匹配,防止物理克隆伪造
|
||||
*/
|
||||
export function verifySecurityHash(
|
||||
uid: string,
|
||||
hash: string,
|
||||
salt: string = DEFAULT_SALT
|
||||
): boolean {
|
||||
if (!uid || !hash) {
|
||||
return false;
|
||||
}
|
||||
const cleanUid = normalizeUid(uid);
|
||||
if (!cleanUid) {
|
||||
return false;
|
||||
}
|
||||
const expected = computeSecurityHash(cleanUid, salt);
|
||||
return expected.toUpperCase() === String(hash).trim().toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化状态对象
|
||||
*/
|
||||
export function createSecurityState(
|
||||
initialDevices?: NfcSecurityDevice[]
|
||||
): SecurityState {
|
||||
const devices = initialDevices ? initialDevices.map((d) => ({ ...d })) : [];
|
||||
const selectedId = devices.length > 0 ? devices[0].id : null;
|
||||
return {
|
||||
devices,
|
||||
selectedId,
|
||||
submitting: false,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 选中指定设备
|
||||
*/
|
||||
export function selectDevice(state: SecurityState, id: number): void {
|
||||
state.selectedId = id;
|
||||
state.errorMessage = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键远程挂失冻结设备 (active -> frozen)
|
||||
*/
|
||||
export async function freezeDevice(
|
||||
state: SecurityState,
|
||||
id: number,
|
||||
api?: SecurityApi
|
||||
): Promise<NfcSecurityDevice> {
|
||||
const device = state.devices.find((d) => d.id === id);
|
||||
if (!device) {
|
||||
throw new Error('NFC 设备不存在');
|
||||
}
|
||||
|
||||
if (device.status === 'frozen') {
|
||||
throw new Error('设备已处于挂失冻结状态');
|
||||
}
|
||||
|
||||
state.submitting = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
if (api != null && typeof api.freeze === 'function') {
|
||||
await api.freeze({ id, uid: device.uid });
|
||||
} else {
|
||||
await freezeNfcDevice({ id, uid: device.uid });
|
||||
}
|
||||
|
||||
device.status = 'frozen';
|
||||
return device;
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : '远程挂失失败';
|
||||
state.errorMessage = message;
|
||||
throw new Error(message);
|
||||
} finally {
|
||||
state.submitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程解除挂失冻结恢复 (frozen -> active)
|
||||
*/
|
||||
export async function unfreezeDevice(
|
||||
state: SecurityState,
|
||||
id: number,
|
||||
api?: SecurityApi
|
||||
): Promise<NfcSecurityDevice> {
|
||||
const device = state.devices.find((d) => d.id === id);
|
||||
if (!device) {
|
||||
throw new Error('NFC 设备不存在');
|
||||
}
|
||||
|
||||
if (device.status !== 'frozen') {
|
||||
throw new Error('设备未处于挂失冻结状态');
|
||||
}
|
||||
|
||||
state.submitting = true;
|
||||
state.errorMessage = '';
|
||||
|
||||
try {
|
||||
if (api != null && typeof api.unfreeze === 'function') {
|
||||
await api.unfreeze({ id, uid: device.uid });
|
||||
} else {
|
||||
await unfreezeNfcDevice({ id, uid: device.uid });
|
||||
}
|
||||
|
||||
device.status = 'active';
|
||||
return device;
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : '解除挂失失败';
|
||||
state.errorMessage = message;
|
||||
throw new Error(message);
|
||||
} finally {
|
||||
state.submitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 国际化多语言文案字典解析
|
||||
*/
|
||||
export function resolveSecurityText(key: SecurityCopyKey): string {
|
||||
const isZh = getCurrentLocale() === 'zh-CN';
|
||||
|
||||
switch (key) {
|
||||
case 'title':
|
||||
return isZh ? 'NFC 安全与挂失' : 'NFC Security & Remote Lock';
|
||||
case 'desc':
|
||||
return isZh
|
||||
? '物理名片丢失或遭遇异常,可立即远程一键挂失冻结,保护商业资产安全。'
|
||||
: 'Remotely freeze lost cards instantly to prevent unauthorized access.';
|
||||
case 'statusActive':
|
||||
return isZh ? '正常使用中' : 'Active';
|
||||
case 'statusFrozen':
|
||||
return isZh ? '已挂失冻结' : 'Frozen';
|
||||
case 'freezeBtn':
|
||||
return isZh ? '一键远程挂失' : 'Freeze Card';
|
||||
case 'unfreezeBtn':
|
||||
return isZh ? '解除挂失恢复' : 'Unfreeze Card';
|
||||
case 'warningTitle':
|
||||
return isZh ? '安全保护机制' : 'Security Policy';
|
||||
case 'warningDesc':
|
||||
return isZh
|
||||
? '挂失后将立即切断该实体 NFC 芯片的触碰跳转与数据传输。如已找回芯片,可在此安全解冻。'
|
||||
: 'Freezing immediately halts touch response and data access on this physical card.';
|
||||
case 'deviceEmpty':
|
||||
return isZh ? '暂无名下 NFC 硬件设备' : 'No NFC hardware registered';
|
||||
case 'uidLabel':
|
||||
return isZh ? '芯片 UID' : 'Chip UID';
|
||||
case 'batchLabel':
|
||||
return isZh ? '出厂批次' : 'Batch No';
|
||||
case 'antiCounterfeitValid':
|
||||
return isZh ? '防伪验签通过' : 'Authenticity Verified';
|
||||
case 'antiCounterfeitInvalid':
|
||||
return isZh ? '防伪校验异常' : 'Verification Failed';
|
||||
case 'errorNotFound':
|
||||
return isZh ? 'NFC 设备不存在' : 'Device not found';
|
||||
case 'errorAlreadyFrozen':
|
||||
return isZh ? '设备已处于挂失冻结状态' : 'Device already frozen';
|
||||
case 'errorNotFrozen':
|
||||
return isZh ? '设备未处于挂失冻结状态' : 'Device is not frozen';
|
||||
case 'freezeSuccess':
|
||||
return isZh ? '设备已成功远程挂失冻结' : 'Card frozen successfully';
|
||||
case 'unfreezeSuccess':
|
||||
return isZh ? '设备已成功解冻恢复' : 'Card unfrozen successfully';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户