feat: 同步管理端、用户端与后端业务,并接通线上 Web 接口
补齐平台订阅、外部登录、CRM 同步与用户端页面;Nginx 转发用户端接口,登录页使用 Google 与 Apple 标志。 Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -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':
|
||||
|
||||
在新工单中引用
屏蔽一个用户