合并 dev:商品发布位置与 Docker 运行环境修复

# Conflicts:
#	Dockerfile.debian13
#	compose.yml
#	docker-compose.debian13-postgres17.yml
#	internal/db/migrate_test.go
#	internal/webui/static/assets/index-Ck_JS4rs.css
#	internal/webui/static/index.html
This commit is contained in:
Christ committed 2026-08-13 09:16:17 +08:00
commit 65bcb8f15c
21 files changed
+434 -176

No files matched your search

+72 -7
View File
@@ -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<ItemListProps> = ({ onConfigureDelivery }) => {
const [batchImagesZip, setBatchImagesZip] = useState<File | null>(null);
const [batchCategoryKeyword, setBatchCategoryKeyword] = useState('');
const [batchCategoryLoading, setBatchCategoryLoading] = useState(false);
const [locationLoading, setLocationLoading] = useState(false);
const [publishLocations, setPublishLocations] = useState<PublishLocation[]>([]);
const [publishLocation, setPublishLocation] = useState<PublishLocation | null>(null);
const [batchLocations, setBatchLocations] = useState<PublishLocation[]>([]);
const [batchLocation, setBatchLocation] = useState<PublishLocation | null>(null);
const [batchFallbackCategory, setBatchFallbackCategory] = useState({
catId: '',
catName: '',
@@ -133,8 +140,8 @@ const ItemList: React.FC<ItemListProps> = ({ 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<ItemListProps> = ({ 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<ItemListProps> = ({ 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<ItemListProps> = ({ 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<ItemListProps> = ({ 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<ItemListProps> = ({ onConfigureDelivery }) => {
imagesZip: batchImagesZip,
defaultCookieId: selectedAccount,
fallbackCategory: batchFallbackCategory,
location: batchLocation!,
});
setBatchPreview(result);
setBatchDetail(null);
@@ -517,6 +531,26 @@ const ItemList: React.FC<ItemListProps> = ({ 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<ItemListProps> = ({ onConfigureDelivery }) => {
</div>
<div className="space-y-2">
<label className="block text-sm font-bold text-gray-700">发布账号</label>
<select className="w-full ios-input px-4 py-3 rounded-xl" value={publishForm.cookie_id} onChange={e => setPublishForm({...publishForm, cookie_id: e.target.value})}>
<select className="w-full ios-input px-4 py-3 rounded-xl" value={publishForm.cookie_id} onChange={e => {
setPublishForm({...publishForm, cookie_id: e.target.value});
setPublishLocations([]);
setPublishLocation(null);
}}>
<option value="">选择账号</option>
{accounts.map(acc => <option key={acc.id} value={acc.id}>{accountName(acc.id)}</option>)}
</select>
@@ -866,6 +904,17 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
<input className="w-full ios-input px-4 py-3 rounded-xl" placeholder="例如 8.00" value={publishForm.postage} onChange={e => setPublishForm({...publishForm, postage: e.target.value})} />
</div>
)}
<div className="rounded-2xl border border-sky-200 bg-sky-50 p-4 space-y-3">
<div className="flex items-center justify-between gap-3">
<div><div className="text-sm font-extrabold text-gray-900">发货地</div><p className="mt-1 text-xs text-sky-800">使用当前位置向闲鱼查询可发布的行政区。</p></div>
<button type="button" disabled={locationLoading || !publishForm.cookie_id} onClick={() => void locateForPublish(false)} className="ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50">
<LocateFixed className="h-4 w-4" />{locationLoading ? '定位中...' : '获取当前位置'}
</button>
</div>
{publishLocations.length > 0 && <select className="w-full ios-input rounded-xl bg-white px-4 py-3" value={String(Math.max(0, publishLocations.indexOf(publishLocation!)))} onChange={e => setPublishLocation(publishLocations[Number(e.target.value)] || null)}>
{publishLocations.map((item, index) => <option key={`${item.division_id}-${item.poi_id}-${index}`} value={String(index)}>{[item.province, item.city, item.area, item.poi_name].filter(Boolean).join(' ')}</option>)}
</select>}
</div>
<div className="space-y-2">
<label className="block text-sm font-bold text-gray-700">商品图片(1-9 张)</label>
<label className="flex min-h-[120px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-emerald-300 hover:bg-emerald-50/50 transition-colors">
@@ -951,7 +1000,11 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
<select
className="w-full ios-input px-4 py-3 rounded-xl"
value={selectedAccount}
onChange={e => setSelectedAccount(e.target.value)}
onChange={e => {
setSelectedAccount(e.target.value);
setBatchLocations([]);
setBatchLocation(null);
}}
>
<option value="">选择账号</option>
{accounts.map(acc => <option key={acc.id} value={acc.id}>{accountName(acc.id)}</option>)}
@@ -1012,6 +1065,18 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
) : null}
</div>
<div className="rounded-xl border border-sky-200 bg-sky-50 p-4 space-y-3">
<div className="flex items-center justify-between gap-3">
<div><div className="text-sm font-extrabold text-gray-900">批次发货地</div><p className="mt-1 text-xs text-sky-800">整个批次使用同一个发货地,并随任务保存用于恢复和重试。</p></div>
<button type="button" disabled={locationLoading || !selectedAccount} onClick={() => void locateForPublish(true)} className="ios-btn-primary flex items-center gap-2 rounded-xl px-4 py-2 text-sm font-bold disabled:opacity-50">
<LocateFixed className="h-4 w-4" />{locationLoading ? '定位中...' : '获取当前位置'}
</button>
</div>
{batchLocations.length > 0 && <select className="w-full ios-input rounded-xl bg-white px-4 py-3" value={String(Math.max(0, batchLocations.indexOf(batchLocation!)))} onChange={e => setBatchLocation(batchLocations[Number(e.target.value)] || null)}>
{batchLocations.map((item, index) => <option key={`${item.division_id}-${item.poi_id}-${index}`} value={String(index)}>{[item.province, item.city, item.area, item.poi_name].filter(Boolean).join(' ')}</option>)}
</select>}
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<label className="flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-blue-300 hover:bg-blue-50 transition-colors">
<UploadCloud className="w-9 h-9 text-blue-600 mb-3" />