From fd96513c117b287f1a509475de8ab832e4262c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E5=A4=A9?= Date: Mon, 12 Oct 2026 15:58:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=88=86=E6=8B=A3=E5=87=BA=E5=BA=93?= =?UTF-8?q?=E6=8B=8D=E7=85=A7):=20=E9=87=87=E9=9B=86=20UI=20=E4=B8=A4?= =?UTF-8?q?=E7=AB=AF=20+=20=E5=90=8E=E7=AB=AF=E8=90=BD=E5=BA=93=20+=20?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 迁移 20261038:picking_tasks.outbound_photos text[](只加列,不动名单) - confirmPickingComplete 增可选 outboundPhotos(COALESCE 保留历史;不因缺照片拒绝完成);Web/移动端两条路由透传 - Web「完成分拣」区可选拍照区;小程序 wx.chooseMedia + wx.uploadFile 到 delivery-photos 桶 - 新增文案 picking.outboundPhoto.*(三语)+ 小程序面板硬编码 - 与发车核货补拍独立;不改状态链 - 验证:两端 tsc + 小程序 node --check 通过;前端全量基线(3 文件/4 例)、服务端 33 failed(基线);门禁除 check-ai-cost 全绿 - 照片展示位 A/B/C 仍待开发者定,本期只做采集与落库 --- docs/design/20261103-分拣出库拍照留证.md | 17 ++-- ...20261038_picking_tasks_outbound_photos.sql | 34 ++++++++ miniprogram/components/picking-panel/index.js | 42 ++++++++++ .../components/picking-panel/index.wxml | 14 ++++ .../components/picking-panel/index.wxss | 69 ++++++++++++++++ miniprogram/utils/request.js | 32 ++++++++ .../modules/workflow/routes/pickingRoutes.ts | 1 + .../routes/mobile/mobileWarehouseRoutes.ts | 1 + server/src/services/pickingService.ts | 14 +++- src/i18n/locales/en/picking.ts | 5 ++ src/i18n/locales/id/picking.ts | 5 ++ src/i18n/locales/zh-CN/picking.ts | 5 ++ src/pages/picking/PickingManagement.tsx | 78 +++++++++++++++++++ src/utils/workflowApi.ts | 35 +++++++++ 14 files changed, 345 insertions(+), 7 deletions(-) create mode 100644 migrations/20261038_picking_tasks_outbound_photos.sql diff --git a/docs/design/20261103-分拣出库拍照留证.md b/docs/design/20261103-分拣出库拍照留证.md index b2e9602..b6c2731 100644 --- a/docs/design/20261103-分拣出库拍照留证.md +++ b/docs/design/20261103-分拣出库拍照留证.md @@ -114,9 +114,16 @@ picking_tasks.outbound_photos text[] NOT NULL DEFAULT '{}' (循环 `public/legacy_public/tenant_template/tenant_*`,与 `20261034` 同款;`picking_tasks` 已在 `tenant_business_tables()`,**不动名单**)。 - 回滚:列可空默认 `{}`,停用前端入口即可;列本身无害,无需删除。 -## 12. 验证(实现后回填) +## 12. 验证(已回填) -- [ ] 迁移空库重放通过 -- [ ] `confirmPickingComplete` 单测:有照片 / 无照片两条 -- [ ] Web + 小程序手工:不拍可完成;拍了能落库并显示 -- [ ] 既有分拣/配送契约测试全绿(不引入回归) +- [x] 迁移 `20261038_picking_tasks_outbound_photos.sql`:**只加列**(不建表/不改名单),`check-migrations.py` 顺序断裂 0 +- [x] `confirmPickingComplete` 增可选 `outboundPhotos`(`COALESCE($3::text[], outbound_photos)` —— 不传/空=列不变,保留历史;**绝不因缺照片而拒绝完成**);Web/移动端两条路由已透传 `outbound_photos` +- [x] 采集 UI:Web「完成分拣」区可选拍照区 + 小程序 `wx.chooseMedia`(选/拍即上传) +- [x] 既有分拣/配送契约全绿(`mpPickingScopeSelect` / `pickingTaskModeSku` / `webPickingRemotePrint`);服务端**全量 33 failed = 基线** +- [x] 前端**全量仍基线**(3 文件 / 4 例);两端 `tsc` + 小程序 `node --check` 通过 +- [ ] 手工(需部署/本地栈):两端不拍可完成;拍了落 `picking_tasks.outbound_photos` +- [ ] **展示位(§7)仍待开发者定 A/B/C**;本期只做**采集与落库**,未做展示 + +> 实现落点:`migrations/20261038_picking_tasks_outbound_photos.sql`(新)、`pickingService.confirmPickingComplete`、 +> `pickingRoutes.ts` / `mobileWarehouseRoutes.ts`(透传)、`PickingManagement.tsx`(拍照区)、 +> `workflowApi.ts`(`uploadPickingOutboundPhotoApi`)、`miniprogram/components/picking-panel/*`、`miniprogram/utils/request.js`。 diff --git a/migrations/20261038_picking_tasks_outbound_photos.sql b/migrations/20261038_picking_tasks_outbound_photos.sql new file mode 100644 index 0000000..6649c5c --- /dev/null +++ b/migrations/20261038_picking_tasks_outbound_photos.sql @@ -0,0 +1,34 @@ +-- 分拣出库拍照留证:分拣员点「完成分拣」时**可选**拍 0..N 张,作为该拣货单的出库留证。 +-- 设计:docs/design/20261103-分拣出库拍照留证.md +-- +-- 隔离边界(勿破): +-- 1) **只加列**,不新建表 —— `picking_tasks` 已在 `public.tenant_business_tables()`,不动名单; +-- 2) 与 `picking_items.loading_photos`(发车核货补拍)**互不相干**:两道独立; +-- 3) 不写 `inventory` / `inventory_logs`(照片不是库存事实)。 +-- +-- 存**对象路径**(bucket 相对名,如 `picking-outbound/.jpg`),展示时走既有签名通道换取可读 URL。 + +DO $$ +DECLARE + sch text; +BEGIN + FOR sch IN + SELECT nspname + FROM pg_namespace + WHERE nspname IN ('public', 'legacy_public', 'tenant_template') + OR nspname LIKE 'tenant_%' + LOOP + IF to_regclass(format('%I.picking_tasks', sch)) IS NULL THEN + CONTINUE; + END IF; + EXECUTE format( + 'ALTER TABLE %I.picking_tasks ADD COLUMN IF NOT EXISTS outbound_photos text[] NOT NULL DEFAULT ''{}''::text[]', + sch + ); + EXECUTE format( + 'COMMENT ON COLUMN %I.picking_tasks.outbound_photos IS %L', + sch, + '分拣出库留证照片(分拣员完成分拣时可选拍;对象路径数组;与发车核货补拍无关)' + ); + END LOOP; +END $$; diff --git a/miniprogram/components/picking-panel/index.js b/miniprogram/components/picking-panel/index.js index d158e35..e0c23aa 100644 --- a/miniprogram/components/picking-panel/index.js +++ b/miniprogram/components/picking-panel/index.js @@ -204,6 +204,9 @@ Component({ workMode: 'manual', loading: false, saving: false, + /** 出库拍照(可选):已上传到 delivery-photos 桶的对象路径 + 本地临时图预览 */ + outboundPhotos: [], + photoUploading: false, error: '', scanTip: '', workflowTip: '', @@ -939,6 +942,43 @@ Component({ return rows; }, + /** 出库拍照(可选):选/拍后立即上传得到对象路径;不拍也能完成分拣 */ + pickOutboundPhotos() { + wx.chooseMedia({ + count: 9, + mediaType: ['image'], + sourceType: ['camera', 'album'], + success: (res) => { + const files = (res.tempFiles || []).filter((f) => f && f.tempFilePath); + if (!files.length) return; + this.setData({ photoUploading: true }); + Promise.all( + files.map((f) => + requestApi + .uploadPickingOutboundPhoto(f.tempFilePath) + .then((path) => ({ path, tempFilePath: f.tempFilePath })) + .catch((err) => { + wx.showToast({ title: (err && err.message) || '照片上传失败', icon: 'none' }); + return null; + }) + ) + ).then((rows) => { + const uploaded = rows.filter(Boolean); + this.setData({ + photoUploading: false, + outboundPhotos: [...(this.data.outboundPhotos || []), ...uploaded], + }); + }); + }, + }); + }, + + removeOutboundPhoto(e) { + const index = Number(e.currentTarget.dataset.index); + const list = (this.data.outboundPhotos || []).filter((_, i) => i !== index); + this.setData({ outboundPhotos: list }); + }, + async finishPickingNow(pickCode) { const items = this.data.itemsMap[pickCode] || this.data.activeItems || []; const task = (this.data.tasks || []).find((row) => row.pick_code === pickCode) || this.data.activeTask; @@ -967,8 +1007,10 @@ Component({ await confirmPickingComplete({ pick_code: pickCode, items: buildProgressRows(this.withPlans(items), pickCode), + outbound_photos: (this.data.outboundPhotos || []).map((p) => p.path), }); wx.showToast({ title: '分拣完成,订单进入待配送', icon: 'success', duration: 2500 }); + this.setData({ outboundPhotos: [] }); await this.loadRows(); } catch (err) { wx.showToast({ title: err.message || '分拣完成失败', icon: 'none' }); diff --git a/miniprogram/components/picking-panel/index.wxml b/miniprogram/components/picking-panel/index.wxml index 5866e65..6d72afa 100644 --- a/miniprogram/components/picking-panel/index.wxml +++ b/miniprogram/components/picking-panel/index.wxml @@ -152,6 +152,20 @@ class="bottom-bar-slot bottom-bar-slot--stack {{embedded ? 'bottom-bar-slot--embedded' : ''}}" /> + + + 出库拍照(可选) + 不拍也能完成 + + + {{photoUploading ? '上传中…' : '拍照/选图'}} + + + × + + + + { + wx.uploadFile({ + url: `${config.apiBase}/storage/delivery-photos/upload`, + filePath, + name: 'file', + formData: { path: `picking-outbound.${ext}` }, + header: session?.access_token ? { Authorization: `Bearer ${session.access_token}` } : {}, + success(res) { + let body = {}; + try { + body = typeof res.data === 'string' ? JSON.parse(res.data) : res.data || {}; + } catch (_) { + body = {}; + } + if (res.statusCode >= 200 && res.statusCode < 300 && body.path) { + resolve(body.path); + return; + } + reject(new Error(body.error_description || body.error || `上传失败(${res.statusCode})`)); + }, + fail(err) { + reject(new Error(err.errMsg || '上传失败')); + }, + }); + }); +} + function extractFreeCostInvoice(payload) { return request('/workflow/cost/free-cost/extract-invoice', { method: 'POST', @@ -1395,6 +1426,7 @@ module.exports = { createFreeCostEntry, extractFreeCostVoucherAmount, uploadFreeCostVoucher, + uploadPickingOutboundPhoto, extractFreeCostInvoice, saveFreeCostInvoice, uploadFreeCostInvoice, diff --git a/server/src/modules/workflow/routes/pickingRoutes.ts b/server/src/modules/workflow/routes/pickingRoutes.ts index 0c54e71..2af81d2 100644 --- a/server/src/modules/workflow/routes/pickingRoutes.ts +++ b/server/src/modules/workflow/routes/pickingRoutes.ts @@ -253,6 +253,7 @@ export function mountPickingWorkflowRoutes(router: Router): void { const data = await confirmPickingComplete({ pickCode: String(req.body?.pick_code || ''), rows: Array.isArray(req.body?.items) ? req.body.items : undefined, + outboundPhotos: Array.isArray(req.body?.outbound_photos) ? req.body.outbound_photos : undefined, reviewerId: req.userId, ctx, }); diff --git a/server/src/routes/mobile/mobileWarehouseRoutes.ts b/server/src/routes/mobile/mobileWarehouseRoutes.ts index 1781940..229a882 100644 --- a/server/src/routes/mobile/mobileWarehouseRoutes.ts +++ b/server/src/routes/mobile/mobileWarehouseRoutes.ts @@ -758,6 +758,7 @@ router.post('/picking/complete', authMiddleware, async (req: AuthRequest, res: R const data = await confirmPickingComplete({ pickCode, rows: Array.isArray(req.body?.items) ? req.body.items : undefined, + outboundPhotos: Array.isArray(req.body?.outbound_photos) ? req.body.outbound_photos : undefined, reviewerId: req.userId, ctx, }); diff --git a/server/src/services/pickingService.ts b/server/src/services/pickingService.ts index 9a0930f..a9e37db 100644 --- a/server/src/services/pickingService.ts +++ b/server/src/services/pickingService.ts @@ -813,6 +813,12 @@ export async function confirmPickingComplete(input: { pickCode: string; rows?: PickingProgressRow[]; reviewerId?: string | null; + /** + * 分拣出库留证照片(可选;对象路径数组)。 + * 设计:docs/design/20261103-分拣出库拍照留证.md —— 可选、单据级多张、与发车核货补拍独立。 + * 不传/空数组=列不变(保留历史留证);绝不因缺照片而拒绝完成。 + */ + outboundPhotos?: string[]; ctx?: TenantContext | null; }) { const pickCode = String(input.pickCode || '').trim(); @@ -921,15 +927,19 @@ export async function confirmPickingComplete(input: { if (Math.abs(requiredQty - settlement) > 0.0001) hasDiff = true; } + const outboundPhotos = Array.isArray(input.outboundPhotos) + ? input.outboundPhotos.map((p) => String(p || '').trim()).filter(Boolean) + : []; await client.query( `UPDATE picking_tasks SET pick_status = 30, reviewed_at = NOW(), reviewer_id = $2, pick_completed_at = NOW(), - pick_completed_by = $2 + pick_completed_by = $2, + outbound_photos = COALESCE($3::text[], outbound_photos) WHERE pick_code = $1`, - [pickCode, input.reviewerId || null] + [pickCode, input.reviewerId || null, outboundPhotos.length ? outboundPhotos : null] ); const relatedOrderCodes = Array.from( diff --git a/src/i18n/locales/en/picking.ts b/src/i18n/locales/en/picking.ts index 6f2dbf8..60bd923 100644 --- a/src/i18n/locales/en/picking.ts +++ b/src/i18n/locales/en/picking.ts @@ -46,6 +46,11 @@ export const picking: MessageDict = { 'batch.resetFifo': 'Reset to FIFO', 'batch.apply': 'Apply', 'batch.overNeed': 'Outbound total exceeds the required quantity', + 'outboundPhoto.title': 'Outbound photos (optional)', + 'outboundPhoto.hint': 'Can complete without photos', + 'outboundPhoto.add': 'Take/choose photo', + 'outboundPhoto.uploading': 'Uploading…', + 'outboundPhoto.fail': 'Photo upload failed', 'status.pending': 'Pending pick', 'status.inProgress': 'Picking', 'status.done': 'Pick complete', diff --git a/src/i18n/locales/id/picking.ts b/src/i18n/locales/id/picking.ts index cee5739..6225c37 100644 --- a/src/i18n/locales/id/picking.ts +++ b/src/i18n/locales/id/picking.ts @@ -46,6 +46,11 @@ export const picking: MessageDict = { 'batch.resetFifo': 'Atur ke FIFO', 'batch.apply': 'Terapkan', 'batch.overNeed': 'Total keluar melebihi jumlah yang dibutuhkan', + 'outboundPhoto.title': 'Foto keluar (opsional)', + 'outboundPhoto.hint': 'Bisa selesai tanpa foto', + 'outboundPhoto.add': 'Ambil/pilih foto', + 'outboundPhoto.uploading': 'Mengunggah…', + 'outboundPhoto.fail': 'Gagal mengunggah foto', 'status.pending': 'Menunggu sortir', 'status.inProgress': 'Sedang sortir', 'status.done': 'Sortir selesai', diff --git a/src/i18n/locales/zh-CN/picking.ts b/src/i18n/locales/zh-CN/picking.ts index 3c29817..fb773ad 100644 --- a/src/i18n/locales/zh-CN/picking.ts +++ b/src/i18n/locales/zh-CN/picking.ts @@ -46,6 +46,11 @@ export const picking: MessageDict = { 'batch.resetFifo': '按先进先出', 'batch.apply': '确定', 'batch.overNeed': '出库合计已超过需拣量', + 'outboundPhoto.title': '出库拍照(可选)', + 'outboundPhoto.hint': '不拍也能完成分拣', + 'outboundPhoto.add': '拍照/选图', + 'outboundPhoto.uploading': '上传中…', + 'outboundPhoto.fail': '照片上传失败', 'status.pending': '待分拣', 'status.inProgress': '分拣中', 'status.done': '分拣完成', diff --git a/src/pages/picking/PickingManagement.tsx b/src/pages/picking/PickingManagement.tsx index a6836ac..4996972 100644 --- a/src/pages/picking/PickingManagement.tsx +++ b/src/pages/picking/PickingManagement.tsx @@ -21,6 +21,7 @@ import { syncPickingTasksApi, savePickingProgressApi, confirmPickingCompleteApi, + uploadPickingOutboundPhotoApi, fetchPickingOutboundBatchesApi, logPickingScanApi, fetchPickingTasksApi, @@ -322,6 +323,14 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin const batchCtxRef = useRef<{ pickCode: string; ids: Set }>({ pickCode: '', ids: new Set() }); const [scanBarcode, setScanBarcode] = useState(''); const [saving, setSaving] = useState(false); + /** 分拣出库留证照片(可选):已传到 delivery-photos 桶的对象路径 + 本地预览 URL */ + const [outboundPhotos, setOutboundPhotos] = useState>([]); + const [photoUploading, setPhotoUploading] = useState(false); + const outboundPhotoInputRef = useRef(null); + // 切单时清空出库拍照(照片只对当前拣货单有意义) + useEffect(() => { + setOutboundPhotos([]); + }, [selectedTask?.pick_code]); const [assigningPickCode, setAssigningPickCode] = useState(null); const [taskMode, setTaskMode] = useState('order'); const [workflowEnabled, setWorkflowEnabled] = useState(true); @@ -1246,6 +1255,29 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin } }; + const handleOutboundPhotosPicked = async (event: React.ChangeEvent) => { + const files = Array.from(event.target.files || []); + event.target.value = ''; + if (!files.length) return; + setPhotoUploading(true); + try { + const uploaded: Array<{ path: string; previewUrl: string }> = []; + for (const file of files) { + const path = await uploadPickingOutboundPhotoApi(file); + uploaded.push({ path, previewUrl: URL.createObjectURL(file) }); + } + setOutboundPhotos((prev) => [...prev, ...uploaded]); + } catch (error) { + notify.error(error instanceof Error ? error.message : t('picking.outboundPhoto.fail')); + } finally { + setPhotoUploading(false); + } + }; + + const removeOutboundPhoto = (path: string) => { + setOutboundPhotos((prev) => prev.filter((photo) => photo.path !== path)); + }; + const handleCompletePicking = async () => { if (!selectedTask || Number(selectedTask.pick_status) >= 30) { notify(t('picking.toast.alreadyDone')); @@ -1283,8 +1315,10 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin await confirmPickingCompleteApi({ pick_code: selectedTask.pick_code, items: buildProgressItems(), + outbound_photos: outboundPhotos.map((photo) => photo.path), }); notify.success(t('picking.toast.completeOk')); + setOutboundPhotos([]); const grouped = await fetchTasks(); await openTask({ ...selectedTask, pick_status: 30 }, grouped); await fetchAll(); @@ -2685,6 +2719,50 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin )} + {Number(selectedTask.pick_status) < 30 && ( +
+
+

{t('picking.outboundPhoto.title')}

+ {t('picking.outboundPhoto.hint')} +
+
+ + {outboundPhotos.map((photo) => ( + + + + + ))} +
+ void handleOutboundPhotosPicked(event)} + /> +
+ )} +