From 7ec0b4a0789e2f3d6f390056e7b4a7a332934d9c Mon Sep 17 00:00:00 2001 From: Christ Date: Thu, 13 Aug 2026 09:12:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=95=86=E5=93=81=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E4=BD=8D=E7=BD=AE=E4=B8=8E=20Docker=20=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile.debian13 | 6 + compose.yml | 4 - docker-compose.debian13-postgres17.yml | 4 - frontend/components/ItemList.tsx | 79 ++++++++- frontend/services/api.ts | 20 +++ internal/db/item_publish_batches.go | 22 ++- internal/db/migrate_test.go | 6 +- .../mysql/00027_publish_location.sql | 7 + .../postgres/00027_publish_location.sql | 5 + .../sqlite/00027_publish_location.sql | 5 + internal/db/multidb_test.go | 6 +- internal/server/item_handlers.go | 62 +++++++ .../server/item_publish_batch_handlers.go | 28 ++++ ...r-DjsKcZkz.js => icons-vendor-DF3hof7q.js} | 155 +++++++++--------- .../webui/static/assets/index-BItFeCFs.js | 19 +++ .../webui/static/assets/index-BIyp4is6.js | 19 --- ...{index-DtBcYu3b.css => index-Ck_JS4rs.css} | 2 +- internal/webui/static/index.html | 6 +- internal/xianyu/mtop/cookie_session_test.go | 7 +- internal/xianyu/mtop/publish.go | 115 ++++++++----- internal/xianyu/mtop/publish_extra_test.go | 30 ++-- 21 files changed, 431 insertions(+), 176 deletions(-) create mode 100644 internal/db/migrations/mysql/00027_publish_location.sql create mode 100644 internal/db/migrations/postgres/00027_publish_location.sql create mode 100644 internal/db/migrations/sqlite/00027_publish_location.sql rename internal/webui/static/assets/{icons-vendor-DjsKcZkz.js => icons-vendor-DF3hof7q.js} (75%) create mode 100644 internal/webui/static/assets/index-BItFeCFs.js delete mode 100644 internal/webui/static/assets/index-BIyp4is6.js rename internal/webui/static/assets/{index-DtBcYu3b.css => index-Ck_JS4rs.css} (53%) diff --git a/Dockerfile.debian13 b/Dockerfile.debian13 index 8b120c1..fb7dc19 100644 --- a/Dockerfile.debian13 +++ b/Dockerfile.debian13 @@ -35,6 +35,7 @@ ENV PLAYWRIGHT_DRIVER_PATH=/ms-playwright-go ENV PLAYWRIGHT_NODEJS_PATH=/usr/bin/node ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt WORKDIR /app RUN apt-get update \ && apt-get install -y --no-install-recommends \ @@ -45,6 +46,11 @@ RUN apt-get update \ fonts-noto-cjk \ nodejs \ tzdata \ + && update-ca-certificates --fresh \ + && test -s "$SSL_CERT_FILE" \ + && grep -q -- '-----BEGIN CERTIFICATE-----' "$SSL_CERT_FILE" \ + && test -x "$PLAYWRIGHT_NODEJS_PATH" \ + && test -x "$PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH" \ && rm -rf /var/lib/apt/lists/* COPY --from=backend /out/xianyu-server /app/xianyu-server COPY --from=backend /out/xianyu-dbseed /app/xianyu-dbseed diff --git a/compose.yml b/compose.yml index c333e0f..2b9b095 100644 --- a/compose.yml +++ b/compose.yml @@ -8,10 +8,6 @@ x-app-env: &app-env LOG_LEVEL: ${LOG_LEVEL:-info} LOG_FORMAT: ${LOG_FORMAT:-json} BROWSER_HEADLESS: ${BROWSER_HEADLESS:-true} - PLAYWRIGHT_DRIVER_PATH: ${PLAYWRIGHT_DRIVER_PATH:-/ms-playwright-go} - PLAYWRIGHT_NODEJS_PATH: ${PLAYWRIGHT_NODEJS_PATH:-/usr/bin/node} - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD:-1} - PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH: ${PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH:-/usr/bin/chromium} x-app-volumes: &app-volumes - app_data:/app/data diff --git a/docker-compose.debian13-postgres17.yml b/docker-compose.debian13-postgres17.yml index a59ec90..c633670 100644 --- a/docker-compose.debian13-postgres17.yml +++ b/docker-compose.debian13-postgres17.yml @@ -6,10 +6,6 @@ x-app-env: &app-env LOG_LEVEL: ${LOG_LEVEL:-info} LOG_FORMAT: ${LOG_FORMAT:-json} BROWSER_HEADLESS: ${BROWSER_HEADLESS:-true} - PLAYWRIGHT_DRIVER_PATH: ${PLAYWRIGHT_DRIVER_PATH:-/ms-playwright-go} - PLAYWRIGHT_NODEJS_PATH: ${PLAYWRIGHT_NODEJS_PATH:-/usr/bin/node} - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD:-1} - PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH: ${PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH:-/usr/bin/chromium} x-app-volumes: &app-volumes - app_data:/app/data diff --git a/frontend/components/ItemList.tsx b/frontend/components/ItemList.tsx index 606e11a..0662193 100644 --- a/frontend/components/ItemList.tsx +++ b/frontend/components/ItemList.tsx @@ -9,6 +9,7 @@ import { createItem, publishItem, recommendPublishCategory, + getPublishLocations, previewItemPublishBatch, startItemPublishBatch, getItemPublishBatch, @@ -20,7 +21,8 @@ import { deleteItem, getShippingRules } from '../services/api'; -import { ArrowRight, Box, CheckCircle2, CircleDashed, Edit, Filter, Link2, PackagePlus, Plus, RefreshCw, Save, Search, ShoppingBag, Trash2, UploadCloud, User, X } from 'lucide-react'; +import type { PublishLocation } from '../services/api'; +import { ArrowRight, Box, CheckCircle2, CircleDashed, Edit, Filter, Link2, LocateFixed, PackagePlus, Plus, RefreshCw, Save, Search, ShoppingBag, Trash2, UploadCloud, User, X } from 'lucide-react'; interface ItemListProps { onConfigureDelivery: (item: Item) => void; @@ -100,6 +102,11 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { const [batchImagesZip, setBatchImagesZip] = useState(null); const [batchCategoryKeyword, setBatchCategoryKeyword] = useState(''); const [batchCategoryLoading, setBatchCategoryLoading] = useState(false); + const [locationLoading, setLocationLoading] = useState(false); + const [publishLocations, setPublishLocations] = useState([]); + const [publishLocation, setPublishLocation] = useState(null); + const [batchLocations, setBatchLocations] = useState([]); + const [batchLocation, setBatchLocation] = useState(null); const [batchFallbackCategory, setBatchFallbackCategory] = useState({ catId: '', catName: '', @@ -133,8 +140,8 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { original_price: '', quantity: '1', postage_mode: 'free', - postage: '', - images: [] as File[] + postage: '', + images: [] as File[], }); const [publishImagePreviews, setPublishImagePreviews] = useState<{ key: string; url: string }[]>([]); @@ -287,10 +294,11 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { if (!publishForm.quantity || Number(publishForm.quantity) <= 0) return alert('库存数量必须大于 0'); if (publishForm.images.length === 0) return alert('至少上传 1 张商品图片'); if (publishForm.postage_mode === 'fixed' && !publishForm.postage.trim()) return alert('请填写一口价邮费'); + if (!publishLocation) return alert('请获取当前位置并选择发货地'); setPublishing(true); try { - const result = await publishItem(publishForm); + const result = await publishItem({ ...publishForm, location: publishLocation }); await loadItems(); setShowPublishModal(false); setPublishForm({ @@ -302,8 +310,10 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { quantity: '1', postage_mode: 'free', postage: '', - images: [] + images: [], }); + setPublishLocations([]); + setPublishLocation(null); if (result?.item_id) { const publishedItem: Item = { id: result.item_id, @@ -339,6 +349,8 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { setBatchImagesZip(null); setBatchCategoryKeyword(''); setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' }); + setBatchLocations([]); + setBatchLocation(null); setShowBatchModal(true); setBatchLoading(true); try { @@ -397,6 +409,7 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { const handlePreviewBatch = async () => { if (!batchFile) return alert('请先上传商品表格'); if (!selectedAccount) return alert('请先选择默认发布账号'); + if (!batchLocation) return alert('请获取当前位置并选择发货地'); setBatchLoading(true); try { const result = await previewItemPublishBatch({ @@ -404,6 +417,7 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { imagesZip: batchImagesZip, defaultCookieId: selectedAccount, fallbackCategory: batchFallbackCategory, + location: batchLocation!, }); setBatchPreview(result); setBatchDetail(null); @@ -517,6 +531,26 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { setShowPublishModal(true); }; + const locateForPublish = async (batch: boolean) => { + const cookieId = batch ? selectedAccount : publishForm.cookie_id; + if (!cookieId) return alert('请先选择发布账号'); + if (!navigator.geolocation) return alert('当前浏览器不支持定位'); + setLocationLoading(true); + navigator.geolocation.getCurrentPosition(async position => { + try { + const locations = await getPublishLocations(cookieId, position.coords.longitude, position.coords.latitude); + if (!locations.length) throw new Error('当前位置没有可用的发货地'); + if (batch) { setBatchLocations(locations); setBatchLocation(locations[0]); } + else { setPublishLocations(locations); setPublishLocation(locations[0]); } + } catch (error: any) { + alert(error?.message || '获取发货地失败'); + } finally { setLocationLoading(false); } + }, error => { + setLocationLoading(false); + alert(error.code === error.PERMISSION_DENIED ? '定位权限被拒绝,请在浏览器设置中允许定位' : '无法获取当前位置,请稍后重试'); + }, { enableHighAccuracy: true, timeout: 15000, maximumAge: 60000 }); + }; + const rulesForItem = (item: Item) => shippingRules.filter(rule => rule.cookie_id === item.cookie_id && rule.item_id === item.item_id ).length > 0 @@ -822,7 +856,11 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => {
- { + setPublishForm({...publishForm, cookie_id: e.target.value}); + setPublishLocations([]); + setPublishLocation(null); + }}> {accounts.map(acc => )} @@ -866,6 +904,17 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { setPublishForm({...publishForm, postage: e.target.value})} />
)} +
+
+
发货地

使用当前位置向闲鱼查询可发布的行政区。

+ +
+ {publishLocations.length > 0 && } +
+