From 1761f7b3bf004613010eb6878da6b023d6842dea Mon Sep 17 00:00:00 2001
From: jacy-dukang
Date: Fri, 10 Jul 2026 13:14:46 +0800
Subject: [PATCH] =?UTF-8?q?=E5=9F=8E=E5=B8=82=E5=90=88=E4=BC=99=E4=BA=BA?=
=?UTF-8?q?=E7=AB=AF=E5=BC=80=E5=BA=97=E5=9F=8E=E5=B8=82=E5=B1=81=E9=BB=98?=
=?UTF-8?q?=E8=AE=A4=E9=83=91=E5=B7=9E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/components/ChinaRegionPicker.tsx | 46 ++++++++++++++++---
apps/h5-partner/src/lib/china-region.ts | 14 ++++++
apps/h5-partner/src/lib/storeDraft.ts | 9 ++--
apps/h5-partner/src/pages/StoreCreatePage.tsx | 24 ++++++++++
4 files changed, 82 insertions(+), 11 deletions(-)
diff --git a/apps/h5-partner/src/components/ChinaRegionPicker.tsx b/apps/h5-partner/src/components/ChinaRegionPicker.tsx
index da79c9c..e7b12a5 100644
--- a/apps/h5-partner/src/components/ChinaRegionPicker.tsx
+++ b/apps/h5-partner/src/components/ChinaRegionPicker.tsx
@@ -1,7 +1,12 @@
import { createPortal } from 'react-dom';
-import { useEffect, useMemo, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import { codeToText } from 'element-china-area-data';
-import { CHINA_REGION_OPTIONS, formatRegionLabel, parseRegionCodes } from '../lib/china-region';
+import {
+ CHINA_REGION_OPTIONS,
+ DEFAULT_REGION_CODES,
+ formatRegionLabel,
+ parseRegionCodes,
+} from '../lib/china-region';
type RegionNode = {
value: string;
@@ -40,10 +45,26 @@ function lockBodyScroll(lock: boolean) {
}
}
+function buildInitialDraft(value: string[]): { draft: string[]; step: number } {
+ if (value.length === 3) {
+ return { draft: [...value], step: 2 };
+ }
+ if (value.length > 0) {
+ const draft = [...value];
+ for (let i = value.length; i < DEFAULT_REGION_CODES.length; i += 1) {
+ draft.push(DEFAULT_REGION_CODES[i]);
+ }
+ return { draft, step: Math.min(value.length, 2) };
+ }
+ return { draft: [...DEFAULT_REGION_CODES], step: 1 };
+}
+
export default function ChinaRegionPicker({ value = [], onChange, disabled }: ChinaRegionPickerProps) {
const [open, setOpen] = useState(false);
const [draft, setDraft] = useState(value);
const [step, setStep] = useState(0);
+ const listRef = useRef(null);
+ const activeItemRef = useRef(null);
const options = CHINA_REGION_OPTIONS as RegionNode[];
const parsed = parseRegionCodes(value);
@@ -69,11 +90,23 @@ export default function ChinaRegionPicker({ value = [], onChange, disabled }: Ch
return () => lockBodyScroll(false);
}, [open]);
+ useEffect(() => {
+ if (!open) return;
+ const timer = window.setTimeout(() => {
+ const container = listRef.current;
+ const activeEl = activeItemRef.current;
+ if (!container || !activeEl) return;
+ const offset = activeEl.offsetTop - container.clientHeight / 2 + activeEl.clientHeight / 2;
+ container.scrollTo({ top: Math.max(0, offset), behavior: 'smooth' });
+ }, 0);
+ return () => window.clearTimeout(timer);
+ }, [open, step, activeCode, listItems]);
+
function openPicker() {
if (disabled) return;
- const next = value.length === 3 ? [...value] : [];
+ const { draft: next, step: initialStep } = buildInitialDraft(value);
setDraft(next);
- setStep(next.length >= 3 ? 2 : next.length);
+ setStep(initialStep);
setOpen(true);
}
@@ -147,13 +180,14 @@ export default function ChinaRegionPicker({ value = [], onChange, disabled }: Ch
)}
-
+
{listItems.map((item) => (