feat: 统一后台与用户端图片与文件上传交互,支持点击放大预览、删除与多图批量多选上传
这个提交包含在:
@@ -26,6 +26,20 @@
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 拍摄的名片图片卡片:可点击放大预览、可删除 -->
|
||||
<view v-if="ocrState.imagePath !== ''" class="ocr-preview-card">
|
||||
<view class="ocr-preview-thumb-wrap" @click="handlePreviewOcrImage">
|
||||
<image class="ocr-preview-img" :src="ocrState.imagePath" mode="aspectFill" />
|
||||
</view>
|
||||
<view class="ocr-preview-info" @click="handlePreviewOcrImage">
|
||||
<text class="ocr-preview-title">名片原图</text>
|
||||
<text class="ocr-preview-hint">点击放大预览原图</text>
|
||||
</view>
|
||||
<view class="ocr-preview-delete" @click="handleRemoveOcrImage">
|
||||
<text class="ocr-preview-delete-text">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">姓名</text>
|
||||
<input
|
||||
@@ -105,6 +119,8 @@ import {
|
||||
import {
|
||||
createOcrScanState,
|
||||
handleCardOcrUpload,
|
||||
previewOcrImage,
|
||||
removeOcrImage,
|
||||
} from './useOcrExchange.uts';
|
||||
|
||||
const pageTheme: Record<string, string> = {
|
||||
@@ -125,6 +141,14 @@ const pageTheme: Record<string, string> = {
|
||||
const state = reactive(createExchangeState());
|
||||
const ocrState = reactive(createOcrScanState());
|
||||
|
||||
function handlePreviewOcrImage(): void {
|
||||
previewOcrImage(ocrState);
|
||||
}
|
||||
|
||||
function handleRemoveOcrImage(): void {
|
||||
removeOcrImage(ocrState);
|
||||
}
|
||||
|
||||
async function handleOcrScan(): Promise<void> {
|
||||
if (ocrState.scanning) {
|
||||
return;
|
||||
@@ -142,6 +166,57 @@ onLoad((options: ExchangePageOptions) => {
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ocr-preview-card {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding: 8px 12px;
|
||||
background-color: var(--oc-surface, #F7F8FA);
|
||||
border: 1px solid var(--oc-border, #E3E7ED);
|
||||
border-radius: var(--oc-radius-btn, 12px);
|
||||
margin-bottom: var(--oc-space-16, 16px);
|
||||
}
|
||||
|
||||
.ocr-preview-thumb-wrap {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.ocr-preview-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ocr-preview-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ocr-preview-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--oc-text, #101828);
|
||||
}
|
||||
|
||||
.ocr-preview-hint {
|
||||
font-size: 11px;
|
||||
color: var(--oc-primary, #0B5CFF);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.ocr-preview-delete {
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.ocr-preview-delete-text {
|
||||
font-size: 12px;
|
||||
color: var(--oc-text-2, #667085);
|
||||
}
|
||||
|
||||
.exchange-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -18,6 +18,7 @@ export type ExtractedContactInfo = {
|
||||
export type OcrScanState = {
|
||||
scanning: boolean;
|
||||
rawText: string;
|
||||
imagePath: string;
|
||||
lastExtracted: ExtractedContactInfo | null;
|
||||
errorMessage: string;
|
||||
};
|
||||
@@ -76,11 +77,37 @@ export function createOcrScanState(): OcrScanState {
|
||||
return {
|
||||
scanning: false,
|
||||
rawText: '',
|
||||
imagePath: '',
|
||||
lastExtracted: null,
|
||||
errorMessage: '',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览已拍照的名片图片
|
||||
*/
|
||||
export function previewOcrImage(ocrState: OcrScanState): void {
|
||||
if (ocrState.imagePath !== '') {
|
||||
// #ifndef UNI-APP-X-TEST
|
||||
try {
|
||||
if (typeof uni !== 'undefined' && typeof uni.previewImage === 'function') {
|
||||
uni.previewImage({
|
||||
urls: [ocrState.imagePath],
|
||||
current: ocrState.imagePath,
|
||||
});
|
||||
}
|
||||
} catch (_e) {}
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除已拍摄的名片图片
|
||||
*/
|
||||
export function removeOcrImage(ocrState: OcrScanState): void {
|
||||
ocrState.imagePath = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为职位关键词
|
||||
*/
|
||||
@@ -571,6 +598,15 @@ export async function handleCardOcrUpload(
|
||||
count: 1,
|
||||
sourceType: sourceTypes,
|
||||
success: (_res: unknown) => {
|
||||
let path = '';
|
||||
if (_res != null && typeof _res === 'object') {
|
||||
const r = _res as Record<string, unknown>;
|
||||
if (Array.isArray(r.tempFilePaths) && r.tempFilePaths.length > 0) {
|
||||
path = String(r.tempFilePaths[0]);
|
||||
}
|
||||
}
|
||||
ocrState.imagePath = path !== '' ? path : 'https://cdn.omnicard.ai/mock-card.jpg';
|
||||
|
||||
// 图像上传与 OCR 解析
|
||||
const sample = simulateOcrScan('cn');
|
||||
ocrState.rawText = sample.rawText;
|
||||
|
||||
在新工单中引用
屏蔽一个用户