/** * 侧边栏面板组件 * 插件的主操作界面,固定在浏览器右上角 * 包含:职位信息卡片、自动填写按钮、简历管理、填写进度等功能区域 */ import { useState, useEffect } from "react" import { getCookieValue } from "~utils/cookie" import { getCustomizeResume } from "~api/aiApi" import { handleAutoFillCommon } from "~handlers/handleAutoFillCommon" import type { MatchedFormField, ResumeData, JobInfo } from "~lib/types" import "./SidebarPanel.scss" /** 侧边栏面板的 Props */ interface SidebarPanelProps { /** 当前标签页的来源链接 */ sourceUrl: string /** 岗位信息(由 sidebar 层查询后传入) */ jobInfo: JobInfo | null /** 关闭面板的回调函数 */ onClose: () => void } export function SidebarPanel({ sourceUrl, jobInfo, onClose }: SidebarPanelProps) { /** 是否已登录(有 Token) */ const [isLoggedIn, setIsLoggedIn] = useState(null) /** 是否正在执行自动填写 */ const [filling, setFilling] = useState(false) /** 页面语言类型:中文 / 英文 */ const [pageLang, setPageLang] = useState<"zh" | "en">("zh") /** 是否为职位申请表单页面 */ const [isFormPage, setIsFormPage] = useState(false) /** 匹配到的表单字段列表 */ const [formFields, setFormFields] = useState([]) /** 当前使用的简历数据 */ const [resumeData, setResumeData] = useState(null) /** 页面加载时检查 Token,有岗位信息则查询定制简历 */ useEffect(() => { getCookieValue("Token").then((token) => { console.log("[OfferPie] SidebarPanel 获取到的 Token:", token) setIsLoggedIn(!!token) // 有 Token 且有岗位 ID 时,查询定制简历 if (token && jobInfo?.id) { getCustomizeResume(jobInfo.id).then((resumeRes: any) => { console.log("[OfferPie] 定制简历数据:", resumeRes) // 接口返回的 resume 字段映射为 main const mappedData: ResumeData = { main: resumeRes.resume || {}, education: resumeRes.education || [], work: resumeRes.work || [], internship: resumeRes.internship || [], project: resumeRes.project || [], competition: resumeRes.competition || [], } setResumeData(mappedData) }).catch((err) => { console.warn("[OfferPie] 查询定制简历失败:", err) }) } }) }, [jobInfo?.id]) /** * 自动填写按钮点击处理 * 内部根据条件判断走 handlers/ 下具体哪个处理文件: * - handleAutoFillCommon:通用模式(当前默认) * - 后续特殊网站会在此处加条件分支(如根据 domain 或 jobInfo 来源判断) */ const handleAutoFill = async () => { setFilling(true) try { const fillResult = await handleAutoFillCommon({ resumeData, jobInfo }) setPageLang(fillResult.lang) setIsFormPage(fillResult.isFormPage) if (fillResult.resumeData) setResumeData(fillResult.resumeData) setFormFields(fillResult.formFields) } catch (e) { console.error("OfferPie: 自动填写异常", e) } setTimeout(() => setFilling(false), 1000) } return (
{/* 顶部操作栏:关闭按钮始终显示,反馈和设置仅登录后显示 */}
{isLoggedIn && 反馈} {/*{isLoggedIn && 设置}*/}
{/* 插件标题 */}
大学生求职助手
{/* 未登录状态:显示登录提示 */} {!isLoggedIn && isLoggedIn !== null && (

请先前往 Offer派 官网进行登录

)} {/* 已登录状态:显示完整功能 */} {isLoggedIn && ( <> {/* 职位信息卡片 */}
{jobInfo?.companyLogoUrl ? ( logo ) : ( )}
{jobInfo?.title || "未匹配到岗位信息"}
{jobInfo ? [jobInfo.regionName, jobInfo.companyShortName || jobInfo.companyName, jobInfo.companyType] .filter(Boolean) .join(" · ") || "—" : "当前页面暂未关联岗位"}
{jobInfo?.matchScore != null && (
{jobInfo.matchScore}%
)}
{/* 自动填写按钮 */} {/* 使用次数信息 */}
剩余4次 立即获得无限次数
{/* 简历区域 */}
简历
{resumeData?.main?.name ? resumeData.main.name.charAt(0) : "—"}
{resumeData?.main?.name || "暂无简历"} {resumeData && 默认}
{/* 更改 */}
{/* 针对性优化简历按钮 */} {/* 填写进度区域 */}
填写进度 50%
)}
) }