2026-05-28 05:54:23 +00:00
|
|
|
|
import React, { useState, useCallback, useEffect, useRef } from 'react';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
import { motion } from 'framer-motion';
|
2026-06-04 13:57:36 +00:00
|
|
|
|
import { Share2, Copy, Check, X, AlertTriangle, Building2, Eye, EyeOff, Link2, Send } from 'lucide-react';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
import { useResponsive } from '../../hooks/useResponsive';
|
2026-06-04 13:57:36 +00:00
|
|
|
|
import { encryptShareParams } from '../../utils/shareCrypto';
|
2026-05-27 03:17:46 +00:00
|
|
|
|
import { supabase } from '../../supabase/client';
|
2026-05-26 05:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
interface ShareModalProps {
|
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
|
planId: string;
|
|
|
|
|
|
factoryType: 'textile' | 'washing';
|
2026-06-04 13:57:36 +00:00
|
|
|
|
factoryId?: string;
|
2026-05-27 03:17:46 +00:00
|
|
|
|
factoryName?: string;
|
2026-06-04 13:57:36 +00:00
|
|
|
|
planProductName?: string;
|
|
|
|
|
|
planColor?: string;
|
|
|
|
|
|
planColorCode?: string;
|
|
|
|
|
|
onDirectPush?: () => void; // 直接推送回调
|
2026-05-26 05:15:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
// 合作关系类型
|
|
|
|
|
|
interface CompanyRelationship {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
purchaser_company_id: string;
|
|
|
|
|
|
factory_company_id: string;
|
|
|
|
|
|
factory_type: 'textile' | 'washing';
|
|
|
|
|
|
status: 'active' | 'inactive';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 分享链接状态
|
|
|
|
|
|
interface ShareLinkStatus {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
short_code: string;
|
|
|
|
|
|
status: 'pending' | 'clicked' | 'confirmed' | 'rejected' | 'expired' | 'cancelled';
|
|
|
|
|
|
clicked_at: string | null;
|
|
|
|
|
|
responded_at: string | null;
|
|
|
|
|
|
response_result: 'confirmed' | 'rejected' | null;
|
|
|
|
|
|
reject_reason: string | null;
|
|
|
|
|
|
expires_at: string;
|
|
|
|
|
|
created_at: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function ShareModal({
|
|
|
|
|
|
isOpen,
|
|
|
|
|
|
onClose,
|
|
|
|
|
|
planId,
|
|
|
|
|
|
factoryType,
|
|
|
|
|
|
factoryId,
|
|
|
|
|
|
factoryName,
|
|
|
|
|
|
planProductName,
|
|
|
|
|
|
planColor,
|
|
|
|
|
|
planColorCode,
|
|
|
|
|
|
onDirectPush
|
|
|
|
|
|
}: ShareModalProps) {
|
2026-05-26 05:15:10 +00:00
|
|
|
|
const { isMobile } = useResponsive();
|
|
|
|
|
|
const [copied, setCopied] = useState(false);
|
2026-05-27 03:17:46 +00:00
|
|
|
|
const [showConfirm, setShowConfirm] = useState(false);
|
|
|
|
|
|
const [recipientCompany, setRecipientCompany] = useState<string>('');
|
|
|
|
|
|
const [confirmFactoryName, setConfirmFactoryName] = useState('');
|
|
|
|
|
|
const [confirmCompanyName, setConfirmCompanyName] = useState('');
|
|
|
|
|
|
const [error, setError] = useState('');
|
2026-05-28 05:54:23 +00:00
|
|
|
|
const [shortCode, setShortCode] = useState<string>('');
|
2026-06-04 13:57:36 +00:00
|
|
|
|
const [hideSensitive, setHideSensitive] = useState(false);
|
2026-05-28 05:54:23 +00:00
|
|
|
|
const shortLinkGenerated = useRef(false);
|
2026-06-04 13:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
// 新流程状态
|
|
|
|
|
|
const [hasRelationship, setHasRelationship] = useState<boolean | null>(null);
|
|
|
|
|
|
const [isCheckingRelationship, setIsCheckingRelationship] = useState(false);
|
|
|
|
|
|
const [existingLink, setExistingLink] = useState<ShareLinkStatus | null>(null);
|
|
|
|
|
|
const [isGeneratingLink, setIsGeneratingLink] = useState(false);
|
|
|
|
|
|
const [pushSuccess, setPushSuccess] = useState(false);
|
2026-05-27 03:17:46 +00:00
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
// 获取当前用户的公司名称和检查合作关系
|
2026-05-27 03:17:46 +00:00
|
|
|
|
useEffect(() => {
|
2026-06-04 13:57:36 +00:00
|
|
|
|
const fetchData = async () => {
|
|
|
|
|
|
if (!isOpen || !factoryId) return;
|
|
|
|
|
|
|
|
|
|
|
|
setIsCheckingRelationship(true);
|
|
|
|
|
|
|
2026-05-27 03:17:46 +00:00
|
|
|
|
const { data: { user } } = await supabase.auth.getUser();
|
2026-06-04 13:57:36 +00:00
|
|
|
|
if (!user) {
|
|
|
|
|
|
setIsCheckingRelationship(false);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前用户的公司信息
|
|
|
|
|
|
const { data: profile } = await supabase
|
|
|
|
|
|
.from('profiles')
|
|
|
|
|
|
.select('company_id')
|
|
|
|
|
|
.eq('id', user.id)
|
|
|
|
|
|
.single();
|
|
|
|
|
|
|
|
|
|
|
|
if (profile?.company_id) {
|
|
|
|
|
|
// 获取公司名称
|
|
|
|
|
|
const { data: company } = await supabase
|
|
|
|
|
|
.from('companies')
|
|
|
|
|
|
.select('name')
|
|
|
|
|
|
.eq('id', profile.company_id)
|
2026-05-27 03:17:46 +00:00
|
|
|
|
.single();
|
2026-06-04 13:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
if (company) {
|
|
|
|
|
|
setRecipientCompany(company.name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已有合作关系
|
|
|
|
|
|
const { data: relationship } = await supabase
|
|
|
|
|
|
.from('company_relationships')
|
|
|
|
|
|
.select('*')
|
|
|
|
|
|
.eq('purchaser_company_id', profile.company_id)
|
|
|
|
|
|
.eq('factory_company_id', factoryId)
|
|
|
|
|
|
.eq('status', 'active')
|
|
|
|
|
|
.maybeSingle();
|
|
|
|
|
|
|
|
|
|
|
|
setHasRelationship(!!relationship);
|
|
|
|
|
|
|
|
|
|
|
|
// 如果没有合作关系,检查是否已有待处理的分享链接
|
|
|
|
|
|
if (!relationship) {
|
|
|
|
|
|
const { data: link } = await supabase
|
|
|
|
|
|
.from('share_links')
|
|
|
|
|
|
.select('*')
|
|
|
|
|
|
.eq('plan_id', planId)
|
|
|
|
|
|
.eq('factory_type', factoryType)
|
|
|
|
|
|
.in('status', ['pending', 'clicked'])
|
|
|
|
|
|
.order('created_at', { ascending: false })
|
|
|
|
|
|
.limit(1)
|
|
|
|
|
|
.maybeSingle();
|
|
|
|
|
|
|
|
|
|
|
|
if (link) {
|
|
|
|
|
|
// 检查是否过期
|
|
|
|
|
|
const expiresAt = link.expires_at ? new Date(link.expires_at) : null;
|
|
|
|
|
|
if (expiresAt && expiresAt > new Date()) {
|
|
|
|
|
|
setExistingLink(link as ShareLinkStatus);
|
|
|
|
|
|
setShortCode(link.short_code);
|
|
|
|
|
|
}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-06-04 13:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
setIsCheckingRelationship(false);
|
2026-05-27 03:17:46 +00:00
|
|
|
|
};
|
2026-06-04 13:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
fetchData();
|
|
|
|
|
|
|
|
|
|
|
|
// 清理
|
|
|
|
|
|
return () => {
|
2026-05-28 05:54:23 +00:00
|
|
|
|
shortLinkGenerated.current = false;
|
|
|
|
|
|
setShortCode('');
|
2026-06-04 13:57:36 +00:00
|
|
|
|
setExistingLink(null);
|
|
|
|
|
|
setHasRelationship(null);
|
|
|
|
|
|
setPushSuccess(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
}, [isOpen, planId, factoryType, factoryId]);
|
2026-05-26 05:15:10 +00:00
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
// 生成短链(30分钟有效)
|
2026-05-28 05:54:23 +00:00
|
|
|
|
const generateShortLink = useCallback(async () => {
|
2026-06-04 13:57:36 +00:00
|
|
|
|
if (!factoryId) return;
|
|
|
|
|
|
|
|
|
|
|
|
setIsGeneratingLink(true);
|
|
|
|
|
|
|
2026-05-28 05:54:23 +00:00
|
|
|
|
const baseUrl = window.location.origin + window.location.pathname;
|
|
|
|
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
|
|
let code = '';
|
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
|
code += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const { data: { user } } = await supabase.auth.getUser();
|
|
|
|
|
|
if (user) {
|
2026-06-04 13:57:36 +00:00
|
|
|
|
// 取消该计划之前未处理的链接
|
|
|
|
|
|
await supabase
|
|
|
|
|
|
.from('share_links')
|
|
|
|
|
|
.update({ status: 'cancelled' })
|
|
|
|
|
|
.eq('plan_id', planId)
|
|
|
|
|
|
.eq('status', 'pending');
|
|
|
|
|
|
|
|
|
|
|
|
// 创建新链接(30分钟过期)
|
|
|
|
|
|
const { data, error } = await supabase.from('share_links').insert({
|
2026-05-28 05:54:23 +00:00
|
|
|
|
short_code: code,
|
|
|
|
|
|
plan_id: planId,
|
|
|
|
|
|
factory_type: factoryType,
|
2026-06-04 13:57:36 +00:00
|
|
|
|
hide_sensitive: hideSensitive,
|
2026-05-28 05:54:23 +00:00
|
|
|
|
created_by: user.id,
|
2026-06-04 13:57:36 +00:00
|
|
|
|
status: 'pending',
|
|
|
|
|
|
expires_at: new Date(Date.now() + 30 * 60 * 1000).toISOString() // 30分钟
|
|
|
|
|
|
}).select().single();
|
2026-05-28 05:54:23 +00:00
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
if (!error && data) {
|
2026-05-28 05:54:23 +00:00
|
|
|
|
setShortCode(code);
|
2026-06-04 13:57:36 +00:00
|
|
|
|
setExistingLink(data as ShareLinkStatus);
|
2026-05-28 05:54:23 +00:00
|
|
|
|
} else {
|
2026-06-04 13:57:36 +00:00
|
|
|
|
setError('生成链接失败,请重试');
|
2026-05-28 05:54:23 +00:00
|
|
|
|
}
|
2026-06-04 13:57:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setIsGeneratingLink(false);
|
|
|
|
|
|
}, [planId, factoryType, hideSensitive, factoryId]);
|
|
|
|
|
|
|
|
|
|
|
|
// 直接推送计划(已有合作关系)
|
|
|
|
|
|
const handleDirectPush = async () => {
|
|
|
|
|
|
if (!factoryId || !onDirectPush) return;
|
|
|
|
|
|
|
|
|
|
|
|
setIsGeneratingLink(true);
|
|
|
|
|
|
|
|
|
|
|
|
// 直接创建 plan_factories 关联
|
|
|
|
|
|
const { error } = await supabase.from('plan_factories').insert({
|
|
|
|
|
|
plan_id: planId,
|
|
|
|
|
|
factory_id: factoryId,
|
|
|
|
|
|
factory_type: factoryType
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
|
|
setPushSuccess(true);
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
onDirectPush();
|
|
|
|
|
|
onClose();
|
|
|
|
|
|
}, 1500);
|
2026-05-28 05:54:23 +00:00
|
|
|
|
} else {
|
2026-06-04 13:57:36 +00:00
|
|
|
|
setError('推送失败,请重试');
|
2026-05-28 05:54:23 +00:00
|
|
|
|
}
|
2026-06-04 13:57:36 +00:00
|
|
|
|
|
|
|
|
|
|
setIsGeneratingLink(false);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 长链接 token(异步生成)
|
|
|
|
|
|
const [longLinkToken, setLongLinkToken] = useState<string>('');
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (isOpen && !hasRelationship) {
|
|
|
|
|
|
encryptShareParams(planId, factoryType, hideSensitive).then(token => {
|
|
|
|
|
|
setLongLinkToken(token);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [isOpen, planId, factoryType, hideSensitive, hasRelationship]);
|
2026-05-28 05:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
// 生成分享链接
|
2026-05-26 05:15:10 +00:00
|
|
|
|
const generateShareLink = useCallback(() => {
|
|
|
|
|
|
const baseUrl = window.location.origin + window.location.pathname;
|
2026-05-28 05:54:23 +00:00
|
|
|
|
if (shortCode) {
|
|
|
|
|
|
return `${baseUrl}#/import?s=${shortCode}`;
|
|
|
|
|
|
}
|
2026-06-04 13:57:36 +00:00
|
|
|
|
if (longLinkToken) {
|
|
|
|
|
|
return `${baseUrl}#/import?token=${longLinkToken}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
return '';
|
|
|
|
|
|
}, [shortCode, longLinkToken]);
|
2026-05-26 05:15:10 +00:00
|
|
|
|
|
|
|
|
|
|
const handleCopy = useCallback(async () => {
|
|
|
|
|
|
const link = generateShareLink();
|
|
|
|
|
|
try {
|
|
|
|
|
|
await navigator.clipboard.writeText(link);
|
|
|
|
|
|
setCopied(true);
|
|
|
|
|
|
setTimeout(() => setCopied(false), 2000);
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
const textarea = document.createElement('textarea');
|
|
|
|
|
|
textarea.value = link;
|
|
|
|
|
|
document.body.appendChild(textarea);
|
|
|
|
|
|
textarea.select();
|
|
|
|
|
|
document.execCommand('copy');
|
|
|
|
|
|
document.body.removeChild(textarea);
|
|
|
|
|
|
setCopied(true);
|
|
|
|
|
|
setTimeout(() => setCopied(false), 2000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [generateShareLink]);
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
// 检查链接状态
|
|
|
|
|
|
const checkLinkStatus = async () => {
|
|
|
|
|
|
if (!existingLink) return;
|
|
|
|
|
|
|
|
|
|
|
|
const { data } = await supabase
|
|
|
|
|
|
.from('share_links')
|
|
|
|
|
|
.select('*')
|
|
|
|
|
|
.eq('id', existingLink.id)
|
|
|
|
|
|
.single();
|
|
|
|
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
|
|
setExistingLink(data as ShareLinkStatus);
|
2026-05-27 03:17:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-26 05:15:10 +00:00
|
|
|
|
if (!isOpen) return null;
|
|
|
|
|
|
|
|
|
|
|
|
const link = generateShareLink();
|
|
|
|
|
|
const factoryLabel = factoryType === 'textile' ? '织布厂' : '水洗厂';
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-3 sm:p-4">
|
|
|
|
|
|
<motion.div
|
|
|
|
|
|
initial={{ opacity: 0, scale: 0.95 }}
|
|
|
|
|
|
animate={{ opacity: 1, scale: 1 }}
|
|
|
|
|
|
exit={{ opacity: 0, scale: 0.95 }}
|
|
|
|
|
|
className="bg-white rounded-2xl p-4 sm:p-6 w-full max-w-md shadow-2xl"
|
|
|
|
|
|
>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{/* 加载中 */}
|
|
|
|
|
|
{isCheckingRelationship && (
|
|
|
|
|
|
<div className="flex flex-col items-center justify-center py-8">
|
|
|
|
|
|
<div className="w-8 h-8 border-2 border-blue-600 border-t-transparent rounded-full animate-spin mb-4" />
|
|
|
|
|
|
<p className="text-gray-600">检查合作关系...</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 已有合作关系 - 直接推送 */}
|
|
|
|
|
|
{!isCheckingRelationship && hasRelationship === true && (
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3 mb-4">
|
|
|
|
|
|
<div className="w-9 h-9 sm:w-10 sm:h-10 bg-emerald-100 rounded-xl flex items-center justify-center flex-shrink-0">
|
|
|
|
|
|
<Send className="w-4 h-4 sm:w-5 sm:h-5 text-emerald-600" />
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="min-w-0">
|
2026-06-04 13:57:36 +00:00
|
|
|
|
<h3 className="text-base sm:text-lg font-semibold text-gray-900">直接推送</h3>
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">已合作工厂,计划将直接推送</p>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
<div className="bg-emerald-50 rounded-xl p-4 mb-4 border border-emerald-200">
|
|
|
|
|
|
<div className="flex items-center gap-2 mb-2">
|
|
|
|
|
|
<Building2 className="w-4 h-4 text-emerald-600" />
|
|
|
|
|
|
<span className="text-sm font-medium text-emerald-800">目标工厂</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-gray-900 font-medium">{factoryName || '未指定'}</p>
|
|
|
|
|
|
<p className="text-xs text-emerald-600 mt-1">✓ 已建立合作关系</p>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{pushSuccess && (
|
|
|
|
|
|
<div className="bg-emerald-100 rounded-xl p-3 mb-4 border border-emerald-200">
|
|
|
|
|
|
<p className="text-sm text-emerald-700 text-center">✓ 计划推送成功!</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div className="bg-red-50 rounded-lg p-3 mb-4 border border-red-100">
|
|
|
|
|
|
<p className="text-sm text-red-600">{error}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<div className="flex gap-2 sm:gap-3">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 border border-gray-300 rounded-xl text-gray-700 hover:bg-gray-50 text-xs sm:text-sm font-medium transition-colors"
|
|
|
|
|
|
>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
取消
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
2026-06-04 13:57:36 +00:00
|
|
|
|
onClick={handleDirectPush}
|
|
|
|
|
|
disabled={isGeneratingLink || pushSuccess}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 bg-emerald-500 hover:bg-emerald-600 disabled:bg-gray-300 rounded-xl text-white text-xs sm:text-sm font-medium transition-colors flex items-center justify-center gap-2"
|
2026-05-27 03:17:46 +00:00
|
|
|
|
>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{isGeneratingLink ? (
|
|
|
|
|
|
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Send size={isMobile ? 14 : 16} />
|
|
|
|
|
|
)}
|
|
|
|
|
|
{pushSuccess ? '已推送' : '直接推送'}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 无合作关系 - 生成分享链接 */}
|
|
|
|
|
|
{!isCheckingRelationship && hasRelationship === false && (
|
2026-05-27 03:17:46 +00:00
|
|
|
|
<>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{!showConfirm ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3 mb-3 sm:mb-4">
|
|
|
|
|
|
<div className="w-9 h-9 sm:w-10 sm:h-10 bg-blue-100 rounded-xl flex items-center justify-center flex-shrink-0">
|
|
|
|
|
|
<Link2 className="w-4 h-4 sm:w-5 sm:h-5 text-blue-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
|
<h3 className="text-base sm:text-lg font-semibold text-gray-900">生成分享链接</h3>
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">首次合作,需生成链接邀请</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{/* 工厂信息 */}
|
|
|
|
|
|
<div className="bg-amber-50 rounded-xl p-3 mb-3 border border-amber-200">
|
|
|
|
|
|
<div className="flex items-center gap-2 mb-1">
|
|
|
|
|
|
<Building2 className="w-4 h-4 text-amber-600" />
|
|
|
|
|
|
<span className="text-xs text-amber-600 font-medium">目标工厂</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-sm text-gray-900 font-medium">{factoryName || '未指定'}</p>
|
|
|
|
|
|
<p className="text-xs text-amber-600 mt-1">⚠ 未建立合作关系</p>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{/* 已有链接状态显示 */}
|
|
|
|
|
|
{existingLink && (
|
|
|
|
|
|
<div className={`rounded-xl p-3 mb-3 border ${
|
|
|
|
|
|
existingLink.status === 'pending' ? 'bg-blue-50 border-blue-200' :
|
|
|
|
|
|
existingLink.status === 'clicked' ? 'bg-yellow-50 border-yellow-200' :
|
|
|
|
|
|
'bg-gray-50 border-gray-200'
|
|
|
|
|
|
}`}>
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<span className="text-sm font-medium text-gray-800">链接状态</span>
|
|
|
|
|
|
<span className={`text-xs px-2 py-0.5 rounded ${
|
|
|
|
|
|
existingLink.status === 'pending' ? 'bg-blue-100 text-blue-700' :
|
|
|
|
|
|
existingLink.status === 'clicked' ? 'bg-yellow-100 text-yellow-700' :
|
|
|
|
|
|
'bg-gray-100 text-gray-600'
|
|
|
|
|
|
}`}>
|
|
|
|
|
|
{existingLink.status === 'pending' && '待点击'}
|
|
|
|
|
|
{existingLink.status === 'clicked' && '已点击'}
|
|
|
|
|
|
{existingLink.status === 'confirmed' && '已确认'}
|
|
|
|
|
|
{existingLink.status === 'rejected' && '已拒绝'}
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{existingLink.status === 'clicked' && (
|
|
|
|
|
|
<p className="text-xs text-yellow-600 mt-1">
|
|
|
|
|
|
工厂已查看,等待确认...
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{existingLink.status === 'rejected' && existingLink.reject_reason && (
|
|
|
|
|
|
<p className="text-xs text-red-600 mt-1">
|
|
|
|
|
|
拒绝原因:{existingLink.reject_reason}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 隐藏敏感信息开关 */}
|
|
|
|
|
|
<div className="bg-gray-50 rounded-xl p-3 sm:p-4 mb-3 sm:mb-4 border border-gray-200">
|
|
|
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
{hideSensitive ? <EyeOff className="w-4 h-4 text-amber-500" /> : <Eye className="w-4 h-4 text-emerald-500" />}
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p className="text-sm font-medium text-gray-800">隐藏成品信息</p>
|
|
|
|
|
|
<p className="text-xs text-gray-500">成品名称、颜色、色号将不在链接中显示</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setHideSensitive(!hideSensitive)}
|
|
|
|
|
|
className={`relative w-11 h-6 rounded-full transition-colors duration-200 ${hideSensitive ? 'bg-amber-500' : 'bg-gray-300'}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
<span className={`absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full shadow-sm transition-transform duration-200 ${hideSensitive ? 'translate-x-5' : 'translate-x-0'}`} />
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{hideSensitive && (
|
|
|
|
|
|
<div className="mt-2 pt-2 border-t border-gray-200">
|
|
|
|
|
|
<p className="text-xs text-amber-600">以下信息将被隐藏:</p>
|
|
|
|
|
|
<div className="flex flex-wrap gap-1 mt-1">
|
|
|
|
|
|
{planProductName && <span className="px-2 py-0.5 text-xs bg-amber-50 text-amber-700 rounded">成品名称: {planProductName}</span>}
|
|
|
|
|
|
{planColor && <span className="px-2 py-0.5 text-xs bg-amber-50 text-amber-700 rounded">颜色: {planColor}</span>}
|
|
|
|
|
|
{planColorCode && <span className="px-2 py-0.5 text-xs bg-amber-50 text-amber-700 rounded">色号: {planColorCode}</span>}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
{/* 链接显示 */}
|
|
|
|
|
|
{shortCode && (
|
|
|
|
|
|
<div className="bg-gray-50 rounded-xl p-2.5 sm:p-3 mb-3 sm:mb-4 border border-gray-200">
|
|
|
|
|
|
<p className="text-xs text-gray-500 mb-1">分享链接(30分钟内有效)</p>
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-700 break-all font-mono">{link}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div className="bg-red-50 rounded-lg p-2 border border-red-100 mb-3">
|
|
|
|
|
|
<p className="text-xs text-red-600">{error}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="flex gap-2 sm:gap-3">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 border border-gray-300 rounded-xl text-gray-700 hover:bg-gray-50 text-xs sm:text-sm font-medium transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
关闭
|
|
|
|
|
|
</button>
|
|
|
|
|
|
{shortCode ? (
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={handleCopy}
|
|
|
|
|
|
className={`flex-1 py-2 sm:py-2.5 rounded-xl text-white flex items-center justify-center gap-1.5 sm:gap-2 transition-colors text-xs sm:text-sm font-medium ${
|
|
|
|
|
|
copied ? 'bg-emerald-500' : 'bg-blue-600 hover:bg-blue-700'
|
|
|
|
|
|
}`}
|
|
|
|
|
|
>
|
|
|
|
|
|
{copied ? <Check size={isMobile ? 14 : 16} /> : <Copy size={isMobile ? 14 : 16} />}
|
|
|
|
|
|
{copied ? '已复制' : '复制链接'}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={generateShortLink}
|
|
|
|
|
|
disabled={isGeneratingLink}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 bg-blue-600 hover:bg-blue-700 disabled:bg-gray-300 rounded-xl text-white text-xs sm:text-sm font-medium transition-colors flex items-center justify-center gap-2"
|
|
|
|
|
|
>
|
|
|
|
|
|
{isGeneratingLink ? (
|
|
|
|
|
|
<div className="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin" />
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<Link2 size={isMobile ? 14 : 16} />
|
|
|
|
|
|
)}
|
|
|
|
|
|
生成链接
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
2026-06-04 13:57:36 +00:00
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className="flex items-center gap-2 sm:gap-3 mb-4">
|
|
|
|
|
|
<div className="w-9 h-9 sm:w-10 sm:h-10 bg-amber-100 rounded-xl flex items-center justify-center flex-shrink-0">
|
|
|
|
|
|
<AlertTriangle className="w-4 h-4 sm:w-5 sm:h-5 text-amber-600" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="min-w-0">
|
|
|
|
|
|
<h3 className="text-base sm:text-lg font-semibold text-gray-900">二次确认</h3>
|
|
|
|
|
|
<p className="text-xs sm:text-sm text-gray-500">请确认分享信息</p>
|
|
|
|
|
|
</div>
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
<div className="space-y-3 mb-4">
|
|
|
|
|
|
<div className="bg-blue-50 rounded-xl p-3 border border-blue-100">
|
|
|
|
|
|
<div className="flex items-center gap-2 mb-1">
|
|
|
|
|
|
<Building2 className="w-4 h-4 text-blue-600" />
|
|
|
|
|
|
<span className="text-xs text-blue-600 font-medium">目标工厂</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-sm text-gray-900 font-medium">{factoryName || '未指定'}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="bg-green-50 rounded-xl p-3 border border-green-100">
|
|
|
|
|
|
<div className="flex items-center gap-2 mb-1">
|
|
|
|
|
|
<Building2 className="w-4 h-4 text-green-600" />
|
|
|
|
|
|
<span className="text-xs text-green-600 font-medium">您的公司</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="text-sm text-gray-900 font-medium">{recipientCompany || '加载中...'}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="text-xs text-gray-500 mb-1 block">请输入工厂名称确认</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={confirmFactoryName}
|
|
|
|
|
|
onChange={(e) => setConfirmFactoryName(e.target.value)}
|
|
|
|
|
|
placeholder="输入工厂名称"
|
|
|
|
|
|
className="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-amber-500/20 focus:border-amber-500"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<label className="text-xs text-gray-500 mb-1 block">请输入对方公司名称确认</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={confirmCompanyName}
|
|
|
|
|
|
onChange={(e) => setConfirmCompanyName(e.target.value)}
|
|
|
|
|
|
placeholder="输入对方公司名称"
|
|
|
|
|
|
className="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:ring-2 focus:ring-amber-500/20 focus:border-amber-500"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
|
<div className="bg-red-50 rounded-lg p-2 border border-red-100">
|
|
|
|
|
|
<p className="text-xs text-red-600">{error}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-06-04 13:57:36 +00:00
|
|
|
|
<div className="flex gap-2 sm:gap-3">
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setShowConfirm(false)}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 border border-gray-300 rounded-xl text-gray-700 hover:bg-gray-50 text-xs sm:text-sm font-medium transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
返回
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
onClick={() => setShowConfirm(false)}
|
|
|
|
|
|
className="flex-1 py-2 sm:py-2.5 bg-amber-500 hover:bg-amber-600 rounded-xl text-white text-xs sm:text-sm font-medium transition-colors"
|
|
|
|
|
|
>
|
|
|
|
|
|
确认分享
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-05-27 03:17:46 +00:00
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-05-26 05:15:10 +00:00
|
|
|
|
</motion.div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|