From fa5d736cae7aa661e160a24f575422af15542baa Mon Sep 17 00:00:00 2001 From: zhangjianjun Date: Wed, 26 Aug 2026 18:25:16 +0800 Subject: [PATCH] ud --- AGENTS.md | 2 +- src/lib/feedback.test.ts | 11 +++++------ src/lib/feedback.ts | 2 +- src/lib/launch.test.ts | 10 +++++----- src/lib/launch.ts | 2 +- src/pages/complaint/index.tsx | 25 +++++++++++++++---------- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index fd5408d..6ad37da 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -34,7 +34,7 @@ Native mini-program for map-label progress query. Pages in `src/app.config.ts`: - API origin comes from `TARO_APP_API_ORIGIN`: `.env.development` → `http://corp-test.batiao8.com`, `.env.production` → `https://nb.zuom8.cn`. - `x-host` prefers the H5 jump `host`, then `TARO_APP_API_HOST`. - Map reverse geocode uses `TARO_APP_TIANDITU_KEY` against `api.tianditu.gov.cn` (add this request domain in WeChat admin). -- Missing launch query fields fall back to `DEFAULT_LAUNCH_SCHEME` in `src/lib/launch.ts` (`scene=/h/KZ9Q`, `host=nb.batiao8.com`, `package=10044`, `phone=17316703138`). +- Missing launch query fields fall back to `DEFAULT_LAUNCH_SCHEME` in `src/lib/launch.ts` (`scene=/h/KZ9Q`, `host=nb.batiao8.com`, `package=10044`). - No token: `GET /api/user/config` then keep the returned guest token. Then `GET /api/h5/corp` for package/config. - Shared client: `src/lib/request.ts` (same MD5 sign + AES decrypt as H5). Platform header is `wx-mp`. diff --git a/src/lib/feedback.test.ts b/src/lib/feedback.test.ts index 74fa79c..ceb5731 100644 --- a/src/lib/feedback.test.ts +++ b/src/lib/feedback.test.ts @@ -14,15 +14,14 @@ describe('complaint types', () => { }) describe('feedback image preview', () => { - it('prefers the uploaded URL over an Android temporary file path', () => { + it('uses the local preview path after upload, matching the storefront image preview', () => { expect(getFeedbackImageSrc({ - url: 'https://cdn.example/a.jpg', - preview: 'wxfile://tmp_android_a.jpg', - })).toBe('https://cdn.example/a.jpg') + preview: 'wxfile://tmp_a.jpg', + })).toBe('wxfile://tmp_a.jpg') }) - it('falls back to the local path before upload completes', () => { - expect(getFeedbackImageSrc({ preview: 'wxfile://tmp_a.jpg' })).toBe('wxfile://tmp_a.jpg') + it('does not use the private CDN URL for preview rendering', () => { + expect(getFeedbackImageSrc({ url: 'https://cdn.example/a.jpg' })).toBe('') }) }) diff --git a/src/lib/feedback.ts b/src/lib/feedback.ts index 88be2ea..ed56f02 100644 --- a/src/lib/feedback.ts +++ b/src/lib/feedback.ts @@ -9,7 +9,7 @@ export const COMPLAINT_TYPES = [ export type ComplaintType = (typeof COMPLAINT_TYPES)[number]['value'] export function getFeedbackImageSrc (image: { url?: string, preview?: string }) { - return image.url || image.preview || '' + return image.preview || '' } export type FeedbackOrder = { diff --git a/src/lib/launch.test.ts b/src/lib/launch.test.ts index feab87a..15b57bb 100644 --- a/src/lib/launch.test.ts +++ b/src/lib/launch.test.ts @@ -12,10 +12,10 @@ describe('parseMiniProgramScheme', () => { appId: 'wxf8a8961f30396c19', path: 'pages/index/index', scene: '/h/KZ9Q', - token: '6224a1fe-d88c-443c-8972-e6a0942d17fd', + token: '', host: 'nb.batiao8.com', package: '10044', - phone: '17316703138', + phone: '', }) }) }) @@ -65,14 +65,14 @@ describe('parseLaunchQuery', () => { describe('resolveLaunchQuery', () => { it('fills missing fields from the default scheme', () => { expect(resolveLaunchQuery({})).toEqual({ - token: '6224a1fe-d88c-443c-8972-e6a0942d17fd', + token: '', host: 'nb.batiao8.com', packageId: '10044', scene: '/h/KZ9Q', linkId: 'KZ9Q', shareId: '', prevId: '', - phone: '17316703138', + phone: '', }) }) @@ -96,7 +96,7 @@ describe('resolveLaunchQuery', () => { linkId: '', shareId: 'SHARE1', prevId: '', - phone: '17316703138', + phone: '', }) }) }) diff --git a/src/lib/launch.ts b/src/lib/launch.ts index 709c0fc..c92ca9b 100644 --- a/src/lib/launch.ts +++ b/src/lib/launch.ts @@ -10,7 +10,7 @@ export type LaunchQuery = { } export const DEFAULT_LAUNCH_SCHEME = - 'weixin://dl/business/?appid=wxf8a8961f30396c19&path=pages/index/index&query=scene%3D%2Fh%2FKZ9Q%26token%3D6224a1fe-d88c-443c-8972-e6a0942d17fd%26host%3Dnb.batiao8.com%26package%3D10044%26phone%3D17316703138' + 'weixin://dl/business/?appid=wxf8a8961f30396c19&path=pages/index/index&query=scene%3D%2Fh%2FKZ9Q%26host%3Dnb.batiao8.com%26package%3D10044' export function parseMiniProgramScheme (scheme: string) { const search = scheme.split('?')[1] || '' diff --git a/src/pages/complaint/index.tsx b/src/pages/complaint/index.tsx index 41968ee..1d6ba91 100644 --- a/src/pages/complaint/index.tsx +++ b/src/pages/complaint/index.tsx @@ -54,22 +54,27 @@ export default function ComplaintPage () { const handleChooseImage = async () => { if (uploading || images.length >= 5) return const res = await Taro.chooseImage({ - count: Math.max(1, 5 - images.length), + count: 1, sizeType: ['compressed'], sourceType: ['album', 'camera'], }) - const paths = res.tempFilePaths || [] - if (!paths.length) return + const filePath = res.tempFilePaths?.[0] + if (!filePath) return + setImages((current) => [ + ...current, + { id: '', url: '', preview: filePath }, + ].slice(0, 5)) setUploading(true) try { - const uploaded: UploadedImage[] = [] - for (const filePath of paths) { - const result = await uploadImage(filePath) - uploaded.push({ id: result.id, url: result.url, preview: filePath }) - } - setImages((current) => [...current, ...uploaded].slice(0, 5)) + const result = await uploadImage(filePath) + setImages((current) => current.map((image) => ( + image.preview === filePath + ? { id: result.id, url: result.url, preview: filePath } + : image + ))) } catch (error) { + setImages((current) => current.filter((image) => image.preview !== filePath)) Taro.showToast({ title: error instanceof Error ? error.message : '图片上传失败', icon: 'none', @@ -185,7 +190,7 @@ export default function ComplaintPage () { {images.map((image, index) => ( - +