diff --git a/Dockerfile.debian13 b/Dockerfile.debian13 index fe2cacf..b83d168 100644 --- a/Dockerfile.debian13 +++ b/Dockerfile.debian13 @@ -70,6 +70,7 @@ ENV PLAYWRIGHT_DRIVER_PATH=/ms-playwright-go ENV PLAYWRIGHT_NODEJS_PATH=/usr/local/bin/node ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt WORKDIR /app COPY --from=backend /out/xianyu-server /app/xianyu-server COPY --from=backend /out/xianyu-dbseed /app/xianyu-dbseed @@ -80,6 +81,14 @@ COPY --from=playwright-runtime /ms-playwright /ms-playwright # driver 只安装 Chromium 所需系统依赖,并在同一镜像层清理 apt/npm/临时缓存。 RUN set -eux; \ node /ms-playwright-go/package/cli.js install-deps chromium; \ + apt-get update; \ + apt-get install --reinstall -y --no-install-recommends ca-certificates; \ + update-ca-certificates --fresh; \ + test -s "$SSL_CERT_FILE"; \ + grep -q -- '-----BEGIN CERTIFICATE-----' "$SSL_CERT_FILE"; \ + test -x "$PLAYWRIGHT_NODEJS_PATH"; \ + test -f "$PLAYWRIGHT_DRIVER_PATH/package/cli.js"; \ + find "$PLAYWRIGHT_BROWSERS_PATH" -type f -perm -111 \( -name chrome -o -name chrome-headless-shell -o -name headless_shell \) -print -quit | grep -q .; \ apt-get clean; \ rm -rf /var/lib/apt/lists/* /var/cache/apt/* /root/.cache /tmp/* /var/tmp/*; \ mkdir -p /app/data /app/browser_data diff --git a/compose.yml b/compose.yml index dfe578b..bdda86f 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/local/bin/node} - PLAYWRIGHT_BROWSERS_PATH: ${PLAYWRIGHT_BROWSERS_PATH:-/ms-playwright} - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD:-1} x-app-volumes: &app-volumes - app_data:/app/data diff --git a/docker-compose.debian13-postgres17.yml b/docker-compose.debian13-postgres17.yml index e8180fa..f9a353d 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/local/bin/node} - PLAYWRIGHT_BROWSERS_PATH: ${PLAYWRIGHT_BROWSERS_PATH:-/ms-playwright} - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: ${PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD:-1} x-app-volumes: &app-volumes - app_data:/app/data diff --git a/frontend/components/ItemList.tsx b/frontend/components/ItemList.tsx index 755bdb9..351ceb8 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 && } +
+